[WK2] Rotation code for Direct Rendering
authorHeejin Chung <heejin.r.chung@samsung.com>
Thu, 30 Aug 2012 07:07:43 +0000 (16:07 +0900)
committerHeejin Chung <heejin.r.chung@samsung.com>
Thu, 30 Aug 2012 07:22:51 +0000 (16:22 +0900)
Rotation related code needed when Direct Rendering is on are added.

Change-Id: I900e883e0fb24afd17f7b65beed0ddefdf3303c8

Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp
Source/WebCore/platform/graphics/texmap/TextureMapperGL.h
Source/WebKit2/UIProcess/API/efl/PageClientImpl.cpp
Source/WebKit2/UIProcess/API/efl/PageClientImpl.h
Source/WebKit2/UIProcess/DrawingAreaProxy.h
Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp
Source/WebKit2/UIProcess/DrawingAreaProxyImpl.h
Source/WebKit2/UIProcess/LayerTreeHostProxy.cpp
Source/WebKit2/UIProcess/LayerTreeHostProxy.h
Source/WebKit2/UIProcess/WebLayerTreeRenderer.cpp
Source/WebKit2/UIProcess/WebLayerTreeRenderer.h

index 23bc5ad..70e04b1 100755 (executable)
@@ -58,6 +58,9 @@
 #endif
 
 namespace WebCore {
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+static int gAngle = 0;
+#endif
 
 struct TextureMapperGLData {
     struct SharedGLData : public RefCounted<SharedGLData> {
@@ -191,6 +194,16 @@ static void scissorClip(const IntRect& rect)
 
     GLint viewport[4];
     GL_CMD(glGetIntegerv(GL_VIEWPORT, viewport));
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    if (gAngle == 90)
+        GL_CMD(glScissor(viewport[3] - rect.maxX(), viewport[2] - rect.maxY(), rect.width(), rect.height()));
+    else if (gAngle == 180)
+        GL_CMD(glScissor(viewport[2] - rect.maxX(), rect.y(), rect.width(), rect.height()));
+    else if (gAngle == 270)
+        GL_CMD(glScissor(rect.x(), rect.y(), rect.width(), rect.height()));
+    else
+#endif
+
     GL_CMD(glScissor(rect.x(), viewport[3] - rect.maxY(), rect.width(), rect.height()));
 }
 
@@ -240,6 +253,13 @@ TextureMapperGL::ClipStack& TextureMapperGL::clipStack()
     return data().currentSurface ? toBitmapTextureGL(data().currentSurface.get())->m_clipStack : m_clipStack;
 }
 
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+void TextureMapperGL::setAngle(int angle)
+{
+    gAngle = angle;
+}
+#endif
+
 void TextureMapperGL::beginPainting(PaintFlags flags)
 {
     // Make sure that no GL error code stays from previous operations.
@@ -632,10 +652,22 @@ PassRefPtr<BitmapTexture> BitmapTextureGL::applyFilters(const BitmapTexture& con
 }
 #endif
 
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+static inline TransformationMatrix createProjectionMatrix(const IntSize& size, bool mirrored, int angle = 0)
+#else
 static inline TransformationMatrix createProjectionMatrix(const IntSize& size, bool mirrored)
+#endif
 {
     const float near = 9999999;
     const float far = -99999;
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    if (angle == 90 || angle == 270)
+        return TransformationMatrix(2.0 / float(size.height()), 0, 0, 0,
+                                    0, (mirrored ? 2.0 : -2.0) / float(size.width()), 0, 0,
+                                    0, 0, -2.f / (far - near), 0,
+                                    -1, mirrored ? -1 : 1, -(far + near) / (far - near), 1);
+    else
+#endif
     return TransformationMatrix(2.0 / float(size.width()), 0, 0, 0,
                                 0, (mirrored ? 2.0 : -2.0) / float(size.height()), 0, 0,
                                 0, 0, -2.f / (far - near), 0,
@@ -725,7 +757,11 @@ void TextureMapperGL::bindDefaultSurface()
     GL_CMD(glBindFramebuffer(GL_FRAMEBUFFER, data().targetFrameBuffer));
     IntSize viewportSize(data().viewport[2], data().viewport[3]);
 
+#if !ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
     data().projectionMatrix = createProjectionMatrix(viewportSize, data().PaintFlags & PaintingMirrored);
+#else
+    data().projectionMatrix = createProjectionMatrix(viewportSize, data().PaintFlags & PaintingMirrored, gAngle);
+#endif
 
 #if !USE(TIZEN_TEXTURE_MAPPER)
     GL_CMD(glViewport(data().viewport[0], data().viewport[1], viewportSize.width(), viewportSize.height()));
@@ -764,6 +800,11 @@ bool TextureMapperGL::beginScissorClip(const TransformationMatrix& modelViewMatr
     if (!quad.isRectilinear() || rect.isEmpty())
         return false;
 
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    if (gAngle == 90 || gAngle == 270)
+        rect = IntRect(rect.y(), rect.x(), rect.height(), rect.width());
+#endif
+
     clipStack().current().scissorBox.intersect(rect);
     clipStack().apply();
     return true;
index 24cbc54..b88a9a9 100755 (executable)
@@ -74,6 +74,10 @@ public:
     virtual AccelerationMode accelerationMode() const OVERRIDE { return OpenGLMode; }
     virtual void setGraphicsContext(GraphicsContext* context) OVERRIDE { m_context = context; }
 
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    void setAngle(int angle);
+#endif
+
 #if ENABLE(CSS_FILTERS)
     void drawFiltered(const BitmapTexture& sourceTexture, const BitmapTexture& contentTexture, const FilterOperation&);
 #endif
index c08d2cf..b4da54c 100755 (executable)
@@ -152,6 +152,9 @@ PageClientImpl::PageClientImpl(WebContext* context, WebPageGroup* pageGroup, Eva
     , m_context(0)
     , m_surface(0)
     , m_config(0)
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    , m_angle(0)
+#endif
     , m_isAcceleratedCompositingModeInitialized(false)
 #endif
 #endif
@@ -1207,10 +1210,36 @@ void PageClientImpl::drawContents()
         // ex) Navigate user typed URL, then IME is hidden and visible content rect's size can be changed.
         m_visibleContentRectForDrawContents.setSize(m_visibleContentRect.size());
     }
-
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_viewWidget));
+    int angle = ecore_evas_rotation_get(ee);
+    m_angle = angle;
+    if (drawingArea())
+        drawingArea()->setAngle(m_angle);
+    matrix.makeIdentity();
+    matrix.rotate3d(0.0, 0.0, 1.0, 360 - m_angle);
+    if (m_angle == 90 || m_angle == 270) {
+        glViewport(0, 0, m_visibleContentRectForDrawContents.height(), m_visibleContentRectForDrawContents.width());
+        if (m_angle == 90)
+            matrix.translate(-m_visibleContentRectForDrawContents.x() -m_visibleContentRectForDrawContents.width(), -m_visibleContentRectForDrawContents.y());
+        else if (m_angle == 270)
+            matrix.translate(-m_visibleContentRectForDrawContents.x(), -m_visibleContentRectForDrawContents.y() - m_visibleContentRectForDrawContents.height());
+        matrix.scale(m_scaleFactor);
+        clipRect = IntRect(0, 0, m_visibleContentRectForDrawContents.height(), m_visibleContentRectForDrawContents.width());
+    } else {
+        glViewport(0, 0, m_visibleContentRectForDrawContents.width(), m_visibleContentRectForDrawContents.height());
+        if (m_angle == 180) {
+            matrix.translate(-m_visibleContentRectForDrawContents.x() - m_visibleContentRectForDrawContents.width(), -m_visibleContentRectForDrawContents.y() - m_visibleContentRectForDrawContents.height());
+            matrix.scale(m_scaleFactor);
+        } else
+            matrix.setMatrix(m_scaleFactor, 0, 0, m_scaleFactor, -m_visibleContentRectForDrawContents.x(), -m_visibleContentRectForDrawContents.y());
+        clipRect = IntRect(IntPoint(), m_visibleContentRectForDrawContents.size());
+    }
+#else
     glViewport(0, 0, m_visibleContentRectForDrawContents.width(), m_visibleContentRectForDrawContents.height());
     matrix.setMatrix(m_scaleFactorForDrawContents, 0, 0, m_scaleFactorForDrawContents, -m_visibleContentRectForDrawContents.x(), -m_visibleContentRectForDrawContents.y());
     clipRect = IntRect(IntPoint(), m_visibleContentRectForDrawContents.size());
+#endif
 
     float bgRed, bgGreen, bgBlue, bgAlpha;
     m_bgColor.getRGBA(bgRed, bgGreen, bgBlue, bgAlpha);
@@ -1277,6 +1306,13 @@ void PageClientImpl::setTargetSurface()
     Evas_Native_Surface nativeSurface;
     evas_gl_native_surface_get(m_evasGL, m_surface, &nativeSurface);
     ewk_view_image_native_surface_set(page()->viewWidget(), &nativeSurface);
+
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_viewWidget));
+    int angle = ecore_evas_rotation_get(ee);
+    m_angle = angle;
+    drawingArea()->setAngle(m_angle);
+#endif
 }
 #endif
 
