Title: [151591] trunk/Source/WebCore
Revision
151591
Author
[email protected]
Date
2013-06-14 07:04:20 -0700 (Fri, 14 Jun 2013)

Log Message

[BlackBerry] Accelerated compositing layers that intersect the image plane are incorrectly transformed
https://bugs.webkit.org/show_bug.cgi?id=117067

Reviewed by Carlos Garcia Campos.

PR 273550

The BlackBerry port used to mathematically project each corner of each
layer bounds rectangle, which gives the wrong results when the layer
intersects the image plane.

For display lists, we still got the correct appearance of the layer
contents, since the display list results in geometry that's transformed
in the vertex shader, on the GPU.

However, the transformed bounds are used for drawing the debug border,
performing visibility calculations on the CPU and drawing of WebGL,
masks/reflections and filters. Using the mathematical projection of
points that lie behind the image plane gives the wrong results.

The most important consequence of this bug was that the wrong area of
the layer would be considered visible, so a tiled layer would not
populate the right tiles (or any tiles at all).

Fixed by implementing something along the lines of the recipe in
section 6.2 of http://www.w3.org/TR/css3-transforms.

No new tests, manually testable by enabling debug border on
https://developer.mozilla.org/en-US/demos/detail/the-box/launch.

* platform/graphics/blackberry/EGLImageLayerCompositingThreadClient.cpp:
(WebCore::EGLImageLayerCompositingThreadClient::drawTextures):
* platform/graphics/blackberry/LayerCompositingThread.cpp:
(WebCore::LayerCompositingThread::LayerCompositingThread):
(WebCore::LayerCompositingThread::setDrawTransform):
(WebCore):
(WebCore::LayerCompositingThread::textureCoordinates):
(WebCore::LayerCompositingThread::drawTextures):
* platform/graphics/blackberry/LayerCompositingThread.h:
(LayerCompositingThread):
(WebCore::LayerCompositingThread::transformedBounds):
(WebCore::LayerCompositingThread::ws):
(WebCore::LayerCompositingThread::centerW):
* platform/graphics/blackberry/LayerFilterRenderer.cpp:
(WebCore::LayerFilterRenderer::applyActions):
* platform/graphics/blackberry/LayerRenderer.cpp:
(WebCore::compareLayerW):
(WebCore::LayerRenderer::compositeLayers):
(WebCore::LayerRenderer::drawDebugBorder):
(WebCore):
(WebCore::LayerRenderer::updateLayersRecursive):
(WebCore::LayerRenderer::compositeLayersRecursive):
* platform/graphics/blackberry/LayerRenderer.h:
(WebCore):
(LayerRenderer):
* platform/graphics/blackberry/LayerRendererSurface.cpp:
(WebCore::LayerRendererSurface::boundingBox):
(WebCore::LayerRendererSurface::transformedBounds):
* platform/graphics/blackberry/LayerRendererSurface.h:
(WebCore::LayerRendererSurface::setDrawTransform):
(WebCore::LayerRendererSurface::setReplicaDrawTransform):
(LayerRendererSurface):
* platform/graphics/blackberry/LayerUtilities.h: Added.
(WebCore):
(LayerClipPlane):
(WebCore::LayerClipPlane::LayerClipPlane):
(WebCore::LayerClipPlane::isPointInside):
(WebCore::LayerClipPlane::computeIntersection):
(WebCore::intersect):
(WebCore::boundingBox):
(WebCore::multVecMatrix):
(WebCore::toVector):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (151590 => 151591)


