summaryrefslogtreecommitdiff
path: root/src/drivers/Quartz
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2017-12-26 16:07:51 +0000
committerManolo Gouy <Manolo>2017-12-26 16:07:51 +0000
commit7758d472c2356f6908bce9fec6aa3e6d7e6a63e1 (patch)
tree0bac011dc51e12d811f249855e91ba60addce2e8 /src/drivers/Quartz
parent8ee87d15e3c369d74752736a9c3e6614e2950cb0 (diff)
Continue support for GUI rescaling under MacOS: fix fl_XXX_offscreen() functions and Fl_Image_Surface class
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12605 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers/Quartz')
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx25
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx13
2 files changed, 29 insertions, 9 deletions
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);