Bug 590367 - Render RGB d2d layers with a RGBA surface and shader r=Bas, a=blocking2.0
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 03 Sep 2010 15:51:04 +1200
changeset 51963 388e25a30cab946c4d7beb3b8f914eeae9c5fa98
parent 51962 e2f75964a5e808f3135962d398ab53f12f9fdb9a
child 51964 1be7580c5c5789f972e82fcd0611da64a4fcd169
push idunknown
push userunknown
push dateunknown
reviewersBas, blocking2
bugs590367
milestone2.0b6pre
Bug 590367 - Render RGB d2d layers with a RGBA surface and shader r=Bas, a=blocking2.0
gfx/layers/d3d9/CanvasLayerD3D9.cpp
gfx/layers/d3d9/ContainerLayerD3D9.cpp
gfx/layers/d3d9/DeviceManagerD3D9.cpp
gfx/layers/d3d9/DeviceManagerD3D9.h
gfx/layers/d3d9/ImageLayerD3D9.cpp
gfx/layers/d3d9/LayerManagerD3D9Shaders.h
gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl
gfx/layers/d3d9/ThebesLayerD3D9.cpp
gfx/layers/d3d9/genshaders.sh
--- a/gfx/layers/d3d9/CanvasLayerD3D9.cpp
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.cpp
@@ -234,17 +234,17 @@ CanvasLayerD3D9::RenderLayer()
   float opacity[4];
   /*
    * We always upload a 4 component float, but the shader will use only the
    * first component since it's declared as a 'float'.
    */
   opacity[0] = GetOpacity();
   device()->SetPixelShaderConstantF(0, opacity, 1);
 
-  mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBLAYER);
+  mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);
 
   if (!mDataIsPremultiplied) {
     device()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
     device()->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
   }
   device()->SetTexture(0, mTexture);
   device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
   if (!mDataIsPremultiplied) {
--- a/gfx/layers/d3d9/ContainerLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ContainerLayerD3D9.cpp
@@ -252,17 +252,17 @@ ContainerLayerD3D9::RenderLayer()
     float opacityVector[4];
     /*
      * We always upload a 4 component float, but the shader will use only the
      * first component since it's declared as a 'float'.
      */
     opacityVector[0] = opacity;
     device()->SetPixelShaderConstantF(0, opacityVector, 1);
 
-    mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBLAYER);
+    mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);
 
     device()->SetTexture(0, renderTexture);
     device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
   }
 }
 
 } /* layers */
 } /* mozilla */
--- a/gfx/layers/d3d9/DeviceManagerD3D9.cpp
+++ b/gfx/layers/d3d9/DeviceManagerD3D9.cpp
@@ -333,16 +333,23 @@ DeviceManagerD3D9::Init()
 
   hr = mDevice->CreatePixelShader((DWORD*)RGBShaderPS,
                                   getter_AddRefs(mRGBPS));
 
   if (FAILED(hr)) {
     return false;
   }
 