--- trunk/Source/WebCore/ChangeLog	2013-06-14 12:53:37 UTC (rev 151590)
+++ trunk/Source/WebCore/ChangeLog	2013-06-14 14:04:20 UTC (rev 151591)
@@ -1,3 +1,78 @@
+2013-06-14  Arvid Nilsson  <[email protected]>
+
+        [BlackBerry] Accelerated compositing layers that intersect the image plane are incorrectly transformed
+        https://bugs.webkit.org/show_bug.cgi?id=117067
+
+        Reviewed by Carlos Garcia Campos.
+
+        PR 273550
+
+        The BlackBerry port used to mathematically project each corner of each
+        layer bounds rectangle, which gives the wrong results when the layer
+        intersects the image plane.
+
+        For display lists, we still got the correct appearance of the layer
+        contents, since the display list results in geometry that's transformed
+        in the vertex shader, on the GPU.
+
+        However, the transformed bounds are used for drawing the debug border,
+        performing visibility calculations on the CPU and drawing of WebGL,
+        masks/reflections and filters. Using the mathematical projection of
+        points that lie behind the image plane gives the wrong results.
+
+        The most important consequence of this bug was that the wrong area of
+        the layer would be considered visible, so a tiled layer would not
+        populate the right tiles (or any tiles at all).
+
+        Fixed by implementing something along the lines of the recipe in
+        section 6.2 of http://www.w3.org/TR/css3-transforms.
+
+        No new tests, manually testable by enabling debug border on
+        https://developer.mozilla.org/en-US/demos/detail/the-box/launch.
+
+        * platform/graphics/blackberry/EGLImageLayerCompositingThreadClient.cpp:
+        (WebCore::EGLImageLayerCompositingThreadClient::drawTextures):
+        * platform/graphics/blackberry/LayerCompositingThread.cpp:
+        (WebCore::LayerCompositingThread::LayerCompositingThread):
+        (WebCore::LayerCompositingThread::setDrawTransform):
+        (WebCore):
+        (WebCore::LayerCompositingThread::textureCoordinates):
+        (WebCore::LayerCompositingThread::drawTextures):
+        * platform/graphics/blackberry/LayerCompositingThread.h:
+        (LayerCompositingThread):
+        (WebCore::LayerCompositingThread::transformedBounds):
+        (WebCore::LayerCompositingThread::ws):
+        (WebCore::LayerCompositingThread::centerW):
+        * platform/graphics/blackberry/LayerFilterRenderer.cpp:
+        (WebCore::LayerFilterRenderer::applyActions):
+        * platform/graphics/blackberry/LayerRenderer.cpp:
+        (WebCore::compareLayerW):
+        (WebCore::LayerRenderer::compositeLayers):
+        (WebCore::LayerRenderer::drawDebugBorder):
+        (WebCore):
+        (WebCore::LayerRenderer::updateLayersRecursive):
+        (WebCore::LayerRenderer::compositeLayersRecursive):
+        * platform/graphics/blackberry/LayerRenderer.h:
+        (WebCore):
+        (LayerRenderer):
+        * platform/graphics/blackberry/LayerRendererSurface.cpp:
+        (WebCore::LayerRendererSurface::boundingBox):
+        (WebCore::LayerRendererSurface::transformedBounds):
+        * platform/graphics/blackberry/LayerRendererSurface.h:
+        (WebCore::LayerRendererSurface::setDrawTransform):
+        (WebCore::LayerRendererSurface::setReplicaDrawTransform):
+        (LayerRendererSurface):
+        * platform/graphics/blackberry/LayerUtilities.h: Added.
+        (WebCore):
+        (LayerClipPlane):
+        (WebCore::LayerClipPlane::LayerClipPlane):
+        (WebCore::LayerClipPlane::isPointInside):
+        (WebCore::LayerClipPlane::computeIntersection):
+        (WebCore::intersect):
+        (WebCore::boundingBox):
+        (WebCore::multVecMatrix):
+        (WebCore::toVector):
+
 2013-06-14  Allan Sandfeld Jensen  <[email protected]>
 
         [Qt] Map rewind and fast forward keys to match GoogleTV

Modified: trunk/Source/WebCore/platform/graphics/blackberry/EGLImageLayerCompositingThreadClient.cpp (151590 => 151591)


--- trunk/Source/WebCore/platform/graphics/blackberry/EGLImageLayerCompositingThreadClient.cpp	2013-06-14 12:53:37 UTC (rev 151590)
+++ trunk/Source/WebCore/platform/graphics/blackberry/EGLImageLayerCompositingThreadClient.cpp	2013-06-14 14:04:20 UTC (rev 151591)
@@ -47,8 +47,6 @@
 
 void EGLImageLayerCompositingThreadClient::drawTextures(LayerCompositingThread* layer, double /*scale*/, const GLES2Program& program)
 {
-    static float upsideDown[4 * 2] = { 0, 1,  1, 1,  1, 0,  0, 0 };
-
     if (!m_textureAccessor || !m_textureAccessor->textureID())
         return;
 
@@ -56,10 +54,10 @@
     glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
     glUseProgram(program.m_program);
     glUniform1f(program.opacityLocation(), layer->drawOpacity());
-    glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, &layer->transformedBounds());
-    glVertexAttribPointer(program.texCoordLocation(), 2, GL_FLOAT, GL_FALSE, 0, upsideDown);
+    glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, layer->transformedBounds().data());
+    glVertexAttribPointer(program.texCoordLocation(), 2, GL_FLOAT, GL_FALSE, 0, layer->textureCoordinates(LayerCompositingThread::UpsideDown).data());
     glBindTexture(GL_TEXTURE_2D, m_textureAccessor->textureID());
-    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+    glDrawArrays(GL_TRIANGLE_FAN, 0, layer->transformedBounds().size());
 }
 
 void EGLImageLayerCompositingThreadClient::deleteTextures(LayerCompositingThread*)

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThread.cpp (151590 => 151591)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThread.cpp	2013-06-14 12:53:37 UTC (rev 151590)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThread.cpp	2013-06-14 14:04:20 UTC (rev 151591)
@@ -40,12 +40,14 @@
 #include "LayerMessage.h"
 #include "LayerRenderer.h"
 #include "LayerRendererClient.h"
