OSDN Git Service

WebView animation support
authorTeng-Hui Zhu <ztenghui@google.com>
Wed, 31 Aug 2011 21:46:17 +0000 (14:46 -0700)
committerTeng-Hui Zhu <ztenghui@google.com>
Wed, 31 Aug 2011 22:33:29 +0000 (15:33 -0700)
bug:4982054
Change-Id: I6f4fe313d242f728a515c485a2531611d7166198

Source/WebCore/platform/graphics/android/GLWebViewState.cpp
Source/WebCore/platform/graphics/android/ShaderProgram.cpp
Source/WebCore/platform/graphics/android/ShaderProgram.h
Source/WebKit/android/nav/WebView.cpp

index e07c86f..bc07925 100644 (file)
@@ -473,7 +473,7 @@ double GLWebViewState::setupDrawing(IntRect& viewRect, SkRect& visibleRect,
     glUseProgram(shader->program());
     glUniform1i(shader->textureSampler(), 0);
     shader->setViewRect(viewRect);
-    shader->setViewport(visibleRect);
+    shader->setViewport(visibleRect, scale);
     shader->setWebViewRect(webViewRect);
     shader->setTitleBarHeight(titleBarHeight);
     shader->setScreenClip(screenClip);
index bf5f760..536d228 100644 (file)
@@ -235,6 +235,8 @@ void ShaderProgram::init()
     glBufferData(GL_ARRAY_BUFFER, 2 * 4 * sizeof(GLfloat), coord, GL_STATIC_DRAW);
 
     GLUtils::checkGlError("init");
+
+    memset(m_webViewMatrix, 0, sizeof(m_webViewMatrix));
 }
 
 void ShaderProgram::resetBlending()
@@ -262,13 +264,14 @@ void ShaderProgram::setBlendingState(bool enableBlending)
 // Drawing
 /////////////////////////////////////////////////////////////////////////////////////////
 
-void ShaderProgram::setViewport(SkRect& viewport)
+void ShaderProgram::setViewport(SkRect& viewport, float scale)
 {
     TransformationMatrix ortho;
     GLUtils::setOrthographicMatrix(ortho, viewport.fLeft, viewport.fTop,
                                    viewport.fRight, viewport.fBottom, -1000, 1000);
     m_projectionMatrix = ortho;
     m_viewport = viewport;
+    m_currentScale = scale;
 }
 
 void ShaderProgram::setProjectionMatrix(SkRect& geometry, GLint projectionMatrixHandle)
@@ -277,8 +280,29 @@ void ShaderProgram::setProjectionMatrix(SkRect& geometry, GLint projectionMatrix
     translate.translate3d(geometry.fLeft, geometry.fTop, 0.0);
     TransformationMatrix scale;
     scale.scale3d(geometry.width(), geometry.height(), 1.0);
-
-    TransformationMatrix total = m_projectionMatrix * translate * scale;
+    // Translate float* to TransformationMatrix
+    TransformationMatrix webViewTransformMatrix(
+        m_webViewMatrix[0], m_webViewMatrix[1], m_webViewMatrix[2], m_webViewMatrix[3],
+        m_webViewMatrix[4], m_webViewMatrix[5], m_webViewMatrix[6], m_webViewMatrix[7],
+        m_webViewMatrix[8], m_webViewMatrix[9], m_webViewMatrix[10], m_webViewMatrix[11],
+        m_webViewMatrix[12], m_webViewMatrix[13], m_webViewMatrix[14], m_webViewMatrix[15] );
+
+
+    TransformationMatrix reposition;
+    // After the webViewTranform, we need to reposition the rect to match our viewport.
+    reposition.translate3d(-m_webViewRect.x(), -m_webViewRect.y() - m_titleBarHeight, 0);
+    reposition.translate3d(m_viewport.fLeft * m_currentScale, m_viewport.fTop * m_currentScale, 0);
+
+    // Basically, the webViewTransformMatrix should apply on the screen resolution.
+    // So we start by doing the scale and translate to get each tile into screen coordinates.
+    // After applying the webViewTransformMatrix, b/c the way it currently set up
+    // for scroll and titlebar, we need to offset both of them.
+    // Finally, map everything back to (-1, 1) by using the m_projectionMatrix.
+    // TODO: Given that webViewTransformMatrix contains most of the tranformation
+    // information, we should be able to get rid of some parameter we got from
+    // Java side and simplify our code.
+    TransformationMatrix total =
+        m_projectionMatrix * reposition * webViewTransformMatrix * translate * scale;
 
     GLfloat projectionMatrix[16];
     GLUtils::toGLMatrix(projectionMatrix, total);
@@ -573,6 +597,12 @@ void ShaderProgram::drawVideoLayerQuad(const TransformationMatrix& drawMatrix,
     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 }
 
+void ShaderProgram::setWebViewMatrix(float* matrix)
+{
+    if (matrix)
+        memcpy(m_webViewMatrix, matrix, sizeof(m_webViewMatrix));
+}
+
 } // namespace WebCore
 
 #endif // USE(ACCELERATED_COMPOSITING)
index d8447bf..f31eb91 100644 (file)
@@ -39,7 +39,7 @@ public:
     int program() { return m_program; }
 
     // Drawing
-    void setViewport(SkRect& viewport);
+    void setViewport(SkRect& viewport, float scale);
     float zValue(const TransformationMatrix& drawMatrix, float w, float h);
 
     // For drawQuad and drawLayerQuad, they can handle 3 cases for now:
@@ -88,6 +88,7 @@ public:
             contrast = MAX_CONTRAST;
         m_contrast = contrast;
     }
+    void setWebViewMatrix(float* matrix);
 
 private:
     GLuint loadShader(GLenum shaderType, const char* pSource);
@@ -149,6 +150,9 @@ private:
     // attribs
     GLint m_hPosition;
     GLint m_hVideoPosition;
+
+    float m_webViewMatrix[16];
+    float m_currentScale;
 };
 
 } // namespace WebCore
index 945a785..f064fdb 100644 (file)
@@ -1576,6 +1576,7 @@ class GLDrawFunctor : Functor {
         WebCore::IntRect clip(info->clipLeft, info->clipTop,
                               info->clipRight - info->clipLeft,
                               info->clipBottom - info->clipTop);
+        TilesManager::instance()->shader()->setWebViewMatrix(info->transform);
 
         bool retVal = (*wvInstance.*funcPtr)(localViewRect, &inval, webViewRect, titlebarHeight, clip, scale, extras);
         if (retVal) {