+  hr = mDevice->CreatePixelShader((DWORD*)RGBAShaderPS,
+                                  getter_AddRefs(mRGBAPS));
+
+  if (FAILED(hr)) {
+    return false;
+  }
+
   hr = mDevice->CreatePixelShader((DWORD*)YCbCrShaderPS,
                                   getter_AddRefs(mYCbCrPS));
 
   if (FAILED(hr)) {
     return false;
   }
 
   hr = mDevice->CreatePixelShader((DWORD*)SolidColorShaderPS,
@@ -454,16 +461,20 @@ DeviceManagerD3D9::CreateSwapChain(HWND 
 void
 DeviceManagerD3D9::SetShaderMode(ShaderMode aMode)
 {
   switch (aMode) {
     case RGBLAYER:
       mDevice->SetVertexShader(mLayerVS);
       mDevice->SetPixelShader(mRGBPS);
       break;
+    case RGBALAYER:
+      mDevice->SetVertexShader(mLayerVS);
+      mDevice->SetPixelShader(mRGBAPS);
+      break;
     case YCBCRLAYER:
       mDevice->SetVertexShader(mLayerVS);
       mDevice->SetPixelShader(mYCbCrPS);
       break;
     case SOLIDCOLORLAYER:
       mDevice->SetVertexShader(mLayerVS);
       mDevice->SetPixelShader(mSolidColorPS);
       break;
--- a/gfx/layers/d3d9/DeviceManagerD3D9.h
+++ b/gfx/layers/d3d9/DeviceManagerD3D9.h
@@ -124,16 +124,17 @@ public:
   IDirect3DDevice9 *device() { return mDevice; }
 
   bool IsD3D9Ex() { return mDeviceEx; }
 
   bool HasDynamicTextures() { return mHasDynamicTextures; }
 
   enum ShaderMode {
     RGBLAYER,
+    RGBALAYER,
     YCBCRLAYER,
     SOLIDCOLORLAYER
   };
 
   void SetShaderMode(ShaderMode aMode);
 
   /** 
    * Return pointer to the Nv3DVUtils instance 
@@ -173,16 +174,19 @@ private:
   nsRefPtr<IDirect3D9Ex> mD3D9Ex;
 
   /* Vertex shader used for layer quads */
   nsRefPtr<IDirect3DVertexShader9> mLayerVS;
 
   /* Pixel shader used for RGB textures */
   nsRefPtr<IDirect3DPixelShader9> mRGBPS;
 
+  /* Pixel shader used for RGBA textures */
+  nsRefPtr<IDirect3DPixelShader9> mRGBAPS;
+
   /* Pixel shader used for RGB textures */
   nsRefPtr<IDirect3DPixelShader9> mYCbCrPS;
 
   /* Pixel shader used for solid colors */
   nsRefPtr<IDirect3DPixelShader9> mSolidColorPS;
 
   /* Vertex buffer containing our basic vertex structure */
   nsRefPtr<IDirect3DVertexBuffer9> mVB;
--- a/gfx/layers/d3d9/ImageLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ImageLayerD3D9.cpp
@@ -238,17 +238,17 @@ ImageLayerD3D9::RenderLayer()
     float opacity[4];
     /*
      * We always upload a 4 component float, but the shader will
      * only use the the first component since it's declared as a 'float'.
      */
     opacity[0] = GetOpacity();
     device()->SetPixelShaderConstantF(0, opacity, 1);
 
-    mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBLAYER);
+    mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);
 
     device()->SetTexture(0, cairoImage->mTexture);
     device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
   }
 }
 
 PlanarYCbCrImageD3D9::PlanarYCbCrImageD3D9(mozilla::layers::LayerManagerD3D9* aManager)
   : PlanarYCbCrImage(static_cast<ImageD3D9*>(this))
--- a/gfx/layers/d3d9/LayerManagerD3D9Shaders.h
+++ b/gfx/layers/d3d9/LayerManagerD3D9Shaders.h
@@ -1,11 +1,11 @@
 #if 0
 //
-// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
+// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
 //
 //   fxc LayerManagerD3D9Shaders.hlsl -ELayerQuadVS -nologo -FhtmpShaderHeader
 //    -VnLayerQuadVS
 //
 //
 // Parameters:
 //
 //   float4x4 mLayerQuadTransform;
@@ -87,18 +87,18 @@ const BYTE LayerQuadVS[] =
       0,   0,   0,   0, 118, 115, 
      95,  50,  95,  48,   0,  77, 
     105,  99, 114, 111, 115, 111, 
     102, 116,  32,  40,  82,  41, 
      32,  72,  76,  83,  76,  32, 
      83, 104,  97, 100, 101, 114, 
      32,  67, 111, 109, 112, 105, 
     108, 101, 114,  32,  57,  46, 
-     50,  57,  46,  57,  53,  50, 
-     46,  51,  49,  49,  49,   0, 
+     50,  55,  46,  57,  53,  50, 
+     46,  51,  48,  50,  50,   0, 
      81,   0,   0,   5,  13,   0, 
      15, 160,   0,   0,   0, 191, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
      31,   0,   0,   2,   0,   0, 
       0, 128,   0,   0,  15, 144, 
       5,   0,   0,   3,   0,   0, 
      15, 128,   0,   0,  85, 144, 
