Bug 1384839 - Part1. Extract the generation of fallback data from PushItemAsImage into a helper function to reuse it for mask painting. r=kats

MozReview-Commit-ID: FUP6bZyfalQ

--HG--
extra : rebase_source : fcea78dc934761c1e6517bd11bd3a9233f4405c6
This commit is contained in:
Ethan Lin 2017-07-28 11:30:05 +08:00
parent cbd7e56969
commit 582a02967a
2 changed files with 35 additions and 13 deletions

View File

@ -386,11 +386,12 @@ PaintItemByDrawTarget(nsDisplayItem* aItem,
}
}
bool
WebRenderLayerManager::PushItemAsImage(nsDisplayItem* aItem,
wr::DisplayListBuilder& aBuilder,
const StackingContextHelper& aSc,
nsDisplayListBuilder* aDisplayListBuilder)
already_AddRefed<WebRenderFallbackData>
WebRenderLayerManager::GenerateFallbackData(nsDisplayItem* aItem,
wr::DisplayListBuilder& aBuilder,
nsDisplayListBuilder* aDisplayListBuilder,
LayerRect& aImageRect,
LayerPoint& aOffset)
{
RefPtr<WebRenderFallbackData> fallbackData = CreateOrRecycleWebRenderUserData<WebRenderFallbackData>(aItem);
@ -409,14 +410,13 @@ WebRenderLayerManager::PushItemAsImage(nsDisplayItem* aItem,
PixelCastJustification::WebRenderHasUnitResolution);
LayerIntSize imageSize = RoundedToInt(bounds.Size());
LayerRect imageRect;
imageRect.SizeTo(LayerSize(imageSize));
aImageRect = LayerRect(LayerPoint(0, 0), LayerSize(imageSize));
if (imageSize.width == 0 || imageSize.height == 0) {
return true;
return nullptr;
}
nsPoint shift = clippedBounds.TopLeft() - itemBounds.TopLeft();
LayerPoint offset = ViewAs<LayerPixel>(
aOffset = ViewAs<LayerPixel>(
LayoutDevicePoint::FromAppUnits(aItem->ToReferenceFrame() + shift, appUnitsPerDevPixel),
PixelCastJustification::WebRenderHasUnitResolution);
@ -448,7 +448,7 @@ WebRenderLayerManager::PushItemAsImage(nsDisplayItem* aItem,
RefPtr<gfx::DrawTarget> dummyDt =
gfx::Factory::CreateDrawTarget(gfx::BackendType::SKIA, gfx::IntSize(1, 1), gfx::SurfaceFormat::B8G8R8X8);
RefPtr<gfx::DrawTarget> dt = gfx::Factory::CreateRecordingDrawTarget(recorder, dummyDt, imageSize.ToUnknownSize());
PaintItemByDrawTarget(aItem, dt, imageRect, offset, aDisplayListBuilder);
PaintItemByDrawTarget(aItem, dt, aImageRect, aOffset, aDisplayListBuilder);
recorder->Finish();
wr::ByteBuffer bytes(recorder->mOutputStream.mLength, (uint8_t*)recorder->mOutputStream.mData);
@ -464,10 +464,10 @@ WebRenderLayerManager::PushItemAsImage(nsDisplayItem* aItem,
UpdateImageHelper helper(imageContainer, imageClient, imageSize.ToUnknownSize());
{
RefPtr<gfx::DrawTarget> dt = helper.GetDrawTarget();
PaintItemByDrawTarget(aItem, dt, imageRect, offset, aDisplayListBuilder);
PaintItemByDrawTarget(aItem, dt, aImageRect, aOffset, aDisplayListBuilder);
}
if (!helper.UpdateImage()) {
return false;
return nullptr;
}
}
@ -475,7 +475,7 @@ WebRenderLayerManager::PushItemAsImage(nsDisplayItem* aItem,
// If not force update, fallbackData may reuse the original key because it
// doesn't know UpdateImageHelper already updated the image container.
if (!fallbackData->UpdateImageKey(imageContainer, true)) {
return false;
return nullptr;
}
}
@ -489,6 +489,23 @@ WebRenderLayerManager::PushItemAsImage(nsDisplayItem* aItem,
MOZ_ASSERT(fallbackData->GetKey());
return fallbackData.forget();
}
bool
WebRenderLayerManager::PushItemAsImage(nsDisplayItem* aItem,
wr::DisplayListBuilder& aBuilder,
const StackingContextHelper& aSc,
nsDisplayListBuilder* aDisplayListBuilder)
{
LayerRect imageRect;
LayerPoint offset;
RefPtr<WebRenderFallbackData> fallbackData = GenerateFallbackData(aItem, aBuilder, aDisplayListBuilder,
imageRect, offset);
if (!fallbackData) {
return false;
}
wr::LayoutRect dest = aSc.ToRelativeLayoutRect(imageRect + offset);
aBuilder.PushImage(dest,
dest,

View File

@ -70,6 +70,11 @@ public:
mozilla::wr::DisplayListBuilder& aBuilder,
const StackingContextHelper& aSc,
const LayerRect& aRect);
already_AddRefed<WebRenderFallbackData> GenerateFallbackData(nsDisplayItem* aItem,
wr::DisplayListBuilder& aBuilder,
nsDisplayListBuilder* aDisplayListBuilder,
LayerRect& aImageRect,
LayerPoint& aOffset);
bool PushItemAsImage(nsDisplayItem* aItem,
wr::DisplayListBuilder& aBuilder,
const StackingContextHelper& aSc,