gfx/layers/d3d11/CompositorD3D11.fx

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 typedef float4 rect;
michael@0 7
michael@0 8 float4x4 mLayerTransform : register(vs, c0);
michael@0 9 float4x4 mProjection : register(vs, c4);
michael@0 10 float4 vRenderTargetOffset : register(vs, c8);
michael@0 11 rect vTextureCoords : register(vs, c9);
michael@0 12 rect vLayerQuad : register(vs, c10);
michael@0 13 rect vMaskQuad : register(vs, c11);
michael@0 14
michael@0 15 float4 fLayerColor : register(ps, c0);
michael@0 16 float fLayerOpacity : register(ps, c1);
michael@0 17
michael@0 18 sampler sSampler : register(ps, s0);
michael@0 19
michael@0 20 Texture2D tRGB;
michael@0 21 Texture2D tY;
michael@0 22 Texture2D tCb;
michael@0 23 Texture2D tCr;
michael@0 24 Texture2D tRGBWhite;
michael@0 25 // Always bind this to slot 3 since this is always available!
michael@0 26 Texture2D tMask : register(ps, t3);
michael@0 27
michael@0 28 struct VS_INPUT {
michael@0 29 float2 vPosition : POSITION;
michael@0 30 };
michael@0 31
michael@0 32 struct VS_OUTPUT {
michael@0 33 float4 vPosition : SV_Position;
michael@0 34 float2 vTexCoords : TEXCOORD0;
michael@0 35 };
michael@0 36
michael@0 37 struct VS_MASK_OUTPUT {
michael@0 38 float4 vPosition : SV_Position;
michael@0 39 float2 vTexCoords : TEXCOORD0;
michael@0 40 float2 vMaskCoords : TEXCOORD1;
michael@0 41 };
michael@0 42
michael@0 43 struct VS_MASK_3D_OUTPUT {
michael@0 44 float4 vPosition : SV_Position;
michael@0 45 float2 vTexCoords : TEXCOORD0;
michael@0 46 float3 vMaskCoords : TEXCOORD1;
michael@0 47 };
michael@0 48
michael@0 49 struct PS_OUTPUT {
michael@0 50 float4 vSrc;
michael@0 51 float4 vAlpha;
michael@0 52 };
michael@0 53
michael@0 54 float2 TexCoords(const float2 aPosition)
michael@0 55 {
michael@0 56 float2 result;
michael@0 57 const float2 size = vTextureCoords.zw;
michael@0 58 result.x = vTextureCoords.x + aPosition.x * size.x;
michael@0 59 result.y = vTextureCoords.y + aPosition.y * size.y;
michael@0 60
michael@0 61 return result;
michael@0 62 }
michael@0 63
michael@0 64 SamplerState LayerTextureSamplerLinear
michael@0 65 {
michael@0 66 Filter = MIN_MAG_MIP_LINEAR;
michael@0 67 AddressU = Clamp;
michael@0 68 AddressV = Clamp;
michael@0 69 };
michael@0 70
michael@0 71 float4 TransformedPosition(float2 aInPosition)
michael@0 72 {
michael@0 73 // the current vertex's position on the quad
michael@0 74 float4 position = float4(0, 0, 0, 1);
michael@0 75
michael@0 76 // We use 4 component floats to uniquely describe a rectangle, by the structure
michael@0 77 // of x, y, width, height. This allows us to easily generate the 4 corners
michael@0 78 // of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the
michael@0 79 // stream source for our LayerQuad vertex shader. We do this by doing:
michael@0 80 // Xout = x + Xin * width
michael@0 81 // Yout = y + Yin * height
michael@0 82 float2 size = vLayerQuad.zw;
michael@0 83 position.x = vLayerQuad.x + aInPosition.x * size.x;
michael@0 84 position.y = vLayerQuad.y + aInPosition.y * size.y;
michael@0 85
michael@0 86 position = mul(mLayerTransform, position);
michael@0 87
michael@0 88 return position;
michael@0 89 }
michael@0 90
michael@0 91 float4 VertexPosition(float4 aTransformedPosition)
michael@0 92 {
michael@0 93 float4 result;
michael@0 94 result.w = aTransformedPosition.w;
michael@0 95 result.xyz = aTransformedPosition.xyz / aTransformedPosition.w;
michael@0 96 result -= vRenderTargetOffset;
michael@0 97 result.xyz *= result.w;
michael@0 98
michael@0 99 result = mul(mProjection, result);
michael@0 100
michael@0 101 return result;
michael@0 102 }
michael@0 103
michael@0 104 VS_OUTPUT LayerQuadVS(const VS_INPUT aVertex)
michael@0 105 {
michael@0 106 VS_OUTPUT outp;
michael@0 107 float4 position = TransformedPosition(aVertex.vPosition);
michael@0 108
michael@0 109 outp.vPosition = VertexPosition(position);
michael@0 110 outp.vTexCoords = TexCoords(aVertex.vPosition.xy);
michael@0 111
michael@0 112 return outp;
michael@0 113 }
michael@0 114
michael@0 115 VS_MASK_OUTPUT LayerQuadMaskVS(const VS_INPUT aVertex)
michael@0 116 {
michael@0 117 VS_MASK_OUTPUT outp;
michael@0 118 float4 position = TransformedPosition(aVertex.vPosition);
michael@0 119
michael@0 120 outp.vPosition = VertexPosition(position);
michael@0 121
michael@0 122 // calculate the position on the mask texture
michael@0 123 outp.vMaskCoords.x = (position.x - vMaskQuad.x) / vMaskQuad.z;
michael@0 124 outp.vMaskCoords.y = (position.y - vMaskQuad.y) / vMaskQuad.w;
michael@0 125
michael@0 126 outp.vTexCoords = TexCoords(aVertex.vPosition.xy);
michael@0 127
michael@0 128 return outp;
michael@0 129 }
michael@0 130
michael@0 131 VS_MASK_3D_OUTPUT LayerQuadMask3DVS(const VS_INPUT aVertex)
michael@0 132 {
michael@0 133 VS_MASK_3D_OUTPUT outp;
michael@0 134 float4 position = TransformedPosition(aVertex.vPosition);
michael@0 135
michael@0 136 outp.vPosition = VertexPosition(position);
michael@0 137
michael@0 138 // calculate the position on the mask texture
michael@0 139 position.xyz /= position.w;
michael@0 140 outp.vMaskCoords.x = (position.x - vMaskQuad.x) / vMaskQuad.z;
michael@0 141 outp.vMaskCoords.y = (position.y - vMaskQuad.y) / vMaskQuad.w;
michael@0 142 // We use the w coord to do non-perspective correct interpolation:
michael@0 143 // the quad might be transformed in 3D, in which case it will have some
michael@0 144 // perspective. The graphics card will do perspective-correct interpolation
michael@0 145 // of the texture, but our mask is already transformed and so we require
michael@0 146 // linear interpolation. Therefore, we must correct the interpolation
michael@0 147 // ourselves, we do this by multiplying all coords by w here, and dividing by
michael@0 148 // w in the pixel shader (post-interpolation), we pass w in outp.vMaskCoords.z.
michael@0 149 // See http://en.wikipedia.org/wiki/Texture_mapping#Perspective_correctness
michael@0 150 outp.vMaskCoords.z = 1;
michael@0 151 outp.vMaskCoords *= position.w;
michael@0 152
michael@0 153 outp.vTexCoords = TexCoords(aVertex.vPosition.xy);
michael@0 154
michael@0 155 return outp;
michael@0 156 }
michael@0 157
michael@0 158 float4 RGBAShaderMask(const VS_MASK_OUTPUT aVertex) : SV_Target
michael@0 159 {
michael@0 160 float2 maskCoords = aVertex.vMaskCoords;
michael@0 161 float mask = tMask.Sample(sSampler, maskCoords).a;
michael@0 162 return tRGB.Sample(sSampler, aVertex.vTexCoords) * fLayerOpacity * mask;
michael@0 163 }
michael@0 164
michael@0 165 float4 RGBAShaderMask3D(const VS_MASK_3D_OUTPUT aVertex) : SV_Target
michael@0 166 {
michael@0 167 float2 maskCoords = aVertex.vMaskCoords.xy / aVertex.vMaskCoords.z;
michael@0 168 float mask = tMask.Sample(LayerTextureSamplerLinear, maskCoords).a;
michael@0 169 return tRGB.Sample(sSampler, aVertex.vTexCoords) * fLayerOpacity * mask;
michael@0 170 }
michael@0 171
michael@0 172 float4 RGBShaderMask(const VS_MASK_OUTPUT aVertex) : SV_Target
michael@0 173 {
michael@0 174 float4 result;
michael@0 175 result = tRGB.Sample(sSampler, aVertex.vTexCoords) * fLayerOpacity;
michael@0 176 result.a = fLayerOpacity;
michael@0 177
michael@0 178 float2 maskCoords = aVertex.vMaskCoords;
michael@0 179 float mask = tMask.Sample(sSampler, maskCoords).a;
michael@0 180 return result * mask;
michael@0 181 }
michael@0 182
michael@0 183 float4 CalculateYCbCrColor(const float2 aTexCoords)
michael@0 184 {
michael@0 185 float4 yuv;
michael@0 186 float4 color;
michael@0 187
michael@0 188 yuv.r = tCr.Sample(sSampler, aTexCoords).a - 0.5;
michael@0 189 yuv.g = tY.Sample(sSampler, aTexCoords).a - 0.0625;
michael@0 190 yuv.b = tCb.Sample(sSampler, aTexCoords).a - 0.5;
michael@0 191
michael@0 192 color.r = yuv.g * 1.164 + yuv.r * 1.596;
michael@0 193 color.g = yuv.g * 1.164 - 0.813 * yuv.r - 0.391 * yuv.b;
michael@0 194 color.b = yuv.g * 1.164 + yuv.b * 2.018;
michael@0 195 color.a = 1.0f;
michael@0 196
michael@0 197 return color;
michael@0 198 }
michael@0 199
michael@0 200 float4 YCbCrShaderMask(const VS_MASK_OUTPUT aVertex) : SV_Target
michael@0 201 {
michael@0 202 float2 maskCoords = aVertex.vMaskCoords;
michael@0 203 float mask = tMask.Sample(sSampler, maskCoords).a;
michael@0 204
michael@0 205 return CalculateYCbCrColor(aVertex.vTexCoords) * fLayerOpacity * mask;
michael@0 206 }
michael@0 207
michael@0 208 PS_OUTPUT ComponentAlphaShaderMask(const VS_MASK_OUTPUT aVertex) : SV_Target
michael@0 209 {
michael@0 210 PS_OUTPUT result;
michael@0 211
michael@0 212 result.vSrc = tRGB.Sample(sSampler, aVertex.vTexCoords);
michael@0 213 result.vAlpha = 1.0 - tRGBWhite.Sample(sSampler, aVertex.vTexCoords) + result.vSrc;
michael@0 214 result.vSrc.a = result.vAlpha.g;
michael@0 215
michael@0 216 float2 maskCoords = aVertex.vMaskCoords;
michael@0 217 float mask = tMask.Sample(sSampler, maskCoords).a;
michael@0 218 result.vSrc *= fLayerOpacity * mask;
michael@0 219 result.vAlpha *= fLayerOpacity * mask;
michael@0 220
michael@0 221 return result;
michael@0 222 }
michael@0 223
michael@0 224 float4 SolidColorShaderMask(const VS_MASK_OUTPUT aVertex) : SV_Target
michael@0 225 {
michael@0 226 float2 maskCoords = aVertex.vMaskCoords;
michael@0 227 float mask = tMask.Sample(sSampler, maskCoords).a;
michael@0 228 return fLayerColor * mask;
michael@0 229 }
michael@0 230
michael@0 231 /*
michael@0 232 * Un-masked versions
michael@0 233 *************************************************************
michael@0 234 */
michael@0 235 float4 RGBAShader(const VS_OUTPUT aVertex) : SV_Target
michael@0 236 {
michael@0 237 return tRGB.Sample(sSampler, aVertex.vTexCoords) * fLayerOpacity;
michael@0 238 }
michael@0 239
michael@0 240 float4 RGBShader(const VS_OUTPUT aVertex) : SV_Target
michael@0 241 {
michael@0 242 float4 result;
michael@0 243 result = tRGB.Sample(sSampler, aVertex.vTexCoords) * fLayerOpacity;
michael@0 244 result.a = fLayerOpacity;
michael@0 245 return result;
michael@0 246 }
michael@0 247
michael@0 248 float4 YCbCrShader(const VS_OUTPUT aVertex) : SV_Target
michael@0 249 {
michael@0 250 return CalculateYCbCrColor(aVertex.vTexCoords) * fLayerOpacity;
michael@0 251 }
michael@0 252
michael@0 253 PS_OUTPUT ComponentAlphaShader(const VS_OUTPUT aVertex) : SV_Target
michael@0 254 {
michael@0 255 PS_OUTPUT result;
michael@0 256
michael@0 257 result.vSrc = tRGB.Sample(sSampler, aVertex.vTexCoords);
michael@0 258 result.vAlpha = 1.0 - tRGBWhite.Sample(sSampler, aVertex.vTexCoords) + result.vSrc;
michael@0 259 result.vSrc.a = result.vAlpha.g;
michael@0 260 result.vSrc *= fLayerOpacity;
michael@0 261 result.vAlpha *= fLayerOpacity;
michael@0 262 return result;
michael@0 263 }
michael@0 264
michael@0 265 float4 SolidColorShader(const VS_OUTPUT aVertex) : SV_Target
michael@0 266 {
michael@0 267 return fLayerColor;
michael@0 268 }

mercurial