Bug 1384839 - Part4. Use A8 format when painting mask image. r=kats
authorEthan Lin <ethlin@mozilla.com>
Mon, 31 Jul 2017 14:00:29 +0800
changeset 420889 8086b15aa74b55cce1d4101eaa41293f88d48c42
parent 420888 0f775046102c8d3113ac8fff4b315dca69e95105
child 420890 0a02ac4abd5e7a921191bb0e1576cf9bf800c7ff
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1384839
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1384839 - Part4. Use A8 format when painting mask image. r=kats MozReview-Commit-ID: 9vMkBxRNAUv
gfx/layers/UpdateImageHelper.h
gfx/layers/wr/WebRenderLayerManager.cpp
gfx/layers/wr/WebRenderPaintedLayer.cpp
--- a/gfx/layers/UpdateImageHelper.h
+++ b/gfx/layers/UpdateImageHelper.h
@@ -14,23 +14,26 @@
 #include "mozilla/gfx/Types.h"
 
 namespace mozilla {
 namespace layers {
 
 class UpdateImageHelper
 {
 public:
-  UpdateImageHelper(ImageContainer* aImageContainer, ImageClient* aImageClient, gfx::IntSize aImageSize) :
+  UpdateImageHelper(ImageContainer* aImageContainer,
+                    ImageClient* aImageClient,
+                    gfx::IntSize aImageSize,
+                    gfx::SurfaceFormat aFormat) :
     mImageContainer(aImageContainer),
     mImageClient(aImageClient),
     mImageSize(aImageSize),
     mIsLocked(false)
   {
-    mTexture = mImageClient->GetTextureClientRecycler()->CreateOrRecycle(gfx::SurfaceFormat::B8G8R8A8,
+    mTexture = mImageClient->GetTextureClientRecycler()->CreateOrRecycle(aFormat,
                                                                          mImageSize,
                                                                          BackendSelector::Content,
                                                                          TextureFlags::DEFAULT);
     if (!mTexture) {
       return;
     }
 
     mIsLocked = mTexture->Lock(OpenMode::OPEN_WRITE_ONLY);
--- a/gfx/layers/wr/WebRenderLayerManager.cpp
+++ b/gfx/layers/wr/WebRenderLayerManager.cpp
@@ -443,36 +443,39 @@ WebRenderLayerManager::GenerateFallbackD
 
       if (!lastBounds.IsEqualInterior(clippedBounds)) {
         invalidRegion.OrWith(lastBounds);
         invalidRegion.OrWith(clippedBounds);
       }
     }
   }
 
+  gfx::SurfaceFormat format = aItem->GetType() == nsDisplayItem::TYPE_MASK ?
+                                                    gfx::SurfaceFormat::A8 : gfx::SurfaceFormat::B8G8R8A8;
   if (!geometry || !invalidRegion.IsEmpty() || fallbackData->IsInvalid()) {
     if (gfxPrefs::WebRenderBlobImages()) {
       RefPtr<gfx::DrawEventRecorderMemory> recorder = MakeAndAddRef<gfx::DrawEventRecorderMemory>();
+      // TODO: should use 'format' to replace gfx::SurfaceFormat::B8G8R8X8. Currently blob image doesn't support A8 format.
       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, aImageRect, aOffset, aDisplayListBuilder);
       recorder->Finish();
 
       wr::ByteBuffer bytes(recorder->mOutputStream.mLength, (uint8_t*)recorder->mOutputStream.mData);
       wr::ImageKey key = WrBridge()->GetNextImageKey();
       WrBridge()->SendAddBlobImage(key, imageSize.ToUnknownSize(), imageSize.width * 4, dt->GetFormat(), bytes);
       fallbackData->SetKey(key);
     } else {
       fallbackData->CreateImageClientIfNeeded();
       RefPtr<ImageClient> imageClient = fallbackData->GetImageClient();
       RefPtr<ImageContainer> imageContainer = LayerManager::CreateImageContainer();
 
       {
-        UpdateImageHelper helper(imageContainer, imageClient, imageSize.ToUnknownSize());
+        UpdateImageHelper helper(imageContainer, imageClient, imageSize.ToUnknownSize(), format);
         {
           RefPtr<gfx::DrawTarget> dt = helper.GetDrawTarget();
           PaintItemByDrawTarget(aItem, dt, aImageRect, aOffset, aDisplayListBuilder);
         }
         if (!helper.UpdateImage()) {
           return nullptr;
         }
       }
--- a/gfx/layers/wr/WebRenderPaintedLayer.cpp
+++ b/gfx/layers/wr/WebRenderPaintedLayer.cpp
@@ -52,17 +52,17 @@ WebRenderPaintedLayer::SetupExternalImag
 bool
 WebRenderPaintedLayer::UpdateImageClient()
 {
   MOZ_ASSERT(WrManager()->GetPaintedLayerCallback());
   nsIntRegion visibleRegion = GetVisibleRegion().ToUnknownRegion();
   IntRect bounds = visibleRegion.GetBounds();
   IntSize imageSize = bounds.Size();
 
-  UpdateImageHelper helper(mImageContainer, mImageClient, imageSize);
+  UpdateImageHelper helper(mImageContainer, mImageClient, imageSize, gfx::SurfaceFormat::B8G8R8A8);
 
   {
     RefPtr<DrawTarget> target = helper.GetDrawTarget();
     if (!target) {
       return false;
     }
 
     target->ClearRect(Rect(0, 0, imageSize.width, imageSize.height));