Bug 601257: Clean up usage of shader constants in D3D9 layers. r=jrmuizel a=joedrew

This commit is contained in:
Bas Schouten 2010-10-02 00:24:58 +02:00
Родитель d8e44f9222
Коммит 06010eada9
10 изменённых файлов: 202 добавлений и 232 удалений

Просмотреть файл

@ -233,31 +233,20 @@ CanvasLayerD3D9::RenderLayer()
Updated(mBounds);
}
float quadTransform[4][4];
/*
* Matrix to transform the <0.0,0.0>, <1.0,1.0> quad to the correct position
* and size. To get pixel perfect mapping we offset the quad half a pixel
* to the top-left. We also flip the Y axis here, note we can only do this
* because we are in CULL_NONE mode!
*
* See: http://msdn.microsoft.com/en-us/library/bb219690%28VS.85%29.aspx
* We flip the Y axis here, note we can only do this because we are in
* CULL_NONE mode!
*/
memset(&quadTransform, 0, sizeof(quadTransform));
quadTransform[0][0] = (float)mBounds.width;
ShaderConstantRect quad(0, 0, mBounds.width, mBounds.height);
if (mNeedsYFlip) {
quadTransform[1][1] = (float)-mBounds.height;
quadTransform[3][1] = (float)mBounds.height;
} else {
quadTransform[1][1] = (float)mBounds.height;
quadTransform[3][1] = 0.0f;
quad.mHeight = (float)-mBounds.height;
quad.mY = (float)mBounds.height;
}
quadTransform[2][2] = 1.0f;
quadTransform[3][0] = 0.0f;
quadTransform[3][3] = 1.0f;
device()->SetVertexShaderConstantF(0, &quadTransform[0][0], 4);
device()->SetVertexShaderConstantF(CBvLayerQuad, quad, 1);
device()->SetVertexShaderConstantF(4, &mTransform._11, 4);
device()->SetVertexShaderConstantF(CBmLayerTransform, &mTransform._11, 4);
float opacity[4];
/*
@ -265,7 +254,7 @@ CanvasLayerD3D9::RenderLayer()
* first component since it's declared as a 'float'.
*/
opacity[0] = GetOpacity();
device()->SetPixelShaderConstantF(0, opacity, 1);
device()->SetPixelShaderConstantF(CBfLayerOpacity, opacity, 1);
mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);

Просмотреть файл

@ -53,19 +53,17 @@ ColorLayerD3D9::RenderLayer()
// XXX we might be able to improve performance by using
// IDirect3DDevice9::Clear
float quadTransform[4][4];
nsIntRect visibleRect = mVisibleRegion.GetBounds();
// Transform the quad to the size of the visible area.
memset(&quadTransform, 0, sizeof(quadTransform));
quadTransform[0][0] = (float)visibleRect.width;
quadTransform[1][1] = (float)visibleRect.height;
quadTransform[2][2] = 1.0f;
quadTransform[3][0] = (float)visibleRect.x;
quadTransform[3][1] = (float)visibleRect.y;
quadTransform[3][3] = 1.0f;
device()->SetVertexShaderConstantF(0, &quadTransform[0][0], 4);
device()->SetVertexShaderConstantF(4, &mTransform._11, 4);
device()->SetVertexShaderConstantF(
CBvLayerQuad,
ShaderConstantRect(visibleRect.x,
visibleRect.y,
visibleRect.width,
visibleRect.height),
1);
device()->SetVertexShaderConstantF(CBmLayerTransform, &mTransform._11, 4);
float color[4];
// color is premultiplied, so we need to adjust all channels

Просмотреть файл

