Title: [118710] trunk/Source/WebCore
Revision
118710
Author
[email protected]
Date
2012-05-28 15:49:16 -0700 (Mon, 28 May 2012)

Log Message

[BlackBerry] Add support for layers with scale invariant size
https://bugs.webkit.org/show_bug.cgi?id=87601

Patch by Arvid Nilsson <[email protected]> on 2012-05-28
Reviewed by Rob Buis.

To support layers that have a "floating" appearance, i.e. don't change size
when the web page is drawn at a different scale, we add a new layer property
named "sizeIsScaleInvariant".

The anchor position will still be given in document coordinates for these
"floating" layers, so this is well suited for interface elements like selection
handles whose size is always the same but move with the web page contents.

PR #156812

* platform/graphics/blackberry/LayerCompositingThread.cpp:
(WebCore::LayerCompositingThread::setDrawTransform):
(WebCore::LayerCompositingThread::drawTextures):
(WebCore::LayerCompositingThread::drawMissingTextures):
* platform/graphics/blackberry/LayerCompositingThread.h:
(LayerCompositingThread):
* platform/graphics/blackberry/LayerCompositingThreadClient.h:
(LayerCompositingThreadClient):
(WebCore::LayerCompositingThreadClient::drawMissingTextures):
* platform/graphics/blackberry/LayerData.h:
(WebCore::LayerData::LayerData):
(WebCore::LayerData::sizeIsScaleInvariant):
(LayerData):
* platform/graphics/blackberry/LayerRenderer.cpp:
(WebCore::LayerRenderer::LayerRenderer):
(WebCore::LayerRenderer::compositeLayers):
(WebCore::LayerRenderer::updateLayersRecursive):
(WebCore::LayerRenderer::compositeLayersRecursive):
* platform/graphics/blackberry/LayerRenderer.h:
(LayerRenderer):
* platform/graphics/blackberry/LayerTiler.cpp:
(WebCore::LayerTiler::updateTextureContentsIfNeeded):
(WebCore::LayerTiler::drawTextures):
(WebCore::LayerTiler::drawMissingTextures):
(WebCore::LayerTiler::drawTexturesInternal):
* platform/graphics/blackberry/LayerTiler.h:
(LayerTiler):
* platform/graphics/blackberry/LayerWebKitThread.h:
(WebCore::LayerWebKitThread::setSizeIsScaleInvariant):
(LayerWebKitThread):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (118709 => 118710)


--- trunk/Source/WebCore/ChangeLog	2012-05-28 22:22:36 UTC (rev 118709)
+++ trunk/Source/WebCore/ChangeLog	2012-05-28 22:49:16 UTC (rev 118710)
@@ -1,5 +1,53 @@
 2012-05-28  Arvid Nilsson  <[email protected]>
 
