Reorganise use of virtual member function Fl_Surface_Device::end_current()

This commit is contained in:
ManoloFLTK 2019-11-07 14:28:20 +01:00
parent 20ab318875
commit 2445797e45
6 changed files with 13 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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