]>
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"
11 #include "rendertexture.hh"
16 #endif // HAVE_STDLIB_H
19 #define _(str) gettext(str)
24 TrueRenderControl::TrueRenderControl(int screen
)
25 : RenderControl(screen
),
30 printf("Initializing TrueColor RenderControl\n");
32 Visual
*visual
= display
->screenInfo(_screen
)->visual();
33 unsigned long red_mask
, green_mask
, blue_mask
;
35 // find the offsets for each color in the visual's masks
36 red_mask
= visual
->red_mask
;
37 green_mask
= visual
->green_mask
;
38 blue_mask
= visual
->blue_mask
;
40 while (! (red_mask
& 1)) { _red_offset
++; red_mask
>>= 1; }
41 while (! (green_mask
& 1)) { _green_offset
++; green_mask
>>= 1; }
42 while (! (blue_mask
& 1)) { _blue_offset
++; blue_mask
>>= 1; }
44 _red_shift
= _green_shift
= _blue_shift
= 8;
45 while (red_mask
) { red_mask
>>= 1; _red_shift
--; }
46 while (green_mask
) { green_mask
>>= 1; _green_shift
--; }
47 while (blue_mask
) { blue_mask
>>= 1; _blue_shift
--; }
50 TrueRenderControl::~TrueRenderControl()
52 printf("Destroying TrueColor RenderControl\n");
58 static inline void renderPixel(XImage
*im
, unsigned char *dp
,
61 unsigned int bpp
= im
->bits_per_pixel
+ (im
->byte_order
== MSBFirst
? 1 : 0);
98 assert(false); // wtf?
102 void TrueRenderControl::drawBackground(Surface
& sf
,
103 const RenderTexture
&texture
) const
105 assert(sf
._screen
== _screen
);
107 int w
= sf
.width(), h
= sf
.height();
109 const ScreenInfo
*info
= display
->screenInfo(_screen
);
110 XImage
*im
= XCreateImage(**display
, info
->visual(), info
->depth(),
111 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
113 unsigned char *data
= new unsigned char[im
->bytes_per_line
* h
];
114 unsigned char *dp
= data
;
115 unsigned int bytes_per_pixel
= im
->bits_per_pixel
/8;
117 for (int y
= 0; y
< h
/3; ++y
)
118 for (int x
= 0; x
< w
; ++x
, dp
+= bytes_per_pixel
)
119 renderPixel(im
, dp
, (255*x
/w
) >> _red_shift
<< _red_offset
);
120 for (int y
= 0; y
< h
/3; ++y
)
121 for (int x
= 0; x
< w
; ++x
, dp
+= bytes_per_pixel
)
122 renderPixel(im
, dp
, (255*x
/w
) >> _green_shift
<< _green_offset
);
123 for (int y
= 0; y
< h
/3; ++y
)
124 for (int x
= 0; x
< w
; ++x
, dp
+= bytes_per_pixel
)
125 renderPixel(im
, dp
, (255*x
/w
) >> _blue_shift
<< _blue_offset
);
127 im
->data
= (char*) data
;
130 sf
.setPixmap(texture
.color());
131 // sf.setPixmap(RenderColor(_screen, 0xff, 0xff, 0));
This page took 0.04444 seconds and 4 git commands to generate.