diff options
author | John Reck <jreck@google.com> | 2011-07-15 10:51:44 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2011-07-15 11:24:51 -0700 |
commit | d2c2030045e0e26787ff8b9935d449e3be8a71cc (patch) | |
tree | 7dbd7f6bbfbaf2bc06967c09ebc858088315cc90 | |
parent | 13a5d6d78c191b79673f2cbe7bbf9d6c9a075fc6 (diff) | |
download | external_webkit-d2c2030045e0e26787ff8b9935d449e3be8a71cc.zip external_webkit-d2c2030045e0e26787ff8b9935d449e3be8a71cc.tar.gz external_webkit-d2c2030045e0e26787ff8b9935d449e3be8a71cc.tar.bz2 |
Implement an invert screen mode
Set through the new property interface
Change-Id: I62e3986a5a0d5a41faf0eeee6cd1c0f7186e1cf5
6 files changed, 135 insertions, 8 deletions
diff --git a/Source/WebCore/platform/graphics/android/BaseLayerAndroid.cpp b/Source/WebCore/platform/graphics/android/BaseLayerAndroid.cpp index 2866ca1..095ada7 100644 --- a/Source/WebCore/platform/graphics/android/BaseLayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/BaseLayerAndroid.cpp @@ -271,9 +271,16 @@ bool BaseLayerAndroid::drawGL(LayerAndroid* compositedRoot, left, top, width, height, scale); m_glWebViewState->setBackgroundColor(color); - glClearColor((float)m_color.red() / 255.0, - (float)m_color.green() / 255.0, - (float)m_color.blue() / 255.0, 1); + if (TilesManager::instance()->invertedScreen()) { + float color = 1.0 - ((((float) m_color.red() / 255.0) + + ((float) m_color.green() / 255.0) + + ((float) m_color.blue() / 255.0)) / 3.0); + glClearColor(color, color, color, 1); + } else { + glClearColor((float)m_color.red() / 255.0, + (float)m_color.green() / 255.0, + (float)m_color.blue() / 255.0, 1); + } glClear(GL_COLOR_BUFFER_BIT); glViewport(left, top, width, height); diff --git a/Source/WebCore/platform/graphics/android/ShaderProgram.cpp b/Source/WebCore/platform/graphics/android/ShaderProgram.cpp index f9f4c4c..ed1ce11 100644 --- a/Source/WebCore/platform/graphics/android/ShaderProgram.cpp +++ b/Source/WebCore/platform/graphics/android/ShaderProgram.cpp @@ -30,6 +30,7 @@ #include "FloatPoint3D.h" #include "GLUtils.h" +#include "TilesManager.h" #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> @@ -96,6 +97,21 @@ static const char gSurfaceTexture2DFragmentShader[] = " gl_FragColor *= alpha; " "}\n"; +static const char gSurfaceTexture2DFragmentShaderInverted[] = + "#extension GL_OES_EGL_image_external : require\n" + "precision mediump float;\n" + "varying vec2 v_texCoord; \n" + "uniform float alpha; \n" + "uniform sampler2D 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; " + "}\n"; + static const char gSurfaceTextureOESFragmentShader[] = "#extension GL_OES_EGL_image_external : require\n" "precision mediump float;\n" @@ -107,6 +123,21 @@ static const char gSurfaceTextureOESFragmentShader[] = " gl_FragColor *= alpha; " "}\n"; +static const char gSurfaceTextureOESFragmentShaderInverted[] = + "#extension GL_OES_EGL_image_external : require\n" + "precision mediump float;\n" + "varying vec2 v_texCoord; \n" + "uniform float alpha; \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; " + "}\n"; + GLuint ShaderProgram::loadShader(GLenum shaderType, const char* pSource) { GLuint shader = glCreateShader(shaderType); @@ -186,13 +217,19 @@ void ShaderProgram::init() m_videoProgram = createProgram(gVideoVertexShader, gVideoFragmentShader); m_surfTex2DProgram = createProgram(gVertexShader, gSurfaceTexture2DFragmentShader); + m_surfTex2DProgramInverted = + createProgram(gVertexShader, gSurfaceTexture2DFragmentShaderInverted); m_surfTexOESProgram = createProgram(gVertexShader, gSurfaceTextureOESFragmentShader); + m_surfTexOESProgramInverted = + createProgram(gVertexShader, gSurfaceTextureOESFragmentShaderInverted); if (m_program == -1 || m_videoProgram == -1 || m_surfTex2DProgram == -1 - || m_surfTexOESProgram == -1) + || m_surfTex2DProgramInverted == -1 + || m_surfTexOESProgram == -1 + || m_surfTexOESProgramInverted == -1) return; m_hProjectionMatrix = glGetUniformLocation(m_program, "projectionMatrix"); @@ -212,12 +249,24 @@ void ShaderProgram::init() m_hST2DTexSampler = glGetUniformLocation(m_surfTex2DProgram, "s_texture"); m_hST2DPosition = glGetAttribLocation(m_surfTex2DProgram, "vPosition"); + m_hST2DProjectionMatrixInverted = + glGetUniformLocation(m_surfTex2DProgramInverted, "projectionMatrix"); + m_hST2DAlphaInverted = glGetUniformLocation(m_surfTex2DProgramInverted, "alpha"); + m_hST2DTexSamplerInverted = glGetUniformLocation(m_surfTex2DProgramInverted, "s_texture"); + m_hST2DPositionInverted = glGetAttribLocation(m_surfTex2DProgramInverted, "vPosition"); + m_hSTOESProjectionMatrix = glGetUniformLocation(m_surfTexOESProgram, "projectionMatrix"); m_hSTOESAlpha = glGetUniformLocation(m_surfTexOESProgram, "alpha"); m_hSTOESTexSampler = glGetUniformLocation(m_surfTexOESProgram, "s_texture"); m_hSTOESPosition = glGetAttribLocation(m_surfTexOESProgram, "vPosition"); + m_hSTOESProjectionMatrixInverted = + glGetUniformLocation(m_surfTexOESProgramInverted, "projectionMatrix"); + m_hSTOESAlphaInverted = glGetUniformLocation(m_surfTexOESProgramInverted, "alpha"); + m_hSTOESTexSamplerInverted = glGetUniformLocation(m_surfTexOESProgramInverted, "s_texture"); + m_hSTOESPositionInverted = glGetAttribLocation(m_surfTexOESProgramInverted, "vPosition"); + const GLfloat coord[] = { 0.0f, 0.0f, // C @@ -319,16 +368,30 @@ void ShaderProgram::drawQuad(SkRect& geometry, int textureId, float opacity, m_hProjectionMatrix, m_hTexSampler, GL_TEXTURE_2D, m_hPosition, alpha()); - } else if (textureTarget == GL_TEXTURE_EXTERNAL_OES) { + } else if (textureTarget == GL_TEXTURE_EXTERNAL_OES + && !TilesManager::instance()->invertedScreen()) { drawQuadInternal(geometry, textureId, opacity, m_surfTexOESProgram, m_hSTOESProjectionMatrix, m_hSTOESTexSampler, GL_TEXTURE_EXTERNAL_OES, m_hSTOESPosition, m_hSTOESAlpha); - } else if (!textureTarget) { + } else if (textureTarget == GL_TEXTURE_EXTERNAL_OES + && TilesManager::instance()->invertedScreen()) { + drawQuadInternal(geometry, textureId, opacity, m_surfTexOESProgramInverted, + m_hSTOESProjectionMatrixInverted, + m_hSTOESTexSamplerInverted, GL_TEXTURE_EXTERNAL_OES, + m_hSTOESPositionInverted, m_hSTOESAlphaInverted); + } else if (!textureTarget + && !TilesManager::instance()->invertedScreen()) { drawQuadInternal(geometry, textureId, opacity, m_surfTex2DProgram, m_hST2DProjectionMatrix, m_hST2DTexSampler, GL_TEXTURE_2D, m_hST2DPosition, m_hST2DAlpha); + } else if (!textureTarget + && TilesManager::instance()->invertedScreen()) { + drawQuadInternal(geometry, textureId, opacity, m_surfTex2DProgramInverted, + m_hST2DProjectionMatrixInverted, + m_hST2DTexSamplerInverted, GL_TEXTURE_2D, + m_hST2DPositionInverted, m_hST2DAlphaInverted); } GLUtils::checkGlError("drawQuad"); } @@ -499,16 +562,30 @@ void ShaderProgram::drawLayerQuad(const TransformationMatrix& drawMatrix, GL_TEXTURE_2D, m_program, m_hProjectionMatrix, m_hTexSampler, m_hPosition, alpha()); - } else if (textureTarget == GL_TEXTURE_EXTERNAL_OES) { + } else if (textureTarget == GL_TEXTURE_EXTERNAL_OES + && !TilesManager::instance()->invertedScreen()) { drawLayerQuadInternal(projectionMatrix, textureId, opacity, GL_TEXTURE_EXTERNAL_OES, m_surfTexOESProgram, m_hSTOESProjectionMatrix, m_hSTOESTexSampler, m_hSTOESPosition, m_hSTOESAlpha); - } else if (!textureTarget) { + } else if (textureTarget == GL_TEXTURE_EXTERNAL_OES + && TilesManager::instance()->invertedScreen()) { + drawLayerQuadInternal(projectionMatrix, textureId, opacity, + GL_TEXTURE_EXTERNAL_OES, m_surfTexOESProgramInverted, + m_hSTOESProjectionMatrixInverted, m_hSTOESTexSamplerInverted, + m_hSTOESPositionInverted, m_hSTOESAlphaInverted); + } else if (!textureTarget + && !TilesManager::instance()->invertedScreen()) { drawLayerQuadInternal(projectionMatrix, textureId, opacity, GL_TEXTURE_2D, m_surfTex2DProgram, m_hST2DProjectionMatrix, m_hST2DTexSampler, m_hST2DPosition, m_hST2DAlpha); + } else if (!textureTarget + && TilesManager::instance()->invertedScreen()) { + drawLayerQuadInternal(projectionMatrix, textureId, opacity, + GL_TEXTURE_2D, m_surfTex2DProgramInverted, + m_hST2DProjectionMatrixInverted, m_hST2DTexSamplerInverted, + m_hST2DPositionInverted, m_hST2DAlphaInverted); } setBlendingState(forceBlending || opacity < 1.0); diff --git a/Source/WebCore/platform/graphics/android/ShaderProgram.h b/Source/WebCore/platform/graphics/android/ShaderProgram.h index 420c540..244f2be 100644 --- a/Source/WebCore/platform/graphics/android/ShaderProgram.h +++ b/Source/WebCore/platform/graphics/android/ShaderProgram.h @@ -100,7 +100,9 @@ private: int m_program; int m_videoProgram; int m_surfTex2DProgram; + int m_surfTex2DProgramInverted; int m_surfTexOESProgram; + int m_surfTexOESProgramInverted; TransformationMatrix m_projectionMatrix; GLuint m_textureBuffer[1]; @@ -127,11 +129,21 @@ private: GLint m_hST2DTexSampler; GLint m_hST2DPosition; + GLint m_hST2DProjectionMatrixInverted; + GLint m_hST2DAlphaInverted; + GLint m_hST2DTexSamplerInverted; + GLint m_hST2DPositionInverted; + GLint m_hSTOESProjectionMatrix; GLint m_hSTOESAlpha; GLint m_hSTOESTexSampler; GLint m_hSTOESPosition; + GLint m_hSTOESProjectionMatrixInverted; + GLint m_hSTOESAlphaInverted; + GLint m_hSTOESTexSamplerInverted; + GLint m_hSTOESPositionInverted; + // attribs GLint m_hPosition; GLint m_hVideoPosition; diff --git a/Source/WebCore/platform/graphics/android/TilesManager.cpp b/Source/WebCore/platform/graphics/android/TilesManager.cpp index 3297cc2..398cb09 100644 --- a/Source/WebCore/platform/graphics/android/TilesManager.cpp +++ b/Source/WebCore/platform/graphics/android/TilesManager.cpp @@ -102,6 +102,7 @@ TilesManager::TilesManager() , m_generatorReady(false) , m_showVisualIndicator(false) , m_drawRegistrationCount(0) + , m_invertedScreen(false) { XLOG("TilesManager ctor"); m_textures.reserveCapacity(MAX_TEXTURE_ALLOCATION); diff --git a/Source/WebCore/platform/graphics/android/TilesManager.h b/Source/WebCore/platform/graphics/android/TilesManager.h index 25e487d..5ea4ccb 100644 --- a/Source/WebCore/platform/graphics/android/TilesManager.h +++ b/Source/WebCore/platform/graphics/android/TilesManager.h @@ -142,6 +142,14 @@ public: return &m_tilesTracker; } + bool invertedScreen() { + return m_invertedScreen; + } + + void setInvertedScreen(bool invert) { + m_invertedScreen = invert; + } + private: TilesManager(); @@ -165,6 +173,7 @@ private: bool m_generatorReady; bool m_showVisualIndicator; + bool m_invertedScreen; sp<TexturesGenerator> m_pixmapsGenerationThread; diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp index dae3cbe..0dc9781 100644 --- a/Source/WebKit/android/nav/WebView.cpp +++ b/Source/WebKit/android/nav/WebView.cpp @@ -2534,6 +2534,23 @@ static void dumpToFile(const char text[], void* file) { } #endif +static void nativeSetProperty(JNIEnv *env, jobject obj, jstring jkey, jstring jvalue) +{ + WTF::String key = jstringToWtfString(env, jkey); + WTF::String value = jstringToWtfString(env, jvalue); + if (key == "gfxInvertedScreen") { + if (value == "true") + TilesManager::instance()->setInvertedScreen(true); + else + TilesManager::instance()->setInvertedScreen(false); + } +} + +static jstring nativeGetProperty(JNIEnv *env, jobject obj, jstring key) +{ + return 0; +} + static void nativeDumpDisplayTree(JNIEnv* env, jobject jwebview, jstring jurl) { #ifdef ANDROID_DUMP_DISPLAY_TREE @@ -2824,6 +2841,10 @@ static JNINativeMethod gJavaWebViewMethods[] = { (void*) nativeSetExpandedTileBounds }, { "nativeGetBackgroundColor", "()I", (void*) nativeGetBackgroundColor }, + { "nativeSetProperty", "(Ljava/lang/String;Ljava/lang/String;)V", + (void*) nativeSetProperty }, + { "nativeGetProperty", "(Ljava/lang/String;)Ljava/lang/String;", + (void*) nativeGetProperty }, }; int registerWebView(JNIEnv* env) |