Bug 1540581 - P13. Properly handle colorspace with D3D11 compositors. r=mattwoodrow
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 11 Apr 2019 12:38:55 +0000
changeset 527958 575c1e8291c7e3c6c2a3b7160a7b862b304520cc
parent 527957 a0176a275ee5a60ce1bef7bde28055cc49cc2a26
child 527959 574e1da58e2e3d2a4a876028940b60cedb0232f6
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [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 - P13. Properly handle colorspace with D3D11 compositors. r=mattwoodrow Also fix 10/12 bits images composition with old D3D11 compositor. Differential Revision: https://phabricator.services.mozilla.com/D26468
gfx/layers/d3d11/CompositorD3D11.cpp
gfx/layers/mlgpu/RenderPassMLGPU.cpp
--- a/gfx/layers/d3d11/CompositorD3D11.cpp
+++ b/gfx/layers/d3d11/CompositorD3D11.cpp
@@ -947,22 +947,22 @@ void CompositorD3D11::DrawGeometry(const
         mContext->OMSetBlendState(mAttachments->mNonPremulBlendState,
                                   sBlendFactor, 0xFFFFFFFF);
         restoreBlendMode = true;
       }
 
       SetSamplerForSamplingFilter(texturedEffect->mSamplingFilter);
     } break;
     case EffectTypes::NV12: {
-      TexturedEffect* texturedEffect =
-          static_cast<TexturedEffect*>(aEffectChain.mPrimaryEffect.get());
+      EffectNV12* effectNV12 =
+          static_cast<EffectNV12*>(aEffectChain.mPrimaryEffect.get());
 
-      pTexCoordRect = &texturedEffect->mTextureCoords;
+      pTexCoordRect = &effectNV12->mTextureCoords;
 
-      TextureSourceD3D11* source = texturedEffect->mTexture->AsSourceD3D11();
+      TextureSourceD3D11* source = effectNV12->mTexture->AsSourceD3D11();
       if (!source) {
         NS_WARNING("Missing texture source!");
         return;
       }
 
       RefPtr<ID3D11Texture2D> texture = source->GetD3D11Texture();
       if (!texture) {
         NS_WARNING("No texture found in texture source!");
@@ -989,24 +989,23 @@ void CompositorD3D11::DrawGeometry(const
                            : DXGI_FORMAT_R16G16_UNORM;
       mDevice->CreateShaderResourceView(texture, &srvDesc,
                                         getter_AddRefs(srViewCbCr));
 
       ID3D11ShaderResourceView* views[] = {srViewY, srViewCbCr};
       mContext->PSSetShaderResources(TexSlot::Y, 2, views);
 
       const float* yuvToRgb =
-          gfxUtils::YuvToRgbMatrix4x3RowMajor(YUVColorSpace::BT601);
+          gfxUtils::YuvToRgbMatrix4x3RowMajor(effectNV12->mYUVColorSpace);
       memcpy(&mPSConstants.yuvColorMatrix, yuvToRgb,
              sizeof(mPSConstants.yuvColorMatrix));
-      // TOTO: need to handle color depth properly. this assumes data is always
-      // 8 or 16 bits.
-      mPSConstants.vCoefficient[0] = 1.0;
+      mPSConstants.vCoefficient[0] =
+          RescalingFactorForColorDepth(effectNV12->mColorDepth);
 
-      SetSamplerForSamplingFilter(texturedEffect->mSamplingFilter);
+      SetSamplerForSamplingFilter(effectNV12->mSamplingFilter);
     } break;
     case EffectTypes::YCBCR: {
       EffectYCbCr* ycbcrEffect =
           static_cast<EffectYCbCr*>(aEffectChain.mPrimaryEffect.get());
 
       SetSamplerForSamplingFilter(SamplingFilter::LINEAR);
 
       pTexCoordRect = &ycbcrEffect->mTextureCoords;
--- a/gfx/layers/mlgpu/RenderPassMLGPU.cpp
+++ b/gfx/layers/mlgpu/RenderPassMLGPU.cpp
@@ -700,26 +700,21 @@ bool VideoRenderPass::AddToPass(LayerMLG
     return false;
   }
   return txn.Commit();
 }
 
 void VideoRenderPass::SetupPipeline() {
   YUVColorSpace colorSpace = YUVColorSpace::UNKNOWN;
   switch (mHost->GetReadFormat()) {
-    case SurfaceFormat::YUV: {
-      colorSpace = mHost->GetYUVColorSpace();
-      break;
-    }
+    case SurfaceFormat::YUV:
     case SurfaceFormat::NV12:
     case SurfaceFormat::P010:
     case SurfaceFormat::P016:
-      // TODO. BT601 is very unlikely to be the right value for high-def
-      // content.
-      colorSpace = YUVColorSpace::BT601;
+      colorSpace = mHost->GetYUVColorSpace();
       break;
     default:
       MOZ_ASSERT_UNREACHABLE("Unexpected surface format in VideoRenderPass");
       break;
   }
   MOZ_ASSERT(colorSpace != YUVColorSpace::UNKNOWN);
 
   RefPtr<MLGBuffer> ps1 = mDevice->GetBufferForColorSpace(colorSpace);