Bug 1364830 - Fix background image layer's draw result and image flags. r=mattwoodrow

This commit is contained in:
Ethan Lin 2017-05-16 10:44:49 +08:00
parent 7ae24a697f
commit e853c9b0a6
4 changed files with 26 additions and 23 deletions

View File

@ -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

View File

@ -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 =

View File

@ -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 {

View File

@ -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<wr::ImageKey> key = aLayer->SendImageContainer(container, aParentCommands);
if (key.isNothing()) {