Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 float4x4 mLayerTransform;
2 float4 vRenderTargetOffset;
3 float4x4 mProjection;
5 typedef float4 rect;
6 rect vTextureCoords;
7 rect vLayerQuad;
8 rect vMaskQuad;
10 texture tex0;
11 sampler s2D;
12 sampler s2DWhite;
13 sampler s2DY;
14 sampler s2DCb;
15 sampler s2DCr;
16 sampler s2DMask;
19 float fLayerOpacity;
20 float4 fLayerColor;
22 struct VS_INPUT {
23 float4 vPosition : POSITION;
24 };
26 struct VS_OUTPUT {
27 float4 vPosition : POSITION;
28 float2 vTexCoords : TEXCOORD0;
29 };
31 struct VS_OUTPUT_MASK {
32 float4 vPosition : POSITION;
33 float2 vTexCoords : TEXCOORD0;
34 float2 vMaskCoords : TEXCOORD1;
35 };
37 struct VS_OUTPUT_MASK_3D {
38 float4 vPosition : POSITION;
39 float2 vTexCoords : TEXCOORD0;
40 float3 vMaskCoords : TEXCOORD1;
41 };
43 VS_OUTPUT LayerQuadVS(const VS_INPUT aVertex)
44 {
45 VS_OUTPUT outp;
46 outp.vPosition = aVertex.vPosition;
48 // We use 4 component floats to uniquely describe a rectangle, by the structure
49 // of x, y, width, height. This allows us to easily generate the 4 corners
50 // of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the
51 // stream source for our LayerQuad vertex shader. We do this by doing:
52 // Xout = x + Xin * width
53 // Yout = y + Yin * height
54 float2 position = vLayerQuad.xy;
55 float2 size = vLayerQuad.zw;
56 outp.vPosition.x = position.x + outp.vPosition.x * size.x;
57 outp.vPosition.y = position.y + outp.vPosition.y * size.y;
59 outp.vPosition = mul(mLayerTransform, outp.vPosition);
60 outp.vPosition.xyz /= outp.vPosition.w;
61 outp.vPosition = outp.vPosition - vRenderTargetOffset;
62 outp.vPosition.xyz *= outp.vPosition.w;
64 // adjust our vertices to match d3d9's pixel coordinate system
65 // which has pixel centers at integer locations
66 outp.vPosition.xy -= 0.5;
68 outp.vPosition = mul(mProjection, outp.vPosition);
70 position = vTextureCoords.xy;
71 size = vTextureCoords.zw;
72 outp.vTexCoords.x = position.x + aVertex.vPosition.x * size.x;
73 outp.vTexCoords.y = position.y + aVertex.vPosition.y * size.y;
75 return outp;
76 }
78 VS_OUTPUT_MASK LayerQuadVSMask(const VS_INPUT aVertex)
79 {
80 VS_OUTPUT_MASK outp;
81 float4 position = float4(0, 0, 0, 1);
83 // We use 4 component floats to uniquely describe a rectangle, by the structure
84 // of x, y, width, height. This allows us to easily generate the 4 corners
85 // of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the
86 // stream source for our LayerQuad vertex shader. We do this by doing:
87 // Xout = x + Xin * width
88 // Yout = y + Yin * height
89 float2 size = vLayerQuad.zw;
90 position.x = vLayerQuad.x + aVertex.vPosition.x * size.x;
91 position.y = vLayerQuad.y + aVertex.vPosition.y * size.y;
93 position = mul(mLayerTransform, position);
94 outp.vPosition.w = position.w;
95 outp.vPosition.xyz = position.xyz / position.w;
96 outp.vPosition = outp.vPosition - vRenderTargetOffset;
97 outp.vPosition.xyz *= outp.vPosition.w;
99 // adjust our vertices to match d3d9's pixel coordinate system
100 // which has pixel centers at integer locations
101 outp.vPosition.xy -= 0.5;
103 outp.vPosition = mul(mProjection, outp.vPosition);
105 // calculate the position on the mask texture
106 outp.vMaskCoords.x = (position.x - vMaskQuad.x) / vMaskQuad.z;
107 outp.vMaskCoords.y = (position.y - vMaskQuad.y) / vMaskQuad.w;
109 size = vTextureCoords.zw;
110 outp.vTexCoords.x = vTextureCoords.x + aVertex.vPosition.x * size.x;
111 outp.vTexCoords.y = vTextureCoords.y + aVertex.vPosition.y * size.y;
113 return outp;
114 }
116 VS_OUTPUT_MASK_3D LayerQuadVSMask3D(const VS_INPUT aVertex)
117 {
118 VS_OUTPUT_MASK_3D outp;
119 float4 position = float4(0, 0, 0, 1);
121 // We use 4 component floats to uniquely describe a rectangle, by the structure
122 // of x, y, width, height. This allows us to easily generate the 4 corners
123 // of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the
124 // stream source for our LayerQuad vertex shader. We do this by doing:
125 // Xout = x + Xin * width
126 // Yout = y + Yin * height
127 float2 size = vLayerQuad.zw;
128 position.x = vLayerQuad.x + aVertex.vPosition.x * size.x;
129 position.y = vLayerQuad.y + aVertex.vPosition.y * size.y;
131 position = mul(mLayerTransform, position);
132 outp.vPosition.w = position.w;
133 outp.vPosition.xyz = position.xyz / position.w;
134 outp.vPosition = outp.vPosition - vRenderTargetOffset;
135 outp.vPosition.xyz *= outp.vPosition.w;
137 // adjust our vertices to match d3d9's pixel coordinate system
138 // which has pixel centers at integer locations
139 outp.vPosition.xy -= 0.5;
141 outp.vPosition = mul(mProjection, outp.vPosition);
143 // calculate the position on the mask texture
144 position.xyz /= position.w;
145 outp.vMaskCoords.x = (position.x - vMaskQuad.x) / vMaskQuad.z;
146 outp.vMaskCoords.y = (position.y - vMaskQuad.y) / vMaskQuad.w;
147 // correct for perspective correct interpolation, see comment in D3D10 shader
148 outp.vMaskCoords.z = 1;
149 outp.vMaskCoords *= position.w;
151 size = vTextureCoords.zw;
152 outp.vTexCoords.x = vTextureCoords.x + aVertex.vPosition.x * size.x;
153 outp.vTexCoords.y = vTextureCoords.y + aVertex.vPosition.y * size.y;
155 return outp;
156 }
158 float4 ComponentPass1Shader(const VS_OUTPUT aVertex) : COLOR
159 {
160 float4 src = tex2D(s2D, aVertex.vTexCoords);
161 float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src;
162 alphas.a = alphas.g;
163 return alphas * fLayerOpacity;
164 }
166 float4 ComponentPass2Shader(const VS_OUTPUT aVertex) : COLOR
167 {
168 float4 src = tex2D(s2D, aVertex.vTexCoords);
169 float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src;
170 src.a = alphas.g;
171 return src * fLayerOpacity;
172 }
174 float4 RGBAShader(const VS_OUTPUT aVertex) : COLOR
175 {
176 return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity;
177 }
179 float4 RGBShader(const VS_OUTPUT aVertex) : COLOR
180 {
181 float4 result;
182 result = tex2D(s2D, aVertex.vTexCoords);
183 result.a = 1.0;
184 return result * fLayerOpacity;
185 }
187 float4 YCbCrShader(const VS_OUTPUT aVertex) : COLOR
188 {
189 float4 yuv;
190 float4 color;
192 yuv.r = tex2D(s2DCr, aVertex.vTexCoords).a - 0.5;
193 yuv.g = tex2D(s2DY, aVertex.vTexCoords).a - 0.0625;
194 yuv.b = tex2D(s2DCb, aVertex.vTexCoords).a - 0.5;
196 color.r = yuv.g * 1.164 + yuv.r * 1.596;
197 color.g = yuv.g * 1.164 - 0.813 * yuv.r - 0.391 * yuv.b;
198 color.b = yuv.g * 1.164 + yuv.b * 2.018;
199 color.a = 1.0f;
201 return color * fLayerOpacity;
202 }
204 float4 SolidColorShader(const VS_OUTPUT aVertex) : COLOR
205 {
206 return fLayerColor;
207 }
209 float4 ComponentPass1ShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR
210 {
211 float4 src = tex2D(s2D, aVertex.vTexCoords);
212 float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src;
213 alphas.a = alphas.g;
214 float2 maskCoords = aVertex.vMaskCoords;
215 float mask = tex2D(s2DMask, maskCoords).a;
216 return alphas * fLayerOpacity * mask;
217 }
219 float4 ComponentPass2ShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR
220 {
221 float4 src = tex2D(s2D, aVertex.vTexCoords);
222 float4 alphas = 1.0 - tex2D(s2DWhite, aVertex.vTexCoords) + src;
223 src.a = alphas.g;
224 float2 maskCoords = aVertex.vMaskCoords;
225 float mask = tex2D(s2DMask, maskCoords).a;
226 return src * fLayerOpacity * mask;
227 }
229 float4 RGBAShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR
230 {
231 float2 maskCoords = aVertex.vMaskCoords;
232 float mask = tex2D(s2DMask, maskCoords).a;
233 return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity * mask;
234 }
236 float4 RGBAShaderMask3D(const VS_OUTPUT_MASK_3D aVertex) : COLOR
237 {
238 float2 maskCoords = aVertex.vMaskCoords.xy / aVertex.vMaskCoords.z;
239 float mask = tex2D(s2DMask, maskCoords).a;
240 return tex2D(s2D, aVertex.vTexCoords) * fLayerOpacity * mask;
241 }
243 float4 RGBShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR
244 {
245 float4 result;
246 result = tex2D(s2D, aVertex.vTexCoords);
247 result.a = 1.0;
248 float2 maskCoords = aVertex.vMaskCoords;
249 float mask = tex2D(s2DMask, maskCoords).a;
250 return result * fLayerOpacity * mask;
251 }
253 float4 YCbCrShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR
254 {
255 float4 yuv;
256 float4 color;
258 yuv.r = tex2D(s2DCr, aVertex.vTexCoords).a - 0.5;
259 yuv.g = tex2D(s2DY, aVertex.vTexCoords).a - 0.0625;
260 yuv.b = tex2D(s2DCb, aVertex.vTexCoords).a - 0.5;
262 color.r = yuv.g * 1.164 + yuv.r * 1.596;
263 color.g = yuv.g * 1.164 - 0.813 * yuv.r - 0.391 * yuv.b;
264 color.b = yuv.g * 1.164 + yuv.b * 2.018;
265 color.a = 1.0f;
267 float2 maskCoords = aVertex.vMaskCoords;
268 float mask = tex2D(s2DMask, maskCoords).a;
269 return color * fLayerOpacity * mask;
270 }
272 float4 SolidColorShaderMask(const VS_OUTPUT_MASK aVertex) : COLOR
273 {
274 float2 maskCoords = aVertex.vMaskCoords;
275 float mask = tex2D(s2DMask, maskCoords).a;
276 return fLayerColor * mask;
277 }