diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2019-05-25 11:59:16 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2019-05-25 11:59:16 +0200 |
| commit | 0d3a37439625e60cf247228412007fabd04ad289 (patch) | |
| tree | 8eac87f1d763dbea5e68ed869a85f9c25217e447 | |
| parent | bf50352afe8c8aee3cfe1779474d6b6c1854f56f (diff) | |
Call virtual member Fl_Surface_Device::end_current() when necessary
Rename member function Fl_Surface_Device::end_current_() to end_current(),
set it protected, and make it called by the destructor of all classes
derived from Fl_Surface_Device that re-implement end_current().
This way, end_current() runs equally if Fl_Surface_Device()::pop_current()
is called before or after the drawing surface is deleted.
| -rw-r--r-- | FL/Fl_Device.H | 4 | ||||
| -rw-r--r-- | src/Fl_Device.cxx | 2 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Graphics_Driver.H | 2 | ||||
| -rw-r--r-- | src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx | 5 | ||||
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx | 5 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx | 5 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx | 5 |
7 files changed, 16 insertions, 12 deletions
diff --git a/FL/Fl_Device.H b/FL/Fl_Device.H index b017e17f3..3a31a49b7 100644 --- a/FL/Fl_Device.H +++ b/FL/Fl_Device.H @@ -70,10 +70,10 @@ class FL_EXPORT Fl_Surface_Device { Fl_Graphics_Driver *pGraphicsDriver; static Fl_Surface_Device *surface_; // the surface that currently receives graphics requests static Fl_Surface_Device *default_surface(); // create surface if none exists yet +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_() {} -protected: + virtual void end_current() {} /** 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_Device.cxx b/src/Fl_Device.cxx index db632d74c..98d8928a1 100644 --- a/src/Fl_Device.cxx +++ b/src/Fl_Device.cxx @@ -63,7 +63,7 @@ is Fl_Surface_Device::push_current( ) / Fl_Surface_Device::pop_current().*/ void Fl_Surface_Device::set_current(void) { - if (surface_) surface_->end_current_(); + if (surface_) surface_->end_current(); fl_graphics_driver = pGraphicsDriver; surface_ = this; pGraphicsDriver->global_gc(); diff --git a/src/drivers/Android/Fl_Android_Graphics_Driver.H b/src/drivers/Android/Fl_Android_Graphics_Driver.H index 67327d4c6..26d0c8509 100644 --- a/src/drivers/Android/Fl_Android_Graphics_Driver.H +++ b/src/drivers/Android/Fl_Android_Graphics_Driver.H @@ -58,7 +58,7 @@ private: virtual void draw_fixed(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy) override; virtual void draw_fixed(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy) override; // some platforms may need to reimplement this - // This is called from the surface device, see: end_current_() + // This is called from the surface device, see: end_current() // super: virtual void set_current_(); protected: /** Sets the current value of the scaling factor */ diff --git a/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx b/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx index bfb528490..5c03621cb 100644 --- a/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx +++ b/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx @@ -24,7 +24,7 @@ #include <windows.h> class Fl_GDI_Image_Surface_Driver : public Fl_Image_Surface_Driver { - virtual void end_current_(); + virtual void end_current(); public: Window pre_window; int _savedc; @@ -61,6 +61,7 @@ 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(); } @@ -93,7 +94,7 @@ 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(); GetWindowOrgEx(gc, &origin); diff --git a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx index b9c7a7432..f7eca97a7 100644 --- a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx @@ -27,7 +27,7 @@ #include <ApplicationServices/ApplicationServices.h> class Fl_Quartz_Image_Surface_Driver : public Fl_Image_Surface_Driver { - virtual void end_current_(); + virtual void end_current(); public: Window pre_window; Fl_Quartz_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off); @@ -89,6 +89,7 @@ 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() { @@ -124,7 +125,7 @@ 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() { 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 2f1edd9dd..5818eb2a5 100644 --- a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx @@ -28,7 +28,7 @@ class Fl_Xlib_Copy_Surface_Driver : public Fl_Copy_Surface_Driver { friend class Fl_Copy_Surface_Driver; - virtual void end_current_(); + virtual void end_current(); protected: Fl_Offscreen xid; Window oldwindow; @@ -70,6 +70,7 @@ Fl_Xlib_Copy_Surface_Driver::~Fl_Xlib_Copy_Surface_Driver() { delete rgb; fl_delete_offscreen(xid); delete driver(); + if (!need_push) end_current(); } @@ -79,7 +80,7 @@ void Fl_Xlib_Copy_Surface_Driver::set_current() { fl_window = xid; } -void Fl_Xlib_Copy_Surface_Driver::end_current_() { +void Fl_Xlib_Copy_Surface_Driver::end_current() { fl_window = oldwindow; } diff --git a/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx index d27fb03f3..1a9e7796d 100644 --- a/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx @@ -21,7 +21,7 @@ #include "../../Fl_Screen_Driver.H" class Fl_Xlib_Image_Surface_Driver : public Fl_Image_Surface_Driver { - virtual void end_current_(); + virtual void end_current(); public: Window pre_window; Fl_Xlib_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off); @@ -55,6 +55,7 @@ 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() { @@ -77,7 +78,7 @@ Fl_RGB_Image* Fl_Xlib_Image_Surface_Driver::image() return image; } -void Fl_Xlib_Image_Surface_Driver::end_current_() +void Fl_Xlib_Image_Surface_Driver::end_current() { fl_window = pre_window; } |
