Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / graphics / GraphicsLayer.cpp
index 0f257b2..6dce54d 100644 (file)
@@ -83,7 +83,7 @@ GraphicsLayer::GraphicsLayer(GraphicsLayerClient* client)
     , m_zPosition(0)
     , m_blendMode(blink::WebBlendModeNormal)
     , m_contentsOpaque(false)
-    , m_preserves3D(false)
+    , m_shouldFlattenTransform(true)
     , m_backfaceVisibility(true)
     , m_masksToBounds(false)
     , m_drawsContent(false)
@@ -103,6 +103,7 @@ GraphicsLayer::GraphicsLayer(GraphicsLayerClient* client)
     , m_contentsLayer(0)
     , m_contentsLayerId(0)
     , m_scrollableArea(0)
+    , m_3dRenderingContext(0)
 {
 #ifndef NDEBUG
     if (m_client)
@@ -343,29 +344,6 @@ void GraphicsLayer::setZPosition(float position)
     m_zPosition = position;
 }
 
-float GraphicsLayer::accumulatedOpacity() const
-{
-    if (!preserves3D())
-        return 1;
-
-    return m_opacity * (parent() ? parent()->accumulatedOpacity() : 1);
-}
-
-void GraphicsLayer::distributeOpacity(float accumulatedOpacity)
-{
-    // If this is a transform layer we need to distribute our opacity to all our children
-
-    // Incoming accumulatedOpacity is the contribution from our parent(s). We mutiply this by our own
-    // opacity to get the total contribution
-    accumulatedOpacity *= m_opacity;
-
-    if (preserves3D()) {
-        size_t numChildren = children().size();
-        for (size_t i = 0; i < numChildren; ++i)
-            children()[i]->distributeOpacity(accumulatedOpacity);
-    }
-}
-
 void GraphicsLayer::updateChildList()
 {
     WebLayer* childHost = m_layer->layer();
@@ -493,6 +471,8 @@ void GraphicsLayer::setupContentsLayer(WebLayer* contentsLayer)
     m_layer->layer()->insertChild(m_contentsLayer, 0);
     WebLayer* borderWebLayer = m_contentsClippingMaskLayer ? m_contentsClippingMaskLayer->platformLayer() : 0;
     m_contentsLayer->setMaskLayer(borderWebLayer);
+
+    m_contentsLayer->setRenderingContext(m_3dRenderingContext);
 }
 
 void GraphicsLayer::clearContentsLayerIfUnregistered()
@@ -522,15 +502,6 @@ WebLayer* GraphicsLayer::contentsLayerIfRegistered()
     return m_contentsLayer;
 }
 
-double GraphicsLayer::backingStoreMemoryEstimate() const
-{
-    if (!drawsContent())
-        return 0;
-
-    // Effects of page and device scale are ignored; subclasses should override to take these into account.
-    return static_cast<double>(4 * size().width()) * size().height();
-}
-
 void GraphicsLayer::resetTrackedRepaints()
 {
     repaintRectMap().remove(this);
@@ -563,7 +534,7 @@ void GraphicsLayer::collectTrackedRepaintRects(Vector<FloatRect>& rects) const
         rects.append(repaintIt->value);
 }
 
-void GraphicsLayer::dumpLayer(TextStream& ts, int indent, LayerTreeFlags flags) const
+void GraphicsLayer::dumpLayer(TextStream& ts, int indent, LayerTreeFlags flags, RenderingContextMap& renderingContextMap) const
 {
     writeIndent(ts, indent);
     ts << "(" << "GraphicsLayer";
@@ -574,12 +545,12 @@ void GraphicsLayer::dumpLayer(TextStream& ts, int indent, LayerTreeFlags flags)
     }
 
     ts << "\n";
-    dumpProperties(ts, indent, flags);
+    dumpProperties(ts, indent, flags, renderingContextMap);
     writeIndent(ts, indent);
     ts << ")\n";
 }
 