+        [BlackBerry] Add support for layers with scale invariant size
+        https://bugs.webkit.org/show_bug.cgi?id=87601
+
+        Reviewed by Rob Buis.
+
+        To support layers that have a "floating" appearance, i.e. don't change size
+        when the web page is drawn at a different scale, we add a new layer property
+        named "sizeIsScaleInvariant".
+
+        The anchor position will still be given in document coordinates for these
+        "floating" layers, so this is well suited for interface elements like selection
+        handles whose size is always the same but move with the web page contents.
+
+        PR #156812
+
+        * platform/graphics/blackberry/LayerCompositingThread.cpp:
+        (WebCore::LayerCompositingThread::setDrawTransform):
+        (WebCore::LayerCompositingThread::drawTextures):
+        (WebCore::LayerCompositingThread::drawMissingTextures):
+        * platform/graphics/blackberry/LayerCompositingThread.h:
+        (LayerCompositingThread):
+        * platform/graphics/blackberry/LayerCompositingThreadClient.h:
+        (LayerCompositingThreadClient):
+        (WebCore::LayerCompositingThreadClient::drawMissingTextures):
+        * platform/graphics/blackberry/LayerData.h:
+        (WebCore::LayerData::LayerData):
+        (WebCore::LayerData::sizeIsScaleInvariant):
+        (LayerData):
+        * platform/graphics/blackberry/LayerRenderer.cpp:
+        (WebCore::LayerRenderer::LayerRenderer):
+        (WebCore::LayerRenderer::compositeLayers):
+        (WebCore::LayerRenderer::updateLayersRecursive):
+        (WebCore::LayerRenderer::compositeLayersRecursive):
+        * platform/graphics/blackberry/LayerRenderer.h:
+        (LayerRenderer):
+        * platform/graphics/blackberry/LayerTiler.cpp:
+        (WebCore::LayerTiler::updateTextureContentsIfNeeded):
+        (WebCore::LayerTiler::drawTextures):
+        (WebCore::LayerTiler::drawMissingTextures):
+        (WebCore::LayerTiler::drawTexturesInternal):
+        * platform/graphics/blackberry/LayerTiler.h:
+        (LayerTiler):
+        * platform/graphics/blackberry/LayerWebKitThread.h:
+        (WebCore::LayerWebKitThread::setSizeIsScaleInvariant):
+        (LayerWebKitThread):
+
+2012-05-28  Arvid Nilsson  <[email protected]>
+
         [BlackBerry] Make it possible to manipulate layers on the compositing thread
         https://bugs.webkit.org/show_bug.cgi?id=87602
 

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


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThread.cpp	2012-05-28 22:22:36 UTC (rev 118709)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThread.cpp	2012-05-28 22:49:16 UTC (rev 118710)
@@ -122,12 +122,18 @@
         m_client->deleteTextures(this);
 }
 
-void LayerCompositingThread::setDrawTransform(const TransformationMatrix& matrix)
+void LayerCompositingThread::setDrawTransform(double scale, const TransformationMatrix& matrix)
 {
     m_drawTransform = matrix;
 
     float bx = m_bounds.width() / 2.0;
     float by = m_bounds.height() / 2.0;
+
+    if (sizeIsScaleInvariant()) {
+        bx /= scale;
+        by /= scale;
+    }
+
     m_transformedBounds.setP1(matrix.mapPoint(FloatPoint(-bx, -by)));
     m_transformedBounds.setP2(matrix.mapPoint(FloatPoint(-bx, by)));
     m_transformedBounds.setP3(matrix.mapPoint(FloatPoint(bx, by)));
@@ -198,7 +204,7 @@
     return getTransformedRect(m_bounds, drawRect, m_drawTransform);
 }
 
-void LayerCompositingThread::drawTextures(int positionLocation, int texCoordLocation, const FloatRect& visibleRect)
+void LayerCompositingThread::drawTextures(double scale, int positionLocation, int texCoordLocation, const FloatRect& visibleRect)
 {
     static float texcoords[4 * 2] = { 0, 0,  0, 1,  1, 1,  1, 0 };
 
@@ -270,7 +276,7 @@
     }
 
     if (m_client)
-        m_client->drawTextures(this, positionLocation, texCoordLocation);
+        m_client->drawTextures(this, scale, positionLocation, texCoordLocation);
 }
 
 void LayerCompositingThread::drawSurface(const TransformationMatrix& drawTransform, LayerCompositingThread* mask, int positionLocation, int texCoordLocation)
@@ -304,10 +310,10 @@
     return m_client ? m_client->hasMissingTextures(this) : false;
 }
 
-void LayerCompositingThread::drawMissingTextures(int positionLocation, int texCoordLocation, const FloatRect& /*visibleRect*/)
+void LayerCompositingThread::drawMissingTextures(double scale, int positionLocation, int texCoordLocation, const FloatRect& /*visibleRect*/)
 {
     if (m_client)
-        m_client->drawMissingTextures(this, positionLocation, texCoordLocation);
+        m_client->drawMissingTextures(this, scale, positionLocation, texCoordLocation);
 }
 
 void LayerCompositingThread::releaseTextureResources()

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


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThread.h	2012-05-28 22:22:36 UTC (rev 118709)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThread.h	2012-05-28 22:49:16 UTC (rev 118710)
@@ -150,7 +150,7 @@
     // The layer renderer must be set if the layer has been rendered
     void setLayerRenderer(LayerRenderer*);
 
