2
// "$Id: Fl_Double_Window.cxx 7671 2010-07-09 17:31:33Z manolo $"
2
// "$Id: Fl_Double_Window.cxx 8383 2011-02-06 12:20:16Z AlbrechtS $"
4
4
// Double-buffered window code for the Fast Light Tool Kit (FLTK).
6
// Copyright 1998-2009 by Bill Spitzak and others.
6
// Copyright 1998-2010 by Bill Spitzak and others.
8
8
// This library is free software; you can redistribute it and/or
9
9
// modify it under the terms of the GNU Library General Public
52
52
int numscreens = 1;
53
53
XdbeScreenVisualInfo *a = XdbeGetVisualInfo(fl_display,&root,&numscreens);
55
for (int j = 0; j < a->count; j++)
55
for (int j = 0; j < a->count; j++) {
56
56
if (a->visinfo[j].visual == fl_visual->visualid
57
/*&& a->visinfo[j].perflevel > 0*/) {use_xdbe = 1; break;}
57
/*&& a->visinfo[j].perflevel > 0*/) {
58
61
XdbeFreeVisualInfo(a);
68
71
static void fl_copy_offscreen_to_display(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
73
/** \addtogroup fl_drawings
76
/** Copy a rectangular area of the given offscreen buffer into the current drawing destination.
77
\param x,y position where to draw the copied rectangle
78
\param w,h size of the copied rectangle
79
\param pixmap offscreen buffer containing the rectangle to copy
80
\param srcx,srcy origin in offscreen buffer of rectangle to copy
70
82
void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy) {
71
if( fl_graphics_driver == fl_display_device->driver()) {
83
if (fl_graphics_driver == Fl_Display_Device::display_device()->driver()) {
72
84
fl_copy_offscreen_to_display(x, y, w, h, pixmap, srcx, srcy);
74
86
else { // when copy is not to the display
76
88
uchar *img = fl_read_image(NULL, srcx, srcy, w, h, 0);
77
89
fl_end_offscreen();
78
90
fl_draw_image(img, x, y, w, h, 3, 0);
83
96
#if defined(USE_X11)
85
98
static void fl_copy_offscreen_to_display(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy) {
86
XCopyArea(fl_display, pixmap, fl_window, fl_gc, srcx, srcy, w, h, x, y);
99
XCopyArea(fl_display, pixmap, fl_window, fl_gc, srcx, srcy, w, h, x, y);
170
183
BOOL alpha_ok = 0;
171
184
// first try to alpha blend
172
185
// if to printer, always try alpha_blend
173
int to_display = Fl_Surface_Device::surface()->type() == Fl_Display_Device::device_type; // true iff display output
174
if ( (to_display && fl_can_do_alpha_blending()) || Fl_Surface_Device::surface()->type() == Fl_Printer::device_type) {
186
int to_display = Fl_Surface_Device::surface()->class_name() == Fl_Display_Device::class_id; // true iff display output
187
if ( (to_display && fl_can_do_alpha_blending()) || Fl_Surface_Device::surface()->class_name() == Fl_Printer::class_id) {
175
188
alpha_ok = fl_alpha_blend(fl_gc, x, y, w, h, new_gc, srcx, srcy, w, h, blendfunc);
177
190
// if that failed (it shouldn't), still copy the bitmap over, but now alpha is 1
179
192
BitBlt(fl_gc, x, y, w, h, new_gc, srcx, srcy, SRCCOPY);
181
194
RestoreDC(new_gc, save);
182
195
DeleteDC(new_gc);
185
198
extern void fl_restore_clip();
187
#elif defined(__APPLE_QUARTZ__)
200
#elif defined(__APPLE_QUARTZ__) || defined(FL_DOXYGEN)
189
202
char fl_can_do_alpha_blending() {
206
Fl_Offscreen fl_create_offscreen_with_alpha(int w, int h) {
207
void *data = calloc(w*h,4);
208
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
209
CGContextRef ctx = CGBitmapContextCreate(
210
data, w, h, 8, w*4, lut, kCGImageAlphaPremultipliedLast);
211
CGColorSpaceRelease(lut);
212
return (Fl_Offscreen)ctx;
215
/** \addtogroup fl_drawings
220
Creation of an offscreen graphics buffer.
221
\param w,h width and height in pixels of the buffer.
222
\return the created graphics buffer.
193
224
Fl_Offscreen fl_create_offscreen(int w, int h) {
194
225
void *data = calloc(w*h,4);
195
226
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
199
230
return (Fl_Offscreen)ctx;
202
Fl_Offscreen fl_create_offscreen_with_alpha(int w, int h) {
203
void *data = calloc(w*h,4);
204
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
205
CGContextRef ctx = CGBitmapContextCreate(
206
data, w, h, 8, w*4, lut, kCGImageAlphaPremultipliedLast);
207
CGColorSpaceRelease(lut);
208
return (Fl_Offscreen)ctx;
211
static void bmProviderRelease (void *src, const void *data, size_t size)
233
static void bmProviderRelease (void *src, const void *data, size_t size) {
213
234
CFIndex count = CFGetRetainCount(src);
215
236
if(count == 1) free((void*)data);
252
276
static Window stack_window[stack_max];
253
277
static Fl_Surface_Device *_ss;
279
/** Send all subsequent drawing commands to this offscreen buffer.
280
\param ctx the offscreen buffer.
255
282
void fl_begin_offscreen(Fl_Offscreen ctx) {
257
fl_display_device->set_current();
283
_ss = Fl_Surface_Device::surface();
284
Fl_Display_Device::display_device()->set_current();
258
285
if (stack_ix<stack_max) {
259
286
stack_gc[stack_ix] = fl_gc;
260
287
stack_window[stack_ix] = fl_window;