From be01b218cc3a2caefc6c7221965be9d28b8856b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Winnem=C3=B6ller?= Date: Fri, 7 Sep 2018 22:28:41 +0200 Subject: [PATCH] Bug 1488555 - Use ImageRendering property to provide proper filtering support for AsyncImage. r=nical Introduce an ImageRendering argument for CreateImageKey which is then used at the CreateAsyncImageWebRenderCommands call to provide the proper filtering instead of using always Auto filtering. Update all calls to CreateImageKey to use the new interface. --- gfx/layers/wr/WebRenderCommandBuilder.cpp | 13 +++++++------ gfx/layers/wr/WebRenderCommandBuilder.h | 1 + layout/generic/nsBulletFrame.cpp | 6 ++++-- layout/painting/nsCSSRenderingBorders.cpp | 13 +++++++++++-- layout/painting/nsImageRenderer.cpp | 17 ++++++++++++----- layout/xul/nsImageBoxFrame.cpp | 18 +++++++++++------- 6 files changed, 46 insertions(+), 22 deletions(-) diff --git a/gfx/layers/wr/WebRenderCommandBuilder.cpp b/gfx/layers/wr/WebRenderCommandBuilder.cpp index 155b4054fe80..61d362a3667c 100644 --- a/gfx/layers/wr/WebRenderCommandBuilder.cpp +++ b/gfx/layers/wr/WebRenderCommandBuilder.cpp @@ -1503,6 +1503,7 @@ WebRenderCommandBuilder::CreateImageKey(nsDisplayItem* aItem, ImageContainer* aContainer, mozilla::wr::DisplayListBuilder& aBuilder, mozilla::wr::IpcResourceUpdateQueue& aResources, + mozilla::wr::ImageRendering aRendering, const StackingContextHelper& aSc, gfx::IntSize& aSize, const Maybe& aAsyncImageBounds) @@ -1530,7 +1531,7 @@ WebRenderCommandBuilder::CreateImageKey(nsDisplayItem* aItem, scBounds, transform, scaleToSize, - wr::ImageRendering::Auto, + aRendering, wr::MixBlendMode::Normal, !aItem->BackfaceIsHidden()); return Nothing(); @@ -1554,10 +1555,11 @@ WebRenderCommandBuilder::PushImage(nsDisplayItem* aItem, const StackingContextHelper& aSc, const LayoutDeviceRect& aRect) { + mozilla::wr::ImageRendering rendering = wr::ToImageRendering( + nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame())); gfx::IntSize size; - Maybe key = CreateImageKey(aItem, aContainer, - aBuilder, aResources, - aSc, size, Some(aRect)); + Maybe key = CreateImageKey( + aItem, aContainer, aBuilder, aResources, rendering, aSc, size, Some(aRect)); if (aContainer->IsAsync()) { // Async ImageContainer does not create ImageKey, instead it uses Pipeline. MOZ_ASSERT(key.isNothing()); @@ -1568,8 +1570,7 @@ WebRenderCommandBuilder::PushImage(nsDisplayItem* aItem, } auto r = wr::ToRoundedLayoutRect(aRect); - gfx::SamplingFilter sampleFilter = nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame()); - aBuilder.PushImage(r, r, !aItem->BackfaceIsHidden(), wr::ToImageRendering(sampleFilter), key.value()); + aBuilder.PushImage(r, r, !aItem->BackfaceIsHidden(), rendering, key.value()); return true; } diff --git a/gfx/layers/wr/WebRenderCommandBuilder.h b/gfx/layers/wr/WebRenderCommandBuilder.h index 8fb555d44cbd..bf893dd8bb5d 100644 --- a/gfx/layers/wr/WebRenderCommandBuilder.h +++ b/gfx/layers/wr/WebRenderCommandBuilder.h @@ -65,6 +65,7 @@ public: ImageContainer* aContainer, mozilla::wr::DisplayListBuilder& aBuilder, mozilla::wr::IpcResourceUpdateQueue& aResources, + mozilla::wr::ImageRendering aRendering, const StackingContextHelper& aSc, gfx::IntSize& aSize, const Maybe& aAsyncImageBounds); diff --git a/layout/generic/nsBulletFrame.cpp b/layout/generic/nsBulletFrame.cpp index c0503f2a23de..6e0392c36599 100644 --- a/layout/generic/nsBulletFrame.cpp +++ b/layout/generic/nsBulletFrame.cpp @@ -485,9 +485,11 @@ BulletRenderer::CreateWebRenderCommandsForImage(nsDisplayItem* aItem, return false; } + mozilla::wr::ImageRendering rendering = wr::ToImageRendering( + nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame())); gfx::IntSize size; - Maybe key = aManager->CommandBuilder().CreateImageKey(aItem, container, aBuilder, aResources, - aSc, size, Nothing()); + Maybe key = aManager->CommandBuilder().CreateImageKey( + aItem, container, aBuilder, aResources, rendering, aSc, size, Nothing()); if (key.isNothing()) { return true; // Nothing to do } diff --git a/layout/painting/nsCSSRenderingBorders.cpp b/layout/painting/nsCSSRenderingBorders.cpp index 8f5d2fdecb00..05e29e147e6b 100644 --- a/layout/painting/nsCSSRenderingBorders.cpp +++ b/layout/painting/nsCSSRenderingBorders.cpp @@ -3859,9 +3859,18 @@ nsCSSBorderImageRenderer::CreateWebRenderCommands( return; } + mozilla::wr::ImageRendering rendering = wr::ToImageRendering( + nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame())); gfx::IntSize size; - Maybe key = aManager->CommandBuilder().CreateImageKey( - aItem, container, aBuilder, aResources, aSc, size, Nothing()); + Maybe key = + aManager->CommandBuilder().CreateImageKey(aItem, + container, + aBuilder, + aResources, + rendering, + aSc, + size, + Nothing()); if (key.isNothing()) { return; } diff --git a/layout/painting/nsImageRenderer.cpp b/layout/painting/nsImageRenderer.cpp index 6792e295704c..d8dba7890786 100644 --- a/layout/painting/nsImageRenderer.cpp +++ b/layout/painting/nsImageRenderer.cpp @@ -649,9 +649,18 @@ nsImageRenderer::BuildWebRenderDisplayItems( return ImgDrawResult::NOT_READY; } + mozilla::wr::ImageRendering rendering = wr::ToImageRendering( + nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame())); gfx::IntSize size; - Maybe key = aManager->CommandBuilder().CreateImageKey( - aItem, container, aBuilder, aResources, aSc, size, Nothing()); + Maybe key = + aManager->CommandBuilder().CreateImageKey(aItem, + container, + aBuilder, + aResources, + rendering, + aSc, + size, + Nothing()); if (key.isNothing()) { return ImgDrawResult::NOT_READY; @@ -672,14 +681,12 @@ nsImageRenderer::BuildWebRenderDisplayItems( LayoutDeviceSize gapSize = LayoutDeviceSize::FromAppUnits( aRepeatSize - aDest.Size(), appUnitsPerDevPixel); - SamplingFilter samplingFilter = - nsLayoutUtils::GetSamplingFilterForFrame(mForFrame); aBuilder.PushImage(fill, clip, !aItem->BackfaceIsHidden(), wr::ToLayoutSize(destRect.Size()), wr::ToLayoutSize(gapSize), - wr::ToImageRendering(samplingFilter), + rendering, key.value()); break; } diff --git a/layout/xul/nsImageBoxFrame.cpp b/layout/xul/nsImageBoxFrame.cpp index 8b5a093296d6..9e970df32533 100644 --- a/layout/xul/nsImageBoxFrame.cpp +++ b/layout/xul/nsImageBoxFrame.cpp @@ -459,20 +459,24 @@ nsImageBoxFrame::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuild return Nothing(); } + mozilla::wr::ImageRendering rendering = wr::ToImageRendering( + nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame())); gfx::IntSize size; - Maybe key = aManager->CommandBuilder().CreateImageKey(aItem, container, - aBuilder, aResources, - aSc, size, Nothing()); + Maybe key = aManager->CommandBuilder().CreateImageKey( + aItem, container, aBuilder, aResources, rendering, aSc, size, Nothing()); if (key.isNothing()) { return Some(ImgDrawResult::NOT_READY); } wr::LayoutRect fill = wr::ToRoundedLayoutRect(fillRect); LayoutDeviceSize gapSize(0, 0); - SamplingFilter sampleFilter = nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame()); - aBuilder.PushImage(fill, fill, !BackfaceIsHidden(), - wr::ToLayoutSize(fillRect.Size()), wr::ToLayoutSize(gapSize), - wr::ToImageRendering(sampleFilter), key.value()); + aBuilder.PushImage(fill, + fill, + !BackfaceIsHidden(), + wr::ToLayoutSize(fillRect.Size()), + wr::ToLayoutSize(gapSize), + rendering, + key.value()); return Some(ImgDrawResult::SUCCESS); }