From 95319c238dbb79dee9cfd2aa79fa1c87c394fb15 Mon Sep 17 00:00:00 2001 From: Koji Nakamaru Date: Thu, 15 Oct 2020 01:48:09 +0900 Subject: [PATCH] fixed osx WebView.mm not for avoiding race condition about bitmap. --- plugins/Mac/Sources/WebView.mm | 38 ++++++++++++++++------------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/plugins/Mac/Sources/WebView.mm b/plugins/Mac/Sources/WebView.mm index 865b01c6..76d17acb 100644 --- a/plugins/Mac/Sources/WebView.mm +++ b/plugins/Mac/Sources/WebView.mm @@ -614,37 +614,34 @@ - (void)update:(BOOL)refreshBitmap bytesPerRow:(4 * rect.size.width) bitsPerPixel:32]; // bitmap = [webView bitmapImageRepForCachingDisplayInRect:webView.frame]; + needsDisplay = true; } inRendering = YES; if (window != nil) { memset([bitmap bitmapData], 128, [bitmap bytesPerRow] * [bitmap pixelsHigh]); + needsDisplay = true; inRendering = NO; } else { - NSBitmapImageRep *bmpRep = bitmap; - // memset([bitmap bitmapData], 0, [bitmap bytesPerRow] * [bitmap pixelsHigh]); - // [webView cacheDisplayInRect:webView.frame toBitmapImageRep:bitmap]; - WKWebView *wkv = webView; - WKSnapshotConfiguration *cfg = [WKSnapshotConfiguration new]; - //cfg.snapshotWidth = [NSNumber numberWithLong:[bitmap pixelsWide]]; - //cfg.rect = webView.frame; - [wkv takeSnapshotWithConfiguration:cfg + [webView takeSnapshotWithConfiguration:[WKSnapshotConfiguration new] completionHandler:^(NSImage *nsImg, NSError *err) { - if (err == nil) { - NSGraphicsContext *ctx = [NSGraphicsContext graphicsContextWithBitmapImageRep:bmpRep]; - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:ctx]; - [nsImg drawAtPoint:CGPointZero - fromRect:CGRectMake(0, 0, [bmpRep pixelsWide], [bmpRep pixelsHigh]) - operation:NSCompositingOperationCopy - fraction:1.0]; - [[NSGraphicsContext currentContext] flushGraphics]; - [NSGraphicsContext restoreGraphicsState]; + @synchronized(self) { + if (err == nil) { + NSGraphicsContext *ctx = [NSGraphicsContext graphicsContextWithBitmapImageRep:self->bitmap]; + [NSGraphicsContext saveGraphicsState]; + [NSGraphicsContext setCurrentContext:ctx]; + [nsImg drawAtPoint:CGPointZero + fromRect:CGRectMake(0, 0, [self->bitmap pixelsWide], [self->bitmap pixelsHigh]) + operation:NSCompositingOperationCopy + fraction:1.0]; + [[NSGraphicsContext currentContext] flushGraphics]; + [NSGraphicsContext restoreGraphicsState]; + } + self->needsDisplay = true; + self->inRendering = NO; } - self->inRendering = NO; }]; } } - needsDisplay = refreshBitmap; } } @@ -698,6 +695,7 @@ - (void)render glPixelStorei(GL_UNPACK_ROW_LENGTH, rowLength); glPixelStorei(GL_UNPACK_ALIGNMENT, unpackAlign); } + needsDisplay = false; } }