summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2018-11-20 12:51:03 +0000
committerManolo Gouy <Manolo>2018-11-20 12:51:03 +0000
commit95aa03d86d3ffd55897d4fc9097f91ff51288f0c (patch)
tree2f8ffdd079b4f1ad9356c05f0fa6691b0d937ee7
parentde797c71010882373d00e56c6ccd95233fcfb097 (diff)
macOS: reorganize the code running when windows are moved between retina and non-retina displays.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@13126 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--src/Fl_cocoa.mm37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 5fb1116ae..0efdadfda 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -598,6 +598,7 @@ void Fl_Cocoa_Screen_Driver::breakMacEventLoop()
- (void)viewFrameDidChange;
- (BOOL)wantsLayer;
- (void)dealloc;
+- (BOOL)did_view_resolution_change;
@end
#endif //10_8
@@ -1255,16 +1256,7 @@ static FLWindowDelegate *flwindowdelegate_instance = nil;
[nsw checkSubwindowFrame];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
FLView *view = (FLView*)[nsw contentView];
- if (views_use_CA && [view did_view_resolution_change]) {
- if (!window->as_gl_window()) { // move layered non-GL window to different resolution
- [(FLViewLayer*)view viewFrameDidChange];
- [(FLViewLayer*)view displayLayer:[view layer]]; // useful for Mandelbrot to recreate the layer's bitmap
- }
- if (fl_mac_os_version < 101401 && window->parent() && window->as_gl_window() && Fl::use_high_res_GL()) {
- Fl_Cocoa_Window_Driver *d = Fl_Cocoa_Window_Driver::driver(window);
- [view layer].contentsScale = d->mapped_to_retina() ? 2. : 1.;
- }
- }
+ if ([view layer]) [view did_view_resolution_change];
#endif
fl_unlock_function();
}
@@ -2181,9 +2173,8 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8
static CGContextRef prepare_bitmap_for_layer(int w, int h ) {
- CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
+ static CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
CGContextRef gc = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, cspace, kCGImageAlphaPremultipliedFirst);
- CGColorSpaceRelease(cspace);
CGContextClearRect(gc, CGRectMake(0,0,w,h));
return gc;
}
@@ -2195,13 +2186,14 @@ static CGContextRef prepare_bitmap_for_layer(int w, int h ) {
- (void)displayLayer:(CALayer *)layer;
- (void)drawRect:(NSRect)rect;
- (BOOL)wantsLayer;
+- (BOOL)did_view_resolution_change;
@end
@implementation FLGLViewLayer
- (void)displayLayer:(CALayer *)layer {
[self drawRect:[self frame]];
}
-- (void)drawRect:(NSRect)rect {
+- (void)drawRect:(NSRect)rect { //runs when layer-backed GL window is created or resized
fl_lock_function();
if (!Fl::use_high_res_GL() && fl_mac_os_version < 101401) [self layer].contentsScale = 1.;
Fl_Window *window = [(FLWindow*)[self window] getFl_Window];
@@ -2223,6 +2215,16 @@ static CGContextRef prepare_bitmap_for_layer(int w, int h ) {
-(BOOL)wantsLayer {
return YES;
}
+- (BOOL)did_view_resolution_change {
+ BOOL retval = [super did_view_resolution_change];
+ if (retval && Fl::use_high_res_GL()) {
+ Fl_Window *window = [(FLWindow*)[self window] getFl_Window];
+ Fl_Cocoa_Window_Driver *d = Fl_Cocoa_Window_Driver::driver(window);
+ [self layer].contentsScale = d->mapped_to_retina() ? 2. : 1.;
+ window->redraw(); // necessary with 10.14.2 public beta 3
+ }
+ return retval;
+}
@end
@@ -2273,7 +2275,14 @@ static CGContextRef prepare_bitmap_for_layer(int w, int h ) {
}
}
}
-
+- (BOOL)did_view_resolution_change {
+ BOOL retval = [super did_view_resolution_change];
+ if (retval) {
+ [self viewFrameDidChange];
+ [self displayLayer:[self layer]]; // useful for Mandelbrot to recreate the layer's bitmap
+ }
+ return retval;
+}
-(void)viewFrameDidChange
{
CGContextRelease(layer_data);