macOS: Don't use offscreen rendering.
Since Catalina or earlier this no longer causes artifacts when Cocoa controls are overlaid on a GL layer. Conversely, offscreen rendering is very slow, especially on HiDPI screens. Co-Authored-By: Koen Schmeets <hello@koenschmeets.nl>pull/507/head
parent
e386d405d6
commit
9b61f988be
|
@ -344,7 +344,7 @@ MenuBarRef GetOrCreateMainMenu(bool *unique) {
|
||||||
// Cocoa NSView and NSWindow extensions
|
// Cocoa NSView and NSWindow extensions
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
@interface SSView : NSView
|
@interface SSView : NSOpenGLView
|
||||||
@property Platform::Window *receiver;
|
@property Platform::Window *receiver;
|
||||||
|
|
||||||
@property BOOL acceptsFirstResponder;
|
@property BOOL acceptsFirstResponder;
|
||||||
|
@ -362,8 +362,6 @@ MenuBarRef GetOrCreateMainMenu(bool *unique) {
|
||||||
|
|
||||||
@implementation SSView
|
@implementation SSView
|
||||||
{
|
{
|
||||||
GlOffscreen offscreen;
|
|
||||||
NSOpenGLContext *glContext;
|
|
||||||
NSTrackingArea *trackingArea;
|
NSTrackingArea *trackingArea;
|
||||||
NSTextField *editor;
|
NSTextField *editor;
|
||||||
}
|
}
|
||||||
|
@ -371,17 +369,15 @@ MenuBarRef GetOrCreateMainMenu(bool *unique) {
|
||||||
@synthesize acceptsFirstResponder;
|
@synthesize acceptsFirstResponder;
|
||||||
|
|
||||||
- (id)initWithFrame:(NSRect)frameRect {
|
- (id)initWithFrame:(NSRect)frameRect {
|
||||||
if(self = [super initWithFrame:frameRect]) {
|
|
||||||
self.wantsLayer = YES;
|
|
||||||
|
|
||||||
NSOpenGLPixelFormatAttribute attrs[] = {
|
NSOpenGLPixelFormatAttribute attrs[] = {
|
||||||
NSOpenGLPFAColorSize, 24,
|
NSOpenGLPFAColorSize, 24,
|
||||||
NSOpenGLPFADepthSize, 24,
|
NSOpenGLPFADepthSize, 24,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
|
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
|
||||||
glContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:NULL];
|
if(self = [super initWithFrame:frameRect pixelFormat:pixelFormat]) {
|
||||||
|
self.wantsBestResolutionOpenGLSurface = YES;
|
||||||
|
self.wantsLayer = YES;
|
||||||
editor = [[NSTextField alloc] init];
|
editor = [[NSTextField alloc] init];
|
||||||
editor.editable = YES;
|
editor.editable = YES;
|
||||||
[[editor cell] setWraps:NO];
|
[[editor cell] setWraps:NO];
|
||||||
|
@ -394,7 +390,6 @@ MenuBarRef GetOrCreateMainMenu(bool *unique) {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
offscreen.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isFlipped {
|
- (BOOL)isFlipped {
|
||||||
|
@ -404,29 +399,11 @@ MenuBarRef GetOrCreateMainMenu(bool *unique) {
|
||||||
@synthesize receiver;
|
@synthesize receiver;
|
||||||
|
|
||||||
- (void)drawRect:(NSRect)aRect {
|
- (void)drawRect:(NSRect)aRect {
|
||||||
[glContext makeCurrentContext];
|
[[self openGLContext] makeCurrentContext];
|
||||||
|
|
||||||
NSSize size = [self convertSizeToBacking:self.bounds.size];
|
|
||||||
int width = (int)size.width,
|
|
||||||
height = (int)size.height;
|
|
||||||
offscreen.Render(width, height, [&] {
|
|
||||||
if(receiver->onRender) {
|
if(receiver->onRender) {
|
||||||
receiver->onRender();
|
receiver->onRender();
|
||||||
}
|
}
|
||||||
});
|
[[self openGLContext] flushBuffer];
|
||||||
|
|
||||||
CGDataProviderRef provider = CGDataProviderCreateWithData(
|
|
||||||
NULL, &offscreen.data[0], width * height * 4, NULL);
|
|
||||||
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
|
|
||||||
CGImageRef image = CGImageCreate(width, height, 8, 32,
|
|
||||||
width * 4, colorspace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst,
|
|
||||||
provider, NULL, true, kCGRenderingIntentDefault);
|
|
||||||
|
|
||||||
CGContextDrawImage((CGContextRef) [[NSGraphicsContext currentContext] CGContext],
|
|
||||||
[self bounds], image);
|
|
||||||
|
|
||||||
CGImageRelease(image);
|
|
||||||
CGDataProviderRelease(provider);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)acceptsFirstMouse:(NSEvent *)event {
|
- (BOOL)acceptsFirstMouse:(NSEvent *)event {
|
||||||
|
@ -892,7 +869,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetContentSize(double *width, double *height) override {
|
void GetContentSize(double *width, double *height) override {
|
||||||
NSSize nsSize = [ssView frame].size;
|
NSSize nsSize = ssView.frame.size;
|
||||||
*width = nsSize.width;
|
*width = nsSize.width;
|
||||||
*height = nsSize.height;
|
*height = nsSize.height;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue