Simplify API for Fl_Image_Surface::Fl_Image_Surface(int w, int h, int high_res, Fl_Offscreen off) with non-null offscreen.

The caller no longer needs to call Fl_Image_Surface::get_offscreen_before_delete() before object deletion,
because the object destructor knows the offscreen has not been created by the Fl_Image_Surface constructor.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12874 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2018-04-26 12:00:49 +00:00
parent dd93cbd888
commit 9c389d34f9
6 changed files with 10 additions and 8 deletions

View File

@ -99,7 +99,8 @@ protected:
int width;
int height;
Fl_Offscreen offscreen;
Fl_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off) : Fl_Widget_Surface(NULL), width(w), height(h), offscreen(off) {}
int external_offscreen;
Fl_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off) : Fl_Widget_Surface(NULL), width(w), height(h), offscreen(off) {external_offscreen = (off != 0);}
virtual ~Fl_Image_Surface_Driver() {}
virtual void set_current() {}
virtual void translate(int x, int y) {}

View File

@ -102,7 +102,6 @@ void Fl_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_Offscreen
uchar *img = fl_read_image(NULL, px, py, pw, ph, 0);
if (surface) {
Fl_Surface_Device::pop_current();
surface->get_offscreen_before_delete(); // so deleting surface does not touch pixmap
delete surface;
} else fl_end_offscreen();
if (img) {

View File

@ -39,11 +39,13 @@ Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, i
\p w x \p h expressed in FLTK units.
If \p highres is non-zero, always use Fl_Image_Surface::highres_image() to get the image data.
\param pixmap Is used internally by FLTK; applications just use its default value.
\param off If not null, the image surface is constructed around a pre-existing
Fl_Offscreen. The caller is responsible for both construction and destruction of this Fl_Offscreen object.
Is mostly intended for internal use by FLTK.
\version 1.3.4 (1.3.3 without the \p highres parameter)
*/
Fl_Image_Surface::Fl_Image_Surface(int w, int h, int high_res, Fl_Offscreen pixmap) : Fl_Widget_Surface(NULL) {
platform_surface = Fl_Image_Surface_Driver::newImageSurfaceDriver(w, h, high_res, pixmap);
Fl_Image_Surface::Fl_Image_Surface(int w, int h, int high_res, Fl_Offscreen off) : Fl_Widget_Surface(NULL) {
platform_surface = Fl_Image_Surface_Driver::newImageSurfaceDriver(w, h, high_res, off);
if (platform_surface) driver(platform_surface->driver());
}

View File

@ -60,7 +60,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) DeleteObject(offscreen);
if (offscreen && !external_offscreen) DeleteObject(offscreen);
delete driver();
}

View File

@ -72,7 +72,7 @@ Fl_Quartz_Image_Surface_Driver::Fl_Quartz_Image_Surface_Driver(int w, int h, int
}
Fl_Quartz_Image_Surface_Driver::~Fl_Quartz_Image_Surface_Driver() {
if (offscreen) {
if (offscreen && !external_offscreen) {
void *data = CGBitmapContextGetData(offscreen);
free(data);
CGContextRelease((CGContextRef)offscreen);

View File

@ -53,7 +53,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) XFreePixmap(fl_display, offscreen);
if (offscreen && !external_offscreen) XFreePixmap(fl_display, offscreen);
delete driver();
}