3 #include "bcresources.h"
5 #include "bcsynchronous.h"
6 #include "bcwindowbase.h"
12 BC_Pixmap::BC_Pixmap(BC_WindowBase *parent_window,
19 BC_Bitmap *opaque_bitmap, *alpha_bitmap, *mask_bitmap;
20 if(frame->get_color_model() != BC_RGBA8888 &&
28 opaque_bitmap = new BC_Bitmap(parent_window,
31 parent_window->get_color_model(),
33 opaque_bitmap->set_bg_color(parent_window->get_bg_color());
34 opaque_bitmap->read_frame(frame,
44 alpha_bitmap = new BC_Bitmap(parent_window,
50 if(frame->get_color_model() != BC_RGBA8888)
51 printf("BC_Pixmap::BC_Pixmap: PIXMAP_ALPHA but frame doesn't have alpha.\n");
52 alpha_bitmap->read_frame(frame,
59 initialize(parent_window,
66 opaque_bitmap->write_drawable(opaque_pixmap,
80 alpha_bitmap->write_drawable(alpha_pixmap,
90 XFreeGC(top_level->display, copy_gc);
92 XSetClipMask(top_level->display, alpha_gc, alpha_pixmap);
96 BC_Pixmap::BC_Pixmap(BC_WindowBase *parent_window, int w, int h)
99 initialize(parent_window, w, h, PIXMAP_OPAQUE);
103 BC_Pixmap::~BC_Pixmap()
109 XftDrawDestroy((XftDraw*)opaque_xft_draw);
111 XFreePixmap(top_level->display, opaque_pixmap);
116 XFreeGC(top_level->display, alpha_gc);
119 XftDrawDestroy((XftDraw*)alpha_xft_draw);
121 XFreePixmap(top_level->display, alpha_pixmap);
125 // Have to delete GL objects because pixmaps are deleted during resizes.
127 if(BC_WindowBase::get_synchronous() && gl_pixmap)
129 BC_WindowBase::get_synchronous()->delete_pixmap(parent_window,
137 void BC_Pixmap::reset()
146 gl_pixmap_context = 0;
151 int BC_Pixmap::initialize(BC_WindowBase *parent_window, int w, int h, int mode)
155 this->parent_window = parent_window;
157 top_level = parent_window->top_level;
161 opaque_pixmap = XCreatePixmap(top_level->display,
165 top_level->default_depth);
167 if(BC_WindowBase::get_resources()->use_xft)
169 opaque_xft_draw = XftDrawCreate(top_level->display,
179 unsigned long gcmask = GCGraphicsExposures |
184 gcvalues.graphics_exposures = 0; // prevent expose events for every redraw
185 gcvalues.foreground = 0;
186 gcvalues.background = 1;
187 gcvalues.function = GXcopy;
189 alpha_pixmap = XCreatePixmap(top_level->display,
195 alpha_gc = XCreateGC(top_level->display,
200 copy_gc = XCreateGC(top_level->display,
206 if(BC_WindowBase::get_resources()->use_xft)
208 alpha_xft_draw = XftDrawCreateBitmap(top_level->display,
216 // // For some reason, this is required in 32 bit.
218 // if(BC_WindowBase::get_resources()->use_xft)
219 // XSync(top_level->display, False);
225 void BC_Pixmap::resize(int w, int h)
227 Pixmap new_pixmap = XCreatePixmap(top_level->display,
231 top_level->default_depth);
233 XftDraw *new_xft_draw;
234 if(BC_WindowBase::get_resources()->use_xft)
236 new_xft_draw = XftDrawCreate(top_level->display,
246 XCopyArea(top_level->display,
259 if(BC_WindowBase::get_resources()->use_xft)
260 XftDrawDestroy((XftDraw*)opaque_xft_draw);
262 XFreePixmap(top_level->display, opaque_pixmap);
264 opaque_pixmap = new_pixmap;
266 if(BC_WindowBase::get_resources()->use_xft)
267 opaque_xft_draw = new_xft_draw;
272 void BC_Pixmap::copy_area(int x, int y, int w, int h, int x2, int y2)
274 XCopyArea(top_level->display,
286 int BC_Pixmap::write_drawable(Drawable &pixmap,
294 //printf("BC_Pixmap::write_drawable 1\n");
309 XSetClipOrigin(top_level->display, alpha_gc, dest_x - src_x, dest_y - src_y);
310 XCopyArea(top_level->display,
324 XCopyArea(top_level->display,
335 //printf("BC_Pixmap::write_drawable 2\n");
340 void BC_Pixmap::draw_vframe(VFrame *frame,
348 parent_window->draw_vframe(frame,
360 void BC_Pixmap::draw_pixmap(BC_Pixmap *pixmap,
368 pixmap->write_drawable(this->opaque_pixmap,
387 int BC_Pixmap::get_w()
392 int BC_Pixmap::get_h()
397 int BC_Pixmap::get_w_fixed()
402 int BC_Pixmap::get_h_fixed()
407 Pixmap BC_Pixmap::get_pixmap()
409 return opaque_pixmap;
412 Pixmap BC_Pixmap::get_alpha()
417 int BC_Pixmap::use_opaque()
422 int BC_Pixmap::use_alpha()
424 return mode == PIXMAP_ALPHA;
428 void BC_Pixmap::enable_opengl()
430 printf("BC_Pixmap::enable_opengl called but it doesn't work.\n");
432 BC_WindowBase *current_window = BC_WindowBase::get_synchronous()->current_window;
433 if(!gl_pixmap_context)
436 // XVisualInfo viproto;
438 // viproto.screen = current_window->get_screen();
439 // static int framebuffer_attributes[] =
443 // GLX_GREEN_SIZE, 1,
447 // XVisualInfo *visinfo = glXChooseVisual(current_window->get_display(),
448 // current_window->get_screen(),
449 // framebuffer_attributes);
450 // printf("BC_Pixmap::enable_opengl 1 %p\n", visinfo->visual);
451 // gl_pixmap = glXCreateGLXPixmap(current_window->get_display(),
454 // printf("BC_Pixmap::enable_opengl 2 %p\n", gl_pixmap);
455 // // This context must be indirect, but because it's indirect, it can't share
456 // // ID's with the window context.
457 // gl_pixmap_context = glXCreateContext(current_window->get_display(),
461 // printf("BC_Pixmap::enable_opengl 3 %p\n", gl_pixmap_context);
463 static int framebuffer_attributes[] =
465 GLX_RENDER_TYPE, GLX_RGBA_BIT,
466 GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
473 XVisualInfo *visinfo = 0;
474 int config_result_count = 0;
475 GLXFBConfig *config_result = glXChooseFBConfig(current_window->get_display(),
476 current_window->get_screen(),
477 framebuffer_attributes,
478 &config_result_count);
481 gl_pixmap = glXCreatePixmap(current_window->get_display(),
486 visinfo = glXGetVisualFromFBConfig(current_window->get_display(),
490 // provide window context to share ID's.
493 gl_pixmap_context = glXCreateContext(current_window->get_display(),
499 if(config_result) XFree(config_result);
500 if(visinfo) XFree(visinfo);
503 if(gl_pixmap_context)
505 glXMakeCurrent(top_level->display,