+#include "LayerUtilities.h"
 #include "LayerWebKitThread.h"
 #if ENABLE(VIDEO)
 #include "MediaPlayer.h"
 #include "MediaPlayerPrivateBlackBerry.h"
 #endif
 #include "PluginView.h"
+#include "StdLibExtras.h"
 #include "TextureCacheCompositingThread.h"
 
 #include <BlackBerryPlatformGLES2ContextState.h>
@@ -76,6 +78,7 @@
     : LayerData(type)
     , m_layerRenderer(0)
     , m_superlayer(0)
+    , m_centerW(0)
     , m_pluginBuffer(0)
     , m_drawOpacity(0)
     , m_visible(false)
@@ -127,19 +130,94 @@
         m_client->deleteTextures(this);
 }
 
-void LayerCompositingThread::setDrawTransform(double scale, const TransformationMatrix& matrix)
+void LayerCompositingThread::setDrawTransform(double scale, const TransformationMatrix& matrix, const TransformationMatrix& projectionMatrix)
 {
-    m_drawTransform = matrix;
+    m_drawTransform = projectionMatrix * matrix;
 
     FloatRect boundsRect(-origin(), bounds());
 
     if (sizeIsScaleInvariant())
         boundsRect.scale(1 / scale);
 
-    m_transformedBounds = matrix.mapQuad(boundsRect);
-    m_boundingBox = m_transformedBounds.boundingBox();
+    m_centerW = 0;
+    m_transformedBounds.clear();
+    m_ws.clear();
+    m_textureCoordinates.clear();
+    if (matrix.hasPerspective() && !m_layerRendererSurface) {
+        // Perform processing according to http://www.w3.org/TR/css3-transforms 6.2
+        // If w < 0 for all four corners of the transformed box, the box is not rendered.
+        // If w < 0 for one to three corners of the transformed box, the box
+        // must be replaced by a polygon that has any parts with w < 0 cut out.
+        // If w = 0, (x′, y′, z′) = (x ⋅ n, y ⋅ n, z ⋅ n)
+        // We implement this by intersecting with the image plane, i.e. the last row of the column-major matrix.
+        // To avoid problems with w close to 0, we use w = epsilon as the near plane by subtracting epsilon from matrix.m44().
+        const float epsilon = 1e-3;
+        Vector<FloatPoint3D, 4> quad = toVector<FloatPoint3D, 4>(boundsRect);
+        Vector<FloatPoint3D, 4> polygon = intersect(quad, LayerClipPlane(FloatPoint3D(matrix.m14(), matrix.m24(), matrix.m34()), matrix.m44() - epsilon));
+
+        // Compute the clipped texture coordinates.
+        if (polygon != quad) {
+            for (size_t i = 0; i < polygon.size(); ++i) {
+                FloatPoint3D& p = polygon[i];
+                m_textureCoordinates.append(FloatPoint(p.x() / boundsRect.width() + 0.5f, p.y() / boundsRect.height() + 0.5f));
+            }
+        }
+
+        // If w > 0, (x′, y′, z′) = (x/w, y/w, z/w)
+        for (size_t i = 0; i < polygon.size(); ++i) {
+            float w;
+            FloatPoint3D p = multVecMatrix(matrix, polygon[i], w);
+            if (w != 1) {
+                p.setX(p.x() / w);
+                p.setY(p.y() / w);
+                p.setZ(p.z() / w);
+            }
+
+            FloatPoint3D q = projectionMatrix.mapPoint(p);
+            m_transformedBounds.append(FloatPoint(q.x(), q.y()));
+            m_ws.append(w);
+        }
+
+        m_centerW = matrix.m44();
+    } else
+        m_transformedBounds = toVector<FloatPoint, 4>(m_drawTransform.mapQuad(boundsRect));
+
+    m_boundingBox = WebCore::boundingBox(m_transformedBounds);
 }
 