-    void setDrawTransform(const TransformationMatrix&);
+    void setDrawTransform(double scale, const TransformationMatrix&);
     const TransformationMatrix& drawTransform() const { return m_drawTransform; }
 
     void setDrawOpacity(float opacity) { m_drawOpacity = opacity; }
@@ -172,9 +172,9 @@
 
     void deleteTextures();
 
-    void drawTextures(int positionLocation, int texCoordLocation, const FloatRect& visibleRect);
+    void drawTextures(double scale, int positionLocation, int texCoordLocation, const FloatRect& visibleRect);
     bool hasMissingTextures() const;
-    void drawMissingTextures(int positionLocation, int texCoordLocation, const FloatRect& visibleRect);
+    void drawMissingTextures(double scale, int positionLocation, int texCoordLocation, const FloatRect& visibleRect);
     void drawSurface(const TransformationMatrix&, LayerCompositingThread* mask, int positionLocation, int texCoordLocation);
 
     void releaseTextureResources();

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThreadClient.h (118709 => 118710)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThreadClient.h	2012-05-28 22:22:36 UTC (rev 118709)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerCompositingThreadClient.h	2012-05-28 22:49:16 UTC (rev 118710)
@@ -34,7 +34,7 @@
     virtual void layerVisibilityChanged(LayerCompositingThread*, bool visible) = 0;
 
     virtual void uploadTexturesIfNeeded(LayerCompositingThread*) = 0;
-    virtual void drawTextures(LayerCompositingThread*, int positionLocation, int texCoordLocation, double scale) = 0;
+    virtual void drawTextures(LayerCompositingThread*, double scale, int positionLocation, int texCoordLocation) = 0;
     virtual void deleteTextures(LayerCompositingThread*) = 0;
 
     // Optional. Allows layers to serve as a mask for other layers
@@ -42,7 +42,7 @@
 
     // Optional. Allows layers to have uncached regions, typically drawn as checkerboard
     virtual bool hasMissingTextures(const LayerCompositingThread*) const { return false; }
-    virtual void drawMissingTextures(LayerCompositingThread*, int positionLocation, int texCoordLocation) { }
+    virtual void drawMissingTextures(LayerCompositingThread*, double scale, int positionLocation, int texCoordLocation) { }
 
     // Unlike the other methods here, this one will be called on the WebKit thread
     virtual void scheduleCommit() { }

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerData.h (118709 => 118710)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerData.h	2012-05-28 22:22:36 UTC (rev 118709)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerData.h	2012-05-28 22:49:16 UTC (rev 118710)
@@ -85,6 +85,7 @@
         , m_hasFixedContainer(false)
         , m_hasFixedAncestorInDOMTree(false)
         , m_isVisible(true)
+        , m_sizeIsScaleInvariant(false)
     {
     }
 
@@ -104,6 +105,8 @@
 
     IntSize bounds() const { return m_bounds; }
 
+    bool sizeIsScaleInvariant() const { return m_sizeIsScaleInvariant; }
+
     bool doubleSided() const { return m_doubleSided; }
 
     FloatRect frame() const { return m_frame; }
@@ -205,6 +208,7 @@
 
     // The following is only available for media (video) and plugin layers.
     unsigned m_isVisible : 1;
+    unsigned m_sizeIsScaleInvariant : 1;
 
     // CAUTION: all the data members are copied from one instance to another
     // i.e. from one thread to another in the replicate method.

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


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.cpp	2012-05-28 22:22:36 UTC (rev 118709)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.cpp	2012-05-28 22:49:16 UTC (rev 118710)
@@ -152,6 +152,7 @@
     , m_checkerProgramObject(0)
     , m_positionLocation(0)
     , m_texCoordLocation(1)
+    , m_scale(1.0)
     , m_animationTime(-numeric_limits<double>::infinity())
     , m_fbo(0)
     , m_currentLayerRendererSurface(0)
@@ -319,6 +320,12 @@
     if (!rootLayer)
         return;
 
