"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)
ShaderProgram::ShaderProgram()
: m_blendingEnabled(false)
+ , m_contrast(1)
{
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");
GLint texSampler,
GLenum textureTarget,
GLint position,
- GLint alpha)
+ GLint alpha,
+ GLint contrast)
{
glUseProgram(program);
setProjectionMatrix(geometry, projectionMatrixHandle);
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);
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,
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);
glEnableVertexAttribArray(position);
glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 0, 0);
glUniform1f(alpha, opacity);
+ if (contrast != -1)
+ glUniform1f(contrast, m_contrast);
}
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,
#include "TransformationMatrix.h"
#include <GLES2/gl2.h>
+#define MAX_CONTRAST 5
+
namespace WebCore {
class ShaderProgram {
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);
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;
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;