+const Vector<FloatPoint>& LayerCompositingThread::textureCoordinates(TextureCoordinateOrientation orientation) const
+{
+    if (m_textureCoordinates.size()) {
+        if (orientation == UpsideDown) {
+            static Vector<FloatPoint> upsideDownCoordinates;
+            upsideDownCoordinates = m_textureCoordinates;
+            for (size_t i = 0; i < upsideDownCoordinates.size(); ++i)
+                upsideDownCoordinates[i].setY(1 - upsideDownCoordinates[i].y());
+            return upsideDownCoordinates;
+        }
+
+        return m_textureCoordinates;
+    }
+
+    if (orientation == UpsideDown) {
+        static FloatPoint data[4] = { FloatPoint(0, 1),  FloatPoint(1, 1),  FloatPoint(1, 0),  FloatPoint(0, 0) };
+        static Vector<FloatPoint>* upsideDownCoordinates = 0;
+        if (!upsideDownCoordinates) {
+            upsideDownCoordinates = new Vector<FloatPoint>();
+            upsideDownCoordinates->append(data, 4);
+        }
+        return *upsideDownCoordinates;
+    }
+
+    static FloatPoint data[4] = { FloatPoint(0, 0),  FloatPoint(1, 0),  FloatPoint(1, 1),  FloatPoint(0, 1) };
+    static Vector<FloatPoint>* coordinates = 0;
+    if (!coordinates) {
+        coordinates = new Vector<FloatPoint>();
+        coordinates->append(data, 4);
+    }
+    return *coordinates;
+}
+
 FloatQuad LayerCompositingThread::transformedHolePunchRect() const
 {
     FloatRect holePunchRect(m_holePunchRect);
@@ -149,8 +227,6 @@
 
 void LayerCompositingThread::drawTextures(double scale, const GLES2Program& program, const FloatRect& visibleRect)
 {
-    static float texcoords[4 * 2] = { 0, 0,  1, 0,  1, 1,  0, 1 };
-
     if (m_pluginView) {
         if (m_isVisible) {
             // The layer contains Flash, video, or other plugin contents.
@@ -169,9 +245,9 @@
             glEnable(GL_BLEND);
             glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
             glUniform1f(program.opacityLocation(), drawOpacity());
-            glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, &m_transformedBounds);
-            glVertexAttribPointer(program.texCoordLocation(), 2, GL_FLOAT, GL_FALSE, 0, texcoords);
-            glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+            glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, m_transformedBounds.data());
+            glVertexAttribPointer(program.texCoordLocation(), 2, GL_FLOAT, GL_FALSE, 0, textureCoordinates().data());
+            glDrawArrays(GL_TRIANGLE_FAN, 0, m_transformedBounds.size());
         }
         return;
     }
@@ -185,8 +261,8 @@
                 // normalized device coordinates [-1, 1] to the 'visibleRect'.
                 float vrw2 = visibleRect.width() / 2.0;
                 float vrh2 = visibleRect.height() / 2.0;
-                FloatPoint p(m_transformedBounds.p1().x() * vrw2 + vrw2 + visibleRect.x(),
-                    -m_transformedBounds.p1().y() * vrh2 + vrh2 + visibleRect.y());
+                FloatPoint p(m_transformedBounds[0].x() * vrw2 + vrw2 + visibleRect.x(),
+                    -m_transformedBounds[0].y() * vrh2 + vrh2 + visibleRect.y());
                 paintRect = IntRect(roundedIntPoint(p), m_bounds);
             } else
                 paintRect = m_layerRenderer->toWindowCoordinates(m_boundingBox);

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThread.h (151590 => 151591)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThread.h	2013-06-14 12:53:37 UTC (rev 151590)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThread.h	2013-06-14 14:04:20 UTC (rev 151591)
@@ -164,7 +164,7 @@
     // The draw transform expects the origin to be located at the center of the layer.
     FloatPoint origin() const { return FloatPoint(m_bounds.width() / 2.0f, m_bounds.height() / 2.0f); }
 
-    void setDrawTransform(double scale, const TransformationMatrix&);
+    void setDrawTransform(double scale, const TransformationMatrix& modelViewMatrix, const TransformationMatrix& projectionMatrix);
     const TransformationMatrix& drawTransform() const { return m_drawTransform; }
 
     void setDrawOpacity(float opacity) { m_drawOpacity = opacity; }
@@ -182,8 +182,18 @@
 
     // These use normalized device coordinates
     FloatRect boundingBox() const { return m_boundingBox; }
-    const FloatQuad& transformedBounds() const { return m_transformedBounds; }
+    // The bounds are processed according to http://www.w3.org/TR/css3-transforms paragraph 6.2, which can result in a polygon with more than 4 sides.
+    const Vector<FloatPoint, 4>& transformedBounds() const { return m_transformedBounds; }
+    const Vector<float, 4>& ws() const { return m_ws; }
+
+    enum TextureCoordinateOrientation {
+        RightSideUp = 0,
+        UpsideDown
+    };
+
+    const Vector<FloatPoint>& textureCoordinates(TextureCoordinateOrientation = RightSideUp) const;
     FloatQuad transformedHolePunchRect() const;
+    float centerW() const { return m_centerW; }
 
     void deleteTextures();
 
@@ -249,8 +259,10 @@
     LayerCompositingThread* m_superlayer;
 
     // Vertex data for the bounds of this layer
-    FloatQuad m_transformedBounds;
-    // The bounding rectangle of the transformed layer
+    Vector<FloatPoint, 4> m_transformedBounds;
+    Vector<float, 4> m_ws;
+    Vector<FloatPoint> m_textureCoordinates; // Only used when a 3D layer is clipped against z = 0
+    float m_centerW;
     FloatRect m_boundingBox;
 
     OwnPtr<LayerRendererSurface> m_layerRendererSurface;

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerFilterRenderer.cpp (151590 => 151591)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerFilterRenderer.cpp	2013-06-14 12:53:37 UTC (rev 151590)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerFilterRenderer.cpp	2013-06-14 14:04:20 UTC (rev 151591)
@@ -682,8 +682,6 @@
     return ret;
 }
 
