diff options
| author | Manolo Gouy <Manolo> | 2016-12-07 15:09:52 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2016-12-07 15:09:52 +0000 |
| commit | 43935dffeb7cb54a97b2a8a610c2e453743c0da9 (patch) | |
| tree | 9f132039b9cf120263bf03965c152ac17853969c /src/drivers | |
| parent | 0a1eed150a9d9215f70f1e50db2ec555199aee7d (diff) | |
Add static void Fl_Surface_Device::push_current(Fl_Surface_Device *new_current) and pop_current() to set/unset the current drawing surface.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12140 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers')
6 files changed, 17 insertions, 27 deletions
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx index ca3d74734..00d96ea42 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx @@ -251,12 +251,11 @@ static void pmProviderRelease (void *ctxt, const void *data, size_t size) { } fl_uintptr_t Fl_Quartz_Graphics_Driver::cache(Fl_Pixmap *img, int w, int h, const char *const*data) { - Fl_Surface_Device *old = Fl_Surface_Device::surface(); Fl_Image_Surface *surf = new Fl_Image_Surface(w, h); - surf->set_current(); + Fl_Surface_Device::push_current(surf); fl_draw_pixmap(data, 0, 0, FL_BLACK); CGContextRef src = surf->get_offscreen_before_delete(); - old->set_current(); + Fl_Surface_Device::pop_current(); delete surf; void *cgdata = CGBitmapContextGetData(src); int sw = CGBitmapContextGetWidth(src); diff --git a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx index 1a2e3de5e..cb22904aa 100644 --- a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx @@ -29,7 +29,6 @@ class Fl_Quartz_Image_Surface_Driver : public Fl_Image_Surface_Driver { friend class Fl_Image_Surface; virtual void end_current_(); public: - Fl_Surface_Device *previous; Window pre_window; Fl_Quartz_Image_Surface_Driver(int w, int h, int high_res); ~Fl_Quartz_Image_Surface_Driver(); @@ -47,7 +46,6 @@ Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, i Fl_Quartz_Image_Surface_Driver::Fl_Quartz_Image_Surface_Driver(int w, int h, int high_res) : Fl_Image_Surface_Driver(w, h, high_res, 0) { - previous = 0; int W = high_res ? 2*w : w; int H = high_res ? 2*h : h; CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB(); @@ -77,7 +75,6 @@ Fl_Quartz_Image_Surface_Driver::~Fl_Quartz_Image_Surface_Driver() { void Fl_Quartz_Image_Surface_Driver::set_current() { pre_window = fl_window; - if (!previous) previous = Fl_Surface_Device::surface(); driver()->gc(offscreen); fl_window = 0; Fl_Surface_Device::set_current(); diff --git a/src/drivers/X11/Fl_X11_Window_Driver.cxx b/src/drivers/X11/Fl_X11_Window_Driver.cxx index 6fc76e325..0f16c7812 100644 --- a/src/drivers/X11/Fl_X11_Window_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Window_Driver.cxx @@ -387,8 +387,7 @@ void Fl_X11_Window_Driver::capture_titlebar_and_borders(Fl_Shared_Image*& top, F top = left = bottom = right = NULL; if (pWindow->decorated_h() == h()) return; Window from = fl_window; - Fl_Surface_Device *previous = Fl_Surface_Device::surface(); - Fl_Display_Device::display_device()->set_current(); + Fl_Surface_Device::push_current( Fl_Display_Device::display_device() ); pWindow->show(); Fl::check(); pWindow->make_current(); @@ -421,7 +420,7 @@ void Fl_X11_Window_Driver::capture_titlebar_and_borders(Fl_Shared_Image*& top, F } } fl_window = from; - previous->Fl_Surface_Device::set_current(); + Fl_Surface_Device::pop_current(); } diff --git a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx index c439ddf94..156bd87d3 100644 --- a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx @@ -28,10 +28,10 @@ class Fl_Xlib_Copy_Surface_Driver : public Fl_Copy_Surface_Driver { friend class Fl_Copy_Surface_Driver; + virtual void end_current_(); protected: Fl_Offscreen xid; Window oldwindow; - Fl_Surface_Device *_ss; Fl_Xlib_Copy_Surface_Driver(int w, int h); ~Fl_Xlib_Copy_Surface_Driver(); void set_current(); @@ -51,26 +51,22 @@ Fl_Copy_Surface_Driver *Fl_Copy_Surface_Driver::newCopySurfaceDriver(int w, int Fl_Xlib_Copy_Surface_Driver::Fl_Xlib_Copy_Surface_Driver(int w, int h) : Fl_Copy_Surface_Driver(w, h) { driver(new Fl_Translated_Xlib_Graphics_Driver()); - Fl::first_window()->make_current(); - oldwindow = fl_xid(Fl::first_window()); + oldwindow = fl_window; xid = fl_create_offscreen(w,h); - _ss = NULL; - Fl_Surface_Device *present_surface = Fl_Surface_Device::surface(); - Fl_Surface_Device::set_current(); - fl_push_no_clip(); + driver()->push_no_clip(); fl_window = xid; driver()->color(FL_WHITE); driver()->rectf(0, 0, w, h); - present_surface->set_current(); fl_window = oldwindow; } Fl_Xlib_Copy_Surface_Driver::~Fl_Xlib_Copy_Surface_Driver() { - fl_pop_clip(); + driver()->pop_clip(); + bool need_push = (Fl_Surface_Device::surface() != this); + if (need_push) Fl_Surface_Device::push_current(this); unsigned char *data = fl_read_image(NULL,0,0,width,height,0); - fl_window = oldwindow; - _ss->set_current(); + if (need_push) Fl_Surface_Device::pop_current(); Fl_X11_Screen_Driver::copy_image(data, width, height, 1); delete[] data; fl_delete_offscreen(xid); @@ -79,11 +75,14 @@ Fl_Xlib_Copy_Surface_Driver::~Fl_Xlib_Copy_Surface_Driver() { void Fl_Xlib_Copy_Surface_Driver::set_current() { + oldwindow = fl_window; fl_window = xid; - if (!_ss) _ss = Fl_Surface_Device::surface(); Fl_Surface_Device::set_current(); } +void Fl_Xlib_Copy_Surface_Driver::end_current_() { + fl_window = oldwindow; +} void Fl_Xlib_Copy_Surface_Driver::translate(int x, int y) { ((Fl_Translated_Xlib_Graphics_Driver*)driver())->translate_all(x, y); diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx index 7ecb5471e..96f8b0685 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx @@ -714,10 +714,9 @@ void Fl_Xlib_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, in depth |= FL_IMAGE_WITH_ALPHA; } if (surface) { - Fl_Surface_Device *old_surf = Fl_Surface_Device::surface(); - surface->set_current(); + Fl_Surface_Device::push_current(surface); fl_draw_image(img->array, 0, 0, img->w(), img->h(), depth, img->ld()); - old_surf->set_current(); + Fl_Surface_Device::pop_current(); *Fl_Graphics_Driver::id(img) = surface->get_offscreen_before_delete(); delete surface; } diff --git a/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx index 022a94066..4ec2bd25d 100644 --- a/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx @@ -29,7 +29,6 @@ class Fl_Xlib_Image_Surface_Driver : public Fl_Image_Surface_Driver { friend class Fl_Image_Surface; virtual void end_current_(); public: - Fl_Surface_Device *previous; Window pre_window; int was_high; Fl_Xlib_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off); @@ -46,7 +45,6 @@ Fl_Image_Surface_Driver *Fl_Image_Surface_Driver::newImageSurfaceDriver(int w, i } Fl_Xlib_Image_Surface_Driver::Fl_Xlib_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off) : Fl_Image_Surface_Driver(w, h, high_res, off) { - previous = 0; if (!off) { fl_open_display(); offscreen = XCreatePixmap(fl_display, RootWindow(fl_display, fl_screen), w, h, fl_visual->depth); @@ -61,7 +59,6 @@ Fl_Xlib_Image_Surface_Driver::~Fl_Xlib_Image_Surface_Driver() { void Fl_Xlib_Image_Surface_Driver::set_current() { pre_window = fl_window; - if (!previous) previous = Fl_Surface_Device::surface(); Fl_Surface_Device::set_current(); fl_window = offscreen; fl_push_no_clip(); |
