From 77ddedaacb18360361381cabe2f14befce369522 Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Mon, 22 Apr 2019 19:41:58 +0000 Subject: [PATCH] Bug 1542454 - Factor out some code. r=spohl Differential Revision: https://phabricator.services.mozilla.com/D26402 --HG-- extra : moz-landing-system : lando --- widget/cocoa/nsChildView.h | 2 ++ widget/cocoa/nsChildView.mm | 51 +++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index 0b41effb9472..33bcd5f541b7 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -440,6 +440,8 @@ class nsChildView final : public nsBaseWidget { void WillPaintWindow(); bool PaintWindow(LayoutDeviceIntRegion aRegion); + bool PaintWindowInDrawTarget(mozilla::gfx::DrawTarget* aDT, const LayoutDeviceIntRegion& aRegion, + const mozilla::gfx::IntSize& aSurfaceSize); bool PaintWindowInContext(CGContextRef aContext, const LayoutDeviceIntRegion& aRegion, mozilla::gfx::IntSize aSurfaceSize); diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 4ef0049bcd17..98d69dfa77d2 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -1309,6 +1309,34 @@ bool nsChildView::PaintWindow(LayoutDeviceIntRegion aRegion) { return returnValue; } +bool nsChildView::PaintWindowInDrawTarget(gfx::DrawTarget* aDT, + const LayoutDeviceIntRegion& aRegion, + const gfx::IntSize& aSurfaceSize) { + RefPtr targetContext = gfxContext::CreateOrNull(aDT); + MOZ_ASSERT(targetContext); + + // Set up the clip region and clear existing contents in the backing surface. + targetContext->NewPath(); + for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) { + const LayoutDeviceIntRect& r = iter.Get(); + targetContext->Rectangle(gfxRect(r.x, r.y, r.width, r.height)); + aDT->ClearRect(gfx::Rect(r.ToUnknownRect())); + } + targetContext->Clip(); + + nsAutoRetainCocoaObject kungFuDeathGrip(mView); + if (GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_BASIC) { + nsBaseWidget::AutoLayerManagerSetup setupLayerManager(this, targetContext, + BufferMode::BUFFER_NONE); + return PaintWindow(aRegion); + } + if (GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_CLIENT) { + // We only need this so that we actually get DidPaintWindow fired + return PaintWindow(aRegion); + } + return false; +} + bool nsChildView::PaintWindowInContext(CGContextRef aContext, const LayoutDeviceIntRegion& aRegion, gfx::IntSize aSurfaceSize) { if (!mBackingSurface || mBackingSurface->GetSize() != aSurfaceSize) { @@ -1319,28 +1347,7 @@ bool nsChildView::PaintWindowInContext(CGContextRef aContext, const LayoutDevice } } - RefPtr targetContext = gfxContext::CreateOrNull(mBackingSurface); - MOZ_ASSERT(targetContext); // already checked the draw target above - - // Set up the clip region and clear existing contents in the backing surface. - targetContext->NewPath(); - for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) { - const LayoutDeviceIntRect& r = iter.Get(); - targetContext->Rectangle(gfxRect(r.x, r.y, r.width, r.height)); - mBackingSurface->ClearRect(gfx::Rect(r.ToUnknownRect())); - } - targetContext->Clip(); - - nsAutoRetainCocoaObject kungFuDeathGrip(mView); - bool painted = false; - if (GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_BASIC) { - nsBaseWidget::AutoLayerManagerSetup setupLayerManager(this, targetContext, - BufferMode::BUFFER_NONE); - painted = PaintWindow(aRegion); - } else if (GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_CLIENT) { - // We only need this so that we actually get DidPaintWindow fired - painted = PaintWindow(aRegion); - } + bool painted = PaintWindowInDrawTarget(mBackingSurface, aRegion, aSurfaceSize); uint8_t* data; gfx::IntSize size;