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"
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,
51 parent_window->get_color_model(),
53 opaque_bitmap->set_bg_color(parent_window->get_bg_color());
54 opaque_bitmap->read_frame(frame,
64 alpha_bitmap = new BC_Bitmap(parent_window,
70 if(frame->get_color_model() != BC_RGBA8888)
71 printf("BC_Pixmap::BC_Pixmap: PIXMAP_ALPHA but frame doesn't have alpha.\n");
72 alpha_bitmap->read_frame(frame,
79 initialize(parent_window,
86 opaque_bitmap->write_drawable(opaque_pixmap,
100 alpha_bitmap->write_drawable(alpha_pixmap,
110 XFreeGC(top_level->display, copy_gc);
112 XSetClipMask(top_level->display, alpha_gc, alpha_pixmap);
116 BC_Pixmap::BC_Pixmap(BC_WindowBase *parent_window, int w, int h)
119 initialize(parent_window, w, h, PIXMAP_OPAQUE);
123 BC_Pixmap::~BC_Pixmap()
129 XftDrawDestroy((XftDraw*)opaque_xft_draw);
131 XFreePixmap(top_level->display, opaque_pixmap);
136 XFreeGC(top_level->display, alpha_gc);
139 XftDrawDestroy((XftDraw*)alpha_xft_draw);
141 XFreePixmap(top_level->display, alpha_pixmap);
145 // Have to delete GL objects because pixmaps are deleted during resizes.
147 if(BC_WindowBase::get_synchronous() && glx_pixmap)
149 BC_WindowBase::get_synchronous()->delete_pixmap(parent_window,
150 glx_pixmap, glx_pixmap_context);
156 void BC_Pixmap::reset()
165 glx_pixmap_context = 0;
170 int BC_Pixmap::initialize(BC_WindowBase *parent_window, int w, int h, int mode)
174 this->parent_window = parent_window;
176 top_level = parent_window->top_level;
180 opaque_pixmap = XCreatePixmap(top_level->display,
184 top_level->default_depth);
186 if(BC_WindowBase::get_resources()->use_xft)
188 opaque_xft_draw = XftDrawCreate(top_level->display,
198 unsigned long gcmask = GCGraphicsExposures |
203 gcvalues.graphics_exposures = 0; // prevent expose events for every redraw
204 gcvalues.foreground = 0;
205 gcvalues.background = 1;
206 gcvalues.function = GXcopy;
208 alpha_pixmap = XCreatePixmap(top_level->display,
214 alpha_gc = XCreateGC(top_level->display,
219 copy_gc = XCreateGC(top_level->display,
225 if(BC_WindowBase::get_resources()->use_xft)
227 alpha_xft_draw = XftDrawCreateBitmap(top_level->display,
235 // // For some reason, this is required in 32 bit.
237 // if(BC_WindowBase::get_resources()->use_xft)
238 // XSync(top_level->display, False);
244 void BC_Pixmap::resize(int w, int h)
246 Pixmap new_pixmap = XCreatePixmap(top_level->display,
250 top_level->default_depth);
252 XftDraw *new_xft_draw = 0;
253 if(BC_WindowBase::get_resources()->use_xft) {
254 new_xft_draw = XftDrawCreate(top_level->display,
264 XCopyArea(top_level->display,
277 if(BC_WindowBase::get_resources()->use_xft)
278 XftDrawDestroy((XftDraw*)opaque_xft_draw);
280 XFreePixmap(top_level->display, opaque_pixmap);
282 opaque_pixmap = new_pixmap;
284 if(BC_WindowBase::get_resources()->use_xft)
285 opaque_xft_draw = new_xft_draw;
290 void BC_Pixmap::copy_area(int x, int y, int w, int h, int x2, int y2)
292 XCopyArea(top_level->display,
304 int BC_Pixmap::write_drawable(Drawable &pixmap,
312 //printf("BC_Pixmap::write_drawable 1\n");
327 XSetClipOrigin(top_level->display, alpha_gc, dest_x - src_x, dest_y - src_y);
328 XCopyArea(top_level->display,
342 XCopyArea(top_level->display,
353 //printf("BC_Pixmap::write_drawable 2\n");
358 void BC_Pixmap::draw_vframe(VFrame *frame,
366 parent_window->draw_vframe(frame,
378 void BC_Pixmap::draw_pixmap(BC_Pixmap *pixmap,
386 pixmap->write_drawable(this->opaque_pixmap,
405 int BC_Pixmap::get_w()
410 int BC_Pixmap::get_h()
415 int BC_Pixmap::get_w_fixed()
420 int BC_Pixmap::get_h_fixed()
425 Pixmap BC_Pixmap::get_pixmap()
427 return opaque_pixmap;
430 Pixmap BC_Pixmap::get_alpha()
435 int BC_Pixmap::use_opaque()
440 int BC_Pixmap::use_alpha()
442 return mode == PIXMAP_ALPHA;
446 void BC_Pixmap::enable_opengl()
448 //printf("BC_Pixmap::enable_opengl called but it doesn't work.\n");
450 BC_WindowBase *current_window = BC_WindowBase::get_synchronous()->current_window;
451 if(!glx_pixmap_context) {
452 GLXFBConfig *glx_fb_configs = current_window->glx_pixmap_fb_configs();
453 if( glx_fb_configs ) {
454 Display *dpy = current_window->get_display();
456 glXCreatePixmap(dpy, *glx_fb_configs, opaque_pixmap, 0);
458 glXCreateNewContext(dpy, *glx_fb_configs, GLX_RGBA_TYPE, 0, True);
462 printf("BC_Pixmap::enable_opengl(): no glx_pixmap\n");
463 else if( !glx_pixmap_context )
464 printf("BC_Pixmap::enable_opengl(): no glx_pixmap_context\n");
466 current_window->glx_make_current(glx_pixmap, glx_pixmap_context);