Bug 894891 - Move texture transform from the RGBATextureLayerExternal shader into the vertex shader, and combine the two GL_TEXTURE_EXTERNAL shaders. r=jrmuziel

This commit is contained in:
Matt Woodrow 2013-07-18 23:05:06 -04:00
parent 39cbcffa7c
commit 25483332a6
11 changed files with 24 additions and 149 deletions

View File

@ -330,6 +330,7 @@ CanvasLayerOGL::RenderLayer(int aPreviousDestination,
}
program->SetLayerQuadRect(drawRect);
program->SetLayerTransform(GetEffectiveTransform());
program->SetTextureTransform(gfx3DMatrix());
program->SetLayerOpacity(GetEffectiveOpacity());
program->SetRenderOffset(aOffset);
program->SetTextureUnit(0);

View File

@ -37,6 +37,7 @@ RenderColorLayer(ColorLayer* aLayer, LayerManagerOGL *aManager,
program->Activate();
program->SetLayerQuadRect(aLayer->GetBounds());
program->SetLayerTransform(aLayer->GetEffectiveTransform());
program->SetTextureTransform(gfx3DMatrix());
program->SetRenderOffset(aOffset);
program->SetRenderColor(color);
program->LoadMask(aLayer->GetMaskLayer());

View File

@ -1038,6 +1038,7 @@ CompositorOGL::DrawQuad(const Rect& aRect, const Rect& aClipRect,
}
program->SetLayerQuadRect(aRect);
program->SetLayerTransform(aTransform);
program->SetTextureTransform(gfx3DMatrix());
program->SetRenderOffset(aOffset.x, aOffset.y);
switch (aEffectChain.mPrimaryEffect->mType) {
@ -1085,9 +1086,8 @@ CompositorOGL::DrawQuad(const Rect& aRect, const Rect& aClipRect,
}
AutoBindTexture bindSource(source->AsSourceOGL(), LOCAL_GL_TEXTURE0);
if (programType == RGBALayerExternalProgramType) {
program->SetTextureTransform(source->AsSourceOGL()->GetTextureTransform());
}
program->SetTextureTransform(source->AsSourceOGL()->GetTextureTransform());
mGLContext->ApplyFilterToBoundTexture(source->AsSourceOGL()->GetTextureTarget(),
ThebesFilter(texturedEffect->mFilter));
@ -1216,6 +1216,7 @@ CompositorOGL::DrawQuad(const Rect& aRect, const Rect& aClipRect,
program->SetWhiteTextureUnit(1);
program->SetLayerOpacity(aOpacity);
program->SetLayerTransform(aTransform);
program->SetTextureTransform(gfx3DMatrix());
program->SetRenderOffset(aOffset.x, aOffset.y);
program->SetLayerQuadRect(aRect);
AutoBindTexture bindMask;

View File

@ -322,6 +322,7 @@ ContainerRender(Container* aContainer,
rgb->Activate();
rgb->SetLayerQuadRect(visibleRect);
rgb->SetLayerTransform(transform);
rgb->SetTextureTransform(gfx3DMatrix());
rgb->SetLayerOpacity(opacity);
rgb->SetRenderOffset(aOffset);
rgb->SetTextureUnit(0);

View File

@ -239,6 +239,7 @@ ImageLayerOGL::RenderLayer(int,
yuvImage->GetSize().width,
yuvImage->GetSize().height));
program->SetLayerTransform(GetEffectiveTransform());
program->SetTextureTransform(gfx3DMatrix());
program->SetLayerOpacity(GetEffectiveOpacity());
program->SetRenderOffset(aOffset);
program->SetYCbCrTextureUnits(0, 1, 2);
@ -297,6 +298,7 @@ ImageLayerOGL::RenderLayer(int,
cairoImage->GetSize().width,
cairoImage->GetSize().height));
program->SetLayerTransform(GetEffectiveTransform());
program->SetTextureTransform(gfx3DMatrix());
program->SetLayerOpacity(GetEffectiveOpacity());
program->SetRenderOffset(aOffset);
program->SetTextureUnit(0);
@ -324,6 +326,7 @@ ImageLayerOGL::RenderLayer(int,
program->SetTexCoordMultiplier(data->mSize.width, data->mSize.height);
}
program->SetLayerTransform(GetEffectiveTransform());
program->SetTextureTransform(gfx3DMatrix());
program->SetLayerOpacity(GetEffectiveOpacity());
program->SetRenderOffset(aOffset);
program->SetTextureUnit(0);

View File

@ -22,6 +22,7 @@ AddCommonArgs(ProgramProfileOGL& aProfile)
{
aProfile.mUniforms.AppendElement(Argument("uLayerTransform"));
aProfile.mUniforms.AppendElement(Argument("uLayerQuadTransform"));
aProfile.mUniforms.AppendElement(Argument("uTextureTransform"));
aProfile.mUniforms.AppendElement(Argument("uMatrixProj"));
aProfile.mHasMatrixProj = true;
aProfile.mUniforms.AppendElement(Argument("uRenderTargetOffset"));
@ -58,23 +59,6 @@ ProgramProfileOGL::GetProfileFor(ShaderProgramType aType,
AddCommonTextureArgs(result);
result.mTextureCount = 1;
break;
case RGBALayerExternalProgramType:
if (aMask == Mask3d) {
result.mVertexShaderString = sLayerMask3DVS;
result.mFragmentShaderString = sRGBATextureLayerExternalMask3DFS;
} else if (aMask == Mask2d) {
result.mVertexShaderString = sLayerMaskVS;
result.mFragmentShaderString = sRGBATextureLayerExternalMaskFS;
} else {
result.mVertexShaderString = sLayerVS;
result.mFragmentShaderString = sRGBATextureLayerExternalFS;
}
AddCommonArgs(result);
AddCommonTextureArgs(result);
result.mUniforms.AppendElement(Argument("uTextureTransform"));
result.mHasTextureTransform = true;
result.mTextureCount = 1;
break;
case BGRALayerProgramType:
if (aMask == Mask2d) {
result.mVertexShaderString = sLayerMaskVS;

View File

@ -189,12 +189,10 @@ struct ProgramProfileOGL
nsTArray<Argument> mAttributes;
uint32_t mTextureCount;
bool mHasMatrixProj;
bool mHasTextureTransform;
private:
ProgramProfileOGL() :
mTextureCount(0),
mHasMatrixProj(false),
mHasTextureTransform(false) {}
mHasMatrixProj(false) {}
};
@ -315,13 +313,11 @@ public:
// sets this program's texture transform, if it uses one
void SetTextureTransform(const gfx3DMatrix& aMatrix) {
if (mProfile.mHasTextureTransform)
SetMatrixUniform(mProfile.LookupUniformLocation("uTextureTransform"), aMatrix);
SetMatrixUniform(mProfile.LookupUniformLocation("uTextureTransform"), aMatrix);
}
void SetTextureTransform(const gfx::Matrix4x4& aMatrix) {
if (mProfile.mHasTextureTransform)
SetMatrixUniform(mProfile.LookupUniformLocation("uTextureTransform"), aMatrix);
SetMatrixUniform(mProfile.LookupUniformLocation("uTextureTransform"), aMatrix);
}
void SetRenderOffset(const nsIntPoint& aOffset) {

View File

@ -6,6 +6,7 @@ static const char sLayerVS[] = "/* sLayerVS */\n\
uniform mat4 uMatrixProj;\n\
uniform mat4 uLayerQuadTransform;\n\
uniform mat4 uLayerTransform;\n\
uniform mat4 uTextureTransform;\n\
uniform vec4 uRenderTargetOffset;\n\
attribute vec4 aVertexCoord;\n\
attribute vec2 aTexCoord;\n\
@ -26,7 +27,7 @@ finalPosition.xyz /= finalPosition.w;\n\
finalPosition = finalPosition - uRenderTargetOffset;\n\
finalPosition.xyz *= finalPosition.w;\n\
finalPosition = uMatrixProj * finalPosition;\n\
vTexCoord = aTexCoord;\n\
vTexCoord = (uTextureTransform * vec4(aTexCoord.x, aTexCoord.y, 0.0, 1.0)).xy;\n\
gl_Position = finalPosition;\n\
}\n\
";
@ -36,6 +37,7 @@ static const char sLayerMaskVS[] = "/* sLayerMaskVS */\n\
uniform mat4 uMatrixProj;\n\
uniform mat4 uLayerQuadTransform;\n\
uniform mat4 uLayerTransform;\n\
uniform mat4 uTextureTransform;\n\
uniform vec4 uRenderTargetOffset;\n\
attribute vec4 aVertexCoord;\n\
attribute vec2 aTexCoord;\n\
@ -59,7 +61,7 @@ vMaskCoord = (uMaskQuadTransform * finalPosition).xy;\n\
finalPosition = finalPosition - uRenderTargetOffset;\n\
finalPosition.xyz *= finalPosition.w;\n\
finalPosition = uMatrixProj * finalPosition;\n\
vTexCoord = aTexCoord;\n\
vTexCoord = (uTextureTransform * vec4(aTexCoord.x, aTexCoord.y, 0.0, 1.0)).xy;\n\
gl_Position = finalPosition;\n\
}\n\
";
@ -69,6 +71,7 @@ static const char sLayerMask3DVS[] = "/* sLayerMask3DVS */\n\
uniform mat4 uMatrixProj;\n\
uniform mat4 uLayerQuadTransform;\n\
uniform mat4 uLayerTransform;\n\
uniform mat4 uTextureTransform;\n\
uniform vec4 uRenderTargetOffset;\n\
attribute vec4 aVertexCoord;\n\
attribute vec2 aTexCoord;\n\
@ -95,7 +98,7 @@ vMaskCoord *= finalPosition.w;\n\
finalPosition = finalPosition - uRenderTargetOffset;\n\
finalPosition.xyz *= finalPosition.w;\n\
finalPosition = uMatrixProj * finalPosition;\n\
vTexCoord = aTexCoord;\n\
vTexCoord = (uTextureTransform * vec4(aTexCoord.x, aTexCoord.y, 0.0, 1.0)).xy;\n\
gl_Position = finalPosition;\n\
}\n\
";
@ -252,106 +255,6 @@ gl_FragColor = texture2D(uTexture, vTexCoord) * uLayerOpacity * mask;\n\
}\n\
";
static const char sRGBATextureLayerExternalFS[] = "/* sRGBATextureLayerExternalFS */\n\
#extension GL_OES_EGL_image_external : require\n\
#define MEDIUMP_SHADER 1\n\
/* Fragment Shader */\n\
#ifdef GL_ES\n\
#ifdef MEDIUMP_SHADER\n\
precision mediump float;\n\
#else\n\
precision lowp float;\n\
#endif\n\
#endif\n\
\n\
#ifndef NO_LAYER_OPACITY\n\
uniform float uLayerOpacity;\n\
#endif\n\
#ifdef GL_ES // for tiling, texcoord can be greater than the lowfp range\n\
varying mediump vec2 vTexCoord;\n\
#else\n\
varying vec2 vTexCoord;\n\
#endif\n\
\n\
uniform samplerExternalOES uTexture;\n\
uniform mat4 uTextureTransform;\n\
void main()\n\
{\n\
float mask = 1.0;\n\
\n\
gl_FragColor = texture2D(uTexture, (uTextureTransform * vec4(vTexCoord.x, vTexCoord.y, 0.0, 1.0)).xy) * uLayerOpacity * mask;\n\
}\n\
";
static const char sRGBATextureLayerExternalMaskFS[] = "/* sRGBATextureLayerExternalMaskFS */\n\
#extension GL_OES_EGL_image_external : require\n\
#define MEDIUMP_SHADER 1\n\
/* Fragment Shader */\n\
#ifdef GL_ES\n\
#ifdef MEDIUMP_SHADER\n\
precision mediump float;\n\
#else\n\
precision lowp float;\n\
#endif\n\
#endif\n\
\n\
#ifndef NO_LAYER_OPACITY\n\
uniform float uLayerOpacity;\n\
#endif\n\
#ifdef GL_ES // for tiling, texcoord can be greater than the lowfp range\n\
varying mediump vec2 vTexCoord;\n\
#else\n\
varying vec2 vTexCoord;\n\
#endif\n\
\n\
varying vec2 vMaskCoord;\n\
uniform sampler2D uMaskTexture;\n\
\n\
uniform samplerExternalOES uTexture;\n\
uniform mat4 uTextureTransform;\n\
void main()\n\
{\n\
float mask = texture2D(uMaskTexture, vMaskCoord).r;\n\
\n\
gl_FragColor = texture2D(uTexture, (uTextureTransform * vec4(vTexCoord.x, vTexCoord.y, 0.0, 1.0)).xy) * uLayerOpacity * mask;\n\
}\n\
";
static const char sRGBATextureLayerExternalMask3DFS[] = "/* sRGBATextureLayerExternalMask3DFS */\n\
#extension GL_OES_EGL_image_external : require\n\
#define MEDIUMP_SHADER 1\n\
/* Fragment Shader */\n\
#ifdef GL_ES\n\
#ifdef MEDIUMP_SHADER\n\
precision mediump float;\n\
#else\n\
precision lowp float;\n\
#endif\n\
#endif\n\
\n\
#ifndef NO_LAYER_OPACITY\n\
uniform float uLayerOpacity;\n\
#endif\n\
#ifdef GL_ES // for tiling, texcoord can be greater than the lowfp range\n\
varying mediump vec2 vTexCoord;\n\
#else\n\
varying vec2 vTexCoord;\n\
#endif\n\
\n\
varying vec3 vMaskCoord;\n\
uniform sampler2D uMaskTexture;\n\
\n\
uniform samplerExternalOES uTexture;\n\
uniform mat4 uTextureTransform;\n\
void main()\n\
{\n\
vec2 maskCoords = vMaskCoord.xy / vMaskCoord.z;\n\
float mask = texture2D(uMaskTexture, maskCoords).r;\n\
\n\
gl_FragColor = texture2D(uTexture, (uTextureTransform * vec4(vTexCoord.x, vTexCoord.y, 0.0, 1.0)).xy) * uLayerOpacity * mask;\n\
}\n\
";
static const char sRGBARectTextureLayerFS[] = "/* sRGBARectTextureLayerFS */\n\
#extension GL_ARB_texture_rectangle : enable\n\
/* Fragment Shader */\n\

View File

@ -62,6 +62,7 @@
uniform mat4 uMatrixProj;
uniform mat4 uLayerQuadTransform;
uniform mat4 uLayerTransform;
uniform mat4 uTextureTransform;
uniform vec4 uRenderTargetOffset;
attribute vec4 aVertexCoord;
@ -123,7 +124,7 @@ $VERTEX_MASK_STUFF<mask>$
finalPosition.xyz *= finalPosition.w;
finalPosition = uMatrixProj * finalPosition;
vTexCoord = aTexCoord;
vTexCoord = (uTextureTransform * vec4(aTexCoord.x, aTexCoord.y, 0.0, 1.0)).xy;
gl_Position = finalPosition;
}
@end
@ -215,24 +216,6 @@ $FRAGMENT_CALC_MASK<mask>$
}
@end
// Single texture in RGBA format for use with GL_TEXTURE_EXTERNAL_OES
@shader sRGBATextureLayerExternal<mask:,Mask,Mask3D>FS
#extension GL_OES_EGL_image_external : require
#define MEDIUMP_SHADER 1
$LAYER_FRAGMENT<mask>$
uniform samplerExternalOES uTexture;
uniform mat4 uTextureTransform;
void main()
{
$FRAGMENT_CALC_MASK<mask>$
gl_FragColor = texture2D(uTexture, (uTextureTransform * vec4(vTexCoord.x, vTexCoord.y, 0.0, 1.0)).xy) * uLayerOpacity * mask;
}
@end
// Single texture in RGBA format, but with a Rect texture.
// Container layer needs this to render a FBO group.
@shader sRGBARectTextureLayer<mask:,Mask,Mask3D>FS

View File

@ -181,6 +181,7 @@ ThebesLayerBufferOGL::RenderTo(const nsIntPoint& aOffset,
program->SetLayerOpacity(mLayer->GetEffectiveOpacity());
program->SetLayerTransform(mLayer->GetEffectiveTransform());
program->SetTextureTransform(gfx3DMatrix());
program->SetRenderOffset(aOffset);
program->LoadMask(mLayer->GetMaskLayer());

View File

@ -2586,6 +2586,7 @@ RectTextureImage::Draw(GLManager* aManager,
program->Activate();
program->SetLayerQuadRect(nsIntRect(nsIntPoint(0, 0), mUsedSize));
program->SetLayerTransform(aTransform * gfx3DMatrix::Translation(aLocation.x, aLocation.y, 0));
program->SetTextureTransform(gfx3DMatrix());
program->SetLayerOpacity(1.0);
program->SetRenderOffset(nsIntPoint(0, 0));
program->SetTexCoordMultiplier(mUsedSize.width, mUsedSize.height);