]>
Dogcows Code - chaz/openbox/blob - rendercolor.cc
5da218ea92f84f101620240714e270ab89be83e8
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
5 #include "rendercolor.hh"
7 #include "screeninfo.hh"
8 #include "rendercontrol.hh"
14 std::map
<unsigned long, RenderColor::CacheItem
*> *RenderColor::_cache
= 0;
16 void RenderColor::initialize()
18 _cache
= new std::map
<unsigned long, CacheItem
*>[ScreenCount(**display
)];
21 void RenderColor::destroy()
26 RenderColor::RenderColor(int screen
, unsigned char red
,
27 unsigned char green
, unsigned char blue
)
36 RenderColor::RenderColor(int screen
, RGB rgb
)
45 void RenderColor::create()
47 unsigned long color
= _blue
| _green
<< 8 | _red
<< 16;
49 // try get a gc from the cache
50 CacheItem
*item
= _cache
[_screen
][color
];
59 // allocate a color and GC from the server
60 const ScreenInfo
*info
= display
->screenInfo(_screen
);
62 XColor xcol
; // convert from 0-0xff to 0-0xffff
63 xcol
.red
= (_red
<< 8) | _red
;
64 xcol
.green
= (_green
<< 8) | _green
;
65 xcol
.blue
= (_blue
<< 8) | _blue
;
67 display
->renderControl(_screen
)->allocateColor(&xcol
);
70 gcv
.foreground
= _pixel
;
71 gcv
.cap_style
= CapProjecting
;
72 _gc
= XCreateGC(**display
, info
->rootWindow(),
73 GCForeground
| GCCapStyle
, &gcv
);
76 // insert into the cache
77 item
= new CacheItem(_gc
, _pixel
);
78 _cache
[_screen
][color
] = item
;
83 RenderColor::~RenderColor()
85 unsigned long color
= _blue
| _green
<< 8 | _red
<< 16;
87 CacheItem
*item
= _cache
[_screen
][color
];
88 assert(item
); // better be...
90 if (--item
->count
<= 0) {
91 // remove from the cache
92 XFreeGC(**display
, _gc
);
93 _cache
[_screen
][color
] = 0;
96 const ScreenInfo
*info
= display
->screenInfo(_screen
);
97 XFreeColors(**display
, info
->colormap(), &_pixel
, 1, 0);
This page took 0.03779 seconds and 3 git commands to generate.