summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorNicolas Roard <nicolasroard@google.com>2011-10-06 18:50:02 -0700
committerNicolas Roard <nicolasroard@google.com>2011-10-06 19:16:54 -0700
commitd30f6301a4ea49037d31781bb238a4230c4c1389 (patch)
tree0a97e24a4aff40a6c693a60f5d4a0be31deec08e /Source
parent7baf9c5d380cd891e4e6488c09a08d0e9c7e1e4f (diff)
downloadexternal_webkit-d30f6301a4ea49037d31781bb238a4230c4c1389.zip
external_webkit-d30f6301a4ea49037d31781bb238a4230c4c1389.tar.gz
external_webkit-d30f6301a4ea49037d31781bb238a4230c4c1389.tar.bz2
Fix inverted mode rendering
The GPU texture upload workaround broke it, as we are not using the Shaders when doing the copy. Adding some code to instead use a final shader that can be either normal or inverted, on demand. bug:5424589 Change-Id: If845233e12c65738925fbc81b21f1dc0fd38546e
Diffstat (limited to 'Source')
-rw-r--r--Source/WebCore/platform/graphics/android/GLWebViewState.cpp2
-rw-r--r--Source/WebCore/platform/graphics/android/ShaderProgram.cpp60
-rw-r--r--Source/WebCore/platform/graphics/android/ShaderProgram.h21
3 files changed, 64 insertions, 19 deletions
diff --git a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
index 09c647b..c273c5c 100644
--- a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
+++ b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
@@ -515,8 +515,6 @@ double GLWebViewState::setupDrawing(IntRect& viewRect, SkRect& visibleRect,
XLOG("Reinit shader");
shader->init();
}
- glUseProgram(shader->program());
- glUniform1i(shader->textureSampler(), 0);
shader->setViewRect(viewRect);
shader->setViewport(visibleRect);
shader->setWebViewRect(webViewRect);
diff --git a/Source/WebCore/platform/graphics/android/ShaderProgram.cpp b/Source/WebCore/platform/graphics/android/ShaderProgram.cpp
index 857623a..797da52 100644
--- a/Source/WebCore/platform/graphics/android/ShaderProgram.cpp
+++ b/Source/WebCore/platform/graphics/android/ShaderProgram.cpp
@@ -62,6 +62,22 @@ static const char gFragmentShader[] =
" gl_FragColor *= alpha; "
"}\n";
+static const char gFragmentShaderInverted[] =
+ "precision mediump float;\n"
+ "varying vec2 v_texCoord; \n"
+ "uniform float alpha; \n"
+ "uniform float contrast; \n"
+ "uniform sampler2D s_texture; \n"
+ "void main() {\n"
+ " vec4 pixel = texture2D(s_texture, v_texCoord); \n"
+ " float a = pixel.a; \n"
+ " float color = a - (0.2989 * pixel.r + 0.5866 * pixel.g + 0.1145 * pixel.b);\n"
+ " color = ((color - a/2.0) * contrast) + a/2.0; \n"
+ " pixel.rgb = vec3(color, color, color); \n "
+ " gl_FragColor = pixel; \n"
+ " gl_FragColor *= alpha; \n"
+ "}\n";
+
static const char gVideoVertexShader[] =
"attribute vec4 vPosition;\n"
"uniform mat4 textureMatrix;\n"
@@ -186,6 +202,7 @@ ShaderProgram::ShaderProgram()
void ShaderProgram::init()
{
m_program = createProgram(gVertexShader, gFragmentShader);
+ m_programInverted = createProgram(gVertexShader, gFragmentShaderInverted);
m_videoProgram = createProgram(gVideoVertexShader, gVideoFragmentShader);
m_surfTexOESProgram =
createProgram(gVertexShader, gSurfaceTextureOESFragmentShader);
@@ -193,6 +210,7 @@ void ShaderProgram::init()
createProgram(gVertexShader, gSurfaceTextureOESFragmentShaderInverted);
if (m_program == -1
+ || m_programInverted == -1
|| m_videoProgram == -1
|| m_surfTexOESProgram == -1
|| m_surfTexOESProgramInverted == -1)
@@ -203,6 +221,12 @@ void ShaderProgram::init()
m_hTexSampler = glGetUniformLocation(m_program, "s_texture");
m_hPosition = glGetAttribLocation(m_program, "vPosition");
+ m_hProjectionMatrixInverted = glGetUniformLocation(m_programInverted, "projectionMatrix");
+ m_hAlphaInverted = glGetUniformLocation(m_programInverted, "alpha");
+ m_hContrastInverted = glGetUniformLocation(m_surfTexOESProgramInverted, "contrast");
+ m_hTexSamplerInverted = glGetUniformLocation(m_programInverted, "s_texture");
+ m_hPositionInverted = glGetAttribLocation(m_programInverted, "vPosition");
+
m_hVideoProjectionMatrix =
glGetUniformLocation(m_videoProgram, "projectionMatrix");
m_hVideoTextureMatrix = glGetUniformLocation(m_videoProgram, "textureMatrix");
@@ -334,10 +358,22 @@ void ShaderProgram::drawQuad(SkRect& geometry, int textureId, float opacity,
GLenum textureTarget, GLint texFilter)
{
if (textureTarget == GL_TEXTURE_2D) {
- drawQuadInternal(geometry, textureId, opacity, m_program,
- m_hProjectionMatrix,
- m_hTexSampler, GL_TEXTURE_2D,
- m_hPosition, alpha(), texFilter);
+ if (!TilesManager::instance()->invertedScreen()) {
+ drawQuadInternal(geometry, textureId, opacity, m_program,
+ m_hProjectionMatrix,
+ m_hTexSampler, GL_TEXTURE_2D,
+ m_hPosition, m_hAlpha, texFilter);
+ } else {
+ // With the new GPU texture upload path, we do not use an FBO
+ // to blit the texture we receive from the TexturesGenerator thread.
+ // To implement inverted rendering, we thus have to do the rendering
+ // live, by using a different shader.
+ drawQuadInternal(geometry, textureId, opacity, m_programInverted,
+ m_hProjectionMatrixInverted,
+ m_hTexSamplerInverted, GL_TEXTURE_2D,
+ m_hPositionInverted, m_hAlphaInverted, texFilter,
+ m_hContrastInverted);
+ }
} else if (textureTarget == GL_TEXTURE_EXTERNAL_OES
&& !TilesManager::instance()->invertedScreen()) {
drawQuadInternal(geometry, textureId, opacity, m_surfTexOESProgram,
@@ -520,10 +556,18 @@ void ShaderProgram::drawLayerQuad(const TransformationMatrix& drawMatrix,
GLfloat projectionMatrix[16];
GLUtils::toGLMatrix(projectionMatrix, renderMatrix);
if (textureTarget == GL_TEXTURE_2D) {
- drawLayerQuadInternal(projectionMatrix, textureId, opacity,
- GL_TEXTURE_2D, m_program,
- m_hProjectionMatrix, m_hTexSampler,
- m_hPosition, alpha());
+ if (!TilesManager::instance()->invertedScreen()) {
+ drawLayerQuadInternal(projectionMatrix, textureId, opacity,
+ GL_TEXTURE_2D, m_program,
+ m_hProjectionMatrix, m_hTexSampler,
+ m_hPosition, m_hAlpha);
+ } else {
+ drawLayerQuadInternal(projectionMatrix, textureId, opacity,
+ GL_TEXTURE_2D, m_programInverted,
+ m_hProjectionMatrixInverted, m_hTexSamplerInverted,
+ m_hPositionInverted, m_hAlphaInverted,
+ m_hContrastInverted);
+ }
} else if (textureTarget == GL_TEXTURE_EXTERNAL_OES
&& !TilesManager::instance()->invertedScreen()) {
drawLayerQuadInternal(projectionMatrix, textureId, opacity,
diff --git a/Source/WebCore/platform/graphics/android/ShaderProgram.h b/Source/WebCore/platform/graphics/android/ShaderProgram.h
index 5f5ce9f..bfb1fb6 100644
--- a/Source/WebCore/platform/graphics/android/ShaderProgram.h
+++ b/Source/WebCore/platform/graphics/android/ShaderProgram.h
@@ -33,9 +33,6 @@ class ShaderProgram {
public:
ShaderProgram();
void init();
- int projectionMatrix() { return m_hProjectionMatrix; }
- int alpha() { return m_hAlpha; }
- int textureSampler() { return m_hTexSampler; }
int program() { return m_program; }
// Drawing
@@ -111,6 +108,7 @@ private:
bool m_blendingEnabled;
int m_program;
+ int m_programInverted;
int m_videoProgram;
int m_surfTexOESProgram;
int m_surfTexOESProgramInverted;
@@ -128,12 +126,16 @@ private:
IntRect m_webViewRect;
// uniforms
- int m_hProjectionMatrix;
- int m_hAlpha;
- int m_hTexSampler;
- int m_hVideoProjectionMatrix;
- int m_hVideoTextureMatrix;
- int m_hVideoTexSampler;
+ GLint m_hProjectionMatrix;
+ GLint m_hAlpha;
+ GLint m_hTexSampler;
+ GLint m_hProjectionMatrixInverted;
+ GLint m_hAlphaInverted;
+ GLint m_hContrastInverted;
+ GLint m_hTexSamplerInverted;
+ GLint m_hVideoProjectionMatrix;
+ GLint m_hVideoTextureMatrix;
+ GLint m_hVideoTexSampler;
GLint m_hSTOESProjectionMatrix;
GLint m_hSTOESAlpha;
@@ -150,6 +152,7 @@ private:
// attribs
GLint m_hPosition;
+ GLint m_hPositionInverted;
GLint m_hVideoPosition;
};