diff --git a/FL/Fl_Device.H b/FL/Fl_Device.H index 3a31a49b7..0c3476590 100644 --- a/FL/Fl_Device.H +++ b/FL/Fl_Device.H @@ -73,7 +73,7 @@ class FL_EXPORT Fl_Surface_Device { protected: /* Some drawing surfaces (e.g., Fl_XXX_Image_Surface_Driver) re-implement this. Gets called each time a surface ceases to be the current drawing surface. */ - virtual void end_current() {} + virtual void end_current() { surface_ = 0;} /** Constructor that sets the graphics driver to use for the created surface. */ Fl_Surface_Device(Fl_Graphics_Driver *graphics_driver) {pGraphicsDriver = graphics_driver; } /** Sets the graphics driver of this drawing surface. */ diff --git a/src/Fl_Image_Surface.cxx b/src/Fl_Image_Surface.cxx index f58949c19..e0c5fe1fc 100644 --- a/src/Fl_Image_Surface.cxx +++ b/src/Fl_Image_Surface.cxx @@ -42,7 +42,10 @@ Fl_Image_Surface::Fl_Image_Surface(int w, int h, int high_res, Fl_Offscreen off) /** The destructor. */ -Fl_Image_Surface::~Fl_Image_Surface() { delete platform_surface; } +Fl_Image_Surface::~Fl_Image_Surface() { + if (is_current()) platform_surface->end_current(); + delete platform_surface; +} void Fl_Image_Surface::origin(int x, int y) {platform_surface->origin(x, y);} diff --git a/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx b/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx index 9308936d3..43fe15dcb 100644 --- a/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx +++ b/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx @@ -61,7 +61,6 @@ Fl_GDI_Image_Surface_Driver::Fl_GDI_Image_Surface_Driver(int w, int h, int high_ Fl_GDI_Image_Surface_Driver::~Fl_GDI_Image_Surface_Driver() { if (offscreen && !external_offscreen) DeleteObject(offscreen); - if (is_current()) end_current(); delete driver(); } @@ -101,6 +100,7 @@ void Fl_GDI_Image_Surface_Driver::end_current() RestoreDC(gc, _savedc); DeleteDC(gc); fl_window = pre_window; + Fl_Surface_Device::end_current(); } diff --git a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx index f7eca97a7..b25bda07c 100644 --- a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx @@ -89,7 +89,6 @@ Fl_Quartz_Image_Surface_Driver::~Fl_Quartz_Image_Surface_Driver() { CGContextRelease((CGContextRef)offscreen); } delete driver(); - if (is_current()) end_current(); } void Fl_Quartz_Image_Surface_Driver::set_current() { @@ -128,6 +127,7 @@ Fl_RGB_Image* Fl_Quartz_Image_Surface_Driver::image() void Fl_Quartz_Image_Surface_Driver::end_current() { fl_window = pre_window; + Fl_Surface_Device::end_current(); } #endif // FL_CFG_GFX_QUARTZ diff --git a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx index 4e9466952..18176a0a6 100644 --- a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx @@ -62,15 +62,15 @@ Fl_Xlib_Copy_Surface_Driver::Fl_Xlib_Copy_Surface_Driver(int w, int h) : Fl_Copy Fl_Xlib_Copy_Surface_Driver::~Fl_Xlib_Copy_Surface_Driver() { driver()->pop_clip(); - bool need_push = !is_current(); - if (need_push) Fl_Surface_Device::push_current(this); + Window old_win = fl_window; + fl_window = xid; Fl_RGB_Image *rgb = Fl::screen_driver()->read_win_rectangle(0, 0, width, height, 0); - if (need_push) Fl_Surface_Device::pop_current(); + fl_window = old_win; + if (is_current()) end_current(); Fl_X11_Screen_Driver::copy_image(rgb->array, rgb->w(), rgb->h(), 1); delete rgb; fl_delete_offscreen(xid); delete driver(); - if (!need_push) end_current(); } @@ -82,6 +82,7 @@ void Fl_Xlib_Copy_Surface_Driver::set_current() { void Fl_Xlib_Copy_Surface_Driver::end_current() { fl_window = oldwindow; + Fl_Surface_Device::end_current(); } void Fl_Xlib_Copy_Surface_Driver::translate(int x, int y) { diff --git a/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx index 54b246955..1f6aa0c1c 100644 --- a/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx @@ -55,7 +55,6 @@ Fl_Xlib_Image_Surface_Driver::Fl_Xlib_Image_Surface_Driver(int w, int h, int hig Fl_Xlib_Image_Surface_Driver::~Fl_Xlib_Image_Surface_Driver() { if (offscreen && !external_offscreen) XFreePixmap(fl_display, offscreen); delete driver(); - if (is_current()) end_current(); } void Fl_Xlib_Image_Surface_Driver::set_current() { @@ -81,6 +80,7 @@ Fl_RGB_Image* Fl_Xlib_Image_Surface_Driver::image() void Fl_Xlib_Image_Surface_Driver::end_current() { fl_window = pre_window; + Fl_Surface_Device::end_current(); } //