@ -159,26 +159,23 @@ ContainerLayerD3D9::RenderLayer()
renderTexture->GetSurfaceLevel(0, getter_AddRefs(renderSurface));
device()->SetRenderTarget(0, renderSurface);
device()->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0, 0, 0, 0), 0, 0);
device()->GetVertexShaderConstantF(12, previousRenderTargetOffset, 1);
device()->GetVertexShaderConstantF(CBvRenderTargetOffset, previousRenderTargetOffset, 1);
renderTargetOffset[0] = (float)visibleRect.x;
renderTargetOffset[1] = (float)visibleRect.y;
device()->SetVertexShaderConstantF(12, renderTargetOffset, 1);
device()->SetVertexShaderConstantF(CBvRenderTargetOffset, renderTargetOffset, 1);
float viewMatrix[4][4];
gfx3DMatrix viewMatrix;
/*
* Matrix to transform to viewport space ( <-1.0, 1.0> topleft,
* <1.0, -1.0> bottomright)
*/
memset(&viewMatrix, 0, sizeof(viewMatrix));
viewMatrix[0][0] = 2.0f / visibleRect.width;
viewMatrix[1][1] = -2.0f / visibleRect.height;
viewMatrix[2][2] = 1.0f;
viewMatrix[3][0] = -1.0f;
viewMatrix[3][1] = 1.0f;
viewMatrix[3][3] = 1.0f;
viewMatrix._11 = 2.0f / visibleRect.width;
viewMatrix._22 = -2.0f / visibleRect.height;
viewMatrix._41 = -1.0f;
viewMatrix._42 = 1.0f;
device()->GetVertexShaderConstantF(8, &oldViewMatrix[0][0], 4);
device()->SetVertexShaderConstantF(8, &viewMatrix[0][0], 4);
device()->GetVertexShaderConstantF(CBmProjection, &oldViewMatrix[0][0], 4);
device()->SetVertexShaderConstantF(CBmProjection, &viewMatrix._11, 4);
}
/*
@ -228,27 +225,17 @@ ContainerLayerD3D9::RenderLayer()
if (useIntermediate) {
device()->SetRenderTarget(0, previousRenderTarget);
device()->SetScissorRect(&oldClipRect);
device()->SetVertexShaderConstantF(12, previousRenderTargetOffset, 1);
device()->SetVertexShaderConstantF(8, &oldViewMatrix[0][0], 4);
device()->SetVertexShaderConstantF(CBvRenderTargetOffset, previousRenderTargetOffset, 1);
device()->SetVertexShaderConstantF(CBmProjection, &oldViewMatrix[0][0], 4);
float quadTransform[4][4];
/*
* Matrix to transform the <0.0,0.0>, <1.0,1.0> quad to the correct position
* and size. To get pixel perfect mapping we offset the quad half a pixel
* to the top-left.
*
* See: http://msdn.microsoft.com/en-us/library/bb219690%28VS.85%29.aspx
*/
memset(&quadTransform, 0, sizeof(quadTransform));
quadTransform[0][0] = (float)visibleRect.width;
quadTransform[1][1] = (float)visibleRect.height;
quadTransform[2][2] = 1.0f;
quadTransform[3][0] = (float)visibleRect.x;
quadTransform[3][1] = (float)visibleRect.y;
quadTransform[3][3] = 1.0f;
device()->SetVertexShaderConstantF(CBvLayerQuad,
ShaderConstantRect(visibleRect.x,
visibleRect.y,
visibleRect.width,
visibleRect.height),
1);
device()->SetVertexShaderConstantF(0, &quadTransform[0][0], 4);
device()->SetVertexShaderConstantF(4, &mTransform._11, 4);
device()->SetVertexShaderConstantF(CBmLayerTransform, &mTransform._11, 4);
float opacityVector[4];
/*
@ -256,7 +243,7 @@ ContainerLayerD3D9::RenderLayer()
* first component since it's declared as a 'float'.
*/
opacityVector[0] = opacity;
device()->SetPixelShaderConstantF(0, opacityVector, 1);
device()->SetPixelShaderConstantF(CBfLayerOpacity, opacityVector, 1);
mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);

Просмотреть файл

