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.
This commit is contained in:
ManoloFLTK 2019-05-25 11:59:16 +02:00
parent bf50352afe
commit 0d3a374396
7 changed files with 16 additions and 12 deletions

View File

@ -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. */

View File

@ -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();

View File

@ -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 */

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}