Bug 593604. Part 8.6: Add component-alpha shaders. r=bas,a=blocking
authorRobert O'Callahan <robert@ocallahan.org>
Mon, 03 Jan 2011 14:48:09 +1300
changeset 59774 02c4dac4ae7d9653ad485c5b0a275cb8e2437f8e
parent 59773 431218b437ab386458d3e64f346d99124fa66e5b
child 59775 b4e0f47b628df4c655025dc9bdfe8364857577cd
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersbas, blocking
bugs593604
milestone2.0b9pre
Bug 593604. Part 8.6: Add component-alpha shaders. r=bas,a=blocking
gfx/layers/d3d9/DeviceManagerD3D9.cpp
gfx/layers/d3d9/DeviceManagerD3D9.h
gfx/layers/d3d9/LayerManagerD3D9Shaders.h
gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl
gfx/layers/d3d9/genshaders.sh
--- a/gfx/layers/d3d9/DeviceManagerD3D9.cpp
+++ b/gfx/layers/d3d9/DeviceManagerD3D9.cpp
@@ -358,16 +358,30 @@ DeviceManagerD3D9::Init()
 
   hr = mDevice->CreatePixelShader((DWORD*)RGBAShaderPS,
                                   getter_AddRefs(mRGBAPS));
 
   if (FAILED(hr)) {
     return false;
   }
 