index 9bf72ea..6774d4e 100755 (executable)
@@ -356,6 +356,9 @@ private:
     Evas_GL_Context* m_context;
     Evas_GL_Surface* m_surface;
     Evas_GL_Config* m_config;
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    int m_angle;
+#endif
     bool m_isAcceleratedCompositingModeInitialized;
 #endif
 #endif
index 65b76d8..286178e 100755 (executable)
@@ -111,6 +111,9 @@ public:
 
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
     virtual void didSuspendPainting() { }
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    virtual void setAngle(int) { }
+#endif
 #endif
 
 protected:
index 6043cc9..279ed78 100755 (executable)
@@ -379,6 +379,16 @@ void DrawingAreaProxyImpl::setVisibleContentsRect(const WebCore::IntRect& visibl
         m_layerTreeHostProxy->setVisibleContentsRect(visibleContentsRect, scale, trajectoryVector, accurateVisibleContentsPosition);
 }
 
+#if ENABLE(TIZEN_WEBKIT2_TILED_AC)
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+void DrawingAreaProxyImpl::setAngle(int angle)
+{
+    if (m_layerTreeHostProxy)
+        m_layerTreeHostProxy->setAngle(angle);
+}
+#endif
+#endif
+
 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
 void DrawingAreaProxyImpl::setVisibleContentsRectForScrollingContentsLayers(const WebCore::IntRect& visibleRect)
 {
index c0ef621..482e65c 100755 (executable)
@@ -54,6 +54,9 @@ public:
 
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
     virtual void didSuspendPainting();
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    virtual void setAngle(int);
+#endif
 #endif
 
 private:
index 6c4dea8..0e46402 100755 (executable)
@@ -179,6 +179,13 @@ void LayerTreeHostProxy::restoreBackingStores()
     m_renderer->setActive(true);
     renderNextFrame();
 }
