Skip to content

Commit

Permalink
bugfix: #16
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuoshi-inagora committed Dec 24, 2020
1 parent e011685 commit 27fbb35
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
54 changes: 33 additions & 21 deletions Mac/GraphicsElement/CoreGraphics/GuiGraphicsCoreGraphics.mm
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,39 @@ - (void)viewDidChangeBackingProperties
[self resize:self.frame.size];
}

- (void)resize:(CGSize)size
- (CGLayerRef)copyLayer:(CGLayerRef *)layer size:(CGSize)newSize
{
if(_drawingLayer)
CGLayerRelease(_drawingLayer);

if(_context)
CGContextRelease(_context);
CGSize size = CGLayerGetSize(*layer);
CGContextRef context = CGBitmapContextCreate(0, newSize.width, newSize.height, 8, 0, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
CGContextSetShouldAntialias(context, true);
CGContextSetShouldSmoothFonts(context, true);
CGLayerRef copyLayer = CGLayerCreateWithContext(context, newSize, NULL);
CGContextRef copyContext = CGLayerGetContext(copyLayer);
//CGContextDrawLayerInRect(copyContext, CGRectMake(0, 0, newSize.width, newSize.height), *layer);
CGContextDrawLayerInRect(copyContext, CGRectMake(0, 0, size.width, size.height), *layer);
CGContextRelease(context);
CGLayerRelease(*layer);
return copyLayer;
}

- (void)resize:(CGSize)size
{
size.width *= [[self window] backingScaleFactor];
size.height *= [[self window] backingScaleFactor];

_context = CGBitmapContextCreate(0, size.width, size.height, 8, 0, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
if(_context)
if (_drawingLayer)
{
CGContextSetShouldAntialias(_context, true);
CGContextSetShouldSmoothFonts(_context, true);
_drawingLayer = CGLayerCreateWithContext(_context, size, NULL);
_drawingLayer = [self copyLayer:&_drawingLayer size:size];
assert(_drawingLayer);
}
else
{
_context = CGBitmapContextCreate(0, size.width, size.height, 8, 0, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
if (_context)
{
_drawingLayer = CGLayerCreateWithContext(_context, size, NULL);
assert(_drawingLayer);
}
}
}

- (void)drawRect:(NSRect)dirtyRect
Expand Down Expand Up @@ -343,7 +357,6 @@ void Moved()

void Paint()
{

}

CoreGraphicsView* GetCoreGraphicsView() const
Expand Down Expand Up @@ -446,6 +459,9 @@ void SetCoreGraphicsObjectProvider(ICoreGrpahicsObjectProvider* provider)

void StartRendering()
{
auto listener = GetNativeWindowListener(window);
listener->StartRendering();

CGContextRef context = (CGContextRef)GetCGContext();
if(!context)
return;
Expand All @@ -462,23 +478,19 @@ void StartRendering()
// just putting it here for now
CGContextTranslateCTM(context, 0, nativeView.frame.size.height * nativeView.window.backingScaleFactor);
CGContextScaleCTM(context, 1.0f * nativeView.window.backingScaleFactor, -1.0f * nativeView.window.backingScaleFactor);

auto listener = GetNativeWindowListener(window);
listener->StartRendering();
}

RenderTargetFailure StopRendering()
{
auto listener = GetNativeWindowListener(window);
listener->StopRendering();
bool moved = listener->RetrieveAndResetMovedWhileRendering();

CGContextRef context = (CGContextRef)GetCGContext();
if (context) {
auto listener = GetNativeWindowListener(window);
listener->StopRendering();

CGContextRestoreGState(context);
[NSGraphicsContext restoreGraphicsState];
SetCurrentRenderTarget(0);

bool moved = listener->RetrieveAndResetMovedWhileRendering();
return !moved ? RenderTargetFailure::None : RenderTargetFailure::ResizeWhileRendering;;
}
return RenderTargetFailure::LostDevice;
Expand Down
1 change: 0 additions & 1 deletion Mac/NativeWindow/OSX/CocoaWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,6 @@ - (void)windowWillClose:(NSNotification *)notification
- (void)windowDidResize:(NSNotification *)notification
{
(dynamic_cast<osx::CocoaWindow*>(_nativeWindow))->InvokeMoved();

}

@end

0 comments on commit 27fbb35

Please sign in to comment.