+  hr = mDevice->CreatePixelShader((DWORD*)ComponentPass1ShaderPS,
+                                  getter_AddRefs(mComponentPass1PS));
+
+  if (FAILED(hr)) {
+    return false;
+  }
+
+  hr = mDevice->CreatePixelShader((DWORD*)ComponentPass2ShaderPS,
+                                  getter_AddRefs(mComponentPass2PS));
+
+  if (FAILED(hr)) {
+    return false;
+  }
+
   hr = mDevice->CreatePixelShader((DWORD*)YCbCrShaderPS,
                                   getter_AddRefs(mYCbCrPS));
 
   if (FAILED(hr)) {
     return false;
   }
 
   hr = mDevice->CreatePixelShader((DWORD*)SolidColorShaderPS,
@@ -478,16 +492,24 @@ DeviceManagerD3D9::SetShaderMode(ShaderM
     case RGBLAYER:
       mDevice->SetVertexShader(mLayerVS);
       mDevice->SetPixelShader(mRGBPS);
       break;
     case RGBALAYER:
       mDevice->SetVertexShader(mLayerVS);
       mDevice->SetPixelShader(mRGBAPS);
       break;
+    case COMPONENTLAYERPASS1:
+      mDevice->SetVertexShader(mLayerVS);
+      mDevice->SetPixelShader(mComponentPass1PS);
+      break;
+    case COMPONENTLAYERPASS2:
+      mDevice->SetVertexShader(mLayerVS);
+      mDevice->SetPixelShader(mComponentPass2PS);
+      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
@@ -137,16 +137,18 @@ public:
 
   bool IsD3D9Ex() { return mDeviceEx; }
 
   bool HasDynamicTextures() { return mHasDynamicTextures; }
 
   enum ShaderMode {
     RGBLAYER,
     RGBALAYER,
+    COMPONENTLAYERPASS1,
+    COMPONENTLAYERPASS2,
     YCBCRLAYER,
     SOLIDCOLORLAYER
   };
 
   void SetShaderMode(ShaderMode aMode);
 
   /** 
    * Return pointer to the Nv3DVUtils instance 
@@ -200,16 +202,22 @@ private:
   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 component alpha textures (pass 1) */
+  nsRefPtr<IDirect3DPixelShader9> mComponentPass1PS;
+
+  /* Pixel shader used for component alpha textures (pass 2) */
+  nsRefPtr<IDirect3DPixelShader9> mComponentPass2PS;
+
   /* 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/LayerManagerD3D9Shaders.h
+++ b/gfx/layers/d3d9/LayerManagerD3D9Shaders.h
@@ -224,16 +224,238 @@ const BYTE RGBAShaderPS[] =
       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
 //
+//   fxc LayerManagerD3D9Shaders.hlsl -EComponentPass1Shader -nologo -Tps_2_0
+//    -FhtmpShaderHeader -VnComponentPass1ShaderPS
+//
+//
+// Parameters:
+//
+//   float fLayerOpacity;
+//   sampler2D s2D;
+//   sampler2D s2DWhite;
+//
+//
+// Registers:
+//
+//   Name          Reg   Size
+//   ------------- ----- ----
+//   fLayerOpacity c0       1
+//   s2D           s0       1
+//   s2DWhite      s1       1
+//
+
+    ps_2_0
+    def c1, 1, 0, 0, 0
+    dcl t0.xy
+    dcl_2d s0
+    dcl_2d s1
+    texld r0, t0, s0
+    texld r1, t0, s1
+    add r0.xyz, r0, -r1
+    add r0.xyz, r0, c1.x
+    mul r0.xyz, r0, c0.x
+    mov r1.xyz, r0
+    mov r1.w, r0.y
+    mov oC0, r1
+
+// approximately 8 instruction slots used (2 texture, 6 arithmetic)
+#endif
+
+const BYTE ComponentPass1ShaderPS[] =
+{
+      0,   2, 255, 255, 254, 255, 
+     57,   0,  67,  84,  65,  66, 
+     28,   0,   0,   0, 175,   0, 
+      0,   0,   0,   2, 255, 255, 
+      3,   0,   0,   0,  28,   0, 
+      0,   0,   0,   1,   0,   0, 
+    168,   0,   0,   0,  88,   0, 
+      0,   0,   2,   0,   0,   0, 
+      1,   0,   0,   0, 104,   0, 
+      0,   0,   0,   0,   0,   0, 
+    120,   0,   0,   0,   3,   0, 
+      0,   0,   1,   0,   0,   0, 
+    124,   0,   0,   0,   0,   0, 
+      0,   0, 140,   0,   0,   0, 
+      3,   0,   1,   0,   1,   0, 
+      0,   0, 152,   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, 115,  50,  68,  87, 
+    104, 105, 116, 101,   0, 171, 
+    171, 171,   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,  57,  46,  57, 
+     53,  50,  46,  51,  49,  49, 
+     49,   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,  31,   0,   0,   2, 
+      0,   0,   0, 144,   1,   8, 
+     15, 160,  66,   0,   0,   3, 
+      0,   0,  15, 128,   0,   0, 
+    228, 176,   0,   8, 228, 160, 
+     66,   0,   0,   3,   1,   0, 
+     15, 128,   0,   0, 228, 176, 
+      1,   8, 228, 160,   2,   0, 
+      0,   3,   0,   0,   7, 128, 
+      0,   0, 228, 128,   1,   0, 
+    228, 129,   2,   0,   0,   3, 
+      0,   0,   7, 128,   0,   0, 
+    228, 128,   1,   0,   0, 160, 
+      5,   0,   0,   3,   0,   0, 
+      7, 128,   0,   0, 228, 128, 
+      0,   0,   0, 160,   1,   0, 
+      0,   2,   1,   0,   7, 128, 
+      0,   0, 228, 128,   1,   0, 
+      0,   2,   1,   0,   8, 128, 
+      0,   0,  85, 128,   1,   0, 
+      0,   2,   0,   8,  15, 128, 
+      1,   0, 228, 128, 255, 255, 
+      0,   0
+};
+#if 0
+//
+// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
+//
+//   fxc LayerManagerD3D9Shaders.hlsl -EComponentPass2Shader -nologo -Tps_2_0
+//    -FhtmpShaderHeader -VnComponentPass2ShaderPS
+//
+//
+// Parameters:
+//
+//   float fLayerOpacity;
+//   sampler2D s2D;
+//   sampler2D s2DWhite;
+//
+//
+// Registers:
+//
+//   Name          Reg   Size
+//   ------------- ----- ----
+//   fLayerOpacity c0       1
+//   s2D           s0       1
+//   s2DWhite      s1       1
+//
+
+    ps_2_0
+    def c1, 1, 0, 0, 0
+    dcl t0.xy
+    dcl_2d s0
+    dcl_2d s1
+    texld r0, t0, s1
+    texld r1, t0, s0
+    add r0.x, -r0.y, r1.y
+    add r1.w, r0.x, c1.x
+    mul r0, r1, c0.x
+    mov oC0, r0
+
+// approximately 6 instruction slots used (2 texture, 4 arithmetic)
+#endif
+
+const BYTE ComponentPass2ShaderPS[] =
+{
+      0,   2, 255, 255, 254, 255, 
+     57,   0,  67,  84,  65,  66, 
+     28,   0,   0,   0, 175,   0, 
+      0,   0,   0,   2, 255, 255, 
+      3,   0,   0,   0,  28,   0, 
+      0,   0,   0,   1,   0,   0, 
+    168,   0,   0,   0,  88,   0, 
+      0,   0,   2,   0,   0,   0, 
+      1,   0,   0,   0, 104,   0, 
+      0,   0,   0,   0,   0,   0, 
+    120,   0,   0,   0,   3,   0, 
+      0,   0,   1,   0,   0,   0, 
+    124,   0,   0,   0,   0,   0, 
+      0,   0, 140,   0,   0,   0, 
+      3,   0,   1,   0,   1,   0, 
+      0,   0, 152,   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, 115,  50,  68,  87, 
+    104, 105, 116, 101,   0, 171, 
+    171, 171,   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,  57,  46,  57, 
+     53,  50,  46,  51,  49,  49, 
+     49,   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,  31,   0,   0,   2, 
+      0,   0,   0, 144,   1,   8, 
+     15, 160,  66,   0,   0,   3, 
+      0,   0,  15, 128,   0,   0, 
+    228, 176,   1,   8, 228, 160, 
+     66,   0,   0,   3,   1,   0, 
+     15, 128,   0,   0, 228, 176, 
+      0,   8, 228, 160,   2,   0, 
+      0,   3,   0,   0,   1, 128, 
+      0,   0,  85, 129,   1,   0, 
+     85, 128,   2,   0,   0,   3, 
+      1,   0,   8, 128,   0,   0, 
+      0, 128,   1,   0,   0, 160, 
+      5,   0,   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
+//
 //   fxc LayerManagerD3D9Shaders.hlsl -ERGBShader -nologo -Tps_2_0
 //    -FhtmpShaderHeader -VnRGBShaderPS
 //
 //
 // Parameters:
 //
 //   float fLayerOpacity;
 //   sampler2D s2D;
--- a/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl
+++ b/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl
@@ -3,16 +3,17 @@ float4 vRenderTargetOffset;
 float4x4 mProjection;
 
 typedef float4 rect;
 rect vTextureCoords;
 rect vLayerQuad;
 
 texture tex0;
 sampler s2D;
+sampler s2DWhite;
 sampler s2DY;
 sampler s2DCb;
 sampler s2DCr;
 
 float fLayerOpacity;
 float4 fLayerColor;
 
 struct VS_INPUT {
@@ -52,16 +53,32 @@ VS_OUTPUT LayerQuadVS(const VS_INPUT aVe
   position = vTextureCoords.xy;
   size = vTextureCoords.zw;
   outp.vTexCoords.x = position.x + aVertex.vPosition.x * size.x;
   outp.vTexCoords.y = position.y + aVertex.vPosition.y * size.y;
 
   return outp;
 }
 
+float4 ComponentPass1Shader(const VS_OUTPUT aVertex) : COLOR
+{
+  float4 src = tex2D(s2D, aVertex.vTexCoords);
+  float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src;
+  alphas.a = alphas.g;
+  return alphas * fLayerOpacity;
+}
+
+float4 ComponentPass2Shader(const VS_OUTPUT aVertex) : COLOR
+{
+  float4 src = tex2D(s2D, aVertex.vTexCoords);
+  float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src;
+  src.a = alphas.g;
+  return src * fLayerOpacity;
+}
+
 float4 RGBAShader(const VS_OUTPUT aVertex) : COLOR
 {
   return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity;
 }
 
 float4 RGBShader(const VS_OUTPUT aVertex) : COLOR
 {
   float4 result;
--- a/gfx/layers/d3d9/genshaders.sh
+++ b/gfx/layers/d3d9/genshaders.sh
@@ -1,13 +1,17 @@
 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 -EComponentPass1Shader -nologo -Tps_2_0 -Fh$tempfile -VnComponentPass1ShaderPS
+cat $tempfile >> LayerManagerD3D9Shaders.h
+fxc LayerManagerD3D9Shaders.hlsl -EComponentPass2Shader -nologo -Tps_2_0 -Fh$tempfile -VnComponentPass2ShaderPS
+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