From e853c9b0a63ed250c1982bf9672e585223d31ad2 Mon Sep 17 00:00:00 2001 From: Ethan Lin Date: Tue, 16 May 2017 10:44:49 +0800 Subject: [PATCH] Bug 1364830 - Fix background image layer's draw result and image flags. r=mattwoodrow --- layout/painting/nsCSSRendering.cpp | 9 +++---- layout/painting/nsDisplayList.cpp | 37 +++++++++++++++-------------- layout/painting/nsDisplayList.h | 1 + layout/painting/nsImageRenderer.cpp | 2 +- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/layout/painting/nsCSSRendering.cpp b/layout/painting/nsCSSRendering.cpp index bfb8e1331f06..840e0b2cfd8d 100644 --- a/layout/painting/nsCSSRendering.cpp +++ b/layout/painting/nsCSSRendering.cpp @@ -2006,12 +2006,12 @@ nsCSSRendering::BuildWebRenderDisplayItemsForStyleImageLayer(const PaintBGParams // draw the background. The canvas really should be drawing the // bg, but there's no way to hook that up via css. if (!aParams.frame->StyleDisplay()->UsedAppearance()) { - return DrawResult::NOT_READY; + return DrawResult::SUCCESS; } nsIContent* content = aParams.frame->GetContent(); if (!content || content->GetParent()) { - return DrawResult::NOT_READY; + return DrawResult::SUCCESS; } sc = aParams.frame->StyleContext(); @@ -2777,11 +2777,12 @@ nsCSSRendering::BuildWebRenderDisplayItemsForStyleImageLayerWithSC(const PaintBG return DrawResult::SUCCESS; } + DrawResult result = DrawResult::SUCCESS; nsBackgroundLayerState state = PrepareImageLayer(&aParams.presCtx, aParams.frame, aParams.paintFlags, paintBorderArea, clipState.mBGClipArea, layer, nullptr); - + result &= state.mImageRenderer.PrepareResult(); if (!state.mFillArea.IsEmpty()) { return state.mImageRenderer.BuildWebRenderDisplayItemsForLayer(&aParams.presCtx, aBuilder, aSc, aParentCommands, aLayer, @@ -2791,7 +2792,7 @@ nsCSSRendering::BuildWebRenderDisplayItemsForStyleImageLayerWithSC(const PaintBG state.mRepeatSize, aParams.opacity); } - return DrawResult::SUCCESS; + return result; } nsRect diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index 79beded902d7..3bde58eec95c 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -2983,6 +2983,7 @@ nsDisplayBackgroundImage::nsDisplayBackgroundImage(const InitData& aInitData) , mLayer(aInitData.layer) , mIsRasterImage(aInitData.isRasterImage) , mShouldFixToViewport(aInitData.shouldFixToViewport) + , mImageFlags(0) { MOZ_COUNT_CTOR(nsDisplayBackgroundImage); @@ -3411,11 +3412,27 @@ nsDisplayBackgroundImage::ShouldCreateOwnLayer(nsDisplayListBuilder* aBuilder, return NO_LAYER_NEEDED; } +static void CheckForBorderItem(nsDisplayItem *aItem, uint32_t& aFlags) +{ + nsDisplayItem* nextItem = aItem->GetAbove(); + while (nextItem && nextItem->GetType() == nsDisplayItem::TYPE_BACKGROUND) { + nextItem = nextItem->GetAbove(); + } + if (nextItem && + nextItem->Frame() == aItem->Frame() && + nextItem->GetType() == nsDisplayItem::TYPE_BORDER) { + aFlags |= nsCSSRendering::PAINTBG_WILL_PAINT_BORDER; + } +} + LayerState nsDisplayBackgroundImage::GetLayerState(nsDisplayListBuilder* aBuilder, LayerManager* aManager, const ContainerLayerParameters& aParameters) { + mImageFlags = aBuilder->GetBackgroundPaintFlags(); + CheckForBorderItem(this, mImageFlags); + if (ShouldUseAdvancedLayer(aManager, gfxPrefs::LayersAllowBackgroundImage) && CanBuildWebRenderDisplayItems(aManager)) { return LAYER_ACTIVE; @@ -3505,7 +3522,7 @@ nsDisplayBackgroundImage::CreateWebRenderCommands(wr::DisplayListBuilder& aBuild nsCSSRendering::PaintBGParams params = nsCSSRendering::PaintBGParams::ForSingleLayer(*StyleFrame()->PresContext(), mVisibleRect, mBackgroundRect, - StyleFrame(), 0, mLayer, + StyleFrame(), mImageFlags, mLayer, CompositionOp::OP_OVER); params.bgClipRect = &mBounds; @@ -3644,19 +3661,6 @@ nsDisplayBackgroundImage::RenderingMightDependOnPositioningAreaSizeChange() return false; } -static void CheckForBorderItem(nsDisplayItem *aItem, uint32_t& aFlags) -{ - nsDisplayItem* nextItem = aItem->GetAbove(); - while (nextItem && nextItem->GetType() == nsDisplayItem::TYPE_BACKGROUND) { - nextItem = nextItem->GetAbove(); - } - if (nextItem && - nextItem->Frame() == aItem->Frame() && - nextItem->GetType() == nsDisplayItem::TYPE_BORDER) { - aFlags |= nsCSSRendering::PAINTBG_WILL_PAINT_BORDER; - } -} - void nsDisplayBackgroundImage::Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) { @@ -3667,9 +3671,6 @@ void nsDisplayBackgroundImage::PaintInternal(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx, const nsRect& aBounds, nsRect* aClipRect) { - uint32_t flags = aBuilder->GetBackgroundPaintFlags(); - CheckForBorderItem(this, flags); - gfxContext* ctx = aCtx->ThebesContext(); StyleGeometryBox clip = mBackgroundStyle->mImage.mLayers[mLayer].mClip; @@ -3682,7 +3683,7 @@ nsDisplayBackgroundImage::PaintInternal(nsDisplayListBuilder* aBuilder, nsCSSRendering::PaintBGParams params = nsCSSRendering::PaintBGParams::ForSingleLayer(*StyleFrame()->PresContext(), aBounds, mBackgroundRect, - StyleFrame(), flags, mLayer, + StyleFrame(), mImageFlags, mLayer, CompositionOp::OP_OVER); params.bgClipRect = aClipRect; image::DrawResult result = diff --git a/layout/painting/nsDisplayList.h b/layout/painting/nsDisplayList.h index be20f98fa6f0..7cbf09903667 100644 --- a/layout/painting/nsDisplayList.h +++ b/layout/painting/nsDisplayList.h @@ -3197,6 +3197,7 @@ protected: bool mIsRasterImage; /* Whether the image should be treated as fixed to the viewport. */ bool mShouldFixToViewport; + uint32_t mImageFlags; }; enum class TableType : uint8_t { diff --git a/layout/painting/nsImageRenderer.cpp b/layout/painting/nsImageRenderer.cpp index b235dbdfa68f..da62f2ed1760 100644 --- a/layout/painting/nsImageRenderer.cpp +++ b/layout/painting/nsImageRenderer.cpp @@ -615,7 +615,7 @@ nsImageRenderer::BuildWebRenderDisplayItems(nsPresContext* aPresContext, ConvertImageRendererToDrawFlags(mFlags)); if (!container) { NS_WARNING("Failed to get image container"); - return DrawResult::BAD_IMAGE; + return DrawResult::NOT_READY; } Maybe key = aLayer->SendImageContainer(container, aParentCommands); if (key.isNothing()) {