-void GraphicsLayer::dumpProperties(TextStream& ts, int indent, LayerTreeFlags flags) const
+void GraphicsLayer::dumpProperties(TextStream& ts, int indent, LayerTreeFlags flags, RenderingContextMap& renderingContextMap) const
 {
     if (m_position != FloatPoint()) {
         writeIndent(ts, indent + 1);
@@ -621,9 +592,21 @@ void GraphicsLayer::dumpProperties(TextStream& ts, int indent, LayerTreeFlags fl
         ts << "(contentsOpaque " << m_contentsOpaque << ")\n";
     }
 
-    if (m_preserves3D) {
+    if (!m_shouldFlattenTransform) {
         writeIndent(ts, indent + 1);
-        ts << "(preserves3D " << m_preserves3D << ")\n";
+        ts << "(shouldFlattenTransform " << m_shouldFlattenTransform << ")\n";
+    }
+
+    if (m_3dRenderingContext) {
+        RenderingContextMap::const_iterator it = renderingContextMap.find(m_3dRenderingContext);
+        int contextId = renderingContextMap.size() + 1;
+        if (it == renderingContextMap.end())
+            renderingContextMap.set(m_3dRenderingContext, contextId);
+        else
+            contextId = it->value;
+
+        writeIndent(ts, indent + 1);
+        ts << "(3dRenderingContext " << contextId << ")\n";
     }
 
     if (m_drawsContent) {
@@ -665,24 +648,13 @@ void GraphicsLayer::dumpProperties(TextStream& ts, int indent, LayerTreeFlags fl
         ts << "[" << m_transform.m41() << " " << m_transform.m42() << " " << m_transform.m43() << " " << m_transform.m44() << "])\n";
     }
 
-    // Avoid dumping the sublayer transform on the root layer, because it's used for geometry flipping, whose behavior
-    // differs between platforms.
-    if (parent() && !m_childrenTransform.isIdentity()) {
-        writeIndent(ts, indent + 1);
-        ts << "(childrenTransform ";
-        ts << "[" << m_childrenTransform.m11() << " " << m_childrenTransform.m12() << " " << m_childrenTransform.m13() << " " << m_childrenTransform.m14() << "] ";
-        ts << "[" << m_childrenTransform.m21() << " " << m_childrenTransform.m22() << " " << m_childrenTransform.m23() << " " << m_childrenTransform.m24() << "] ";
-        ts << "[" << m_childrenTransform.m31() << " " << m_childrenTransform.m32() << " " << m_childrenTransform.m33() << " " << m_childrenTransform.m34() << "] ";
-        ts << "[" << m_childrenTransform.m41() << " " << m_childrenTransform.m42() << " " << m_childrenTransform.m43() << " " << m_childrenTransform.m44() << "])\n";
-    }
-
     if (m_replicaLayer) {
         writeIndent(ts, indent + 1);
         ts << "(replica layer";
         if (flags & LayerTreeIncludesDebugInfo)
             ts << " " << m_replicaLayer;
         ts << ")\n";
-        m_replicaLayer->dumpLayer(ts, indent + 2, flags);
+        m_replicaLayer->dumpLayer(ts, indent + 2, flags, renderingContextMap);
     }
 
     if (m_replicatedLayer) {
@@ -759,7 +731,7 @@ void GraphicsLayer::dumpProperties(TextStream& ts, int indent, LayerTreeFlags fl
 
         unsigned i;
         for (i = 0; i < m_children.size(); i++)
-            m_children[i]->dumpLayer(ts, indent + 2, flags);
+            m_children[i]->dumpLayer(ts, indent + 2, flags, renderingContextMap);
         writeIndent(ts, indent + 1);
         ts << ")\n";
     }
@@ -769,7 +741,8 @@ String GraphicsLayer::layerTreeAsText(LayerTreeFlags flags) const
 {
     TextStream ts;
 
-    dumpLayer(ts, 0, flags);
+    RenderingContextMap renderingContextMap;
+    dumpLayer(ts, 0, flags, renderingContextMap);
     return ts.release();
 }
 
@@ -841,19 +814,26 @@ void GraphicsLayer::setTransform(const TransformationMatrix& transform)
     platformLayer()->setTransform(TransformationMatrix::toSkMatrix44(m_transform));
 }
 
-void GraphicsLayer::setChildrenTransform(const TransformationMatrix& transform)
+void GraphicsLayer::setShouldFlattenTransform(bool shouldFlatten)
 {
-    m_childrenTransform = transform;
-    platformLayer()->setSublayerTransform(TransformationMatrix::toSkMatrix44(m_childrenTransform));
+    if (shouldFlatten == m_shouldFlattenTransform)
+        return;
+
+    m_shouldFlattenTransform = shouldFlatten;
+
+    m_layer->layer()->setShouldFlattenTransform(shouldFlatten);
 }
 
-void GraphicsLayer::setPreserves3D(bool preserves3D)
+void GraphicsLayer::setRenderingContext(int context)
 {
-    if (preserves3D == m_preserves3D)
+    if (m_3dRenderingContext == context)
         return;
 
-    m_preserves3D = preserves3D;
-    m_layer->layer()->setPreserves3D(m_preserves3D);
+    m_3dRenderingContext = context;
+    m_layer->layer()->setRenderingContext(context);
+
+    if (m_contentsLayer)
+        m_contentsLayer->setRenderingContext(m_3dRenderingContext);
 }
 
 void GraphicsLayer::setMasksToBounds(bool masksToBounds)