-static float texcoords[4 * 2] = { 0, 0,  1, 0,  1, 1,  0, 1 };
-
 void LayerFilterRenderer::applyActions(unsigned& fbo, LayerCompositingThread* layer, Vector<RefPtr<LayerFilterRendererAction> > actions)
 {
     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@@ -709,9 +707,16 @@
 
     LayerRendererSurface* surface = layer->layerRendererSurface();
 
-    glVertexAttribPointer(m_positionLocation, 2, GL_FLOAT, GL_FALSE, 0, &layer->transformedBounds());
+    // From the code in LayerRenderer, we see that the layer will have a trivial transform that will
+    // result in the transformed bounds being a polygon with 4 vertices, i.e. a quad.
+    // The LayerFilterRenderer depends on the layer being a quad, so assert to make sure.
+    ASSERT(layer->transformedBounds().size() == 4);
+    if (layer->transformedBounds().size() != 4)
+        return;
+
+    glVertexAttribPointer(m_positionLocation, 2, GL_FLOAT, GL_FALSE, 0, layer->transformedBounds().data());
     glEnableVertexAttribArray(m_positionLocation);
-    glVertexAttribPointer(m_texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, texcoords);
+    glVertexAttribPointer(m_texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, layer->textureCoordinates().data());
     glEnableVertexAttribArray(m_texCoordLocation);
 
     m_texture->protect(surface->texture()->size(), BlackBerry::Platform::Graphics::AlwaysBacked);
@@ -764,9 +769,9 @@
 
         actions[i]->restoreState();
 
-        glVertexAttribPointer(m_positionLocation, 2, GL_FLOAT, GL_FALSE, 0, &layer->transformedBounds());
+        glVertexAttribPointer(m_positionLocation, 2, GL_FLOAT, GL_FALSE, 0, layer->transformedBounds().data());
         glEnableVertexAttribArray(m_positionLocation);
-        glVertexAttribPointer(m_texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, texcoords);
+        glVertexAttribPointer(m_texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, layer->textureCoordinates().data());
         glEnableVertexAttribArray(m_texCoordLocation);
     }
 

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.cpp (151590 => 151591)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.cpp	2013-06-14 12:53:37 UTC (rev 151590)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.cpp	2013-06-14 14:04:20 UTC (rev 151591)
@@ -201,12 +201,9 @@
     }
 }
 
-static inline bool compareLayerZ(const LayerCompositingThread* a, const LayerCompositingThread* b)
+static inline bool compareLayerW(const LayerCompositingThread* a, const LayerCompositingThread* b)
 {
-    const TransformationMatrix& transformA = a->drawTransform();
-    const TransformationMatrix& transformB = b->drawTransform();
-
-    return transformA.m43() < transformB.m43();
+    return a->centerW() > b->centerW();
 }
 
 void LayerRenderer::prepareFrame(double animationTime, LayerCompositingThread* rootLayer)
@@ -313,7 +310,7 @@
     for (size_t i = 0; i < sublayers.size(); i++) {
         float opacity = 1;
         FloatRect clipRect(m_clipRect);
-        updateLayersRecursive(sublayers[i].get(), matrix, surfaceLayers, opacity, clipRect);
+        updateLayersRecursive(sublayers[i].get(), TransformationMatrix(), matrix, surfaceLayers, opacity, clipRect);
     }
 
     // Decompose the dirty rect into a set of non-overlaping rectangles
@@ -580,6 +577,22 @@
     return enclosingIntRect(result);
 }
 
+void LayerRenderer::drawDebugBorder(const Vector<FloatPoint>& transformedBounds, const Color& borderColor, float borderWidth)
+{
+    if (borderColor.alpha() < 255) {
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+    } else
+        glDisable(GL_BLEND);
+
+    const GLES2Program& program = useProgram(ColorProgram);
+    glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, transformedBounds.data());
+    glUniform4f(m_colorColorLocation, borderColor.red() / 255.0, borderColor.green() / 255.0, borderColor.blue() / 255.0, borderColor.alpha() / 255.0);
+
+    glLineWidth(borderWidth);
+    glDrawArrays(GL_LINE_LOOP, 0, transformedBounds.size());
+}
+
 // Draws a debug border around the layer's bounds.
 void LayerRenderer::drawDebugBorder(LayerCompositingThread* layer)
 {
@@ -593,28 +606,17 @@
     if (!borderColor.alpha())
         return;
 
-    if (borderColor.alpha() < 255) {
-        glEnable(GL_BLEND);
-        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-    } else
-        glDisable(GL_BLEND);
-
     // If we're rendering to a surface, don't include debug border inside the surface.
     if (m_currentLayerRendererSurface)
         return;
 
-    FloatQuad transformedBounds;
+    Vector<FloatPoint> transformedBounds;
     if (layerAlreadyOnSurface(layer))
         transformedBounds = layer->layerRendererSurface()->transformedBounds();
     else
         transformedBounds = layer->transformedBounds();
 
-    const GLES2Program& program = useProgram(ColorProgram);
-    glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, &transformedBounds);
-    glUniform4f(m_colorColorLocation, borderColor.red() / 255.0, borderColor.green() / 255.0, borderColor.blue() / 255.0, 1);
-
-    glLineWidth(std::max(1.0f, layer->borderWidth()));
-    glDrawArrays(GL_LINE_LOOP, 0, 4);
+    drawDebugBorder(transformedBounds, borderColor, std::max(1.0f, layer->borderWidth()));
 }
 
 // Clears a rectangle inside the layer's bounds.
