| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PaintArtifactCompositor_h | 5 #ifndef PaintArtifactCompositor_h |
| 6 #define PaintArtifactCompositor_h | 6 #define PaintArtifactCompositor_h |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "platform/PlatformExport.h" | 9 #include "platform/PlatformExport.h" |
| 10 #include "platform/RuntimeEnabledFeatures.h" | 10 #include "platform/RuntimeEnabledFeatures.h" |
| 11 #include "platform/graphics/GraphicsLayerClient.h" | 11 #include "platform/graphics/GraphicsLayerClient.h" |
| 12 #include "platform/graphics/paint/PaintController.h" | 12 #include "platform/graphics/paint/PaintController.h" |
| 13 #include "wtf/Noncopyable.h" | 13 #include "wtf/Noncopyable.h" |
| 14 #include "wtf/PtrUtil.h" | 14 #include "wtf/PtrUtil.h" |
| 15 #include "wtf/Vector.h" | 15 #include "wtf/Vector.h" |
| 16 #include <memory> | 16 #include <memory> |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 class Layer; | 19 class Layer; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace gfx { | 22 namespace gfx { |
| 23 class Vector2dF; | 23 class Vector2dF; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace blink { | 26 namespace blink { |
| 27 | 27 |
| 28 class GeometryMapper; |
| 28 class JSONObject; | 29 class JSONObject; |
| 29 class PaintArtifact; | 30 class PaintArtifact; |
| 30 class WebLayer; | 31 class WebLayer; |
| 31 struct PaintChunk; | 32 struct PaintChunk; |
| 32 | 33 |
| 33 // Responsible for managing compositing in terms of a PaintArtifact. | 34 // Responsible for managing compositing in terms of a PaintArtifact. |
| 34 // | 35 // |
| 35 // Owns a subtree of the compositor layer tree, and updates it in response to | 36 // Owns a subtree of the compositor layer tree, and updates it in response to |
| 36 // changes in the paint artifact. | 37 // changes in the paint artifact. |
| 37 // | 38 // |
| (...skipping 10 matching lines...) Expand all Loading... |
| 48 return WTF::wrapUnique(new PaintArtifactCompositor()); | 49 return WTF::wrapUnique(new PaintArtifactCompositor()); |
| 49 } | 50 } |
| 50 | 51 |
| 51 // Updates the layer tree to match the provided paint artifact. | 52 // Updates the layer tree to match the provided paint artifact. |
| 52 // If |storeDebugInfo| is true, stores detailed debugging information in | 53 // If |storeDebugInfo| is true, stores detailed debugging information in |
| 53 // the layers that will be output as part of a call to layersAsJSON | 54 // the layers that will be output as part of a call to layersAsJSON |
| 54 // (if LayerTreeIncludesDebugInfo is specified). | 55 // (if LayerTreeIncludesDebugInfo is specified). |
| 55 void update( | 56 void update( |
| 56 const PaintArtifact&, | 57 const PaintArtifact&, |
| 57 RasterInvalidationTrackingMap<const PaintChunk>* paintChunkInvalidations, | 58 RasterInvalidationTrackingMap<const PaintChunk>* paintChunkInvalidations, |
| 58 bool storeDebugInfo); | 59 bool storeDebugInfo, |
| 60 GeometryMapper&); |
| 59 | 61 |
| 60 // The root layer of the tree managed by this object. | 62 // The root layer of the tree managed by this object. |
| 61 cc::Layer* rootLayer() const { return m_rootLayer.get(); } | 63 cc::Layer* rootLayer() const { return m_rootLayer.get(); } |
| 62 | 64 |
| 63 // Wraps rootLayer(), so that it can be attached as a child of another | 65 // Wraps rootLayer(), so that it can be attached as a child of another |
| 64 // WebLayer. | 66 // WebLayer. |
| 65 WebLayer* getWebLayer() const { return m_webLayer.get(); } | 67 WebLayer* getWebLayer() const { return m_webLayer.get(); } |
| 66 | 68 |
| 67 // Returns extra information recorded during unit tests. | 69 // Returns extra information recorded during unit tests. |
| 68 // While not part of the normal output of this class, this provides a simple | 70 // While not part of the normal output of this class, this provides a simple |
| (...skipping 19 matching lines...) Expand all Loading... |
| 88 | 90 |
| 89 private: | 91 private: |
| 90 // A pending layer is a collection of paint chunks that will end up in | 92 // A pending layer is a collection of paint chunks that will end up in |
| 91 // the same cc::Layer. | 93 // the same cc::Layer. |
| 92 struct PLATFORM_EXPORT PendingLayer { | 94 struct PLATFORM_EXPORT PendingLayer { |
| 93 PendingLayer(const PaintChunk& firstPaintChunk, bool chunkIsForeign); | 95 PendingLayer(const PaintChunk& firstPaintChunk, bool chunkIsForeign); |
| 94 // Merge another pending layer after this one, appending all its paint | 96 // Merge another pending layer after this one, appending all its paint |
| 95 // chunks after chunks in this layer, with appropriate space conversion | 97 // chunks after chunks in this layer, with appropriate space conversion |
| 96 // applied. The merged layer must have a property tree state that's deeper | 98 // applied. The merged layer must have a property tree state that's deeper |
| 97 // than this layer, i.e. can "upcast" to this layer's state. | 99 // than this layer, i.e. can "upcast" to this layer's state. |
| 98 void merge(const PendingLayer& guest); | 100 void merge(const PendingLayer& guest, GeometryMapper&); |
| 99 bool canMerge(const PendingLayer& guest) const; | 101 bool canMerge(const PendingLayer& guest) const; |
| 100 // Mutate this layer's property tree state to a more general (shallower) | 102 // Mutate this layer's property tree state to a more general (shallower) |
| 101 // state, thus the name "upcast". The concrete effect of this is to | 103 // state, thus the name "upcast". The concrete effect of this is to |
| 102 // "decomposite" some of the properties, so that fewer properties will be | 104 // "decomposite" some of the properties, so that fewer properties will be |
| 103 // applied by the compositor, and more properties will be applied internally | 105 // applied by the compositor, and more properties will be applied internally |
| 104 // to the chunks as Skia commands. | 106 // to the chunks as Skia commands. |
| 105 void upcast(const PropertyTreeState&); | 107 void upcast(const PropertyTreeState&, GeometryMapper&); |
| 106 FloatRect bounds; | 108 FloatRect bounds; |
| 107 Vector<const PaintChunk*> paintChunks; | 109 Vector<const PaintChunk*> paintChunks; |
| 108 bool knownToBeOpaque; | 110 bool knownToBeOpaque; |
| 109 bool backfaceHidden; | 111 bool backfaceHidden; |
| 110 PropertyTreeState propertyTreeState; | 112 PropertyTreeState propertyTreeState; |
| 111 bool isForeign; | 113 bool isForeign; |
| 112 }; | 114 }; |
| 113 | 115 |
| 114 PaintArtifactCompositor(); | 116 PaintArtifactCompositor(); |
| 115 | 117 |
| 116 class ContentLayerClientImpl; | 118 class ContentLayerClientImpl; |
| 117 | 119 |
| 118 // Collects the PaintChunks into groups which will end up in the same | 120 // Collects the PaintChunks into groups which will end up in the same |
| 119 // cc layer. This is the entry point of the layerization algorithm. | 121 // cc layer. This is the entry point of the layerization algorithm. |
| 120 void collectPendingLayers(const PaintArtifact&, | 122 void collectPendingLayers(const PaintArtifact&, |
| 121 Vector<PendingLayer>& pendingLayers); | 123 Vector<PendingLayer>& pendingLayers, |
| 124 GeometryMapper&); |
| 122 // This is the internal recursion of collectPendingLayers. This function | 125 // This is the internal recursion of collectPendingLayers. This function |
| 123 // loops over the list of paint chunks, scoped by an isolated group | 126 // loops over the list of paint chunks, scoped by an isolated group |
| 124 // (i.e. effect node). Inside of the loop, chunks are tested for overlap | 127 // (i.e. effect node). Inside of the loop, chunks are tested for overlap |
| 125 // and merge compatibility. Subgroups are handled by recursion, and will | 128 // and merge compatibility. Subgroups are handled by recursion, and will |
| 126 // be tested for "decompositing" upon return. | 129 // be tested for "decompositing" upon return. |
| 127 // Merge compatibility means consecutive chunks may be layerized into the | 130 // Merge compatibility means consecutive chunks may be layerized into the |
| 128 // same backing (i.e. merged) if their property states don't cross | 131 // same backing (i.e. merged) if their property states don't cross |
| 129 // direct-compositing boundary. | 132 // direct-compositing boundary. |
| 130 // Non-consecutive chunks that are nevertheless compatible may still be | 133 // Non-consecutive chunks that are nevertheless compatible may still be |
| 131 // merged, if reordering of the chunks won't affect the ultimate result. | 134 // merged, if reordering of the chunks won't affect the ultimate result. |
| 132 // This is determined by overlap testing such that chunks can be safely | 135 // This is determined by overlap testing such that chunks can be safely |
| 133 // reordered if their effective bounds in screen space can't overlap. | 136 // reordered if their effective bounds in screen space can't overlap. |
| 134 // The recursion only tests merge & overlap for chunks scoped by the same | 137 // The recursion only tests merge & overlap for chunks scoped by the same |
| 135 // group. This is where "decompositing" came in. Upon returning from a | 138 // group. This is where "decompositing" came in. Upon returning from a |
| 136 // recursion, the layerization of the subgroup may be tested for merge & | 139 // recursion, the layerization of the subgroup may be tested for merge & |
| 137 // overlap with other chunks in the parent group, if grouping requirement | 140 // overlap with other chunks in the parent group, if grouping requirement |
| 138 // can be satisfied (and the effect node has no direct reason). | 141 // can be satisfied (and the effect node has no direct reason). |
| 139 static void layerizeGroup(const PaintArtifact&, | 142 static void layerizeGroup(const PaintArtifact&, |
| 140 Vector<PendingLayer>& pendingLayers, | 143 Vector<PendingLayer>& pendingLayers, |
| 144 GeometryMapper&, |
| 141 const EffectPaintPropertyNode&, | 145 const EffectPaintPropertyNode&, |
| 142 Vector<PaintChunk>::const_iterator& chunkCursor); | 146 Vector<PaintChunk>::const_iterator& chunkCursor); |
| 143 static bool mightOverlap(const PendingLayer&, const PendingLayer&); | 147 static bool mightOverlap(const PendingLayer&, |
| 148 const PendingLayer&, |
| 149 GeometryMapper&); |
| 144 static bool canDecompositeEffect(const EffectPaintPropertyNode*, | 150 static bool canDecompositeEffect(const EffectPaintPropertyNode*, |
| 145 const PendingLayer&); | 151 const PendingLayer&); |
| 146 | 152 |
| 147 // Builds a leaf layer that represents a single paint chunk. | 153 // Builds a leaf layer that represents a single paint chunk. |
| 148 // Note: cc::Layer API assumes the layer bounds start at (0, 0), but the | 154 // Note: cc::Layer API assumes the layer bounds start at (0, 0), but the |
| 149 // bounding box of a paint chunk does not necessarily start at (0, 0) (and | 155 // bounding box of a paint chunk does not necessarily start at (0, 0) (and |
| 150 // could even be negative). Internally the generated layer translates the | 156 // could even be negative). Internally the generated layer translates the |
| 151 // paint chunk to align the bounding box to (0, 0) and return the actual | 157 // paint chunk to align the bounding box to (0, 0) and return the actual |
| 152 // origin of the paint chunk in the |layerOffset| outparam. | 158 // origin of the paint chunk in the |layerOffset| outparam. |
| 153 scoped_refptr<cc::Layer> compositedLayerForPendingLayer( | 159 scoped_refptr<cc::Layer> compositedLayerForPendingLayer( |
| 154 const PaintArtifact&, | 160 const PaintArtifact&, |
| 155 const PendingLayer&, | 161 const PendingLayer&, |
| 156 gfx::Vector2dF& layerOffset, | 162 gfx::Vector2dF& layerOffset, |
| 157 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, | 163 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, |
| 158 RasterInvalidationTrackingMap<const PaintChunk>*, | 164 RasterInvalidationTrackingMap<const PaintChunk>*, |
| 159 bool storeDebugInfo); | 165 bool storeDebugInfo, |
| 166 GeometryMapper&); |
| 160 | 167 |
| 161 // Finds a client among the current vector of clients that matches the paint | 168 // Finds a client among the current vector of clients that matches the paint |
| 162 // chunk's id, or otherwise allocates a new one. | 169 // chunk's id, or otherwise allocates a new one. |
| 163 std::unique_ptr<ContentLayerClientImpl> clientForPaintChunk( | 170 std::unique_ptr<ContentLayerClientImpl> clientForPaintChunk( |
| 164 const PaintChunk&, | 171 const PaintChunk&, |
| 165 const PaintArtifact&); | 172 const PaintArtifact&); |
| 166 | 173 |
| 167 scoped_refptr<cc::Layer> m_rootLayer; | 174 scoped_refptr<cc::Layer> m_rootLayer; |
| 168 std::unique_ptr<WebLayer> m_webLayer; | 175 std::unique_ptr<WebLayer> m_webLayer; |
| 169 Vector<std::unique_ptr<ContentLayerClientImpl>> m_contentLayerClients; | 176 Vector<std::unique_ptr<ContentLayerClientImpl>> m_contentLayerClients; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 PendingLayer); | 219 PendingLayer); |
| 213 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, | 220 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 214 PendingLayerWithGeometry); | 221 PendingLayerWithGeometry); |
| 215 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, | 222 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 216 PendingLayerKnownOpaque_DISABLED); | 223 PendingLayerKnownOpaque_DISABLED); |
| 217 }; | 224 }; |
| 218 | 225 |
| 219 } // namespace blink | 226 } // namespace blink |
| 220 | 227 |
| 221 #endif // PaintArtifactCompositor_h | 228 #endif // PaintArtifactCompositor_h |
| OLD | NEW |