summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/FbTk/Transparent.cc43
-rw-r--r--src/FbTk/Transparent.hh6
2 files changed, 37 insertions, 12 deletions
diff --git a/src/FbTk/Transparent.cc b/src/FbTk/Transparent.cc
index 152e2a4..5072a81 100644
--- a/src/FbTk/Transparent.cc
+++ b/src/FbTk/Transparent.cc
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: Transparent.cc,v 1.3 2003/04/26 12:44:24 fluxgen Exp $ 22// $Id: Transparent.cc,v 1.4 2003/05/07 09:31:29 fluxgen Exp $
23 23
24#include "Transparent.hh" 24#include "Transparent.hh"
25#include "App.hh" 25#include "App.hh"
@@ -92,15 +92,35 @@ Picture createAlphaPic(Window drawable, unsigned char alpha) {
92 92
93namespace FbTk { 93namespace FbTk {
94 94
95bool Transparent::s_init = false;
96bool Transparent::s_render = false;
95 97
96Transparent::Transparent(Drawable src, Drawable dest, unsigned char alpha, int screen_num): 98Transparent::Transparent(Drawable src, Drawable dest, unsigned char alpha, int screen_num):
97 m_alpha_pic(0), m_src_pic(0), m_dest_pic(0), 99 m_alpha_pic(0), m_src_pic(0), m_dest_pic(0),
98 m_source(src), m_dest(dest), m_alpha(alpha) { 100 m_source(src), m_dest(dest), m_alpha(alpha) {
99 101
102 Display *disp = FbTk::App::instance()->display();
103
104 // check for RENDER support
105 if (!s_init) {
106 int major_opcode, first_event, first_error;
107 if (XQueryExtension(disp, "RENDER",
108 &major_opcode,
109 &first_event, &first_error) == False) {
110 s_render = false;
111 } else { // we got RENDER support
112 s_render = true;
113 }
114 s_init = true;
115 }
116
117
100#ifdef HAVE_XRENDER 118#ifdef HAVE_XRENDER
119 if (!s_render)
120 return;
121
101 allocAlpha(m_alpha); 122 allocAlpha(m_alpha);
102 123
103 Display *disp = FbTk::App::instance()->display();
104 124
105 XRenderPictFormat *format = 125 XRenderPictFormat *format =
106 XRenderFindVisualFormat(disp, 126 XRenderFindVisualFormat(disp,
@@ -121,21 +141,21 @@ Transparent::Transparent(Drawable src, Drawable dest, unsigned char alpha, int s
121 141
122Transparent::~Transparent() { 142Transparent::~Transparent() {
123#ifdef HAVE_XRENDER 143#ifdef HAVE_XRENDER
124 if (m_alpha_pic != 0) 144 if (m_alpha_pic != 0 && s_render)
125 freeAlpha(); 145 freeAlpha();
126 146
127 Display *disp = FbTk::App::instance()->display(); 147 Display *disp = FbTk::App::instance()->display();
128 148
129 if (m_dest_pic != 0) 149 if (m_dest_pic != 0 && s_render)
130 XRenderFreePicture(disp, m_dest_pic); 150 XRenderFreePicture(disp, m_dest_pic);
131 151
132 if (m_src_pic != 0) 152 if (m_src_pic != 0 && s_render)
133 XRenderFreePicture(disp, m_src_pic); 153 XRenderFreePicture(disp, m_src_pic);
134#endif // HAVE_XRENDER 154#endif // HAVE_XRENDER
135} 155}
136 156
137void Transparent::setAlpha(unsigned char alpha) { 157void Transparent::setAlpha(unsigned char alpha) {
138 if (m_source == 0) 158 if (m_source == 0 || !s_render)
139 return; 159 return;
140 160
141 freeAlpha(); 161 freeAlpha();
@@ -144,7 +164,7 @@ void Transparent::setAlpha(unsigned char alpha) {
144 164
145void Transparent::setDest(Drawable dest, int screen_num) { 165void Transparent::setDest(Drawable dest, int screen_num) {
146#ifdef HAVE_XRENDER 166#ifdef HAVE_XRENDER
147 if (m_dest == dest) 167 if (m_dest == dest || !s_render)
148 return; 168 return;
149 169
150 Display *disp = FbTk::App::instance()->display(); 170 Display *disp = FbTk::App::instance()->display();
@@ -171,7 +191,7 @@ void Transparent::setDest(Drawable dest, int screen_num) {
171 191
172void Transparent::setSource(Drawable source, int screen_num) { 192void Transparent::setSource(Drawable source, int screen_num) {
173#ifdef HAVE_XRENDER 193#ifdef HAVE_XRENDER
174 if (m_source == source) 194 if (m_source == source || !s_render)
175 return; 195 return;
176 // save old alpha value so we can recreate new later 196 // save old alpha value so we can recreate new later
177 // with the same value 197 // with the same value
@@ -211,7 +231,7 @@ void Transparent::render(int src_x, int src_y,
211 unsigned int width, unsigned int height) const { 231 unsigned int width, unsigned int height) const {
212#ifdef HAVE_XRENDER 232#ifdef HAVE_XRENDER
213 if (m_src_pic == 0 || m_dest_pic == 0 || 233 if (m_src_pic == 0 || m_dest_pic == 0 ||
214 m_alpha_pic == 0) 234 m_alpha_pic == 0 || !s_render)
215 return; 235 return;
216 // render src+alpha to dest picture 236 // render src+alpha to dest picture
217 XRenderComposite(FbTk::App::instance()->display(), 237 XRenderComposite(FbTk::App::instance()->display(),
@@ -229,7 +249,7 @@ void Transparent::render(int src_x, int src_y,
229 249
230void Transparent::allocAlpha(unsigned char alpha) { 250void Transparent::allocAlpha(unsigned char alpha) {
231#ifdef HAVE_XRENDER 251#ifdef HAVE_XRENDER
232 if (m_source == 0) 252 if (m_source == 0 || !s_render)
233 return; 253 return;
234 if (m_alpha_pic != 0) 254 if (m_alpha_pic != 0)
235 freeAlpha(); 255 freeAlpha();
@@ -241,7 +261,8 @@ void Transparent::allocAlpha(unsigned char alpha) {
241 261
242void Transparent::freeAlpha() { 262void Transparent::freeAlpha() {
243#ifdef HAVE_XRENDER 263#ifdef HAVE_XRENDER
244 XRenderFreePicture(FbTk::App::instance()->display(), m_alpha_pic); 264 if (s_render && m_alpha_pic != 0)
265 XRenderFreePicture(FbTk::App::instance()->display(), m_alpha_pic);
245#endif // HAVE_XRENDER 266#endif // HAVE_XRENDER
246 m_alpha_pic = 0; 267 m_alpha_pic = 0;
247 m_alpha = 255; 268 m_alpha = 255;
diff --git a/src/FbTk/Transparent.hh b/src/FbTk/Transparent.hh
index 8652568..1b36b94 100644
--- a/src/FbTk/Transparent.hh
+++ b/src/FbTk/Transparent.hh
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: Transparent.hh,v 1.1 2003/04/20 13:27:16 fluxgen Exp $ 22// $Id: Transparent.hh,v 1.2 2003/05/07 09:30:53 fluxgen Exp $
23 23
24#ifndef FBTK_TRANSPARENT_HH 24#ifndef FBTK_TRANSPARENT_HH
25#define FBTK_TRANSPARENT_HH 25#define FBTK_TRANSPARENT_HH
@@ -54,6 +54,10 @@ private:
54 unsigned long m_dest_pic; 54 unsigned long m_dest_pic;
55 Drawable m_source, m_dest; 55 Drawable m_source, m_dest;
56 unsigned char m_alpha; 56 unsigned char m_alpha;
57
58 static bool s_init;
59 static bool s_render; ///< wheter we have RENDER support
60
57}; 61};
58 62
59}; // end namespace FbTk 63}; // end namespace FbTk