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)
176 this->parent_window = parent_window;
178 top_level = parent_window->top_level;
182 opaque_pixmap = XCreatePixmap(top_level->display,
186 top_level->default_depth);
188 if(BC_WindowBase::get_resources()->use_xft)
190 opaque_xft_draw = XftDrawCreate(top_level->display,
200 unsigned long gcmask = GCGraphicsExposures |
205 gcvalues.graphics_exposures = 0; // prevent expose events for every redraw
206 gcvalues.foreground = 0;
207 gcvalues.background = 1;
208 gcvalues.function = GXcopy;
210 alpha_pixmap = XCreatePixmap(top_level->display,
216 alpha_gc = XCreateGC(top_level->display,
221 copy_gc = XCreateGC(top_level->display,
227 if(BC_WindowBase::get_resources()->use_xft)
229 alpha_xft_draw = XftDrawCreateBitmap(top_level->display,
237 // // For some reason, this is required in 32 bit.
239 // if(BC_WindowBase::get_resources()->use_xft)
240 // XSync(top_level->display, False);
246 void BC_Pixmap::resize(int w, int h)
248 Pixmap new_pixmap = XCreatePixmap(top_level->display,
252 top_level->default_depth);
254 XftDraw *new_xft_draw = 0;
255 if(BC_WindowBase::get_resources()->use_xft) {
256 new_xft_draw = XftDrawCreate(top_level->display,
266 XCopyArea(top_level->display,
279 if(BC_WindowBase::get_resources()->use_xft)
280 XftDrawDestroy((XftDraw*)opaque_xft_draw);
282 XFreePixmap(top_level->display, opaque_pixmap);
284 opaque_pixmap = new_pixmap;
286 if(BC_WindowBase::get_resources()->use_xft)
287 opaque_xft_draw = new_xft_draw;
292 void BC_Pixmap::copy_area(int x, int y, int w, int h, int x2, int y2)
294 XCopyArea(top_level->display,
306 int BC_Pixmap::write_drawable(Drawable &pixmap,
314 //printf("BC_Pixmap::write_drawable 1\n");
329 XSetClipOrigin(top_level->display, alpha_gc, dest_x - src_x, dest_y - src_y);
330 XCopyArea(top_level->display,
344 XCopyArea(top_level->display,
355 //printf("BC_Pixmap::write_drawable 2\n");
360 void BC_Pixmap::draw_vframe(VFrame *frame,
368 parent_window->draw_vframe(frame,
380 void BC_Pixmap::draw_pixmap(BC_Pixmap *pixmap,
388 pixmap->write_drawable(this->opaque_pixmap,
407 int BC_Pixmap::get_w()
412 int BC_Pixmap::get_h()
417 int BC_Pixmap::get_w_fixed()
422 int BC_Pixmap::get_h_fixed()
427 Pixmap BC_Pixmap::get_pixmap()
429 return opaque_pixmap;
432 Pixmap BC_Pixmap::get_alpha()
437 int BC_Pixmap::use_opaque()
442 int BC_Pixmap::use_alpha()
444 return mode == PIXMAP_ALPHA;
448 void BC_Pixmap::enable_opengl()
450 //printf("BC_Pixmap::enable_opengl called but it doesn't work.\n");
452 BC_WindowBase *current_window = BC_WindowBase::get_synchronous()->current_window;
453 if(!glx_pixmap_context) {
454 GLXFBConfig *glx_fb_configs = current_window->glx_pixmap_fb_configs();
455 if( glx_fb_configs ) {
456 Display *dpy = current_window->get_display();
458 glXCreatePixmap(dpy, *glx_fb_configs, opaque_pixmap, 0);
460 glXCreateNewContext(dpy, *glx_fb_configs, GLX_RGBA_TYPE, 0, True);
464 printf("BC_Pixmap::enable_opengl(): no glx_pixmap\n");
465 else if( !glx_pixmap_context )
466 printf("BC_Pixmap::enable_opengl(): no glx_pixmap_context\n");
468 current_window->glx_make_current(glx_pixmap, glx_pixmap_context);