]>
Dogcows Code - chaz/openbox/blob - otk/truerendercontrol.cc
a1995c4ce7032d76e367c550ff3b53b2bdafba93
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
7 #include "truerendercontrol.hh"
9 #include "screeninfo.hh"
15 #endif // HAVE_STDLIB_H
18 #define _(str) gettext(str)
23 TrueRenderControl::TrueRenderControl(const ScreenInfo
*screen
)
24 : RenderControl(screen
),
29 printf("Initializing TrueColor RenderControl\n");
31 unsigned long red_mask
, green_mask
, blue_mask
;
33 // find the offsets for each color in the visual's masks
34 red_mask
= screen
->visual()->red_mask
;
35 green_mask
= screen
->visual()->green_mask
;
36 blue_mask
= screen
->visual()->blue_mask
;
38 while (! (red_mask
& 1)) { _red_offset
++; red_mask
>>= 1; }
39 while (! (green_mask
& 1)) { _green_offset
++; green_mask
>>= 1; }
40 while (! (blue_mask
& 1)) { _blue_offset
++; blue_mask
>>= 1; }
42 _red_shift
= _green_shift
= _blue_shift
= 8;
43 while (red_mask
) { red_mask
>>= 1; _red_shift
--; }
44 while (green_mask
) { green_mask
>>= 1; _green_shift
--; }
45 while (blue_mask
) { blue_mask
>>= 1; _blue_shift
--; }
48 TrueRenderControl::~TrueRenderControl()
50 printf("Destroying TrueColor RenderControl\n");
55 static inline void renderPixel(XImage
*im
, unsigned char *dp
,
58 unsigned int bpp
= im
->bits_per_pixel
+ (im
->byte_order
== MSBFirst
? 1 : 0);
95 assert(false); // wtf?
99 void TrueRenderControl::drawBackground(Surface
*sf
,
100 const RenderTexture
&texture
) const
104 int w
= sf
->width(), h
= sf
->height();
106 XImage
*im
= XCreateImage(**display
, _screen
->visual(), _screen
->depth(),
107 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
109 unsigned char *data
= new unsigned char[im
->bytes_per_line
* h
];
110 unsigned char *dp
= data
;
112 for (int y
= 0; y
< h
/3; ++y
)
113 for (int x
= 0; x
< w
; ++x
, dp
+= im
->bits_per_pixel
/8)
114 renderPixel(im
, dp
, (255*x
/w
) << _red_offset
<< _red_shift
);
115 for (int y
= 0; y
< h
/3; ++y
)
116 for (int x
= 0; x
< w
; ++x
, dp
+= im
->bits_per_pixel
/8)
117 renderPixel(im
, dp
, (255*x
/w
) << _green_offset
<< _green_shift
);
118 for (int y
= 0; y
< h
/3; ++y
)
119 for (int x
= 0; x
< w
; ++x
, dp
+= im
->bits_per_pixel
/8)
120 renderPixel(im
, dp
, (255*x
/w
) << _blue_offset
<< _blue_shift
);
122 im
->data
= (char*) data
;
125 sf
->_pm
= XCreatePixmap(**display
, _screen
->rootWindow(), w
, h
,
127 XPutImage(**display
, sf
->_pm
, DefaultGC(**display
, _screen
->screen()),
128 im
, 0, 0, 0, 0, w
, h
);
130 //delete [] image->data;
131 //image->data = NULL;
This page took 0.038538 seconds and 4 git commands to generate.