summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx25
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx25
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx13
3 files changed, 35 insertions, 28 deletions
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
index 59a4c538c..d46134c87 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
+++ b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
@@ -26,7 +26,6 @@
#include <FL/fl_draw.H>
#include <FL/Fl.H>
#include <FL/x.H>
-#include <ApplicationServices/ApplicationServices.h>
Fl_Window_Driver *Fl_Window_Driver::newWindowDriver(Fl_Window *w)
{
@@ -66,32 +65,20 @@ void Fl_Cocoa_Window_Driver::flush_overlay()
if (!oWindow->shown()) return;
pWindow->make_current(); // make sure fl_gc is non-zero
- Fl_Quartz_Graphics_Driver *g_driver = (Fl_Quartz_Graphics_Driver*)&Fl_Graphics_Driver::default_driver();
- float s = g_driver->scale() * (mapped_to_retina() ? 2 : 1);
- if (!other_xid) { // create offscreen accounting for GUI scaling and retina
- other_xid = (Fl_Offscreen)new Fl_Image_Surface(s * oWindow->w(), s * oWindow->h());
+ if (!other_xid) {
+ other_xid = fl_create_offscreen(oWindow->w(), oWindow->h());
oWindow->clear_damage(FL_DAMAGE_ALL);
- // scale the offscreen buffer's graphics context
- Fl_Surface_Device::push_current((Fl_Image_Surface*)other_xid);
- CGContextRestoreGState(fl_gc);
- CGContextScaleCTM(fl_gc, s, s);
- CGContextSaveGState(fl_gc);
- Fl_Surface_Device::pop_current();
}
if (oWindow->damage() & ~FL_DAMAGE_EXPOSE) {
Fl_X *myi = Fl_X::i(pWindow);
fl_clip_region(myi->region); myi->region = 0;
- Fl_Surface_Device::push_current((Fl_Image_Surface*)other_xid);
+ fl_begin_offscreen(other_xid);
draw();
- Fl_Surface_Device::pop_current();
+ fl_end_offscreen();
}
if (erase_overlay) fl_clip_region(0);
if (other_xid) {
- CGContextSaveGState(fl_gc);
- CGContextScaleCTM(fl_gc, 1/s, 1/s);
- // copy offscreen to window using adequate scaling
- fl_copy_offscreen(0, 0, s * oWindow->w(),s * oWindow->h(), ((Fl_Image_Surface*)other_xid)->offscreen(), 0, 0);
- CGContextRestoreGState(fl_gc);
+ fl_copy_offscreen(0, 0, oWindow->w(), oWindow->h(), other_xid, 0, 0);
}
if (overlay() == oWindow) oWindow->draw_overlay();
}
@@ -99,7 +86,7 @@ void Fl_Cocoa_Window_Driver::flush_overlay()
void Fl_Cocoa_Window_Driver::destroy_double_buffer()
{
- if (pWindow->as_overlay_window()) delete (Fl_Image_Surface*)other_xid;
+ if (pWindow->as_overlay_window()) fl_delete_offscreen(other_xid);
other_xid = 0;
}
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
index 26f12d6e5..8e9ae0906 100644
--- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx
@@ -20,6 +20,8 @@
#include "Fl_Quartz_Graphics_Driver.H"
#include "../Darwin/Fl_Darwin_System_Driver.H"
#include <FL/x.H>
+#include <FL/fl_draw.H>
+#include <FL/Fl_Image_Surface.H>
#if HAS_ATSU && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
Fl_Quartz_Graphics_Driver::pter_to_draw_member Fl_Quartz_Graphics_Driver::CoreText_or_ATSU_draw;
@@ -84,7 +86,8 @@ void Fl_Quartz_Graphics_Driver::global_gc()
fl_gc = (CGContextRef)gc();
}
-void Fl_Quartz_Graphics_Driver::copy_offscreen(int x,int y,int w,int h,Fl_Offscreen osrc,int srcx,int srcy) {
+void Fl_Quartz_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_Offscreen osrc, int srcx, int srcy) {
+ // draw portion srcx,srcy,w,h of osrc to position x,y (top-left) of the graphics driver's surface
CGContextRef src = (CGContextRef)osrc;
void *data = CGBitmapContextGetData(src);
int sw = CGBitmapContextGetWidth(src);
@@ -92,16 +95,26 @@ void Fl_Quartz_Graphics_Driver::copy_offscreen(int x,int y,int w,int h,Fl_Offscr
CGImageAlphaInfo alpha = CGBitmapContextGetAlphaInfo(src);
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
// when output goes to a Quartz printercontext, release of the bitmap must be
- // delayed after the end of the print page
+ // delayed after the end of the printed page
CFRetain(src);
CGDataProviderRef src_bytes = CGDataProviderCreateWithData( src, data, sw*sh*4, bmProviderRelease);
CGImageRef img = CGImageCreate( sw, sh, 8, 4*8, 4*sw, lut, alpha,
src_bytes, 0L, false, kCGRenderingIntentDefault);
- draw_CGImage(img, x, y, w, h, srcx, srcy, sw, sh);
-
- CGImageRelease(img);
- CGColorSpaceRelease(lut);
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();
+ }
+ draw_CGImage(img, x, y, w, h, srcx, srcy, sw/s, sh/s);
+ CGImageRelease(img);
}
// so a CGRect matches exactly what is denoted x,y,w,h for clipping purposes
diff --git a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx
index c8d751aa1..573a5df8e 100644
--- a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx
@@ -23,6 +23,7 @@
#include <FL/fl_draw.H>
#include <FL/Fl_Image_Surface.H>
#include "Fl_Quartz_Graphics_Driver.H"
+#include "../Cocoa/Fl_Cocoa_Window_Driver.H"
#include <ApplicationServices/ApplicationServices.h>
class Fl_Quartz_Image_Surface_Driver : public Fl_Image_Surface_Driver {
@@ -46,15 +47,21 @@ 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_Offscreen off) : Fl_Image_Surface_Driver(w, h, high_res, 0) {
- int W = high_res ? 2*w : w;
- int H = high_res ? 2*h : h;
+ int W = w, H = h;
+ float s = 1;
+ if (high_res) {
+ s = Fl_Graphics_Driver::default_driver().scale();
+ Fl_Window *cw = Fl_Window::current();
+ if (cw && ((Fl_Cocoa_Window_Driver*)cw->driver())->mapped_to_retina()) s *= 2;
+ W *= s; H *= s;
+ }
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
offscreen = off ? off : CGBitmapContextCreate(calloc(W*H,4), W, H, 8, W*4, lut, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(lut);
driver(new Fl_Quartz_Graphics_Driver);
CGContextTranslateCTM(offscreen, 0.5, -0.5); // as when drawing to a window
if (high_res) {
- CGContextScaleCTM(offscreen, 2, 2);
+ CGContextScaleCTM(offscreen, s, s);
}
CGContextSetShouldAntialias(offscreen, false);
CGContextTranslateCTM(offscreen, 0, height);