+    // Used to draw scale invariant layers. We assume uniform scale.
+    // The matrix maps to normalized device coordinates, a system that maps the
+    // viewport to the interval -1 to 1.
+    // So it has to scale down by a factor equal to one half the viewport.
+    m_scale = matrix.m11() * m_viewport.width() / 2;
+
     Vector<RefPtr<LayerCompositingThread> > surfaceLayers;
     const Vector<RefPtr<LayerCompositingThread> >& sublayers = rootLayer->getSublayers();
     for (size_t i = 0; i < sublayers.size(); i++) {
@@ -658,7 +665,9 @@
     // Where: P is the projection matrix
     //        M is the layer's matrix computed above
     //        S is the scale adjustment (to scale up to the layer size)
-    IntSize bounds = layer->bounds();
+    FloatSize bounds = layer->bounds();
+    if (layer->sizeIsScaleInvariant())
+        bounds.scale(1.0 / m_scale);
     FloatPoint anchorPoint = layer->anchorPoint();
     FloatPoint position = layer->position();
 
@@ -725,7 +734,7 @@
             surface->setReplicaDrawTransform(replicaMatrix);
         }
 
-        IntRect drawRect = IntRect(IntPoint(), bounds);
+        IntRect drawRect = enclosingIntRect(FloatRect(FloatPoint(), bounds));
         surface->setContentRect(drawRect);
 
         TransformationMatrix projectionMatrix = orthoMatrix(drawRect.x(), drawRect.maxX(), drawRect.y(), drawRect.maxY(), -1000, 1000);
@@ -738,7 +747,7 @@
         surfaceLayers.append(layer);
     }
 
-    layer->setDrawTransform(localMatrix);
+    layer->setDrawTransform(m_scale, localMatrix);
 
 #if ENABLE(VIDEO)
     bool layerVisible = clipRect.intersects(layer->getDrawRect()) || layer->mediaPlayer();
