Bug 1366502 - Move the various of image key and WR command settings from WebRenderCompositableHolder into textureHosts. r=sotaro
authorJerryShih <hshih@mozilla.com>
Wed, 07 Jun 2017 23:44:03 +0800
changeset 410832 abac100c9ba4b5dc1f675ff0787e509cb0671fe3
parent 410831 a03ce839ba8f11d0274f9e14fe17881db4559a28
child 410833 8aee729888017908497d38bacbceca1149603596
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1366502
milestone55.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 1366502 - Move the various of image key and WR command settings from WebRenderCompositableHolder into textureHosts. r=sotaro It's awful to put all combination of image key and WR command settings in the same place. Make the settings go back to textureHosts. Each textureHost should implement GetWRImageKeys() and PushExternalImage() function. MozReview-Commit-ID: 5Bmiuv5HgmX
gfx/layers/wr/WebRenderCompositableHolder.cpp
gfx/layers/wr/WebRenderCompositableHolder.h
--- a/gfx/layers/wr/WebRenderCompositableHolder.cpp
+++ b/gfx/layers/wr/WebRenderCompositableHolder.cpp
@@ -7,19 +7,16 @@
 
 #include "CompositableHost.h"
 #include "mozilla/gfx/gfxVars.h"
 #include "mozilla/layers/WebRenderImageHost.h"
 #include "mozilla/layers/WebRenderTextureHost.h"
 #include "mozilla/webrender/WebRenderAPI.h"
 
 namespace mozilla {
-
-using namespace gfx;
-
 namespace layers {
 
 WebRenderCompositableHolder::AsyncImagePipelineHolder::AsyncImagePipelineHolder()
  : mInitialised(false)
  , mIsChanged(false)
  , mUseExternalImage(false)
  , mFilter(WrImageRendering::Auto)
  , mMixBlendMode(WrMixBlendMode::Normal)
@@ -152,127 +149,53 @@ WebRenderCompositableHolder::UpdateAsync
   holder->mScTransform = aScTransform;
   holder->mScaleToSize = aScaleToSize;
   holder->mClipRect = aClipRect;
   holder->mMask = aMask;
   holder->mFilter = aFilter;
   holder->mMixBlendMode = aMixBlendMode;
 }
 
-void
-WebRenderCompositableHolder::GetImageKeys(nsTArray<wr::ImageKey>& aKeys, size_t aChannelNumber)
-{
-  MOZ_ASSERT(aChannelNumber > 0);
-  for (size_t i = 0; i < aChannelNumber; ++i) {
-    wr::ImageKey key = GetImageKey();
-    aKeys.AppendElement(key);
-  }
-}
-
-void
-WebRenderCompositableHolder::GetImageKeysForExternalImage(nsTArray<wr::ImageKey>& aKeys)
-{
-  MOZ_ASSERT(aKeys.IsEmpty());
-
-  // XXX (Jerry): Remove the hardcode image format setting.
-#if defined(XP_WIN)
-  // Use libyuv to convert the buffer to rgba format. So, use 1 image key here.
-  GetImageKeys(aKeys, 1);
-#elif defined(XP_MACOSX)
-  if (gfxVars::CanUseHardwareVideoDecoding()) {
-    // Use the hardware MacIOSurface with YCbCr interleaved format. It uses 1
-    // image key.
-    GetImageKeys(aKeys, 1);
-  } else {
-    // Use libyuv.
-    GetImageKeys(aKeys, 1);
-  }
-#elif defined(MOZ_WIDGET_GTK)
-  // Use libyuv.
-  GetImageKeys(aKeys, 1);
-#elif defined(ANDROID)
-  // Use libyuv.
-  GetImageKeys(aKeys, 1);
-#endif
-
-  MOZ_ASSERT(!aKeys.IsEmpty());
-}
-
 bool
 WebRenderCompositableHolder::GetImageKeyForTextureHost(wr::WebRenderAPI* aApi, TextureHost* aTexture, nsTArray<wr::ImageKey>& aKeys)
 {
   MOZ_ASSERT(aKeys.IsEmpty());
   MOZ_ASSERT(aTexture);
 
   WebRenderTextureHost* wrTexture = aTexture->AsWebRenderTextureHost();
 
   if (wrTexture) {
-    GetImageKeysForExternalImage(aKeys);
+    wrTexture->GetWRImageKeys(aKeys, std::bind(&WebRenderCompositableHolder::GetImageKey, this));
     MOZ_ASSERT(!aKeys.IsEmpty());
     Range<const wr::ImageKey> keys(&aKeys[0], aKeys.Length());
     wrTexture->AddWRImage(aApi, keys, wrTexture->GetExternalImageKey());
     return true;
   } else {
-    RefPtr<DataSourceSurface> dSurf = aTexture->GetAsSurface();
+    RefPtr<gfx::DataSourceSurface> dSurf = aTexture->GetAsSurface();
     if (!dSurf) {
       NS_ERROR("TextureHost does not return DataSourceSurface");
       return false;
     }
-    DataSourceSurface::MappedSurface map;
+    gfx::DataSourceSurface::MappedSurface map;
     if (!dSurf->Map(gfx::DataSourceSurface::MapType::READ, &map)) {
       NS_ERROR("DataSourceSurface failed to map");
       return false;
     }
-    IntSize size = dSurf->GetSize();
+    gfx::IntSize size = dSurf->GetSize();
     wr::ImageDescriptor descriptor(size, map.mStride, dSurf->GetFormat());
     auto slice = Range<uint8_t>(map.mData, size.height * map.mStride);
 
     wr::ImageKey key = GetImageKey();
     aKeys.AppendElement(key);
     aApi->AddImage(key, descriptor, slice);
     dSurf->Unmap();
   }
   return false;
 }
 
-void
-WebRenderCompositableHolder::PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                                               const WrRect& aBounds,
-                                               const WrClipRegionToken aClip,
-                                               wr::ImageRendering aFilter,
-                                               nsTArray<wr::ImageKey>& aKeys)
-{
-  // XXX (Jerry): Remove the hardcode image format setting. The format of
-  // textureClient could change from time to time. So, we just set the most
-  // usable format here.
-#if defined(XP_WIN)
-  // Use libyuv to convert the buffer to rgba format.
-  MOZ_ASSERT(aKeys.Length() == 1);
-  aBuilder.PushImage(aBounds, aClip, aFilter, aKeys[0]);
-#elif defined(XP_MACOSX)
-  if (gfx::gfxVars::CanUseHardwareVideoDecoding()) {
-    // Use the hardware MacIOSurface with YCbCr interleaved format.
-    MOZ_ASSERT(aKeys.Length() == 1);
-    aBuilder.PushYCbCrInterleavedImage(aBounds, aClip, aKeys[0], WrYuvColorSpace::Rec601, aFilter);
-  } else {
-    // Use libyuv to convert the buffer to rgba format.
-    MOZ_ASSERT(aKeys.Length() == 1);
-    aBuilder.PushImage(aBounds, aClip, aFilter, aKeys[0]);
-  }
-#elif defined(MOZ_WIDGET_GTK)
-  // Use libyuv to convert the buffer to rgba format.
-  MOZ_ASSERT(aKeys.Length() == 1);
-  aBuilder.PushImage(aBounds, aClip, aFilter, aKeys[0]);
-#elif defined(ANDROID)
-  // Use libyuv to convert the buffer to rgba format.
-  MOZ_ASSERT(aKeys.Length() == 1);
-  aBuilder.PushImage(aBounds, aClip, aFilter, aKeys[0]);
-#endif
-}
-
 bool
 WebRenderCompositableHolder::UpdateImageKeys(wr::WebRenderAPI* aApi,
                                              bool& aUseExternalImage,
                                              AsyncImagePipelineHolder* aHolder,
                                              nsTArray<wr::ImageKey>& aKeys,
                                              nsTArray<wr::ImageKey>& aKeysToDelete)
 {
   MOZ_ASSERT(aKeys.IsEmpty());
@@ -361,21 +284,22 @@ WebRenderCompositableHolder::ApplyAsyncI
       }
       LayerRect clipRect = holder->mClipRect.valueOr(rect);
       WrClipRegionToken clip = builder.PushClipRegion(
         wr::ToWrRect(clipRect),
         holder->mMask.ptrOr(nullptr));
 
       if (useExternalImage) {
         MOZ_ASSERT(holder->mCurrentTexture->AsWebRenderTextureHost());
-        PushExternalImage(builder,
-                          wr::ToWrRect(rect),
-                          clip,
-                          holder->mFilter,
-                          keys);
+        Range<const wr::ImageKey> range_keys(&keys[0], keys.Length());
+        holder->mCurrentTexture->PushExternalImage(builder,
+                                                   wr::ToWrRect(rect),
+                                                   clip,
+                                                   holder->mFilter,
+                                                   range_keys);
         HoldExternalImage(pipelineId, epoch, holder->mCurrentTexture->AsWebRenderTextureHost());
       } else {
         MOZ_ASSERT(keys.Length() == 1);
         builder.PushImage(wr::ToWrRect(rect),
                           clip,
                           holder->mFilter,
                           keys[0]);
       }
