]>
Dogcows Code - chaz/openbox/blob - otk/rendercolor.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
7 #include "rendercolor.hh"
9 #include "screeninfo.hh"
13 std::map
<unsigned long, RenderColor::CacheItem
*> *RenderColor::_cache
= 0;
15 void RenderColor::initialize()
17 _cache
= new std::map
<unsigned long, CacheItem
*>[ScreenCount(**display
)];
20 void RenderColor::destroy()
25 RenderColor::RenderColor(int screen
, unsigned char red
,
26 unsigned char green
, unsigned char blue
)
36 RenderColor::RenderColor(int screen
, RGB rgb
)
46 void RenderColor::create()
48 unsigned long color
= _blue
| _green
<< 8 | _red
<< 16;
50 printf("CREATE COLOR: %lx\n", color
);
52 // try get a gc from the cache
53 CacheItem
*item
= _cache
[_screen
][color
];
61 // allocate a color and GC from the server
62 const ScreenInfo
*info
= display
->screenInfo(_screen
);
64 XColor xcol
; // convert from 0-0xff to 0-0xffff
65 xcol
.red
= _red
; xcol
.red
|= xcol
.red
<< 8;
66 xcol
.green
= _green
; xcol
.green
|= xcol
.green
<< 8;
67 xcol
.blue
= _blue
; xcol
.blue
|= xcol
.blue
<< 8;
70 if (! XAllocColor(**display
, info
->colormap(), &xcol
)) {
71 fprintf(stderr
, "RenderColor: color alloc error: rgb:%x/%x/%x\n",
77 gcv
.foreground
= _pixel
;
78 gcv
.cap_style
= CapProjecting
;
79 _gc
= XCreateGC(**display
, info
->rootWindow(),
80 GCForeground
| GCCapStyle
, &gcv
);
83 // insert into the cache
84 item
= new CacheItem(_gc
);
85 _cache
[_screen
][color
] = item
;
90 RenderColor::~RenderColor()
92 unsigned long color
= _blue
| _green
<< 8 | _red
<< 16;
94 CacheItem
*item
= _cache
[_screen
][color
];
95 assert(item
); // it better be in the cache ...
97 printf("DESTROY COLOR: %lx %d\n", color
, item
->count
);
99 if (--item
->count
<= 0) {
100 // remove from the cache
101 XFreeGC(**display
, _gc
);
102 _cache
[_screen
][color
] = 0;
This page took 0.041872 seconds and 5 git commands to generate.