@@ -657,7 +659,7 @@
         prepareFrameRecursive(sublayers[i].get(), animationTime, isContextCurrent);
 }
 
-void LayerRenderer::updateLayersRecursive(LayerCompositingThread* layer, const TransformationMatrix& matrix, Vector<RefPtr<LayerCompositingThread> >& surfaceLayers, float opacity, FloatRect clipRect)
+void LayerRenderer::updateLayersRecursive(LayerCompositingThread* layer, const TransformationMatrix& matrix, const TransformationMatrix& projectionMatrix, Vector<RefPtr<LayerCompositingThread> >& surfaceLayers, float opacity, FloatRect clipRect)
 {
     // The contract for LayerCompositingThread::setLayerRenderer is it must be set if the layer has been rendered.
     // So do it now, before we render it in compositeLayersRecursive.
@@ -768,6 +770,7 @@
     // Calculate the layer's opacity.
     opacity *= layer->opacity();
 
+    TransformationMatrix localProjectionMatrix = projectionMatrix;
 #if ENABLE(CSS_FILTERS)
     bool useLayerRendererSurface = layer->maskLayer() || layer->replicaLayer() || layer->filters().size();
 #else
@@ -785,30 +788,30 @@
         layer->setDrawOpacity(1.0);
         surface->setDrawOpacity(opacity);
 
-        surface->setDrawTransform(localMatrix);
+        surface->setDrawTransform(localMatrix, projectionMatrix);
         if (layer->replicaLayer()) {
             TransformationMatrix replicaMatrix = localMatrix;
             replicaMatrix.translate3d(-0.5 * bounds.width(), -0.5 * bounds.height(), 0);
             replicaMatrix.translate3d(layer->replicaLayer()->position().x(), layer->replicaLayer()->position().y(), 0);
             replicaMatrix.multiply(layer->replicaLayer()->transform());
             replicaMatrix.translate3d(centerOffsetX, centerOffsetY, 0);
-            surface->setReplicaDrawTransform(replicaMatrix);
+            surface->setReplicaDrawTransform(replicaMatrix, projectionMatrix);
         }
 
         IntRect contentRect = enclosingIntRect(FloatRect(FloatPoint::zero(), bounds));
         surface->setContentRect(contentRect);
 
-        TransformationMatrix projectionMatrix = orthoMatrix(contentRect.x(), contentRect.maxX(), contentRect.y(), contentRect.maxY(), -1000, 1000);
+        localProjectionMatrix = orthoMatrix(contentRect.x(), contentRect.maxX(), contentRect.y(), contentRect.maxY(), -1000, 1000);
         // The origin of the new surface is the upper left corner of the layer.
         TransformationMatrix drawTransform;
         drawTransform.translate3d(0.5 * bounds.width(), 0.5 * bounds.height(), 0);
         // This layer will start using new transformation.
-        localMatrix = projectionMatrix * drawTransform;
+        localMatrix = drawTransform;
 
         surfaceLayers.append(layer);
     }
 
-    layer->setDrawTransform(m_scale, localMatrix);
+    layer->setDrawTransform(m_scale, localMatrix, localProjectionMatrix);
 
 #if ENABLE(VIDEO)
     bool layerVisible = clipRect.intersects(layer->boundingBox()) || layer->mediaPlayer();
@@ -830,8 +833,7 @@
         localMatrix.setM23(0);
         localMatrix.setM31(0);
         localMatrix.setM32(0);
-        // This corresponds to the depth range specified in the original orthographic projection matrix
-        localMatrix.setM33(0.001);
+        localMatrix.setM33(1);
         localMatrix.setM34(0);
         localMatrix.setM43(0);
     }
@@ -847,7 +849,7 @@
 
     const Vector<RefPtr<LayerCompositingThread> >& sublayers = layer->sublayers();
     for (size_t i = 0; i < sublayers.size(); i++)
-        updateLayersRecursive(sublayers[i].get(), localMatrix, surfaceLayers, opacity, clipRect);
+        updateLayersRecursive(sublayers[i].get(), localMatrix, localProjectionMatrix, surfaceLayers, opacity, clipRect);
 }
 
 static bool hasRotationalComponent(const TransformationMatrix& m)
