]>
Dogcows Code - chaz/openbox/blob - otk/truerendercontrol.cc
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(int screen
)
24 : RenderControl(screen
),
29 printf("Initializing TrueColor RenderControl\n");
31 Visual
*visual
= display
->screenInfo(_screen
)->visual();
32 unsigned long red_mask
, green_mask
, blue_mask
;
34 // find the offsets for each color in the visual's masks
35 red_mask
= visual
->red_mask
;
36 green_mask
= visual
->green_mask
;
37 blue_mask
= visual
->blue_mask
;
39 while (! (red_mask
& 1)) { _red_offset
++; red_mask
>>= 1; }
40 while (! (green_mask
& 1)) { _green_offset
++; green_mask
>>= 1; }
41 while (! (blue_mask
& 1)) { _blue_offset
++; blue_mask
>>= 1; }
43 _red_shift
= _green_shift
= _blue_shift
= 8;
44 while (red_mask
) { red_mask
>>= 1; _red_shift
--; }
45 while (green_mask
) { green_mask
>>= 1; _green_shift
--; }
46 while (blue_mask
) { blue_mask
>>= 1; _blue_shift
--; }
49 TrueRenderControl::~TrueRenderControl()
51 printf("Destroying TrueColor RenderControl\n");
57 static inline void renderPixel(XImage
*im
, unsigned char *dp
,
60 unsigned int bpp
= im
->bits_per_pixel
+ (im
->byte_order
== MSBFirst
? 1 : 0);
97 assert(false); // wtf?
101 void TrueRenderControl::drawBackground(Surface
& sf
,
102 const RenderTexture
&texture
) const
106 assert(sf
._screen
== _screen
);
108 int w
= sf
.width(), h
= sf
.height();
110 const ScreenInfo
*info
= display
->screenInfo(_screen
);
111 XImage
*im
= XCreateImage(**display
, info
->visual(), info
->depth(),
112 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
114 unsigned char *data
= new unsigned char[im
->bytes_per_line
* h
];
115 unsigned char *dp
= data
;
116 unsigned int bytes_per_pixel
= im
->bits_per_pixel
/8;
118 for (int y
= 0; y
< h
/3; ++y
)
119 for (int x
= 0; x
< w
; ++x
, dp
+= bytes_per_pixel
)
120 renderPixel(im
, dp
, (255*x
/w
) >> _red_shift
<< _red_offset
);
121 for (int y
= 0; y
< h
/3; ++y
)
122 for (int x
= 0; x
< w
; ++x
, dp
+= bytes_per_pixel
)
123 renderPixel(im
, dp
, (255*x
/w
) >> _green_shift
<< _green_offset
);
124 for (int y
= 0; y
< h
/3; ++y
)
125 for (int x
= 0; x
< w
; ++x
, dp
+= bytes_per_pixel
)
126 renderPixel(im
, dp
, (255*x
/w
) >> _blue_shift
<< _blue_offset
);
128 im
->data
= (char*) data
;
This page took 0.040304 seconds and 4 git commands to generate.