@@ -846,7 +855,7 @@
         if (!drawSurface) {
             glUseProgram(m_layerProgramObject[shader]);
             glUniform1f(m_alphaLocation[shader], layer->drawOpacity());
-            layer->drawTextures(m_positionLocation, m_texCoordLocation, m_visibleRect);
+            layer->drawTextures(m_scale, m_positionLocation, m_texCoordLocation, m_visibleRect);
         } else {
             // Draw the reflection if it exists.
             if (layer->replicaLayer()) {
@@ -870,7 +879,7 @@
         if (layer->hasMissingTextures()) {
             glDisable(GL_BLEND);
             glUseProgram(m_checkerProgramObject);
-            layer->drawMissingTextures(m_positionLocation, m_texCoordLocation, m_visibleRect);
+            layer->drawMissingTextures(m_scale, m_positionLocation, m_texCoordLocation, m_visibleRect);
             glEnable(GL_BLEND);
             glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
         }

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


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.h	2012-05-28 22:22:36 UTC (rev 118709)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerRenderer.h	2012-05-28 22:49:16 UTC (rev 118710)
@@ -176,6 +176,7 @@
     int m_checkerSurfaceHeightLocation;
 
     // Current draw configuration.
+    double m_scale;
     double m_animationTime;
     FloatRect m_visibleRect;
     IntRect m_layoutRect;

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerTiler.cpp (118709 => 118710)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerTiler.cpp	2012-05-28 22:22:36 UTC (rev 118709)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerTiler.cpp	2012-05-28 22:49:16 UTC (rev 118710)
@@ -122,6 +122,11 @@
         renderJobs = m_renderJobs;
     }
 
+    // There's no point in drawing contents at a higher resolution for scale
+    // invariant layers.
+    if (m_layer->sizeIsScaleInvariant())
+        scale = 1.0;
+
     bool isZoomJob = false;
     if (scale != m_contentsScale) {
         // The first time around, it does not count as a zoom job.
@@ -470,21 +475,26 @@
     ASSERT_NOT_REACHED();
 }
 
-void LayerTiler::drawTextures(LayerCompositingThread* layer, int pos, int texCoord)
+void LayerTiler::drawTextures(LayerCompositingThread* layer, double scale, int pos, int texCoord)
 {
-    drawTexturesInternal(layer, pos, texCoord, false /* drawMissing */);
+    drawTexturesInternal(layer, scale, pos, texCoord, false /* drawMissing */);
 }
 
-void LayerTiler::drawMissingTextures(LayerCompositingThread* layer, int pos, int texCoord)
+void LayerTiler::drawMissingTextures(LayerCompositingThread* layer, double scale, int pos, int texCoord)
 {
-    drawTexturesInternal(layer, pos, texCoord, true /* drawMissing */);
+    drawTexturesInternal(layer, scale, pos, texCoord, true /* drawMissing */);
 }
 
-void LayerTiler::drawTexturesInternal(LayerCompositingThread* layer, int positionLocation, int texCoordLocation, bool drawMissing)
+void LayerTiler::drawTexturesInternal(LayerCompositingThread* layer, double scale, int positionLocation, int texCoordLocation, bool drawMissing)
 {
     const TransformationMatrix& drawTransform = layer->drawTransform();
-    IntSize bounds = layer->bounds();
+    FloatSize bounds = layer->bounds();
 
+    if (layer->sizeIsScaleInvariant()) {
+        bounds.setWidth(bounds.width() / scale);
+        bounds.setHeight(bounds.width() / scale);
+    }
+
     float texcoords[4 * 2] = { 0, 0,  0, 1,  1, 1,  1, 0 };
     float vertices[4 * 4];
 

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerTiler.h (118709 => 118710)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerTiler.h	2012-05-28 22:22:36 UTC (rev 118709)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerTiler.h	2012-05-28 22:49:16 UTC (rev 118710)
@@ -66,9 +66,9 @@
     virtual void layerVisibilityChanged(LayerCompositingThread*, bool visible);
     virtual void uploadTexturesIfNeeded(LayerCompositingThread*);
     virtual void bindContentsTexture(LayerCompositingThread*);
-    virtual void drawTextures(LayerCompositingThread*, int positionLocation, int texCoordLocation);
+    virtual void drawTextures(LayerCompositingThread*, double scale, int positionLocation, int texCoordLocation);
     virtual bool hasMissingTextures(const LayerCompositingThread*) const { return m_hasMissingTextures; }
-    virtual void drawMissingTextures(LayerCompositingThread*, int positionLocation, int texCoordLocation);
+    virtual void drawMissingTextures(LayerCompositingThread*, double scale, int positionLocation, int texCoordLocation);
     virtual void deleteTextures(LayerCompositingThread*);
     void commitPendingTextureUploads();
 
@@ -157,7 +157,7 @@
     void addTileJob(const TileIndex&, const TextureJob&, TileJobsMap&);
     void performTileJob(LayerTile*, const TextureJob&, const IntRect&);
     void processTextureJob(const TextureJob&, TileJobsMap&);
-    void drawTexturesInternal(LayerCompositingThread*, int positionLocation, int texCoordLocation, bool missing);
+    void drawTexturesInternal(LayerCompositingThread*, double scale, int positionLocation, int texCoordLocation, bool missing);
     void pruneTextures();
     void visibilityChanged(bool needsDisplay);
 

Modified: trunk/Source/WebCore/platform/graphics/blackberry/LayerWebKitThread.h (118709 => 118710)


--- trunk/Source/WebCore/platform/graphics/blackberry/LayerWebKitThread.h	2012-05-28 22:22:36 UTC (rev 118709)
+++ trunk/Source/WebCore/platform/graphics/blackberry/LayerWebKitThread.h	2012-05-28 22:49:16 UTC (rev 118710)
@@ -74,6 +74,8 @@
 
     void setBounds(const IntSize&);
 
+    void setSizeIsScaleInvariant(bool invariant) { m_sizeIsScaleInvariant = invariant; setNeedsCommit(); }
+
     void setDoubleSided(bool doubleSided) { m_doubleSided = doubleSided; setNeedsCommit(); }
 
     void setFrame(const FloatRect&);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to