From b11ef202f4d4d21a48f353357e99169e0a86386b Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Fri, 3 Sep 2010 15:51:04 +1200 Subject: [PATCH] Bug 590367 - Render RGB d2d layers with a RGBA surface and shader r=Bas, a=blocking2.0 --- gfx/layers/d3d9/CanvasLayerD3D9.cpp | 2 +- gfx/layers/d3d9/ContainerLayerD3D9.cpp | 2 +- gfx/layers/d3d9/DeviceManagerD3D9.cpp | 11 ++ gfx/layers/d3d9/DeviceManagerD3D9.h | 4 + gfx/layers/d3d9/ImageLayerD3D9.cpp | 2 +- gfx/layers/d3d9/LayerManagerD3D9Shaders.h | 119 ++++++++++++++++--- gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl | 10 +- gfx/layers/d3d9/ThebesLayerD3D9.cpp | 7 +- gfx/layers/d3d9/genshaders.sh | 2 + 9 files changed, 138 insertions(+), 21 deletions(-) diff --git a/gfx/layers/d3d9/CanvasLayerD3D9.cpp b/gfx/layers/d3d9/CanvasLayerD3D9.cpp index b34a45ed496..7bfdff06192 100644 --- a/gfx/layers/d3d9/CanvasLayerD3D9.cpp +++ b/gfx/layers/d3d9/CanvasLayerD3D9.cpp @@ -239,7 +239,7 @@ CanvasLayerD3D9::RenderLayer() opacity[0] = GetOpacity(); device()->SetPixelShaderConstantF(0, opacity, 1); - mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBLAYER); + mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER); if (!mDataIsPremultiplied) { device()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); diff --git a/gfx/layers/d3d9/ContainerLayerD3D9.cpp b/gfx/layers/d3d9/ContainerLayerD3D9.cpp index 3e6a21d39c9..97815aefbf7 100644 --- a/gfx/layers/d3d9/ContainerLayerD3D9.cpp +++ b/gfx/layers/d3d9/ContainerLayerD3D9.cpp @@ -257,7 +257,7 @@ ContainerLayerD3D9::RenderLayer() 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); diff --git a/gfx/layers/d3d9/DeviceManagerD3D9.cpp b/gfx/layers/d3d9/DeviceManagerD3D9.cpp index 7c00fe308a7..228fe9adcb8 100644 --- a/gfx/layers/d3d9/DeviceManagerD3D9.cpp +++ b/gfx/layers/d3d9/DeviceManagerD3D9.cpp @@ -338,6 +338,13 @@ DeviceManagerD3D9::Init() return false; } + hr = mDevice->CreatePixelShader((DWORD*)RGBAShaderPS, + getter_AddRefs(mRGBAPS)); + + if (FAILED(hr)) { + return false; + } + hr = mDevice->CreatePixelShader((DWORD*)YCbCrShaderPS, getter_AddRefs(mYCbCrPS)); @@ -459,6 +466,10 @@ DeviceManagerD3D9::SetShaderMode(ShaderMode aMode) mDevice->SetVertexShader(mLayerVS); mDevice->SetPixelShader(mRGBPS); break; + case RGBALAYER: + mDevice->SetVertexShader(mLayerVS); + mDevice->SetPixelShader(mRGBAPS); + break; case YCBCRLAYER: mDevice->SetVertexShader(mLayerVS); mDevice->SetPixelShader(mYCbCrPS); diff --git a/gfx/layers/d3d9/DeviceManagerD3D9.h b/gfx/layers/d3d9/DeviceManagerD3D9.h index 8be99987efe..095a5c3423a 100644 --- a/gfx/layers/d3d9/DeviceManagerD3D9.h +++ b/gfx/layers/d3d9/DeviceManagerD3D9.h @@ -129,6 +129,7 @@ public: enum ShaderMode { RGBLAYER, + RGBALAYER, YCBCRLAYER, SOLIDCOLORLAYER }; @@ -178,6 +179,9 @@ private: /* Pixel shader used for RGB textures */ nsRefPtr mRGBPS; + /* Pixel shader used for RGBA textures */ + nsRefPtr mRGBAPS; + /* Pixel shader used for RGB textures */ nsRefPtr mYCbCrPS; diff --git a/gfx/layers/d3d9/ImageLayerD3D9.cpp b/gfx/layers/d3d9/ImageLayerD3D9.cpp index eef6c6bf235..f204eed0c06 100644 --- a/gfx/layers/d3d9/ImageLayerD3D9.cpp +++ b/gfx/layers/d3d9/ImageLayerD3D9.cpp @@ -243,7 +243,7 @@ ImageLayerD3D9::RenderLayer() 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); diff --git a/gfx/layers/d3d9/LayerManagerD3D9Shaders.h b/gfx/layers/d3d9/LayerManagerD3D9Shaders.h index 7201f070f27..4d22b6f8c6c 100644 --- a/gfx/layers/d3d9/LayerManagerD3D9Shaders.h +++ b/gfx/layers/d3d9/LayerManagerD3D9Shaders.h @@ -1,6 +1,6 @@ #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 @@ -92,8 +92,8 @@ const BYTE LayerQuadVS[] = 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, @@ -149,10 +149,10 @@ const BYTE LayerQuadVS[] = }; #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: @@ -179,6 +179,87 @@ const BYTE LayerQuadVS[] = // 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, @@ -210,9 +291,13 @@ const BYTE RGBShaderPS[] = 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, @@ -220,15 +305,17 @@ const BYTE RGBShaderPS[] = 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 @@ -323,9 +410,9 @@ const BYTE YCbCrShaderPS[] = 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, @@ -384,7 +471,7 @@ const BYTE YCbCrShaderPS[] = }; #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 @@ -432,8 +519,8 @@ const BYTE SolidColorShaderPS[] = 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 diff --git a/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl b/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl index 0bbba3c216e..4b01ec50ec6 100644 --- a/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl +++ b/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl @@ -39,11 +39,19 @@ VS_OUTPUT LayerQuadVS(const VS_INPUT aVertex) return outp; } -float4 RGBShader(const VS_OUTPUT aVertex) : COLOR +float4 RGBAShader(const VS_OUTPUT aVertex) : COLOR { return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity; } +float4 RGBShader(const VS_OUTPUT aVertex) : COLOR +{ + float4 result; + result = tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity; + result.a = 1.0; + return result; +} + float4 YCbCrShader(const VS_OUTPUT aVertex) : COLOR { float4 yuv; diff --git a/gfx/layers/d3d9/ThebesLayerD3D9.cpp b/gfx/layers/d3d9/ThebesLayerD3D9.cpp index 8e7092a4f08..a532e46cf35 100644 --- a/gfx/layers/d3d9/ThebesLayerD3D9.cpp +++ b/gfx/layers/d3d9/ThebesLayerD3D9.cpp @@ -234,7 +234,12 @@ ThebesLayerD3D9::RenderLayer() 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); diff --git a/gfx/layers/d3d9/genshaders.sh b/gfx/layers/d3d9/genshaders.sh index bf6bd835566..383041ad03d 100644 --- a/gfx/layers/d3d9/genshaders.sh +++ b/gfx/layers/d3d9/genshaders.sh @@ -2,6 +2,8 @@ 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