@ -51,6 +51,14 @@ class DeviceManagerD3D9;
class LayerD3D9;
class Nv3DVUtils;
// Shader Constant locations
const int CBmLayerTransform = 0;
const int CBmProjection = 4;
const int CBvRenderTargetOffset = 8;
const int CBvTextureCoords = 9;
const int CBvLayerQuad = 10;
const int CBfLayerOpacity = 0;
/**
* SwapChain class, this class manages the swap chain belonging to a
* LayerManagerD3D9.

Просмотреть файл

@ -165,21 +165,14 @@ ImageLayerD3D9::RenderLayer()
}
yuvImage->AllocateTextures();
float quadTransform[4][4];
/*
* Matrix to transform the <0.0,0.0>, <1.0,1.0> quad to the correct position
* and size. To get pixel perfect mapping we extend the quad half a pixel
* beyond all edges.
*/
memset(&quadTransform, 0, sizeof(quadTransform));
quadTransform[0][0] = (float)yuvImage->mSize.width;
quadTransform[1][1] = (float)yuvImage->mSize.height;
quadTransform[2][2] = 1.0f;
quadTransform[3][3] = 1.0f;
device()->SetVertexShaderConstantF(CBvLayerQuad,
ShaderConstantRect(0,
0,
yuvImage->mSize.width,
yuvImage->mSize.height),
1);
device()->SetVertexShaderConstantF(0, &quadTransform[0][0], 4);
device()->SetVertexShaderConstantF(4, &mTransform._11, 4);
device()->SetVertexShaderConstantF(CBmLayerTransform, &mTransform._11, 4);
float opacity[4];
/*
@ -187,7 +180,7 @@ ImageLayerD3D9::RenderLayer()
* only use the the first component since it's declared as a 'float'.
*/
opacity[0] = GetOpacity();
device()->SetPixelShaderConstantF(0, opacity, 1);
device()->SetPixelShaderConstantF(CBfLayerOpacity, opacity, 1);
mD3DManager->SetShaderMode(DeviceManagerD3D9::YCBCRLAYER);
@ -219,21 +212,15 @@ ImageLayerD3D9::RenderLayer()
CairoImageD3D9 *cairoImage =
static_cast<CairoImageD3D9*>(image.get());
float quadTransform[4][4];
/*
* Matrix to transform the <0.0,0.0>, <1.0,1.0> quad to the correct position
* and size. To get pixel perfect mapping we extend the quad half a pixel
* beyond all edges.
*/
memset(&quadTransform, 0, sizeof(quadTransform));
quadTransform[0][0] = (float)cairoImage->mSize.width;
quadTransform[1][1] = (float)cairoImage->mSize.height;
quadTransform[2][2] = 1.0f;
quadTransform[3][3] = 1.0f;
device()->SetVertexShaderConstantF(CBvLayerQuad,
ShaderConstantRect(0,
0,
cairoImage->mSize.width,
cairoImage->mSize.height),
1);
device()->SetVertexShaderConstantF(0, &quadTransform[0][0], 4);
device()->SetVertexShaderConstantF(4, &mTransform._11, 4);
device()->SetVertexShaderConstantF(CBmLayerTransform, &mTransform._11, 4);
float opacity[4];
/*
@ -241,7 +228,7 @@ ImageLayerD3D9::RenderLayer()
* only use the the first component since it's declared as a 'float'.
*/
opacity[0] = GetOpacity();
device()->SetPixelShaderConstantF(0, opacity, 1);
device()->SetPixelShaderConstantF(CBfLayerOpacity, opacity, 1);
mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);

Просмотреть файл

