summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2023-04-23 10:03:02 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2023-04-23 10:03:02 +0200
commit4bf9172a8e4f76842a2e011671cf5c057e8fe1d1 (patch)
tree1c87724b15d5166a6c6f62204f5de2d3e4ac8dd0 /src/drivers
parent897a6910b60ad8331ddb451d9dbc6c62da2b4657 (diff)
Replace internal fl_create_offscreen() calls by new Fl_Image_Surface
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx10
-rw-r--r--src/drivers/PostScript/Fl_PostScript.cxx9
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx13
-rw-r--r--src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx8
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx19
-rw-r--r--src/drivers/X11/Fl_X11_Window_Driver.cxx11
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.H4
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx13
8 files changed, 41 insertions, 46 deletions
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
index 4d3c3ab3d..e479a4d8b 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
+++ b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
@@ -54,20 +54,18 @@ void Fl_Cocoa_Window_Driver::flush_overlay()
if (!oWindow->shown()) return;
pWindow->make_current(); // make sure fl_gc is non-zero
if (!other_xid) {
- other_xid = fl_create_offscreen(oWindow->w(), oWindow->h());
+ other_xid = new Fl_Image_Surface(oWindow->w(), oWindow->h(), 1);
oWindow->clear_damage(FL_DAMAGE_ALL);
}
if (oWindow->damage() & ~FL_DAMAGE_EXPOSE) {
Fl_X *myi = Fl_X::flx(pWindow);
fl_clip_region(myi->region); myi->region = 0;
- fl_begin_offscreen(other_xid);
+ Fl_Surface_Device::push_current(other_xid);
draw();
- fl_end_offscreen();
+ Fl_Surface_Device::pop_current();
}
if (erase_overlay) fl_clip_region(0);
- if (other_xid) {
- fl_copy_offscreen(0, 0, oWindow->w(), oWindow->h(), other_xid, 0, 0);
- }
+ fl_copy_offscreen(0, 0, oWindow->w(), oWindow->h(), other_xid->offscreen(), 0, 0);
if (overlay() == oWindow) oWindow->draw_overlay();
}
diff --git a/src/drivers/PostScript/Fl_PostScript.cxx b/src/drivers/PostScript/Fl_PostScript.cxx
index 1db0cc68c..4ce3f67b9 100644
--- a/src/drivers/PostScript/Fl_PostScript.cxx
+++ b/src/drivers/PostScript/Fl_PostScript.cxx
@@ -22,6 +22,7 @@
#include <stdio.h>
#include "Fl_PostScript_Graphics_Driver.H"
#include <FL/Fl_PostScript.H>
+#include <FL/Fl_Image_Surface.H>
#include <FL/Fl_Native_File_Chooser.H>
#include "../../Fl_System_Driver.H"
#include <FL/fl_string_functions.h>
@@ -1128,8 +1129,8 @@ void Fl_PostScript_Graphics_Driver::transformed_draw_extra(const char* str, int
// create an offscreen image of the string
Fl_Color text_color = Fl_Graphics_Driver::color();
Fl_Color bg_color = fl_contrast(FL_WHITE, text_color);
- Fl_Offscreen off = fl_create_offscreen(w_scaled, (int)(h+3*scale) );
- fl_begin_offscreen(off);
+ Fl_Image_Surface *off = new Fl_Image_Surface(w_scaled, (int)(h+3*scale), 1);
+ Fl_Surface_Device::push_current(off);
fl_color(bg_color);
// color offscreen background with a shade contrasting with the text color
fl_rectf(0, 0, w_scaled, (int)(h+3*scale) );
@@ -1147,9 +1148,9 @@ void Fl_PostScript_Graphics_Driver::transformed_draw_extra(const char* str, int
else fl_draw(str, n, 0, (int)(h * 0.8) );
// read (most of) the offscreen image
uchar *img = fl_read_image(NULL, 0, 1, w2, h, 0);
- fl_end_offscreen();
+ Fl_Surface_Device::pop_current();
font(fontnum, old_size);
- fl_delete_offscreen(off);
+ delete off;
// compute the mask of what is not the background
uchar *img_mask = calc_mask(img, w2, h, bg_color);
delete[] img;
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
index d3f3d343a..fcd9e89c7 100644
--- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
@@ -111,17 +111,8 @@ void Fl_Quartz_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_Of
CGDataProviderRelease(src_bytes);
CGColorSpaceRelease(lut);
}
- float s = scale();
- Fl_Surface_Device *current = Fl_Surface_Device::surface();
- // test whether osrc was created by fl_create_offscreen()
- fl_begin_offscreen(osrc); // does nothing if osrc was not created by fl_create_offscreen()
- if (current != Fl_Surface_Device::surface()) { // osrc was created by fl_create_offscreen()
- Fl_Image_Surface *imgs = (Fl_Image_Surface*)Fl_Surface_Device::surface();
- int pw, ph;
- imgs->printable_rect(&pw, &ph);
- s = sw / float(pw);
- fl_end_offscreen();
- }
+ CGAffineTransform at = CGContextGetCTM(src);
+ float s = at.a;
draw_CGImage(img, x, y, w, h, srcx, srcy, sw/s, sh/s);
CGImageRelease(img);
}
diff --git a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx
index 4f57c1ae5..d4b02679a 100644
--- a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx
+++ b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx
@@ -176,19 +176,19 @@ void Fl_Wayland_Window_Driver::flush_overlay()
pWindow->clear_damage((uchar)(pWindow->damage()&~FL_DAMAGE_OVERLAY));
pWindow->make_current();
if (!other_xid) {
- other_xid = fl_create_offscreen(oWindow->w(), oWindow->h());
+ other_xid = new Fl_Image_Surface(oWindow->w(), oWindow->h(), 1);
oWindow->clear_damage(FL_DAMAGE_ALL);
}
if (oWindow->damage() & ~FL_DAMAGE_EXPOSE) {
Fl_X *myi = Fl_X::flx(pWindow);
fl_clip_region(myi->region); myi->region = 0;
- fl_begin_offscreen(other_xid);
+ Fl_Surface_Device::push_current(other_xid);
draw();
- fl_end_offscreen();
+ Fl_Surface_Device::pop_current();
}
if (erase_overlay) fl_clip_region(0);
if (other_xid) {
- fl_copy_offscreen(0, 0, oWindow->w(), oWindow->h(), other_xid, 0, 0);
+ fl_copy_offscreen(0, 0, oWindow->w(), oWindow->h(), other_xid->offscreen(), 0, 0);
}
if (overlay() == oWindow) oWindow->draw_overlay();
}
diff --git a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx
index 9783efde6..063d24552 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx
+++ b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx
@@ -22,6 +22,7 @@
#include <FL/Fl_Image.H>
#include <FL/Fl_Bitmap.H>
#include <FL/Fl_Window.H>
+#include <FL/Fl_Image_Surface.H>
#include <FL/Fl_Overlay_Window.H>
#include <FL/platform.H>
#include "Fl_WinAPI_Window_Driver.H"
@@ -290,16 +291,16 @@ void Fl_WinAPI_Window_Driver::flush_double()
if (!i) return; // window not yet created
if (!other_xid) {
- other_xid = fl_create_offscreen(w(), h());
+ other_xid = new Fl_Image_Surface(w(), h(), 1);
pWindow->clear_damage(FL_DAMAGE_ALL);
}
if (pWindow->damage() & ~FL_DAMAGE_EXPOSE) {
fl_clip_region(i->region); i->region = 0;
#if 0 /* Short form that transiently changes the current Fl_Surface_Device */
- fl_begin_offscreen(other_xid);
+ Fl_Surface_Device::push_current(other_xid);
fl_graphics_driver->clip_region( 0 );
draw();
- fl_end_offscreen();
+ Fl_Surface_Device::pop_current();
#else
/* Alternative form that avoids changing the current Fl_Surface_Device.
The code run in the window draw() method can call Fl_Surface_Device::surface()
@@ -307,7 +308,7 @@ void Fl_WinAPI_Window_Driver::flush_double()
for an Fl_Double_Window.
*/
HDC sgc = fl_gc;
- fl_gc = fl_makeDC((HBITMAP)other_xid);
+ fl_gc = fl_makeDC((HBITMAP)other_xid->offscreen());
int savedc = SaveDC(fl_gc);
fl_graphics_driver->gc(fl_gc);
fl_graphics_driver->restore_clip(); // duplicate clip region into new gc
@@ -322,7 +323,7 @@ void Fl_WinAPI_Window_Driver::flush_double()
}
int X = 0, Y = 0, W = 0, H = 0;
fl_clip_box(0, 0, w(), h(), X, Y, W, H);
- if (other_xid) fl_copy_offscreen(X, Y, W, H, other_xid, X, Y);
+ if (other_xid) fl_copy_offscreen(X, Y, W, H, other_xid->offscreen(), X, Y);
}
@@ -339,20 +340,20 @@ void Fl_WinAPI_Window_Driver::flush_overlay()
pWindow->clear_damage((uchar)(pWindow->damage()&~FL_DAMAGE_OVERLAY));
if (!other_xid) {
- other_xid = fl_create_offscreen(w(), h());
+ other_xid = new Fl_Image_Surface(w(), h(), 1);
pWindow->clear_damage(FL_DAMAGE_ALL);
}
if (pWindow->damage() & ~FL_DAMAGE_EXPOSE) {
fl_clip_region(i->region); i->region = 0;
- fl_begin_offscreen(other_xid);
+ Fl_Surface_Device::push_current(other_xid);
fl_graphics_driver->clip_region(0);
draw();
- fl_end_offscreen();
+ Fl_Surface_Device::pop_current();
}
if (eraseoverlay) fl_clip_region(0);
int X, Y, W, H; fl_clip_box(0, 0, w(), h(), X, Y, W, H);
- if (other_xid) fl_copy_offscreen(X, Y, W, H, other_xid, X, Y);
+ if (other_xid) fl_copy_offscreen(X, Y, W, H, other_xid->offscreen(), X, Y);
if (overlay() == oWindow) oWindow->draw_overlay();
}
diff --git a/src/drivers/X11/Fl_X11_Window_Driver.cxx b/src/drivers/X11/Fl_X11_Window_Driver.cxx
index 9b4b45de9..c30f36e49 100644
--- a/src/drivers/X11/Fl_X11_Window_Driver.cxx
+++ b/src/drivers/X11/Fl_X11_Window_Driver.cxx
@@ -26,6 +26,7 @@
#endif // FLTK_USE_CAIRO
#include <FL/Fl_Tooltip.H>
+#include <FL/Fl_Image_Surface.H>
#include <FL/fl_draw.H>
#include <FL/fl_ask.H>
#include <FL/Fl.H>
@@ -158,11 +159,11 @@ void Fl_X11_Window_Driver::flush_double(int erase_overlay)
pWindow->make_current(); // make sure fl_gc is non-zero
Fl_X *i = Fl_X::flx(pWindow);
if (!other_xid) {
- other_xid = fl_create_offscreen(w(), h());
+ other_xid = new Fl_Image_Surface(w(), h(), 1);
#if FLTK_USE_CAIRO
- fl_begin_offscreen(other_xid);
+ Fl_Surface_Device::push_current(other_xid);
cairo_ = ((Fl_Cairo_Graphics_Driver*)fl_graphics_driver)->cr();
- fl_end_offscreen();
+ Fl_Surface_Device::pop_current();
#endif
pWindow->clear_damage(FL_DAMAGE_ALL);
}
@@ -171,7 +172,7 @@ void Fl_X11_Window_Driver::flush_double(int erase_overlay)
#endif
if (pWindow->damage() & ~FL_DAMAGE_EXPOSE) {
fl_clip_region(i->region); i->region = 0;
- fl_window = other_xid;
+ fl_window = other_xid->offscreen();
# if defined(FLTK_HAVE_CAIROEXT)
if (Fl::cairo_autolink_context()) Fl::cairo_make_current(pWindow);
# endif
@@ -181,7 +182,7 @@ void Fl_X11_Window_Driver::flush_double(int erase_overlay)
if (erase_overlay) fl_clip_region(0);
int X = 0, Y = 0, W = 0, H = 0;
fl_clip_box(0, 0, w(), h(), X, Y, W, H);
- if (other_xid) fl_copy_offscreen(X, Y, W, H, other_xid, X, Y);
+ if (other_xid) fl_copy_offscreen(X, Y, W, H, other_xid->offscreen(), X, Y);
}
diff --git a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.H b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.H
index 2932a3f1c..fa3c0ee90 100644
--- a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.H
+++ b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.H
@@ -23,11 +23,13 @@
# include <cairo/cairo.h>
#endif // FLTK_USE_CAIRO
+class Fl_Image_Surface;
+
class Fl_Xlib_Copy_Surface_Driver : public Fl_Copy_Surface_Driver {
friend class Fl_Copy_Surface_Driver;
void end_current() FL_OVERRIDE;
protected:
- Fl_Offscreen xid;
+ Fl_Image_Surface *xid;
Window oldwindow;
Fl_Xlib_Copy_Surface_Driver(int w, int h);
~Fl_Xlib_Copy_Surface_Driver();
diff --git a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx
index 014314def..95ee14e99 100644
--- a/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx
@@ -18,6 +18,7 @@
#include "Fl_Xlib_Copy_Surface_Driver.H"
#include <FL/Fl.H>
#include <FL/platform.H>
+#include <FL/Fl_Image_Surface.H>
#include <FL/fl_draw.H>
#include "../X11/Fl_X11_Screen_Driver.H"
#if FLTK_USE_CAIRO
@@ -39,9 +40,9 @@ Fl_Xlib_Copy_Surface_Driver::Fl_Xlib_Copy_Surface_Driver(int w, int h) : Fl_Copy
float s = Fl_Graphics_Driver::default_driver().scale();
driver()->scale(s);
oldwindow = fl_window;
- xid = fl_create_offscreen(w,h);
+ xid = new Fl_Image_Surface(w, h, 1);
#if FLTK_USE_CAIRO
- cairo_surface_t *surf = cairo_xlib_surface_create(fl_display, xid, fl_visual->visual, w * s, h * s);
+ cairo_surface_t *surf = cairo_xlib_surface_create(fl_display, xid->offscreen(), fl_visual->visual, w * s, h * s);
cairo_ = cairo_create(surf);
cairo_surface_destroy(surf);
cairo_scale(cairo_, 1/s, 1/s);
@@ -49,7 +50,7 @@ Fl_Xlib_Copy_Surface_Driver::Fl_Xlib_Copy_Surface_Driver(int w, int h) : Fl_Copy
((Fl_X11_Cairo_Graphics_Driver*)driver())->set_cairo(cairo_);
#endif
driver()->push_no_clip();
- fl_window = xid;
+ fl_window = xid->offscreen();
driver()->color(FL_WHITE);
driver()->rectf(0, 0, w, h);
fl_window = oldwindow;
@@ -59,13 +60,13 @@ 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();
Window old_win = fl_window;
- fl_window = xid;
+ fl_window = xid->offscreen();
Fl_RGB_Image *rgb = Fl::screen_driver()->read_win_rectangle(0, 0, width, height, 0);
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 xid;
#if FLTK_USE_CAIRO
cairo_destroy(cairo_);
#endif
@@ -76,7 +77,7 @@ Fl_Xlib_Copy_Surface_Driver::~Fl_Xlib_Copy_Surface_Driver() {
void Fl_Xlib_Copy_Surface_Driver::set_current() {
Fl_Surface_Device::set_current();
oldwindow = fl_window;
- fl_window = xid;
+ fl_window = xid->offscreen();
#if FLTK_USE_CAIRO
((Fl_X11_Cairo_Graphics_Driver*)driver())->set_cairo(cairo_);
#endif