Bug 1540581 - P4. Add ColorSpace/ColorDepth component to NV12 gfx::Effect. r=mattwoodrow
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 11 Apr 2019 12:36:19 +0000
changeset 469149 9a4305ff9a2dd501279f98c01ea0609952c4b72c
parent 469148 961e937daf7bc23193924e4d16404cc2c11120c9
child 469150 c8d5854c0ef078fe1f725530c8fc4479abe65b1c
push id82995
push userjyavenard@mozilla.com
push dateThu, 11 Apr 2019 23:28:35 +0000
treeherderautoland@ee00c85b09c5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1540581
milestone68.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 1540581 - P4. Add ColorSpace/ColorDepth component to NV12 gfx::Effect. r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D26057
gfx/layers/Effects.h
--- a/gfx/layers/Effects.h
+++ b/gfx/layers/Effects.h
@@ -152,19 +152,22 @@ struct EffectYCbCr : public TexturedEffe
         mColorDepth(aColorDepth) {}
 
   virtual const char* Name() override { return "EffectYCbCr"; }
 
   gfx::YUVColorSpace mYUVColorSpace;
   gfx::ColorDepth mColorDepth;
 };
 
-struct EffectNV12 : public TexturedEffect {
-  EffectNV12(TextureSource* aSource, gfx::SamplingFilter aSamplingFilter)
-      : TexturedEffect(EffectTypes::NV12, aSource, false, aSamplingFilter) {}
+struct EffectNV12 : public EffectYCbCr {
+  EffectNV12(TextureSource* aSource, gfx::YUVColorSpace aYUVColorSpace,
+             gfx::ColorDepth aColorDepth, gfx::SamplingFilter aSamplingFilter)
+      : EffectYCbCr(aSource, aYUVColorSpace, aColorDepth, aSamplingFilter) {
+    mType = EffectTypes::NV12;
+  }
 
   virtual const char* Name() override { return "EffectNV12"; }
 };
 
 struct EffectComponentAlpha : public TexturedEffect {
   EffectComponentAlpha(TextureSource* aOnBlack, TextureSource* aOnWhite,
                        gfx::SamplingFilter aSamplingFilter)
       : TexturedEffect(EffectTypes::COMPONENT_ALPHA, nullptr, false,
@@ -199,62 +202,71 @@ struct EffectChain {
 };
 
 /**
  * Create a Textured effect corresponding to aFormat and using
  * aSource as the (first) texture source.
  *
  * Note that aFormat can be different form aSource->GetFormat if, we are
  * creating an effect that takes several texture sources (like with YCBCR
- * where aFormat would be FOMRAT_YCBCR and each texture source would be
+ * where aFormat would be FORMAT_YCBCR and each texture source would be
  * a one-channel A8 texture)
  */
 inline already_AddRefed<TexturedEffect> CreateTexturedEffect(
     gfx::SurfaceFormat aFormat, TextureSource* aSource,
     const gfx::SamplingFilter aSamplingFilter, bool isAlphaPremultiplied) {
   MOZ_ASSERT(aSource);
   RefPtr<TexturedEffect> result;
   switch (aFormat) {
     case gfx::SurfaceFormat::B8G8R8A8:
     case gfx::SurfaceFormat::B8G8R8X8:
     case gfx::SurfaceFormat::R8G8B8X8:
     case gfx::SurfaceFormat::R5G6B5_UINT16:
     case gfx::SurfaceFormat::R8G8B8A8:
       result = new EffectRGB(aSource, isAlphaPremultiplied, aSamplingFilter);
       break;
+    case gfx::SurfaceFormat::YUV:
     case gfx::SurfaceFormat::NV12:
     case gfx::SurfaceFormat::P010:
     case gfx::SurfaceFormat::P016:
-      result = new EffectNV12(aSource, aSamplingFilter);
-      break;
-    case gfx::SurfaceFormat::YUV:
-      MOZ_ASSERT_UNREACHABLE("gfx::SurfaceFormat::YUV is invalid");
+      MOZ_ASSERT_UNREACHABLE(
+          "gfx::SurfaceFormat::YUV/NV12/P010/P016 is invalid");
       break;
     default:
       NS_WARNING("unhandled program type");
       break;
   }
 
   return result.forget();
 }
 
 inline already_AddRefed<TexturedEffect> CreateTexturedEffect(
     TextureHost* aHost, TextureSource* aSource,
     const gfx::SamplingFilter aSamplingFilter, bool isAlphaPremultiplied) {
   MOZ_ASSERT(aHost);
   MOZ_ASSERT(aSource);
 
   RefPtr<TexturedEffect> result;
-  if (aHost->GetReadFormat() == gfx::SurfaceFormat::YUV) {
-    MOZ_ASSERT(aHost->GetYUVColorSpace() != gfx::YUVColorSpace::UNKNOWN);
-    result = new EffectYCbCr(aSource, aHost->GetYUVColorSpace(),
-                             aHost->GetColorDepth(), aSamplingFilter);
-  } else {
-    result = CreateTexturedEffect(aHost->GetReadFormat(), aSource,
-                                  aSamplingFilter, isAlphaPremultiplied);
+
+  switch (aHost->GetReadFormat()) {
+    case gfx::SurfaceFormat::YUV:
+      MOZ_ASSERT(aHost->GetYUVColorSpace() != gfx::YUVColorSpace::UNKNOWN);
+      result = new EffectYCbCr(aSource, aHost->GetYUVColorSpace(),
+                               aHost->GetColorDepth(), aSamplingFilter);
+      break;
+    case gfx::SurfaceFormat::NV12:
+    case gfx::SurfaceFormat::P010:
+    case gfx::SurfaceFormat::P016:
+      result = new EffectNV12(aSource, aHost->GetYUVColorSpace(),
+                              aHost->GetColorDepth(), aSamplingFilter);
+      break;
+    default:
+      result = CreateTexturedEffect(aHost->GetReadFormat(), aSource,
+                                    aSamplingFilter, isAlphaPremultiplied);
+      break;
   }
   return result.forget();
 }
 
 /**
  * Create a textured effect based on aSource format and the presence of
  * aSourceOnWhite.
  *