@ -310,26 +310,26 @@ LayerManagerD3D9::SetupPipeline()
nsIntRect rect;
mWidget->GetClientBounds(rect);
float viewMatrix[4][4];
gfx3DMatrix viewMatrix;
/*
* Matrix to transform to viewport space ( <-1.0, 1.0> topleft,
* <1.0, -1.0> bottomright)
*/
memset(&viewMatrix, 0, sizeof(viewMatrix));
viewMatrix[0][0] = 2.0f / rect.width;
viewMatrix[1][1] = -2.0f / rect.height;
viewMatrix[2][2] = 1.0f;
viewMatrix[3][0] = -1.0f;
viewMatrix[3][1] = 1.0f;
viewMatrix[3][3] = 1.0f;
viewMatrix._11 = 2.0f / rect.width;
viewMatrix._22 = -2.0f / rect.height;
viewMatrix._41 = -1.0f;
viewMatrix._42 = 1.0f;
HRESULT hr = device()->SetVertexShaderConstantF(8, &viewMatrix[0][0], 4);
HRESULT hr = device()->SetVertexShaderConstantF(CBmProjection,
&viewMatrix._11, 4);
if (FAILED(hr)) {
NS_WARNING("Failed to set projection shader constant!");
}
hr = device()->SetVertexShaderConstantF(13, ShaderConstantRect(0, 0, 1.0f, 1.0f), 1);
hr = device()->SetVertexShaderConstantF(CBvTextureCoords,
ShaderConstantRect(0, 0, 1.0f, 1.0f),
1);
if (FAILED(hr)) {
NS_WARNING("Failed to set texCoords shader constant!");

Просмотреть файл

@ -66,10 +66,22 @@ class ThebesLayerD3D9;
struct ShaderConstantRect
{
float mX, mY, mWidth, mHeight;
// Provide all the commonly used argument types to prevent all the local
// casts in the code.
ShaderConstantRect(float aX, float aY, float aWidth, float aHeight)
: mX(aX), mY(aY), mWidth(aWidth), mHeight(aHeight)
{ }
ShaderConstantRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
: mX((float)aX), mY((float)aY)
, mWidth((float)aWidth), mHeight((float)aHeight)
{ }
ShaderConstantRect(PRInt32 aX, PRInt32 aY, float aWidth, float aHeight)
: mX((float)aX), mY((float)aY), mWidth(aWidth), mHeight(aHeight)
{ }
// For easy passing to SetVertexShaderConstantF.
operator float* () { return &mX; }
};

Просмотреть файл

@ -8,9 +8,9 @@
//
// Parameters:
//
// float4x4 mLayerQuadTransform;
// float4x4 mLayerTransform;
// float4x4 mProjection;
// float4 vLayerQuad;
// float4 vRenderTargetOffset;
// float4 vTextureCoords;
//
@ -19,145 +19,132 @@
//
// Name Reg Size
// ------------------- ----- ----
// mLayerQuadTransform c0 4
// mLayerTransform c4 4
// mProjection c8 4
// vRenderTargetOffset c12 1
// vTextureCoords c13 1
// mLayerTransform c0 4
// mProjection c4 4
// vRenderTargetOffset c8 1
// vTextureCoords c9 1
// vLayerQuad c10 1
//
vs_2_0
def c14, -0.5, 0, 0, 0
def c11, -0.5, 0, 0, 0
dcl_position v0
mul r0, v0.y, c1
mad r0, c0, v0.x, r0
mad r0.xy, v0, c10.zwzw, c10
mul r1, r0.y, c1
mad r0, c0, r0.x, r1
mad r0, c2, v0.z, r0
mad r0, c3, v0.w, r0
add r0, r0, -c8
add r0.xy, r0, c11.x
mul r1, r0.y, c5
mad r1, c4, r0.x, r1
mad r1, c6, r0.z, r1
mad r0, c7, r0.w, r1
add r0, r0, -c12
add r0.xy, r0, c14.x
mul r1, r0.y, c9
mad r1, c8, r0.x, r1
mad r1, c10, r0.z, r1
mad oPos, c11, r0.w, r1
mad oT0.xy, v0, c13.zwzw, c13
mad oPos, c7, r0.w, r1
mad oT0.xy, v0, c9.zwzw, c9
// approximately 15 instruction slots used
// approximately 12 instruction slots used
#endif
const BYTE LayerQuadVS[] =
{
0, 2, 254, 255, 254, 255,
80, 0, 67, 84, 65, 66,
28, 0, 0, 0, 11, 1,
78, 0, 67, 84, 65, 66,
28, 0, 0, 0, 2, 1,
0, 0, 0, 2, 254, 255,
5, 0, 0, 0, 28, 0,
0, 0, 0, 1, 0, 0,
4, 1, 0, 0, 128, 0,
251, 0, 0, 0, 128, 0,
0, 0, 2, 0, 0, 0,
4, 0, 0, 0, 148, 0,
4, 0, 0, 0, 144, 0,
0, 0, 0, 0, 0, 0,
164, 0, 0, 0, 2, 0,
160, 0, 0, 0, 2, 0,
4, 0, 4, 0, 0, 0,
148, 0, 0, 0, 0, 0,
0, 0, 180, 0, 0, 0,
2, 0, 8, 0, 4, 0,
0, 0, 148, 0, 0, 0,
0, 0, 0, 0, 192, 0,
0, 0, 2, 0, 12, 0,
1, 0, 0, 0, 212, 0,
144, 0, 0, 0, 0, 0,
0, 0, 172, 0, 0, 0,
2, 0, 10, 0, 1, 0,
0, 0, 184, 0, 0, 0,
0, 0, 0, 0, 200, 0,
0, 0, 2, 0, 8, 0,
1, 0, 0, 0, 220, 0,
0, 0, 0, 0, 0, 0,
228, 0, 0, 0, 2, 0,
13, 0, 1, 0, 0, 0,
244, 0, 0, 0, 0, 0,
0, 0, 109, 76, 97, 121,
101, 114, 81, 117, 97, 100,
84, 114, 97, 110, 115, 102,
111, 114, 109, 0, 3, 0,
3, 0, 4, 0, 4, 0,
1, 0, 0, 0, 0, 0,
236, 0, 0, 0, 2, 0,
9, 0, 1, 0, 0, 0,
184, 0, 0, 0, 0, 0,
0, 0, 109, 76, 97, 121,
101, 114, 84, 114, 97, 110,
115, 102, 111, 114, 109, 0,
109, 80, 114, 111, 106, 101,
99, 116, 105, 111, 110, 0,
118, 82, 101, 110, 100, 101,
114, 84, 97, 114, 103, 101,
116, 79, 102, 102, 115, 101,
116, 0, 1, 0, 3, 0,
1, 0, 4, 0, 1, 0,
0, 0, 0, 0, 0, 0,
118, 84, 101, 120, 116, 117,
114, 101, 67, 111, 111, 114,
100, 115, 0, 171, 1, 0,
3, 0, 3, 0, 4, 0,
4, 0, 1, 0, 0, 0,
0, 0, 0, 0, 109, 80,
114, 111, 106, 101, 99, 116,
105, 111, 110, 0, 118, 76,
97, 121, 101, 114, 81, 117,
97, 100, 0, 171, 1, 0,
3, 0, 1, 0, 4, 0,
1, 0, 0, 0, 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, 81, 0,
0, 5, 14, 0, 15, 160,
0, 0, 0, 191, 0, 0,
0, 0, 118, 82, 101, 110,
100, 101, 114, 84, 97, 114,
103, 101, 116, 79, 102, 102,
115, 101, 116, 0, 1, 0,
3, 0, 1, 0, 4, 0,
1, 0, 0, 0, 0, 0,
0, 0, 118, 84, 101, 120,
116, 117, 114, 101, 67, 111,
111, 114, 100, 115, 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, 171, 81, 0, 0, 5,
11, 0, 15, 160, 0, 0,
0, 191, 0, 0, 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, 1, 0,
0, 0, 31, 0, 0, 2,
0, 0, 0, 128, 0, 0,
15, 144, 4, 0, 0, 4,
0, 0, 3, 128, 0, 0,
228, 144, 10, 0, 238, 160,
10, 0, 228, 160, 5, 0,
0, 3, 1, 0, 15, 128,
0, 0, 85, 128, 1, 0,
228, 160, 4, 0, 0, 4,
0, 0, 15, 128, 0, 0,
228, 160, 0, 0, 0, 144,
0, 0, 228, 128, 4, 0,
228, 160, 0, 0, 0, 128,
1, 0, 228, 128, 4, 0,
0, 4, 0, 0, 15, 128,
2, 0, 228, 160, 0, 0,
170, 144, 0, 0, 228, 128,
4, 0, 0, 4, 0, 0,
15, 128, 3, 0, 228, 160,
0, 0, 255, 144, 0, 0,
228, 128, 5, 0, 0, 3,
1, 0, 15, 128, 0, 0,
85, 128, 5, 0, 228, 160,
4, 0, 0, 4, 1, 0,
15, 128, 4, 0, 228, 160,
0, 0, 0, 128, 1, 0,
228, 128, 4, 0, 0, 4,
1, 0, 15, 128, 6, 0,
228, 160, 0, 0, 170, 128,
1, 0, 228, 128, 4, 0,
0, 4, 0, 0, 15, 128,
7, 0, 228, 160, 0, 0,
255, 128, 1, 0, 228, 128,
228, 128, 2, 0, 0, 3,
0, 0, 15, 128, 0, 0,
228, 128, 8, 0, 228, 161,
2, 0, 0, 3, 0, 0,
15, 128, 0, 0, 228, 128,
12, 0, 228, 161, 2, 0,
0, 3, 0, 0, 3, 128,
0, 0, 228, 128, 14, 0,
0, 160, 5, 0, 0, 3,
1, 0, 15, 128, 0, 0,
85, 128, 9, 0, 228, 160,
4, 0, 0, 4, 1, 0,
15, 128, 8, 0, 228, 160,
0, 0, 0, 128, 1, 0,
228, 128, 4, 0, 0, 4,
1, 0, 15, 128, 10, 0,
228, 160, 0, 0, 170, 128,
3, 128, 0, 0, 228, 128,
11, 0, 0, 160, 5, 0,
0, 3, 1, 0, 15, 128,
0, 0, 85, 128, 5, 0,
228, 160, 4, 0, 0, 4,
1, 0, 15, 128, 4, 0,
228, 160, 0, 0, 0, 128,
1, 0, 228, 128, 4, 0,
0, 4, 0, 0, 15, 192,
11, 0, 228, 160, 0, 0,
255, 128, 1, 0, 228, 128,
0, 4, 1, 0, 15, 128,
6, 0, 228, 160, 0, 0,
170, 128, 1, 0, 228, 128,
4, 0, 0, 4, 0, 0,
3, 224, 0, 0, 228, 144,
13, 0, 238, 160, 13, 0,
228, 160, 255, 255, 0, 0
15, 192, 7, 0, 228, 160,
0, 0, 255, 128, 1, 0,
228, 128, 4, 0, 0, 4,
0, 0, 3, 224, 0, 0,
228, 144, 9, 0, 238, 160,
9, 0, 228, 160, 255, 255,
0, 0
};
#if 0
//

Просмотреть файл

@ -1,10 +1,10 @@
float4x4 mLayerQuadTransform;
float4x4 mLayerTransform;
float4 vRenderTargetOffset;
float4x4 mProjection;
typedef float4 rect;
rect vTextureCoords;
rect vLayerQuad;
texture tex0;
sampler s2D;
@ -28,7 +28,18 @@ VS_OUTPUT LayerQuadVS(const VS_INPUT aVertex)
{
VS_OUTPUT outp;
outp.vPosition = aVertex.vPosition;
outp.vPosition = mul(mLayerQuadTransform, outp.vPosition);
// We use 4 component floats to uniquely describe a rectangle, by the structure
// of x, y, width, height. This allows us to easily generate the 4 corners
// of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the
// stream source for our LayerQuad vertex shader. We do this by doing:
// Xout = x + Xin * width
// Yout = y + Yin * height
float2 position = vLayerQuad.xy;
float2 size = vLayerQuad.zw;
outp.vPosition.x = position.x + outp.vPosition.x * size.x;
outp.vPosition.y = position.y + outp.vPosition.y * size.y;
outp.vPosition = mul(mLayerTransform, outp.vPosition);
outp.vPosition = outp.vPosition - vRenderTargetOffset;
@ -37,17 +48,12 @@ VS_OUTPUT LayerQuadVS(const VS_INPUT aVertex)
outp.vPosition.xy -= 0.5;
outp.vPosition = mul(mProjection, outp.vPosition);
// We use 4 component floats to uniquely describe a rectangle, by the structure
// of x, y, width, height. This allows us to easily generate the 4 corners
// of any rectangle from the 4 corners of the 0,0-1,1 quad that we use as the
// stream source for our LayerQuad vertex shader. We do this by doing:
// Xout = x + Xin * width
// Yout = y + Yin * height
float2 position = vTextureCoords.xy;
float2 size = vTextureCoords.zw;
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;
}

Просмотреть файл

@ -225,16 +225,7 @@ ThebesLayerD3D9::RenderLayer()
mValidRegion = mVisibleRegion;
}
float quadTransform[4][4];
/*
* Matrix to transform the <0.0,0.0>, <1.0,1.0> quad to the correct position
* and size.
*/
memset(&quadTransform, 0, sizeof(quadTransform));
quadTransform[2][2] = 1.0f;
quadTransform[3][3] = 1.0f;
device()->SetVertexShaderConstantF(4, &mTransform._11, 4);
device()->SetVertexShaderConstantF(CBmLayerTransform, &mTransform._11, 4);
float opacity[4];
/*
@ -257,22 +248,27 @@ ThebesLayerD3D9::RenderLayer()
const nsIntRect *iterRect;
while ((iterRect = iter.Next())) {
quadTransform[0][0] = (float)iterRect->width;
quadTransform[1][1] = (float)iterRect->height;
quadTransform[3][0] = (float)iterRect->x;
quadTransform[3][1] = (float)iterRect->y;
device()->SetVertexShaderConstantF(0, &quadTransform[0][0], 4);
device()->SetVertexShaderConstantF(13, ShaderConstantRect(
device()->SetVertexShaderConstantF(CBvLayerQuad,
ShaderConstantRect(iterRect->x,
iterRect->y,
iterRect->width,
iterRect->height),
1);
device()->SetVertexShaderConstantF(CBvTextureCoords,
ShaderConstantRect(
(float)(iterRect->x - visibleRect.x) / (float)visibleRect.width,
(float)(iterRect->y - visibleRect.y) / (float)visibleRect.height,
(float)iterRect->width / (float)visibleRect.width,
(float)iterRect->height / (float)visibleRect.height), 1);
device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
// Set back to default.
device()->SetVertexShaderConstantF(13, ShaderConstantRect(0, 0, 1.0f, 1.0f), 1);
device()->SetVertexShaderConstantF(CBvTextureCoords,
ShaderConstantRect(0, 0, 1.0f, 1.0f),
1);
}
void