--- a/gfx/layers/wr/WebRenderCompositableHolder.h
+++ b/gfx/layers/wr/WebRenderCompositableHolder.h
@@ -88,24 +88,17 @@ private:
   uint32_t GetNamespace() { return mIdNamespace; }
   wr::ImageKey GetImageKey()
   {
     wr::ImageKey key;
     key.mNamespace = GetNamespace();
     key.mHandle = GetNextResourceId();
     return key;
   }
-  void GetImageKeys(nsTArray<wr::ImageKey>& aKeys, size_t aChannelNumber);
-  void GetImageKeysForExternalImage(nsTArray<wr::ImageKey>& aKeys);
   bool GetImageKeyForTextureHost(wr::WebRenderAPI* aApi, TextureHost* aTexture, nsTArray<wr::ImageKey>& aKeys);
-  void PushExternalImage(wr::DisplayListBuilder& aBuilder,
-                         const WrRect& aBounds,
-                         const WrClipRegionToken aClip,
-                         wr::ImageRendering aFilter,
-                         nsTArray<wr::ImageKey>& aKeys);
 
   struct ForwardingTextureHost {
     ForwardingTextureHost(const wr::Epoch& aEpoch, TextureHost* aTexture)
       : mEpoch(aEpoch)
       , mTexture(aTexture)
     {}
     wr::Epoch mEpoch;
     CompositableTextureHostRef mTexture;