]> Dogcows Code - chaz/openbox/blob - otk/truerendercontrol.cc
bd413cff8974eb10492159bf3c2e4196f919083a
[chaz/openbox] / otk / truerendercontrol.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
6
7 #include "truerendercontrol.hh"
8 #include "display.hh"
9 #include "screeninfo.hh"
10 #include "surface.hh"
11
12 extern "C" {
13 #ifdef HAVE_STDLIB_H
14 # include <stdlib.h>
15 #endif // HAVE_STDLIB_H
16
17 #include "gettext.h"
18 #define _(str) gettext(str)
19 }
20
21 namespace otk {
22
23 TrueRenderControl::TrueRenderControl(int screen)
24 : RenderControl(screen),
25 _red_offset(0),
26 _green_offset(0),
27 _blue_offset(0)
28 {
29 printf("Initializing TrueColor RenderControl\n");
30
31 Visual *visual = display->screenInfo(_screen)->visual();
32 unsigned long red_mask, green_mask, blue_mask;
33
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;
38
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; }
42
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--; }
47 }
48
49 TrueRenderControl::~TrueRenderControl()
50 {
51 printf("Destroying TrueColor RenderControl\n");
52
53
54 }
55
56
57 static inline void renderPixel(XImage *im, unsigned char *dp,
58 unsigned long pixel)
59 {
60 unsigned int bpp = im->bits_per_pixel + (im->byte_order == MSBFirst ? 1 : 0);
61
62 switch (bpp) {
63 case 8: // 8bpp
64 *dp++ = pixel;
65 break;
66 case 16: // 16bpp LSB
67 *dp++ = pixel;
68 *dp++ = pixel >> 8;
69 break;
70 case 17: // 16bpp MSB
71 *dp++ = pixel >> 8;
72 *dp++ = pixel;
73 break;
74 case 24: // 24bpp LSB
75 *dp++ = pixel;
76 *dp++ = pixel >> 8;
77 *dp++ = pixel >> 16;
78 break;
79 case 25: // 24bpp MSB
80 *dp++ = pixel >> 16;
81 *dp++ = pixel >> 8;
82 *dp++ = pixel;
83 break;
84 case 32: // 32bpp LSB
85 *dp++ = pixel;
86 *dp++ = pixel >> 8;
87 *dp++ = pixel >> 16;
88 *dp++ = pixel >> 24;
89 break;
90 case 33: // 32bpp MSB
91 *dp++ = pixel >> 24;
92 *dp++ = pixel >> 16;
93 *dp++ = pixel >> 8;
94 *dp++ = pixel;
95 break;
96 default:
97 assert(false); // wtf?
98 }
99 }
100
101 void TrueRenderControl::drawBackground(Surface& sf,
102 const RenderTexture &texture) const
103 {
104 (void)texture;
105
106 assert(sf._screen == _screen);
107
108 int w = sf.width(), h = sf.height();
109
110 const ScreenInfo *info = display->screenInfo(_screen);
111 XImage *im = XCreateImage(**display, info->visual(), info->depth(),
112 ZPixmap, 0, NULL, w, h, 32, 0);
113
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;
117
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);
127
128 im->data = (char*) data;
129
130 sf.setPixmap(im);
131
132 delete [] im->data;
133 im->data = NULL;
134 XDestroyImage(im);}
135 }
This page took 0.042925 seconds and 4 git commands to generate.