From 7b029c48bfbde523aa60b56bcf607b1cb8b739b3 Mon Sep 17 00:00:00 2001 From: Roger Luo Date: Sun, 11 Jul 2021 13:37:36 +0800 Subject: [PATCH] fix UI call from background in main thread check --- framework/Source/Apple/RenderView-Cocoa.swift | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/framework/Source/Apple/RenderView-Cocoa.swift b/framework/Source/Apple/RenderView-Cocoa.swift index 81f4d475..90edbb6b 100755 --- a/framework/Source/Apple/RenderView-Cocoa.swift +++ b/framework/Source/Apple/RenderView-Cocoa.swift @@ -18,20 +18,23 @@ public class RenderView:NSOpenGLView, ImageConsumer { // TODO: Need to set viewport to appropriate size, resize viewport on view reshape public func newFramebufferAvailable(_ framebuffer:Framebuffer, fromSourceIndex:UInt) { - glBindFramebuffer(GLenum(GL_FRAMEBUFFER), 0) - glBindRenderbuffer(GLenum(GL_RENDERBUFFER), 0) + DispatchQueue.main.async { [self] in + glBindFramebuffer(GLenum(GL_FRAMEBUFFER), 0) + glBindRenderbuffer(GLenum(GL_RENDERBUFFER), 0) - let viewSize = GLSize(width:GLint(round(self.bounds.size.width)), height:GLint(round(self.bounds.size.height))) - glViewport(0, 0, viewSize.width, viewSize.height) + let viewSize = GLSize(width:GLint(round(self.bounds.size.width)), height:GLint(round(self.bounds.size.height))) + glViewport(0, 0, viewSize.width, viewSize.height) - clearFramebufferWithColor(backgroundColor) + clearFramebufferWithColor(backgroundColor) + + // TODO: Cache these scaled vertices + let scaledVertices = fillMode.transformVertices(verticallyInvertedImageVertices, fromInputSize:framebuffer.sizeForTargetOrientation(.portrait), toFitSize:viewSize) + renderQuadWithShader(self.displayShader, vertices:scaledVertices, inputTextures:[framebuffer.texturePropertiesForTargetOrientation(.portrait)]) + sharedImageProcessingContext.presentBufferForDisplay() + + framebuffer.unlock() + } - // TODO: Cache these scaled vertices - let scaledVertices = fillMode.transformVertices(verticallyInvertedImageVertices, fromInputSize:framebuffer.sizeForTargetOrientation(.portrait), toFitSize:viewSize) - renderQuadWithShader(self.displayShader, vertices:scaledVertices, inputTextures:[framebuffer.texturePropertiesForTargetOrientation(.portrait)]) - sharedImageProcessingContext.presentBufferForDisplay() - - framebuffer.unlock() } }