@@ -144,20 +144,20 @@ const BYTE LayerQuadVS[] =
      15, 192,  11,   0, 228, 160, 
       0,   0, 255, 128,   1,   0, 
     228, 128,   1,   0,   0,   2, 
       0,   0,   3, 224,   0,   0, 
     228, 144, 255, 255,   0,   0
 };
 #if 0
 //
-// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
+// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
 //
-//   fxc LayerManagerD3D9Shaders.hlsl -ERGBShader -nologo -Tps_2_0
-//    -FhtmpShaderHeader -VnRGBShaderPS
+//   fxc LayerManagerD3D9Shaders.hlsl -ERGBAShader -nologo -Tps_2_0
+//    -FhtmpShaderHeader -VnRGBAShaderPS
 //
 //
 // Parameters:
 //
 //   float fLayerOpacity;
 //   sampler2D s2D;
 //
 //
@@ -174,16 +174,97 @@ const BYTE LayerQuadVS[] =
     dcl_2d s0
     texld r0, t0, s0
     mul r0, r0, c0.x
     mov oC0, r0
 
 // approximately 3 instruction slots used (1 texture, 2 arithmetic)
 #endif
 
+const BYTE RGBAShaderPS[] =
+{
+      0,   2, 255, 255, 254, 255, 
+     45,   0,  67,  84,  65,  66, 
+     28,   0,   0,   0, 127,   0, 
+      0,   0,   0,   2, 255, 255, 
+      2,   0,   0,   0,  28,   0, 
+      0,   0,   0,   1,   0,   0, 
+    120,   0,   0,   0,  68,   0, 
+      0,   0,   2,   0,   0,   0, 
+      1,   0,   0,   0,  84,   0, 
+      0,   0,   0,   0,   0,   0, 
+    100,   0,   0,   0,   3,   0, 
+      0,   0,   1,   0,   0,   0, 
+    104,   0,   0,   0,   0,   0, 
+      0,   0, 102,  76,  97, 121, 
+    101, 114,  79, 112,  97,  99, 
+    105, 116, 121,   0, 171, 171, 
+      0,   0,   3,   0,   1,   0, 
+      1,   0,   1,   0,   0,   0, 
+      0,   0,   0,   0, 115,  50, 
+     68,   0,   4,   0,  12,   0, 
+      1,   0,   1,   0,   1,   0, 
+      0,   0,   0,   0,   0,   0, 
+    112, 115,  95,  50,  95,  48, 
+      0,  77, 105,  99, 114, 111, 
+    115, 111, 102, 116,  32,  40, 
+     82,  41,  32,  72,  76,  83, 
+     76,  32,  83, 104,  97, 100, 
+    101, 114,  32,  67, 111, 109, 
+    112, 105, 108, 101, 114,  32, 
+     57,  46,  50,  55,  46,  57, 
+     53,  50,  46,  51,  48,  50, 
+     50,   0,  31,   0,   0,   2, 
+      0,   0,   0, 128,   0,   0, 
+      3, 176,  31,   0,   0,   2, 
+      0,   0,   0, 144,   0,   8, 
+     15, 160,  66,   0,   0,   3, 
+      0,   0,  15, 128,   0,   0, 
+    228, 176,   0,   8, 228, 160, 
+      5,   0,   0,   3,   0,   0, 
+     15, 128,   0,   0, 228, 128, 
+      0,   0,   0, 160,   1,   0, 
+      0,   2,   0,   8,  15, 128, 
+      0,   0, 228, 128, 255, 255, 
+      0,   0
+};
+#if 0
+//
+// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
+//
+//   fxc LayerManagerD3D9Shaders.hlsl -ERGBShader -nologo -Tps_2_0
+//    -FhtmpShaderHeader -VnRGBShaderPS
+//
+//
+// Parameters:
+//
+//   float fLayerOpacity;
+//   sampler2D s2D;
+//
+//
+// Registers:
+//
+//   Name          Reg   Size
+//   ------------- ----- ----
+//   fLayerOpacity c0       1
+//   s2D           s0       1
+//
+
+    ps_2_0
+    def c1, 1, 0, 0, 0
+    dcl t0.xy
+    dcl_2d s0
+    texld r0, t0, s0
+    mul r0.xyz, r0, c0.x
+    mov r0.w, c1.x
+    mov oC0, r0
+
+// approximately 4 instruction slots used (1 texture, 3 arithmetic)
+#endif
+
 const BYTE RGBShaderPS[] =
 {
       0,   2, 255, 255, 254, 255, 
      45,   0,  67,  84,  65,  66, 
      28,   0,   0,   0, 127,   0, 
       0,   0,   0,   2, 255, 255, 
       2,   0,   0,   0,  28,   0, 
       0,   0,   0,   1,   0,   0, 
@@ -205,35 +286,41 @@ const BYTE RGBShaderPS[] =
       0,   0,   0,   0,   0,   0, 
     112, 115,  95,  50,  95,  48, 
       0,  77, 105,  99, 114, 111, 
     115, 111, 102, 116,  32,  40, 
      82,  41,  32,  72,  76,  83, 
      76,  32,  83, 104,  97, 100, 
     101, 114,  32,  67, 111, 109, 
     112, 105, 108, 101, 114,  32, 
-     57,  46,  50,  57,  46,  57, 
-     53,  50,  46,  51,  49,  49, 
-     49,   0,  31,   0,   0,   2, 
+     57,  46,  50,  55,  46,  57, 
+     53,  50,  46,  51,  48,  50, 
+     50,   0,  81,   0,   0,   5, 
+      1,   0,  15, 160,   0,   0, 
+    128,  63,   0,   0,   0,   0, 
+      0,   0,   0,   0,   0,   0, 
+      0,   0,  31,   0,   0,   2, 
       0,   0,   0, 128,   0,   0, 
       3, 176,  31,   0,   0,   2, 
       0,   0,   0, 144,   0,   8, 
      15, 160,  66,   0,   0,   3, 
       0,   0,  15, 128,   0,   0, 
     228, 176,   0,   8, 228, 160, 
       5,   0,   0,   3,   0,   0, 
-     15, 128,   0,   0, 228, 128, 
+      7, 128,   0,   0, 228, 128, 
       0,   0,   0, 160,   1,   0, 
+      0,   2,   0,   0,   8, 128, 
+      1,   0,   0, 160,   1,   0, 
       0,   2,   0,   8,  15, 128, 
       0,   0, 228, 128, 255, 255, 
       0,   0
 };
 #if 0
 //
-// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
+// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
 //
 //   fxc LayerManagerD3D9Shaders.hlsl -EYCbCrShader -nologo -Tps_2_0
 //    -FhtmpShaderHeader -VnYCbCrShaderPS
 //
 //
 // Parameters:
 //
 //   float fLayerOpacity;
@@ -318,19 +405,19 @@ const BYTE YCbCrShaderPS[] =
       1,   0,   0,   0,   0,   0, 
       0,   0, 112, 115,  95,  50, 
      95,  48,   0,  77, 105,  99, 
     114, 111, 115, 111, 102, 116, 
      32,  40,  82,  41,  32,  72, 
      76,  83,  76,  32,  83, 104, 
      97, 100, 101, 114,  32,  67, 
     111, 109, 112, 105, 108, 101, 
-    114,  32,  57,  46,  50,  57, 
+    114,  32,  57,  46,  50,  55, 
      46,  57,  53,  50,  46,  51, 
-     49,  49,  49,   0,  81,   0, 
+     48,  50,  50,   0,  81,   0, 
       0,   5,   1,   0,  15, 160, 
       0,   0,   0, 191,   0,   0, 
     128, 189, 244, 253, 148,  63, 
     186,  73, 204,  63,  81,   0, 
       0,   5,   2,   0,  15, 160, 
     197,  32,  80,  63,  39,  49, 
     200,  62, 233,  38,   1,  64, 
       0,   0, 128,  63,  31,   0, 
@@ -379,17 +466,17 @@ const BYTE YCbCrShaderPS[] =
       0,   3,   0,   0,  15, 128, 
       1,   0, 228, 128,   0,   0, 
       0, 160,   1,   0,   0,   2, 
       0,   8,  15, 128,   0,   0, 
     228, 128, 255, 255,   0,   0
 };
 #if 0
 //
-// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
+// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
 //
 //   fxc LayerManagerD3D9Shaders.hlsl -ESolidColorShader -nologo -Tps_2_0
 //    -FhtmpShaderHeader -VnSolidColorShaderPS
 //
 //
 // Parameters:
 //
 //   float4 fLayerColor;
@@ -427,14 +514,14 @@ const BYTE SolidColorShaderPS[] =
       0,   0,   0,   0, 112, 115, 
      95,  50,  95,  48,   0,  77, 
     105,  99, 114, 111, 115, 111, 
     102, 116,  32,  40,  82,  41, 
      32,  72,  76,  83,  76,  32, 
      83, 104,  97, 100, 101, 114, 
      32,  67, 111, 109, 112, 105, 
     108, 101, 114,  32,  57,  46, 
-     50,  57,  46,  57,  53,  50, 
-     46,  51,  49,  49,  49,   0, 
+     50,  55,  46,  57,  53,  50, 
+     46,  51,  48,  50,  50,   0, 
       1,   0,   0,   2,   0,   8, 
      15, 128,   0,   0, 228, 160, 
     255, 255,   0,   0
 };
--- a/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl
+++ b/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl
@@ -34,19 +34,27 @@ VS_OUTPUT LayerQuadVS(const VS_INPUT aVe
   outp.vPosition.xy -= 0.5;
   
   outp.vPosition = mul(mProjection, outp.vPosition);
   
   outp.vTexCoords = aVertex.vPosition.xy;
   return outp;
 }
 
+float4 RGBAShader(const VS_OUTPUT aVertex) : COLOR
+{
+  return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity;
+}
+
 float4 RGBShader(const VS_OUTPUT aVertex) : COLOR
 {
-  return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity;
+  float4 result;
+  result = tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity;
+  result.a = 1.0;
+  return result;
 }
 
 float4 YCbCrShader(const VS_OUTPUT aVertex) : COLOR
 {
   float4 yuv;
   float4 color;
 
   yuv.r = tex2D(s2DCr, aVertex.vTexCoords).r - 0.5;
--- a/gfx/layers/d3d9/ThebesLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ThebesLayerD3D9.cpp
@@ -229,17 +229,22 @@ ThebesLayerD3D9::RenderLayer()
   float opacity[4];
   /*
    * We always upload a 4 component float, but the shader will use only the
    * first component since it's declared as a 'float'.
    */
   opacity[0] = GetOpacity();
   device()->SetPixelShaderConstantF(0, opacity, 1);
 
-  mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBLAYER);
+#ifdef CAIRO_HAS_D2D_SURFACE
+  if (mD2DSurface && UseOpaqueSurface(this)) {
+    mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBLAYER);
+  } else
+#endif
+  mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);
 
   device()->SetTexture(0, mTexture);
   device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
 }
 
 void
 ThebesLayerD3D9::CleanResources()
 {
--- a/gfx/layers/d3d9/genshaders.sh
+++ b/gfx/layers/d3d9/genshaders.sh
@@ -1,11 +1,13 @@
 tempfile=tmpShaderHeader
 rm LayerManagerD3D9Shaders.h
 fxc LayerManagerD3D9Shaders.hlsl -ELayerQuadVS -nologo -Fh$tempfile -VnLayerQuadVS
 cat $tempfile >> LayerManagerD3D9Shaders.h
+fxc LayerManagerD3D9Shaders.hlsl -ERGBAShader -nologo -Tps_2_0 -Fh$tempfile -VnRGBAShaderPS
+cat $tempfile >> LayerManagerD3D9Shaders.h
 fxc LayerManagerD3D9Shaders.hlsl -ERGBShader -nologo -Tps_2_0 -Fh$tempfile -VnRGBShaderPS
 cat $tempfile >> LayerManagerD3D9Shaders.h
 fxc LayerManagerD3D9Shaders.hlsl -EYCbCrShader -nologo -Tps_2_0 -Fh$tempfile -VnYCbCrShaderPS
 cat $tempfile >> LayerManagerD3D9Shaders.h
 fxc LayerManagerD3D9Shaders.hlsl -ESolidColorShader -nologo -Tps_2_0 -Fh$tempfile -VnSolidColorShaderPS
 cat $tempfile >> LayerManagerD3D9Shaders.h
 rm $tempfile