summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Device.cxx4
-rw-r--r--src/Fl_Image_Surface.cxx14
-rw-r--r--src/Fl_win32.cxx2
-rw-r--r--src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx6
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx3
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx5
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx2
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx3
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx8
9 files changed, 22 insertions, 25 deletions
diff --git a/src/Fl_Device.cxx b/src/Fl_Device.cxx
index 430aa2bf5..9f0b6292c 100644
--- a/src/Fl_Device.cxx
+++ b/src/Fl_Device.cxx
@@ -48,14 +48,17 @@ TODO:
*/
+Fl_Surface_Device *Fl_Surface_Device::pre_surface_ = NULL;
/** \brief Make this surface the current drawing surface.
This surface will receive all future graphics requests. */
void Fl_Surface_Device::set_current(void)
{
+ if (pre_surface_) pre_surface_->end_current_();
fl_graphics_driver = pGraphicsDriver;
_surface = this;
pGraphicsDriver->global_gc();
+ pre_surface_ = this;
}
Fl_Surface_Device* Fl_Surface_Device::_surface; // the current target surface of graphics operations
@@ -63,6 +66,7 @@ Fl_Surface_Device* Fl_Surface_Device::_surface; // the current target surface of
Fl_Surface_Device::~Fl_Surface_Device()
{
+ if (pre_surface_ == this) pre_surface_ = NULL;
}
diff --git a/src/Fl_Image_Surface.cxx b/src/Fl_Image_Surface.cxx
index d26a53600..0dd2f6ff7 100644
--- a/src/Fl_Image_Surface.cxx
+++ b/src/Fl_Image_Surface.cxx
@@ -55,9 +55,6 @@ void Fl_Image_Surface::set_current() {
if (platform_surface) platform_surface->set_current();
}
-/** Stop sending graphics commands to the surface */
-void Fl_Image_Surface::end_current() {platform_surface->end_current();}
-
void Fl_Image_Surface::translate(int x, int y) {
if (platform_surface) platform_surface->translate(x, y);
}
@@ -149,7 +146,7 @@ void fl_delete_offscreen(Fl_Offscreen ctx) {
}
}
-static int stack_current_offscreen[16];
+static Fl_Surface_Device* stack_surface[16];
static unsigned stack_height = 0;
/** Send all subsequent drawing commands to this offscreen buffer.
@@ -158,12 +155,12 @@ static unsigned stack_height = 0;
void fl_begin_offscreen(Fl_Offscreen ctx) {
for (int i = 0; i < count_offscreens; i++) {
if (offscreen_api_surface[i] && offscreen_api_surface[i]->offscreen() == ctx) {
- offscreen_api_surface[i]->set_current();
- if (stack_height < sizeof(stack_current_offscreen)/sizeof(int)) {
- stack_current_offscreen[stack_height++] = i;
+ if (stack_height < sizeof(stack_surface)/sizeof(void*)) {
+ stack_surface[stack_height++] = Fl_Surface_Device::surface();
} else {
fprintf(stderr, "FLTK fl_begin_offscreen Stack overflow error\n");
}
+ offscreen_api_surface[i]->set_current();
return;
}
}
@@ -173,8 +170,7 @@ void fl_begin_offscreen(Fl_Offscreen ctx) {
*/
void fl_end_offscreen() {
if (stack_height > 0) {
- int i = stack_current_offscreen[--stack_height];
- offscreen_api_surface[i]->end_current();
+ stack_surface[--stack_height]->set_current();
}
}
diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx
index ab1c4c099..3b981ae4b 100644
--- a/src/Fl_win32.cxx
+++ b/src/Fl_win32.cxx
@@ -2417,7 +2417,7 @@ void Fl_WinAPI_Window_Driver::capture_titlebar_and_borders(Fl_Shared_Image*& top
ReleaseDC(NULL, (HDC)fl_graphics_driver->gc());
fl_window = save_win;
fl_graphics_driver->gc(save_gc);
- previous->Fl_Surface_Device::set_current();
+ previous->set_current();
}
diff --git a/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx b/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx
index 9c72b7ac0..54a4a038f 100644
--- a/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx
+++ b/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx
@@ -28,6 +28,7 @@
class Fl_GDI_Image_Surface_Driver : public Fl_Image_Surface_Driver {
friend class Fl_Image_Surface;
+ virtual void end_current_();
public:
Fl_Surface_Device *previous;
Window pre_window;
@@ -39,7 +40,6 @@ public:
void translate(int x, int y);
void untranslate();
Fl_RGB_Image *image();
- void end_current();
};
@@ -90,7 +90,6 @@ Fl_RGB_Image* Fl_GDI_Image_Surface_Driver::image()
{
unsigned char *data;
data = fl_read_image(NULL, 0, 0, width, height, 0);
- end_current();
previous->driver()->gc(_sgc);
Fl_RGB_Image *image = new Fl_RGB_Image(data, width, height);
image->alloc_array = 1;
@@ -98,13 +97,12 @@ Fl_RGB_Image* Fl_GDI_Image_Surface_Driver::image()
}
-void Fl_GDI_Image_Surface_Driver::end_current()
+void Fl_GDI_Image_Surface_Driver::end_current_()
{
HDC gc = (HDC)driver()->gc();
RestoreDC(gc, _savedc);
DeleteDC(gc);
fl_pop_clip();
- previous->Fl_Surface_Device::set_current();
fl_window = pre_window;
}
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
index 0c1e59678..ca3d74734 100644
--- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
@@ -251,11 +251,12 @@ static void pmProviderRelease (void *ctxt, const void *data, size_t size) {
}
fl_uintptr_t Fl_Quartz_Graphics_Driver::cache(Fl_Pixmap *img, int w, int h, const char *const*data) {
+ Fl_Surface_Device *old = Fl_Surface_Device::surface();
Fl_Image_Surface *surf = new Fl_Image_Surface(w, h);
surf->set_current();
fl_draw_pixmap(data, 0, 0, FL_BLACK);
CGContextRef src = surf->get_offscreen_before_delete();
- surf->end_current();
+ old->set_current();
delete surf;
void *cgdata = CGBitmapContextGetData(src);
int sw = CGBitmapContextGetWidth(src);
diff --git a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx
index 59a3b5e93..1a2e3de5e 100644
--- a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx
@@ -27,6 +27,7 @@
class Fl_Quartz_Image_Surface_Driver : public Fl_Image_Surface_Driver {
friend class Fl_Image_Surface;
+ virtual void end_current_();
public:
Fl_Surface_Device *previous;
Window pre_window;
@@ -36,7 +37,6 @@ public:
void translate(int x, int y);
void untranslate();
Fl_RGB_Image *image();
- void end_current();
};
@@ -108,9 +108,8 @@ Fl_RGB_Image* Fl_Quartz_Image_Surface_Driver::image()
return image;
}
-void Fl_Quartz_Image_Surface_Driver::end_current()
+void Fl_Quartz_Image_Surface_Driver::end_current_()
{
- previous->Fl_Surface_Device::set_current();
fl_window = pre_window;
}
diff --git a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx
index e4b1f7979..c439ddf94 100644
--- a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx
@@ -57,6 +57,7 @@ Fl_Xlib_Copy_Surface_Driver::Fl_Xlib_Copy_Surface_Driver(int w, int h) : Fl_Copy
_ss = NULL;
Fl_Surface_Device *present_surface = Fl_Surface_Device::surface();
Fl_Surface_Device::set_current();
+ fl_push_no_clip();
fl_window = xid;
driver()->color(FL_WHITE);
driver()->rectf(0, 0, w, h);
@@ -81,7 +82,6 @@ void Fl_Xlib_Copy_Surface_Driver::set_current() {
fl_window = xid;
if (!_ss) _ss = Fl_Surface_Device::surface();
Fl_Surface_Device::set_current();
- fl_push_no_clip();
}
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
index 543e2ba7f..7ecb5471e 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
@@ -714,9 +714,10 @@ void Fl_Xlib_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, in
depth |= FL_IMAGE_WITH_ALPHA;
}
if (surface) {
+ Fl_Surface_Device *old_surf = Fl_Surface_Device::surface();
surface->set_current();
fl_draw_image(img->array, 0, 0, img->w(), img->h(), depth, img->ld());
- surface->end_current();
+ old_surf->set_current();
*Fl_Graphics_Driver::id(img) = surface->get_offscreen_before_delete();
delete surface;
}
diff --git a/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx
index 0c8303bf9..022a94066 100644
--- a/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx
@@ -27,6 +27,7 @@
class Fl_Xlib_Image_Surface_Driver : public Fl_Image_Surface_Driver {
friend class Fl_Image_Surface;
+ virtual void end_current_();
public:
Fl_Surface_Device *previous;
Window pre_window;
@@ -37,7 +38,6 @@ public:
void translate(int x, int y);
void untranslate();
Fl_RGB_Image *image();
- void end_current();
};
Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, int h, int high_res, Fl_Offscreen off)
@@ -62,8 +62,8 @@ Fl_Xlib_Image_Surface_Driver::~Fl_Xlib_Image_Surface_Driver() {
void Fl_Xlib_Image_Surface_Driver::set_current() {
pre_window = fl_window;
if (!previous) previous = Fl_Surface_Device::surface();
- fl_window = offscreen;
Fl_Surface_Device::set_current();
+ fl_window = offscreen;
fl_push_no_clip();
}
@@ -78,16 +78,14 @@ void Fl_Xlib_Image_Surface_Driver::untranslate() {
Fl_RGB_Image* Fl_Xlib_Image_Surface_Driver::image()
{
unsigned char *data = fl_read_image(NULL, 0, 0, width, height, 0);
- end_current();
Fl_RGB_Image *image = new Fl_RGB_Image(data, width, height);
image->alloc_array = 1;
return image;
}
-void Fl_Xlib_Image_Surface_Driver::end_current()
+void Fl_Xlib_Image_Surface_Driver::end_current_()
{
fl_pop_clip();
- previous->Fl_Surface_Device::set_current();
fl_window = pre_window;
}