]>
Dogcows Code - chaz/openbox/blob - otk/truerendercontrol.cc
dc52bc37bb43a088cb4b6036839a625516b0e961
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"
12 #include "rendercolor.hh"
17 #endif // HAVE_STDLIB_H
20 #define _(str) gettext(str)
25 TrueRenderControl::TrueRenderControl(int screen
)
26 : RenderControl(screen
),
31 printf("Initializing TrueColor RenderControl\n");
33 Visual
*visual
= display
->screenInfo(_screen
)->visual();
34 unsigned long red_mask
, green_mask
, blue_mask
;
36 // find the offsets for each color in the visual's masks
37 red_mask
= visual
->red_mask
;
38 green_mask
= visual
->green_mask
;
39 blue_mask
= visual
->blue_mask
;
41 while (! (red_mask
& 1)) { _red_offset
++; red_mask
>>= 1; }
42 while (! (green_mask
& 1)) { _green_offset
++; green_mask
>>= 1; }
43 while (! (blue_mask
& 1)) { _blue_offset
++; blue_mask
>>= 1; }
45 _red_shift
= _green_shift
= _blue_shift
= 8;
46 while (red_mask
) { red_mask
>>= 1; _red_shift
--; }
47 while (green_mask
) { green_mask
>>= 1; _green_shift
--; }
48 while (blue_mask
) { blue_mask
>>= 1; _blue_shift
--; }
51 TrueRenderControl::~TrueRenderControl()
53 printf("Destroying TrueColor RenderControl\n");
59 static inline void renderPixel(XImage
*im
, unsigned char *dp
,
62 unsigned int bpp
= im
->bits_per_pixel
+ (im
->byte_order
== MSBFirst
? 1 : 0);
99 assert(false); // wtf?
103 void TrueRenderControl::drawBackground(Surface
& sf
,
104 const RenderTexture
&texture
) const
108 assert(sf
._screen
== _screen
);
110 int w
= sf
.width(), h
= sf
.height();
112 const ScreenInfo
*info
= display
->screenInfo(_screen
);
113 XImage
*im
= XCreateImage(**display
, info
->visual(), info
->depth(),
114 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
116 unsigned char *data
= new unsigned char[im
->bytes_per_line
* h
];
117 unsigned char *dp
= data
;
118 unsigned int bytes_per_pixel
= im
->bits_per_pixel
/8;
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
) >> _red_shift
<< _red_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
) >> _green_shift
<< _green_offset
);
126 for (int y
= 0; y
< h
/3; ++y
)
127 for (int x
= 0; x
< w
; ++x
, dp
+= bytes_per_pixel
)
128 renderPixel(im
, dp
, (255*x
/w
) >> _blue_shift
<< _blue_offset
);
130 im
->data
= (char*) data
;
133 sf
.setPixmap(RenderColor(_screen
, 0xff, 0xff, 0));
This page took 0.041021 seconds and 4 git commands to generate.