Bug 875232 - Add a BGRX shader program that reads from GL_TEXTURE_RECTANGLE. r=jrmuziel

This commit is contained in:
Matt Woodrow 2013-07-17 23:24:15 -04:00
Родитель 1806ba3946
Коммит f181e9a218
6 изменённых файлов: 171 добавлений и 5 удалений

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

@ -222,7 +222,7 @@ CanvasLayerOGL::UpdateSurface()
SharedSurface_IOSurface *ioSurf = SharedSurface_IOSurface::Cast(surf);
mTexture = ioSurf->Texture();
mTextureTarget = ioSurf->TextureTarget();
mLayerProgram = RGBARectLayerProgramType;
mLayerProgram = ioSurf->HasAlpha() ? RGBARectLayerProgramType : RGBXRectLayerProgramType;
break;
}
#endif
@ -323,7 +323,8 @@ CanvasLayerOGL::RenderLayer(int aPreviousDestination,
gl()->ApplyFilterToBoundTexture(mFilter);
program->Activate();
if (mLayerProgram == RGBARectLayerProgramType) {
if (mLayerProgram == RGBARectLayerProgramType ||
mLayerProgram == RGBXRectLayerProgramType) {
// This is used by IOSurface that use 0,0...w,h coordinate rather then 0,0..1,1.
program->SetTexCoordMultiplier(mBounds.width, mBounds.height);
}

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

@ -1028,7 +1028,8 @@ CompositorOGL::DrawQuad(const Rect& aRect, const Rect& aClipRect,
ShaderProgramType programType = GetProgramTypeForEffect(aEffectChain.mPrimaryEffect);
ShaderProgramOGL *program = GetProgram(programType, maskType);
program->Activate();
if (programType == RGBARectLayerProgramType) {
if (programType == RGBARectLayerProgramType ||
programType == RGBXRectLayerProgramType) {
TexturedEffect* texturedEffect =
static_cast<TexturedEffect*>(aEffectChain.mPrimaryEffect.get());
TextureSourceOGL* source = texturedEffect->mTexture->AsSourceOGL();

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

@ -126,6 +126,21 @@ ProgramProfileOGL::GetProfileFor(ShaderProgramType aType,
AddCommonTextureArgs(result);
result.mTextureCount = 1;
break;
case RGBXRectLayerProgramType:
if (aMask == Mask3d) {
result.mVertexShaderString = sLayerMask3DVS;
result.mFragmentShaderString = sRGBXRectTextureLayerMask3DFS;
} else if (aMask == Mask2d) {
result.mVertexShaderString = sLayerMaskVS;
result.mFragmentShaderString = sRGBXRectTextureLayerMaskFS;
} else {
result.mVertexShaderString = sLayerVS;
result.mFragmentShaderString = sRGBXRectTextureLayerFS;
}
AddCommonArgs(result);
AddCommonTextureArgs(result);
result.mTextureCount = 1;
break;
case BGRARectLayerProgramType:
MOZ_ASSERT(aMask == MaskNone, "BGRARectLayerProgramType can't handle masks.");
result.mVertexShaderString = sLayerVS;

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

@ -37,6 +37,7 @@ enum ShaderProgramType {
RGBXLayerProgramType,
BGRXLayerProgramType,
RGBARectLayerProgramType,
RGBXRectLayerProgramType,
BGRARectLayerProgramType,
RGBAExternalLayerProgramType,
ColorLayerProgramType,
@ -81,8 +82,12 @@ ShaderProgramFromTargetAndFormat(GLenum aTarget,
MOZ_ASSERT(aFormat == gfx::FORMAT_R8G8B8A8);
return RGBALayerExternalProgramType;
case LOCAL_GL_TEXTURE_RECTANGLE_ARB:
MOZ_ASSERT(aFormat == gfx::FORMAT_R8G8B8A8);
return RGBARectLayerProgramType;
MOZ_ASSERT(aFormat == gfx::FORMAT_R8G8B8A8 ||
aFormat == gfx::FORMAT_R8G8B8X8);
if (aFormat == gfx::FORMAT_R8G8B8A8)
return RGBARectLayerProgramType;
else
return RGBXRectLayerProgramType;
default:
return ShaderProgramFromSurfaceFormat(aFormat);
}
@ -135,6 +140,7 @@ struct ProgramProfileOGL
return aMask != Mask3d ||
aType == RGBARectLayerProgramType ||
aType == RGBXRectLayerProgramType ||
aType == RGBALayerProgramType;
}

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

@ -473,6 +473,127 @@ gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n\
#endif\n\
";
static const char sRGBXRectTextureLayerFS[] = "/* sRGBXRectTextureLayerFS */\n\
#extension GL_ARB_texture_rectangle : enable\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\
/* This should not be used on GL ES */\n\
#ifndef GL_ES\n\
uniform sampler2DRect uTexture;\n\
uniform vec2 uTexCoordMultiplier;\n\
void main()\n\
{\n\
float mask = 1.0;\n\
\n\
gl_FragColor = vec4(texture2DRect(uTexture, vec2(vTexCoord * uTexCoordMultiplier)).rgb, 1.0) * uLayerOpacity * mask;\n\
}\n\
#else\n\
void main()\n\
{\n\
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n\
}\n\
#endif\n\
";
static const char sRGBXRectTextureLayerMaskFS[] = "/* sRGBXRectTextureLayerMaskFS */\n\
#extension GL_ARB_texture_rectangle : enable\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\
/* This should not be used on GL ES */\n\
#ifndef GL_ES\n\
uniform sampler2DRect uTexture;\n\
uniform vec2 uTexCoordMultiplier;\n\
void main()\n\
{\n\
float mask = texture2D(uMaskTexture, vMaskCoord).r;\n\
\n\
gl_FragColor = vec4(texture2DRect(uTexture, vec2(vTexCoord * uTexCoordMultiplier)).rgb, 1.0) * uLayerOpacity * mask;\n\
}\n\
#else\n\
void main()\n\
{\n\
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n\
}\n\
#endif\n\
";
static const char sRGBXRectTextureLayerMask3DFS[] = "/* sRGBXRectTextureLayerMask3DFS */\n\
#extension GL_ARB_texture_rectangle : enable\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\
/* This should not be used on GL ES */\n\
#ifndef GL_ES\n\
uniform sampler2DRect uTexture;\n\
uniform vec2 uTexCoordMultiplier;\n\
void main()\n\
{\n\
vec2 maskCoords = vMaskCoord.xy / vMaskCoord.z;\n\
float mask = texture2D(uMaskTexture, maskCoords).r;\n\
\n\
gl_FragColor = vec4(texture2DRect(uTexture, vec2(vTexCoord * uTexCoordMultiplier)).rgb, 1.0) * uLayerOpacity * mask;\n\
}\n\
#else\n\
void main()\n\
{\n\
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n\
}\n\
#endif\n\
";
static const char sBGRARectTextureLayerFS[] = "/* sBGRARectTextureLayerFS */\n\
#extension GL_ARB_texture_rectangle : enable\n\
/* Fragment Shader */\n\

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

@ -257,6 +257,28 @@ void main()
#endif
@end
@shader sRGBXRectTextureLayer<mask:,Mask,Mask3D>FS
#extension GL_ARB_texture_rectangle : enable
$LAYER_FRAGMENT<mask>$
/* This should not be used on GL ES */
#ifndef GL_ES
uniform sampler2DRect uTexture;
uniform vec2 uTexCoordMultiplier;
void main()
{
$FRAGMENT_CALC_MASK<mask>$
gl_FragColor = vec4(texture2DRect(uTexture, vec2(vTexCoord * uTexCoordMultiplier)).rgb, 1.0) * uLayerOpacity * mask;
}
#else
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
#endif
@end
// Single texture in BGRA format, but with a Rect texture.
// nsChildView needs this for old Mac hardware.
@shader sBGRARectTextureLayerFS