+
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+void LayerTreeHostProxy::setAngle(int angle)
+{
+    m_renderer->setAngle(angle);
+}
+#endif
 #endif
 
 #if ENABLE(TIZEN_ONESHOT_DRAWING_SYNCHRONIZATION)
index 0d1ed9b..9264abb 100755 (executable)
@@ -77,6 +77,10 @@ public:
     WebLayerTreeRenderer* layerTreeRenderer() const { return m_renderer.get(); }
 
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    void setAngle(int);
+#endif
+
     void clearBackingStores();
     void restoreBackingStores();
 #endif
index 9eb7d34..84b60fc 100755 (executable)
@@ -112,6 +112,9 @@ WebLayerTreeRenderer::WebLayerTreeRenderer(LayerTreeHostProxy* layerTreeHostProx
     : m_layerTreeHostProxy(layerTreeHostProxy)
     , m_rootLayerID(InvalidWebLayerID)
     , m_isActive(false)
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    , m_angle(0)
+#endif
 {
 }
 
@@ -165,6 +168,10 @@ void WebLayerTreeRenderer::paintToCurrentGLContext(const TransformationMatrix& m
     if (!layer)
         return;
 
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    static_cast<TextureMapperGL*>(m_textureMapper.get())->setAngle(m_angle);
+#endif
+
     layer->setTextureMapper(m_textureMapper.get());
     m_textureMapper->beginPainting(PaintFlags);
     m_textureMapper->beginClip(TransformationMatrix(), clipRect);
index 62148a2..c3d1b2b 100755 (executable)
@@ -108,6 +108,10 @@ public:
     virtual void platformLayerChanged(WebCore::GraphicsLayer*, WebCore::PlatformLayer* oldPlatformLayer, WebCore::PlatformLayer* newPlatformLayer);
 #endif
 
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    void setAngle(int angle) { m_angle = angle; }
+#endif
+
 #if ENABLE(TIZEN_ONESHOT_DRAWING_SYNCHRONIZATION)
     void setNeedsOneShotDrawingSynchronization();
     void doOneShotDrawingSynchronization();
@@ -189,6 +193,9 @@ private:
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
     DrawingAreaProxy* m_drawingAreaProxy;
 
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    int m_angle;
+#endif
 #if ENABLE(TIZEN_ONESHOT_DRAWING_SYNCHRONIZATION)
     bool m_needsOneShotDrawingSynchronization;
 #endif