| 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" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 std::unique_ptr<JSONObject> layersAsJSON(LayerTreeFlags) const; | 85 std::unique_ptr<JSONObject> layersAsJSON(LayerTreeFlags) const; |
| 86 | 86 |
| 87 #ifndef NDEBUG | 87 #ifndef NDEBUG |
| 88 void showDebugData(); | 88 void showDebugData(); |
| 89 #endif | 89 #endif |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 // 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 |
| 93 // the same cc::Layer. | 93 // the same cc::Layer. |
| 94 struct PLATFORM_EXPORT PendingLayer { | 94 struct PLATFORM_EXPORT PendingLayer { |
| 95 PendingLayer(const PaintChunk& firstPaintChunk); | 95 PendingLayer(const PaintChunk& firstPaintChunk, |
| 96 void add(const PaintChunk&, GeometryMapper*); | 96 bool chunkIsForeign, |
| 97 GeometryMapper&); |
| 98 // Merge another pending layer after this one, appending all its paint |
| 99 // chunks after chunks in this layer, with appropriate space conversion |
| 100 // applied. The merged layer must have a property tree state that's deeper |
| 101 // than this layer, i.e. can "upcast" to this layer's state. |
| 102 void merge(const PendingLayer& guest, GeometryMapper&); |
| 103 bool canMerge(const PendingLayer& guest) const; |
| 104 // Mutate this layer's property tree state to a more general (shallower) |
| 105 // state, thus the name "upcast". The concrete effect of this is to |
| 106 // "decomposite" some of the properties, so that fewer properties will be |
| 107 // applied by the compositor, and more properties will be applied internally |
| 108 // to the chunks as Skia commands. |
| 109 void upcast(const PropertyTreeState&, GeometryMapper&); |
| 97 FloatRect bounds; | 110 FloatRect bounds; |
| 98 Vector<const PaintChunk*> paintChunks; | 111 Vector<const PaintChunk*> paintChunks; |
| 99 bool knownToBeOpaque; | 112 bool knownToBeOpaque; |
| 100 bool backfaceHidden; | 113 bool backfaceHidden; |
| 101 PropertyTreeState propertyTreeState; | 114 PropertyTreeState propertyTreeState; |
| 115 bool isForeign; |
| 102 }; | 116 }; |
| 103 | 117 |
| 104 PaintArtifactCompositor(); | 118 PaintArtifactCompositor(); |
| 105 | 119 |
| 106 class ContentLayerClientImpl; | 120 class ContentLayerClientImpl; |
| 107 | 121 |
| 108 // Collects the PaintChunks into groups which will end up in the same | 122 // Collects the PaintChunks into groups which will end up in the same |
| 109 // cc layer. This includes testing PaintChunks for "merge" compatibility (e.g. | 123 // cc layer. This is the entry point of the layerization algorithm. |
| 110 // directly composited property tree states are separately composited) | |
| 111 // and overlap testing (PaintChunks that overlap existing PaintLayers they | |
| 112 // are not compatible with must be separately composited). | |
| 113 void collectPendingLayers(const PaintArtifact&, | 124 void collectPendingLayers(const PaintArtifact&, |
| 114 Vector<PendingLayer>& pendingLayers, | 125 Vector<PendingLayer>& pendingLayers, |
| 115 GeometryMapper&); | 126 GeometryMapper&); |
| 127 // This is the internal recursion of collectPendingLayers. This function |
| 128 // loops over the list of paint chunks, scoped by an isolated group |
| 129 // (i.e. effect node). Inside of the loop, chunks are tested for overlap |
| 130 // and merge compatibility. Subgroups are handled by recursion, and will |
| 131 // be tested for "decompositing" upon return. |
| 132 // Merge compatibility means consecutive chunks may be layerized into the |
| 133 // same backing (i.e. merged) if their property states don't cross |
| 134 // direct-compositing boundary. |
| 135 // Non-consecutive chunks that are nevertheless compatible may still be |
| 136 // merged, if reordering of the chunks won't affect the ultimate result. |
| 137 // This is determined by overlap testing such that chunks can be safely |
| 138 // reordered if their effective bounds in screen space can't overlap. |
| 139 // The recursion only tests merge & overlap for chunks scoped by the same |
| 140 // group. This is where "decompositing" came in. Upon returning from a |
| 141 // recursion, the layerization of the subgroup may be tested for merge & |
| 142 // overlap with other chunks in the parent group, if grouping requirement |
| 143 // can be satisfied (and the effect node has no direct reason). |
| 144 static void layerizeGroup(const PaintArtifact&, |
| 145 Vector<PendingLayer>& pendingLayers, |
| 146 GeometryMapper&, |
| 147 const EffectPaintPropertyNode&, |
| 148 Vector<PaintChunk>::const_iterator& chunkCursor); |
| 116 | 149 |
| 117 // Builds a leaf layer that represents a single paint chunk. | 150 // Builds a leaf layer that represents a single paint chunk. |
| 118 // Note: cc::Layer API assumes the layer bounds start at (0, 0), but the | 151 // Note: cc::Layer API assumes the layer bounds start at (0, 0), but the |
| 119 // bounding box of a paint chunk does not necessarily start at (0, 0) (and | 152 // bounding box of a paint chunk does not necessarily start at (0, 0) (and |
| 120 // could even be negative). Internally the generated layer translates the | 153 // could even be negative). Internally the generated layer translates the |
| 121 // paint chunk to align the bounding box to (0, 0) and return the actual | 154 // paint chunk to align the bounding box to (0, 0) and return the actual |
| 122 // origin of the paint chunk in the |layerOffset| outparam. | 155 // origin of the paint chunk in the |layerOffset| outparam. |
| 123 scoped_refptr<cc::Layer> compositedLayerForPendingLayer( | 156 scoped_refptr<cc::Layer> compositedLayerForPendingLayer( |
| 124 const PaintArtifact&, | 157 const PaintArtifact&, |
| 125 const PendingLayer&, | 158 const PendingLayer&, |
| 126 gfx::Vector2dF& layerOffset, | 159 gfx::Vector2dF& layerOffset, |
| 127 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, | 160 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, |
| 128 RasterInvalidationTrackingMap<const PaintChunk>*, | 161 RasterInvalidationTrackingMap<const PaintChunk>*, |
| 129 bool storeDebugInfo, | 162 bool storeDebugInfo, |
| 130 GeometryMapper&); | 163 GeometryMapper&); |
| 131 | 164 |
| 132 // Finds a client among the current vector of clients that matches the paint | 165 // Finds a client among the current vector of clients that matches the paint |
| 133 // chunk's id, or otherwise allocates a new one. | 166 // chunk's id, or otherwise allocates a new one. |
| 134 std::unique_ptr<ContentLayerClientImpl> clientForPaintChunk( | 167 std::unique_ptr<ContentLayerClientImpl> clientForPaintChunk( |
| 135 const PaintChunk&, | 168 const PaintChunk&, |
| 136 const PaintArtifact&); | 169 const PaintArtifact&); |
| 137 | 170 |
| 138 // This method is an implementation of Algorithm step 4 from goo.gl/6xP8Oe. | 171 // This method is an implementation of Algorithm step 4 from goo.gl/6xP8Oe. |
| 139 static scoped_refptr<cc::DisplayItemList> recordPendingLayer( | 172 static scoped_refptr<cc::DisplayItemList> recordPendingLayer( |
| 140 const PaintArtifact&, | 173 const PaintArtifact&, |
| 141 const PendingLayer&, | 174 const PendingLayer&, |
| 142 const gfx::Rect& combinedBounds, | 175 const gfx::Rect& combinedBounds, |
| 143 GeometryMapper&); | 176 GeometryMapper&); |
| 144 | 177 |
| 145 static bool canMergeInto(const PaintArtifact&, | |
| 146 const PaintChunk& newChunk, | |
| 147 const PendingLayer& candidatePendingLayer); | |
| 148 | |
| 149 // Returns true if |newChunk| might overlap |candidatePendingLayer| in the | |
| 150 // root property tree space. If it does overlap, it will always return true. | |
| 151 // If it doesn't overlap, it might return true in cases were we can't | |
| 152 // efficiently determine a false value, or the truth depends on | |
| 153 // compositor animations. | |
| 154 static bool mightOverlap(const PaintChunk& newChunk, | |
| 155 const PendingLayer& candidatePendingLayer, | |
| 156 GeometryMapper&); | |
| 157 | |
| 158 scoped_refptr<cc::Layer> m_rootLayer; | 178 scoped_refptr<cc::Layer> m_rootLayer; |
| 159 std::unique_ptr<WebLayer> m_webLayer; | 179 std::unique_ptr<WebLayer> m_webLayer; |
| 160 Vector<std::unique_ptr<ContentLayerClientImpl>> m_contentLayerClients; | 180 Vector<std::unique_ptr<ContentLayerClientImpl>> m_contentLayerClients; |
| 161 | 181 |
| 162 bool m_extraDataForTestingEnabled = false; | 182 bool m_extraDataForTestingEnabled = false; |
| 163 std::unique_ptr<ExtraDataForTesting> m_extraDataForTesting; | 183 std::unique_ptr<ExtraDataForTesting> m_extraDataForTesting; |
| 164 friend class StubChromeClientForSPv2; | 184 friend class StubChromeClientForSPv2; |
| 165 | 185 |
| 166 bool m_isTrackingRasterInvalidations; | 186 bool m_isTrackingRasterInvalidations; |
| 167 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, | 187 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 PendingLayer); | 223 PendingLayer); |
| 204 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, | 224 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 205 PendingLayerWithGeometry); | 225 PendingLayerWithGeometry); |
| 206 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, | 226 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 207 PendingLayerKnownOpaque); | 227 PendingLayerKnownOpaque); |
| 208 }; | 228 }; |
| 209 | 229 |
| 210 } // namespace blink | 230 } // namespace blink |
| 211 | 231 |
| 212 #endif // PaintArtifactCompositor_h | 232 #endif // PaintArtifactCompositor_h |
| OLD | NEW |