@@ -965,8 +967,8 @@
         updateScissorIfNeeded(clipRect);
         const GLES2Program& program = useProgram(ColorProgram);
         glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-        glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, &layer->transformedBounds());
-        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+        glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, layer->transformedBounds().data());
+        glDrawArrays(GL_TRIANGLE_FAN, 0, layer->transformedBounds().size());
         glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
     }
 
@@ -986,7 +988,7 @@
     // children, so bail.
     if (preserves3D && !superlayerPreserves3D) {
         collect3DPreservingLayers(sublayers);
-        std::stable_sort(sublayers.begin(), sublayers.end(), compareLayerZ);
+        std::stable_sort(sublayers.begin(), sublayers.end(), compareLayerW);
     }
 
     int newStencilValue = stencilClip ? stencilValue+1 : stencilValue;
@@ -1008,8 +1010,8 @@
         updateScissorIfNeeded(clipRect);
         const GLES2Program& program = useProgram(ColorProgram);
         glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-        glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, &layer->transformedBounds());
-        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+        glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, layer->transformedBounds().data());
+        glDrawArrays(GL_TRIANGLE_FAN, 0, layer->transformedBounds().size());
         glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
 
         if (!stencilValue)

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.h (151590 => 151591)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.h	2013-06-14 12:53:37 UTC (rev 151590)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.h	2013-06-14 14:04:20 UTC (rev 151591)
@@ -50,6 +50,7 @@
 
 namespace WebCore {
 
+class Color;
 class LayerCompositingThread;
 class LayerRendererClient;
 class LayerRendererSurface;
@@ -133,12 +134,14 @@
     // If the layer has already been drawed on a surface.
     bool layerAlreadyOnSurface(LayerCompositingThread*) const;
 
+    void drawDebugBorder(const Vector<FloatPoint>&, const Color&, float borderWidth);
+
     static GLuint loadShader(GLenum type, const char* shaderSource);
     static GLuint loadShaderProgram(const char* vertexShaderSource, const char* fragmentShaderSource);
 
 private:
     void prepareFrameRecursive(LayerCompositingThread*, double animationTime, bool isContextCurrent);
-    void updateLayersRecursive(LayerCompositingThread*, const TransformationMatrix& parentMatrix, Vector<RefPtr<LayerCompositingThread> >& surfaceLayers, float opacity, FloatRect clipRect);
+    void updateLayersRecursive(LayerCompositingThread*, const TransformationMatrix& parentMatrix, const TransformationMatrix& projectionMatrix, Vector<RefPtr<LayerCompositingThread> >& surfaceLayers, float opacity, FloatRect clipRect);
     void compositeLayersRecursive(LayerCompositingThread*, int stencilValue, FloatRect clipRect);
     void updateScissorIfNeeded(const FloatRect& clipRect);
 

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerRendererSurface.cpp (151590 => 151591)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerRendererSurface.cpp	2013-06-14 12:53:37 UTC (rev 151590)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerRendererSurface.cpp	2013-06-14 14:04:20 UTC (rev 151591)
@@ -24,6 +24,7 @@
 
 #include "LayerCompositingThread.h"
 #include "LayerRenderer.h"
+#include "LayerUtilities.h"
 #include "TextureCacheCompositingThread.h"
 
 namespace WebCore {
@@ -47,7 +48,7 @@
 
 FloatRect LayerRendererSurface::boundingBox() const
 {
-    FloatRect rect = transformedBounds().boundingBox();
+    FloatRect rect = WebCore::boundingBox(transformedBounds());
 
     if (m_ownerLayer->replicaLayer())
         rect.unite(m_replicaDrawTransform.mapQuad(FloatRect(-origin(), size())).boundingBox());
@@ -55,9 +56,9 @@
     return rect;
 }
 
-FloatQuad LayerRendererSurface::transformedBounds() const
+Vector<FloatPoint, 4> LayerRendererSurface::transformedBounds() const
 {
-    return m_drawTransform.mapQuad(FloatRect(-origin(), size()));
+    return toVector<FloatPoint, 4>(m_drawTransform.mapQuad(FloatRect(-origin(), size())));
 }
 
 bool LayerRendererSurface::ensureTexture()

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerRendererSurface.h (151590 => 151591)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerRendererSurface.h	2013-06-14 12:53:37 UTC (rev 151590)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerRendererSurface.h	2013-06-14 14:04:20 UTC (rev 151591)
@@ -47,14 +47,14 @@
 
     FloatPoint origin() const { return FloatPoint(m_size.width() / 2.0f, m_size.height() / 2.0f); }
 
-    void setDrawTransform(const TransformationMatrix& matrix) { m_drawTransform = matrix; }
+    void setDrawTransform(const TransformationMatrix& matrix, const TransformationMatrix& projectionMatrix) { m_drawTransform = projectionMatrix * matrix; }
     const TransformationMatrix& drawTransform() const { return m_drawTransform; }
-    void setReplicaDrawTransform(const TransformationMatrix& matrix) { m_replicaDrawTransform = matrix; }
+    void setReplicaDrawTransform(const TransformationMatrix& matrix, const TransformationMatrix& projectionMatrix) { m_replicaDrawTransform = projectionMatrix * matrix; }
     const TransformationMatrix& replicaDrawTransform() const { return m_replicaDrawTransform; }
 
     // These use normalized device coordinates
     FloatRect boundingBox() const;
-    FloatQuad transformedBounds() const;
+    Vector<FloatPoint, 4> transformedBounds() const;
 
     bool ensureTexture();
     void releaseTexture();

Added: trunk/Source/WebCore/platform/graphics/blackberry/LayerUtilities.h (0 => 151591)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerUtilities.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerUtilities.h	2013-06-14 14:04:20 UTC (rev 151591)
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2013 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef LayerUtilities_h
+#define LayerUtilities_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "FloatPoint.h"
+#include "FloatPoint3D.h"
+#include "FloatQuad.h"
+#include "FloatSize.h"
+#include "LayerCompositingThread.h"
+#include "TransformationMatrix.h"
+
+#include <algorithm>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+// Specifies a clip plane with normal n and containing point p_0
+// as p * n + d = 0, d = -p_0 * n. The asterisk is dot product.
+class LayerClipPlane {
+public:
+    LayerClipPlane(FloatPoint3D n, float d)
+        : m_n(n)
+        , m_d(d)
+    {
+    }
+
+    inline bool isPointInside(const FloatPoint3D& p) const
+    {
+        return p * m_n + m_d > 0;
+    }
+
+    inline FloatPoint3D computeIntersection(const FloatPoint3D& p1, const FloatPoint3D& p2) const
+    {
+        float u = (-m_d - p1 * m_n) / ((p2 - p1) * m_n);
+        return p1 + u * (p2 - p1);
+    }
+
+protected:
+    FloatPoint3D m_n;
+    float m_d;
+};
+
+// Sutherland - Hodgman, inner loop
+template<typename Point, size_t inlineCapacity, typename ClipPrimitive>
+inline Vector<Point, inlineCapacity> intersect(const Vector<Point, inlineCapacity>& inputList, const ClipPrimitive& clipPrimitive)
+{
+    Vector<Point, inlineCapacity> outputList;
+    Point s;
+    if (!inputList.isEmpty())
+        s = inputList.last();
+    for (typename Vector<Point, inlineCapacity>::const_iterator eIterator = inputList.begin(); eIterator != inputList.end(); ++eIterator) {
+        const Point& e = *eIterator;
+        if (clipPrimitive.isPointInside(e)) {
+            if (!clipPrimitive.isPointInside(s))
+                outputList.append(clipPrimitive.computeIntersection(s, e));
+            outputList.append(e);
+        } else if (clipPrimitive.isPointInside(s))
+            outputList.append(clipPrimitive.computeIntersection(s, e));
+        s = e;
+    }
+    return outputList;
+}
+
+template<size_t inlineCapacity>
+inline FloatRect boundingBox(const Vector<FloatPoint, inlineCapacity>& points)
+{
+    if (points.isEmpty())
+        return FloatRect();
+    float xmin, xmax, ymin, ymax;
+    xmin = ymin = std::numeric_limits<float>::infinity();
+    xmax = ymax = -std::numeric_limits<float>::infinity();
+    for (size_t i = 0; i < points.size(); ++i) {
+        const FloatPoint& p = points[i];
+        if (p.x() < xmin)
+            xmin = p.x();
+        if (p.x() > xmax)
+            xmax = p.x();
+        if (p.y() < ymin)
+            ymin = p.y();
+        if (p.y() > ymax)
+            ymax = p.y();
+    }
+    return FloatRect(xmin, ymin, xmax - xmin, ymax - ymin);
+}
+
+inline FloatPoint3D multVecMatrix(const TransformationMatrix& matrix, const FloatPoint3D& p, float& w)
+{
+    FloatPoint3D result(
+        matrix.m41() + p.x() * matrix.m11() + p.y() * matrix.m21() + p.z() * matrix.m31(),
+        matrix.m42() + p.x() * matrix.m12() + p.y() * matrix.m22() + p.z() * matrix.m32(),
+        matrix.m43() + p.x() * matrix.m13() + p.y() * matrix.m23() + p.z() * matrix.m33());
+    w = matrix.m44() + p.x() * matrix.m14() + p.y() * matrix.m24() + p.z() * matrix.m34();
+    return result;
+}
+
+template<typename Point, size_t inlineCapacity>
+inline Vector<Point, inlineCapacity> toVector(const FloatQuad& quad)
+{
+    Vector<Point, inlineCapacity> result;
+    result.append(quad.p1());
+    result.append(quad.p2());
+    result.append(quad.p3());
+    result.append(quad.p4());
+    return result;
+}
+
+} // namespace WebCore
+
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif // LayerUtilities_h
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to