From a31d080fc67db9fb022050a446f08a95a737edff Mon Sep 17 00:00:00 2001 From: Tor Arvid Lund Date: Wed, 12 Feb 2014 10:07:47 -0500 Subject: [PATCH] Bug 948765 - Implement BasicImageLayer::Paint. r=nical --- gfx/layers/basic/BasicImageLayer.cpp | 87 +++++++++++++++++++++++----- gfx/layers/basic/BasicLayers.h | 7 --- 2 files changed, 71 insertions(+), 23 deletions(-) diff --git a/gfx/layers/basic/BasicImageLayer.cpp b/gfx/layers/basic/BasicImageLayer.cpp index b2188c842cf..9e0074f80bb 100644 --- a/gfx/layers/basic/BasicImageLayer.cpp +++ b/gfx/layers/basic/BasicImageLayer.cpp @@ -65,33 +65,88 @@ protected: } // only paints the image if aContext is non-null - already_AddRefed - GetAndPaintCurrentImage(gfxContext* aContext, + void + GetAndPaintCurrentImage(DrawTarget* aTarget, float aOpacity, - Layer* aMaskLayer); + SourceSurface* aMaskSurface); + already_AddRefed + DeprecatedGetAndPaintCurrentImage(gfxContext* aContext, + float aOpacity, + Layer* aMaskLayer); gfx::IntSize mSize; }; +static void +DeprecatedPaintContext(gfxPattern* aPattern, + const nsIntRegion& aVisible, + float aOpacity, + gfxContext* aContext, + Layer* aMaskLayer); + void BasicImageLayer::Paint(DrawTarget* aTarget, SourceSurface* aMaskSurface) { - DeprecatedPaint(new gfxContext(aTarget), nullptr); //TODO: null->aMaskSurface + if (IsHidden()) { + return; + } + GetAndPaintCurrentImage(aTarget, GetEffectiveOpacity(), aMaskSurface); } void BasicImageLayer::DeprecatedPaint(gfxContext* aContext, Layer* aMaskLayer) { - if (IsHidden()) + if (IsHidden()) { return; + } nsRefPtr dontcare = - GetAndPaintCurrentImage(aContext, GetEffectiveOpacity(), aMaskLayer); + DeprecatedGetAndPaintCurrentImage(aContext, + GetEffectiveOpacity(), + aMaskLayer); +} + +void +BasicImageLayer::GetAndPaintCurrentImage(DrawTarget* aTarget, + float aOpacity, + SourceSurface* aMaskSurface) +{ + if (!mContainer) { + return; + } + + mContainer->SetImageFactory(mManager->IsCompositingCheap() ? + nullptr : + BasicManager()->GetImageFactory()); + IntSize size; + Image* image = nullptr; + RefPtr surf = + mContainer->LockCurrentAsSourceSurface(&size, &image); + + if (!surf) { + return; + } + + if (aTarget) { + // The visible region can extend outside the image, so just draw + // within the image bounds. + SurfacePattern pat(surf, ExtendMode::CLAMP, Matrix(), ToFilter(mFilter)); + CompositionOp mixBlendMode = GetEffectiveMixBlendMode(); + CompositionOp op = + mixBlendMode != CompositionOp::OP_OVER ? mixBlendMode : GetOperator(); + DrawOptions opts(aOpacity, op); + + aTarget->MaskSurface(pat, aMaskSurface, Point(0, 0), opts); + + GetContainer()->NotifyPaintedImage(image); + } + + mContainer->UnlockCurrentImage(); } already_AddRefed -BasicImageLayer::GetAndPaintCurrentImage(gfxContext* aContext, - float aOpacity, - Layer* aMaskLayer) +BasicImageLayer::DeprecatedGetAndPaintCurrentImage(gfxContext* aContext, + float aOpacity, + Layer* aMaskLayer) { if (!mContainer) return nullptr; @@ -122,7 +177,7 @@ BasicImageLayer::GetAndPaintCurrentImage(gfxContext* aContext, mixBlendMode != CompositionOp::OP_OVER ? mixBlendMode : GetOperator(); AutoSetOperator setOptimizedOperator(aContext, ThebesOp(op)); - PaintContext(pat, + DeprecatedPaintContext(pat, nsIntRegion(nsIntRect(0, 0, size.width, size.height)), aOpacity, aContext, aMaskLayer); @@ -132,12 +187,12 @@ BasicImageLayer::GetAndPaintCurrentImage(gfxContext* aContext, return pat.forget(); } -void -PaintContext(gfxPattern* aPattern, - const nsIntRegion& aVisible, - float aOpacity, - gfxContext* aContext, - Layer* aMaskLayer) +static void +DeprecatedPaintContext(gfxPattern* aPattern, + const nsIntRegion& aVisible, + float aOpacity, + gfxContext* aContext, + Layer* aMaskLayer) { // Set PAD mode so that when the video is being scaled, we do not sample // outside the bounds of the video image. diff --git a/gfx/layers/basic/BasicLayers.h b/gfx/layers/basic/BasicLayers.h index b52ea4367b7..6101c0a7cca 100644 --- a/gfx/layers/basic/BasicLayers.h +++ b/gfx/layers/basic/BasicLayers.h @@ -197,13 +197,6 @@ protected: bool mCompositorMightResample; }; -void -PaintContext(gfxPattern* aPattern, - const nsIntRegion& aVisible, - float aOpacity, - gfxContext* aContext, - Layer* aMaskLayer); - } }