4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "bcresources.h"
25 #include "bcsignals.h"
26 #include "bcsynchronous.h"
27 #include "bcwindowbase.h"
29 #include "workarounds.h"
33 BC_Pixmap::BC_Pixmap(BC_WindowBase *parent_window,
40 BC_Bitmap *opaque_bitmap = 0, *alpha_bitmap = 0;
41 if(frame->get_color_model() != BC_RGBA8888 && mode == PIXMAP_ALPHA)
48 opaque_bitmap = new BC_Bitmap(parent_window,
49 frame->get_w(), frame->get_h(),
50 parent_window->get_color_model(), 0);
51 opaque_bitmap->read_frame(frame,
52 0, 0, frame->get_w(), frame->get_h());
58 alpha_bitmap = new BC_Bitmap(parent_window,
64 if(frame->get_color_model() != BC_RGBA8888)
65 printf("BC_Pixmap::BC_Pixmap: PIXMAP_ALPHA but frame doesn't have alpha.\n");
66 alpha_bitmap->read_frame(frame,
73 initialize(parent_window,
80 opaque_bitmap->write_drawable(opaque_pixmap,
94 alpha_bitmap->write_drawable(alpha_pixmap,
104 XFreeGC(top_level->display, copy_gc);
106 XSetClipMask(top_level->display, alpha_gc, alpha_pixmap);
110 BC_Pixmap::BC_Pixmap(BC_WindowBase *parent_window, int w, int h)
113 initialize(parent_window, w, h, PIXMAP_OPAQUE);
117 BC_Pixmap::~BC_Pixmap()
123 xftDrawDestroy((XftDraw*)opaque_xft_draw);
125 XFreePixmap(top_level->display, opaque_pixmap);
130 XFreeGC(top_level->display, alpha_gc);
133 xftDrawDestroy((XftDraw*)alpha_xft_draw);
135 XFreePixmap(top_level->display, alpha_pixmap);
139 // Have to delete GL objects because pixmaps are deleted during resizes.
141 if(BC_WindowBase::get_synchronous() && glx_pixmap)
143 BC_WindowBase::get_synchronous()->delete_pixmap(parent_window,
144 glx_pixmap, glx_pixmap_context);
150 void BC_Pixmap::reset()
159 glx_pixmap_context = 0;
164 int BC_Pixmap::initialize(BC_WindowBase *parent_window, int w, int h, int mode)
170 this->parent_window = parent_window;
172 top_level = parent_window->top_level;
176 opaque_pixmap = XCreatePixmap(top_level->display,
180 top_level->default_depth);
182 if(BC_WindowBase::get_resources()->use_xft)
184 opaque_xft_draw = xftDrawCreate(top_level->display,
194 unsigned long gcmask = GCGraphicsExposures |
199 gcvalues.graphics_exposures = 0; // prevent expose events for every redraw
200 gcvalues.foreground = 0;
201 gcvalues.background = 1;
202 gcvalues.function = GXcopy;
204 alpha_pixmap = XCreatePixmap(top_level->display,
210 alpha_gc = XCreateGC(top_level->display,
215 copy_gc = XCreateGC(top_level->display,
221 if(BC_WindowBase::get_resources()->use_xft)
223 alpha_xft_draw = xftDrawCreateBitmap(top_level->display,
231 // // For some reason, this is required in 32 bit.
233 // if(BC_WindowBase::get_resources()->use_xft)
234 // XSync(top_level->display, False);
240 void BC_Pixmap::resize(int w, int h)
242 Pixmap new_pixmap = XCreatePixmap(top_level->display,
246 top_level->default_depth);
248 XftDraw *new_xft_draw = 0;
249 if(BC_WindowBase::get_resources()->use_xft) {
250 new_xft_draw = xftDrawCreate(top_level->display,
260 XCopyArea(top_level->display,
273 if(BC_WindowBase::get_resources()->use_xft)
274 xftDrawDestroy((XftDraw*)opaque_xft_draw);
276 XFreePixmap(top_level->display, opaque_pixmap);
278 opaque_pixmap = new_pixmap;
280 if(BC_WindowBase::get_resources()->use_xft)
281 opaque_xft_draw = new_xft_draw;
286 void BC_Pixmap::copy_area(int x, int y, int w, int h, int x2, int y2)
288 XCopyArea(top_level->display,
300 int BC_Pixmap::write_drawable(Drawable &pixmap,
308 //printf("BC_Pixmap::write_drawable 1\n");
323 XSetClipOrigin(top_level->display, alpha_gc, dest_x - src_x, dest_y - src_y);
324 XCopyArea(top_level->display,
338 XCopyArea(top_level->display,
349 //printf("BC_Pixmap::write_drawable 2\n");
354 void BC_Pixmap::draw_vframe(VFrame *frame,
362 parent_window->draw_vframe(frame,
374 void BC_Pixmap::draw_pixmap(BC_Pixmap *pixmap,
382 pixmap->write_drawable(this->opaque_pixmap,
401 int BC_Pixmap::get_w()
406 int BC_Pixmap::get_h()
411 int BC_Pixmap::get_w_fixed()
416 int BC_Pixmap::get_h_fixed()
421 Pixmap BC_Pixmap::get_pixmap()
423 return opaque_pixmap;
426 Pixmap BC_Pixmap::get_alpha()
431 int BC_Pixmap::use_opaque()
436 int BC_Pixmap::use_alpha()
438 return mode == PIXMAP_ALPHA;
442 void BC_Pixmap::enable_opengl()
444 //printf("BC_Pixmap::enable_opengl called but it doesn't work.\n");
446 BC_WindowBase *current_window = BC_WindowBase::get_synchronous()->current_window;
447 if(!glx_pixmap_context) {
448 GLXFBConfig *glx_fb_configs = current_window->glx_pixmap_fb_configs();
449 if( glx_fb_configs ) {
450 Display *dpy = current_window->get_display();
452 glXCreatePixmap(dpy, *glx_fb_configs, opaque_pixmap, 0);
454 glXCreateNewContext(dpy, *glx_fb_configs, GLX_RGBA_TYPE, 0, True);
458 printf("BC_Pixmap::enable_opengl(): no glx_pixmap\n");
459 else if( !glx_pixmap_context )
460 printf("BC_Pixmap::enable_opengl(): no glx_pixmap_context\n");
462 current_window->glx_make_current(glx_pixmap, glx_pixmap_context);