]> Dogcows Code - chaz/openbox/blob - otk/truerendercontrol.cc
a1995c4ce7032d76e367c550ff3b53b2bdafba93
[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(const ScreenInfo *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 unsigned long red_mask, green_mask, blue_mask;
32
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;
37
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; }
41
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--; }
46 }
47
48 TrueRenderControl::~TrueRenderControl()
49 {
50 printf("Destroying TrueColor RenderControl\n");
51
52
53 }
54
55 static inline void renderPixel(XImage *im, unsigned char *dp,
56 unsigned long pixel)
57 {
58 unsigned int bpp = im->bits_per_pixel + (im->byte_order == MSBFirst ? 1 : 0);
59
60 switch (bpp) {
61 case 8: // 8bpp
62 *dp++ = pixel;
63 break;
64 case 16: // 16bpp LSB
65 *dp++ = pixel;
66 *dp++ = pixel >> 8;
67 break;
68 case 17: // 16bpp MSB
69 *dp++ = pixel >> 8;
70 *dp++ = pixel;
71 break;
72 case 24: // 24bpp LSB
73 *dp++ = pixel;
74 *dp++ = pixel >> 8;
75 *dp++ = pixel >> 16;
76 break;
77 case 25: // 24bpp MSB
78 *dp++ = pixel >> 16;
79 *dp++ = pixel >> 8;
80 *dp++ = pixel;
81 break;
82 case 32: // 32bpp LSB
83 *dp++ = pixel;
84 *dp++ = pixel >> 8;
85 *dp++ = pixel >> 16;
86 *dp++ = pixel >> 24;
87 break;
88 case 33: // 32bpp MSB
89 *dp++ = pixel >> 24;
90 *dp++ = pixel >> 16;
91 *dp++ = pixel >> 8;
92 *dp++ = pixel;
93 break;
94 default:
95 assert(false); // wtf?
96 }
97 }
98
99 void TrueRenderControl::drawBackground(Surface *sf,
100 const RenderTexture &texture) const
101 {
102 assert(sf);
103
104 int w = sf->width(), h = sf->height();
105
106 XImage *im = XCreateImage(**display, _screen->visual(), _screen->depth(),
107 ZPixmap, 0, NULL, w, h, 32, 0);
108
109 unsigned char *data = new unsigned char[im->bytes_per_line * h];
110 unsigned char *dp = data;
111
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);
121
122 im->data = (char*) data;
123
124 if (!sf->_pm)
125 sf->_pm = XCreatePixmap(**display, _screen->rootWindow(), w, h,
126 _screen->depth());
127 XPutImage(**display, sf->_pm, DefaultGC(**display, _screen->screen()),
128 im, 0, 0, 0, 0, w, h);
129
130 //delete [] image->data;
131 //image->data = NULL;
132 XDestroyImage(im);
133 }
134
135 }
This page took 0.038538 seconds and 4 git commands to generate.