summaryrefslogtreecommitdiff
path: root/src/Fl_Graphics_Driver.cxx
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2016-12-16 16:06:07 +0000
committerManolo Gouy <Manolo>2016-12-16 16:06:07 +0000
commitd0f6ef5d3207d39b5209a608117d3078e40acb39 (patch)
treefecace913df1491a5a93725e0e70a859dffc6d2a /src/Fl_Graphics_Driver.cxx
parent1fc01c7cbb23fe21b1cf07261659badfb1dd3fb9 (diff)
Improve Fl_Graphics_Driver::copy_offscreen() so it accepts an Fl_Offscreen argument even if not created by fl_create_offscreen().
With this, fl_copy_offscreen() can be used with any drawing surface (e.g., PostScript) and any Fl_Offscreen argument (e.g., returned by Fl_image_Surface::offscreen()). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12148 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Graphics_Driver.cxx')
-rw-r--r--src/Fl_Graphics_Driver.cxx19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/Fl_Graphics_Driver.cxx b/src/Fl_Graphics_Driver.cxx
index 0429eac0c..b47b8fd88 100644
--- a/src/Fl_Graphics_Driver.cxx
+++ b/src/Fl_Graphics_Driver.cxx
@@ -22,6 +22,7 @@
#include <FL/Fl_Screen_Driver.H>
#include <FL/Fl_Image.H>
#include <FL/fl_draw.H>
+#include <FL/Fl_Image_Surface.H>
FL_EXPORT Fl_Graphics_Driver *fl_graphics_driver; // the current driver of graphics operations
@@ -75,8 +76,10 @@ int Fl_Graphics_Driver::draw_scaled(Fl_Image *img, int X, int Y, int W, int H) {
/** see fl_copy_offscreen() */
void Fl_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy)
{
- // This platform-independent version is used when the current graphics driver is PostScript.
- // It requires that pixmap has been created by fl_create_offscreen().
+ // This platform-independent version can be used by any graphics driver,
+ // noticeably the PostScript driver.
+ // More efficient platform-specific implementations exist for other graphics drivers.
+ Fl_Image_Surface *surface = NULL;
int px_width = w, px_height = h;
Fl::screen_driver()->offscreen_size(pixmap, px_width, px_height);
int px = srcx, py = srcy, pw = w, ph = h;
@@ -84,9 +87,19 @@ void Fl_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_Offscreen
if (py < 0) {py = 0; ph += srcy; y -= srcy;}
if (px + pw > px_width) {pw = px_width - px;}
if (py + ph > px_height) {ph = px_height - py;}
+ Fl_Surface_Device *current = Fl_Surface_Device::surface();
fl_begin_offscreen(pixmap);
+ // test whether pixmap was not created by fl_create_offscreen()
+ if (current == Fl_Surface_Device::surface()) {
+ surface = new Fl_Image_Surface(px_width, px_height, 0, pixmap);
+ Fl_Surface_Device::push_current(surface);
+ }
uchar *img = fl_read_image(NULL, px, py, pw, ph, 0);
- fl_end_offscreen();
+ 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) {
fl_draw_image(img, x, y, pw, ph, 3, 0);
delete[] img;