summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/WebCore/platform/graphics/android/ShaderProgram.cpp32
-rw-r--r--Source/WebCore/platform/graphics/android/ShaderProgram.h18
-rw-r--r--Source/WebCore/platform/graphics/android/TilesManager.h4
-rw-r--r--Source/WebKit/android/nav/WebView.cpp4
4 files changed, 46 insertions, 12 deletions
diff --git a/Source/WebCore/platform/graphics/android/ShaderProgram.cpp b/Source/WebCore/platform/graphics/android/ShaderProgram.cpp
index be979ab..c9d2d56 100644
--- a/Source/WebCore/platform/graphics/android/ShaderProgram.cpp
+++ b/Source/WebCore/platform/graphics/android/ShaderProgram.cpp
@@ -128,14 +128,16 @@ static const char gSurfaceTextureOESFragmentShaderInverted[] =
"precision mediump float;\n"
"varying vec2 v_texCoord; \n"
"uniform float alpha; \n"
+ "uniform float contrast; \n"
"uniform samplerExternalOES s_texture; \n"
"void main() {\n"
- " gl_FragColor = texture2D(s_texture, v_texCoord); \n"
- " float color = 1.0 - (gl_FragColor.r + gl_FragColor.g + gl_FragColor.b) / 3.0; \n"
- " gl_FragColor.r = color; \n"
- " gl_FragColor.g = color; \n"
- " gl_FragColor.b = color; \n"
- " gl_FragColor *= alpha; "
+ " 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";
GLuint ShaderProgram::loadShader(GLenum shaderType, const char* pSource)
@@ -207,6 +209,7 @@ GLuint ShaderProgram::createProgram(const char* pVertexSource, const char* pFrag
ShaderProgram::ShaderProgram()
: m_blendingEnabled(false)
+ , m_contrast(1)
{
init();
}
@@ -264,6 +267,7 @@ void ShaderProgram::init()
m_hSTOESProjectionMatrixInverted =
glGetUniformLocation(m_surfTexOESProgramInverted, "projectionMatrix");
m_hSTOESAlphaInverted = glGetUniformLocation(m_surfTexOESProgramInverted, "alpha");
+ m_hSTOESContrastInverted = glGetUniformLocation(m_surfTexOESProgramInverted, "contrast");
m_hSTOESTexSamplerInverted = glGetUniformLocation(m_surfTexOESProgramInverted, "s_texture");
m_hSTOESPositionInverted = glGetAttribLocation(m_surfTexOESProgramInverted, "vPosition");
@@ -338,7 +342,8 @@ void ShaderProgram::drawQuadInternal(SkRect& geometry,
GLint texSampler,
GLenum textureTarget,
GLint position,
- GLint alpha)
+ GLint alpha,
+ GLint contrast)
{
glUseProgram(program);
@@ -366,6 +371,8 @@ void ShaderProgram::drawQuadInternal(SkRect& geometry,
glEnableVertexAttribArray(position);
glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 0, 0);
glUniform1f(alpha, opacity);
+ if (contrast != -1)
+ glUniform1f(contrast, m_contrast);
setBlendingState(opacity < 1.0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@@ -390,7 +397,8 @@ void ShaderProgram::drawQuad(SkRect& geometry, int textureId, float opacity,
drawQuadInternal(geometry, textureId, opacity, m_surfTexOESProgramInverted,
m_hSTOESProjectionMatrixInverted,
m_hSTOESTexSamplerInverted, GL_TEXTURE_EXTERNAL_OES,
- m_hSTOESPositionInverted, m_hSTOESAlphaInverted);
+ m_hSTOESPositionInverted, m_hSTOESAlphaInverted,
+ m_hSTOESContrastInverted);
} else if (!textureTarget
&& !TilesManager::instance()->invertedScreen()) {
drawQuadInternal(geometry, textureId, opacity, m_surfTex2DProgram,
@@ -534,7 +542,8 @@ void ShaderProgram::drawLayerQuadInternal(const GLfloat* projectionMatrix,
int textureId, float opacity,
GLenum textureTarget, GLint program,
GLint matrix, GLint texSample,
- GLint position, GLint alpha)
+ GLint position, GLint alpha,
+ GLint contrast)
{
glUseProgram(program);
glUniformMatrix4fv(matrix, 1, GL_FALSE, projectionMatrix);
@@ -552,6 +561,8 @@ void ShaderProgram::drawLayerQuadInternal(const GLfloat* projectionMatrix,
glEnableVertexAttribArray(position);
glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 0, 0);
glUniform1f(alpha, opacity);
+ if (contrast != -1)
+ glUniform1f(contrast, m_contrast);
}
@@ -584,7 +595,8 @@ void ShaderProgram::drawLayerQuad(const TransformationMatrix& drawMatrix,
drawLayerQuadInternal(projectionMatrix, textureId, opacity,
GL_TEXTURE_EXTERNAL_OES, m_surfTexOESProgramInverted,
m_hSTOESProjectionMatrixInverted, m_hSTOESTexSamplerInverted,
- m_hSTOESPositionInverted, m_hSTOESAlphaInverted);
+ m_hSTOESPositionInverted, m_hSTOESAlphaInverted,
+ m_hSTOESContrastInverted);
} else if (!textureTarget
&& !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 244f2be..5c1f324 100644
--- a/Source/WebCore/platform/graphics/android/ShaderProgram.h
+++ b/Source/WebCore/platform/graphics/android/ShaderProgram.h
@@ -25,6 +25,8 @@
#include "TransformationMatrix.h"
#include <GLES2/gl2.h>
+#define MAX_CONTRAST 5
+
namespace WebCore {
class ShaderProgram {
@@ -77,6 +79,15 @@ public:
IntRect clippedRectWithViewport(const IntRect& rect, int margin = 0);
void resetBlending();
+ float contrast() { return m_contrast; }
+ void setContrast(float c) {
+ float contrast = c;
+ if (contrast < 0)
+ contrast = 0;
+ if (contrast > MAX_CONTRAST)
+ contrast = MAX_CONTRAST;
+ m_contrast = contrast;
+ }
private:
GLuint loadShader(GLenum shaderType, const char* pSource);
@@ -88,12 +99,12 @@ private:
void drawQuadInternal(SkRect& geometry, GLint textureId, float opacity,
GLint program, GLint projectionMatrixHandle,
GLint texSampler, GLenum textureTarget,
- GLint position, GLint alpha);
+ GLint position, GLint alpha, GLint contrast = -1);
void drawLayerQuadInternal(const GLfloat* projectionMatrix, int textureId,
float opacity, GLenum textureTarget, GLint program,
GLint matrix, GLint texSample,
- GLint position, GLint alpha);
+ GLint position, GLint alpha, GLint contrast = -1);
bool m_blendingEnabled;
@@ -141,9 +152,12 @@ private:
GLint m_hSTOESProjectionMatrixInverted;
GLint m_hSTOESAlphaInverted;
+ GLint m_hSTOESContrastInverted;
GLint m_hSTOESTexSamplerInverted;
GLint m_hSTOESPositionInverted;
+ float m_contrast;
+
// attribs
GLint m_hPosition;
GLint m_hVideoPosition;
diff --git a/Source/WebCore/platform/graphics/android/TilesManager.h b/Source/WebCore/platform/graphics/android/TilesManager.h
index f5db599..e884fc0 100644
--- a/Source/WebCore/platform/graphics/android/TilesManager.h
+++ b/Source/WebCore/platform/graphics/android/TilesManager.h
@@ -152,6 +152,10 @@ public:
m_invertedScreen = invert;
}
+ void setInvertedScreenContrast(float contrast) {
+ m_shader.setContrast(contrast);
+ }
+
private:
TilesManager();
diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp
index 69d1ee8..a19e7f4 100644
--- a/Source/WebKit/android/nav/WebView.cpp
+++ b/Source/WebKit/android/nav/WebView.cpp
@@ -2524,6 +2524,10 @@ static void nativeSetProperty(JNIEnv *env, jobject obj, jstring jkey, jstring jv
else
TilesManager::instance()->setInvertedScreen(false);
}
+ if (key == "gfxInvertedScreenContrast") {
+ float contrast = value.toFloat();
+ TilesManager::instance()->setInvertedScreenContrast(contrast);
+ }
}
static jstring nativeGetProperty(JNIEnv *env, jobject obj, jstring key)