| 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 DisplayItemList; |
| 19 class Layer; | 20 class Layer; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace gfx { | 23 namespace gfx { |
| 23 class Vector2dF; | 24 class Vector2dF; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace blink { | 27 namespace blink { |
| 27 | 28 |
| 29 class GeometryMapper; |
| 28 class JSONObject; | 30 class JSONObject; |
| 29 class PaintArtifact; | 31 class PaintArtifact; |
| 30 class WebLayer; | 32 class WebLayer; |
| 31 struct PaintChunk; | 33 struct PaintChunk; |
| 32 | 34 |
| 33 // Responsible for managing compositing in terms of a PaintArtifact. | 35 // Responsible for managing compositing in terms of a PaintArtifact. |
| 34 // | 36 // |
| 35 // Owns a subtree of the compositor layer tree, and updates it in response to | 37 // Owns a subtree of the compositor layer tree, and updates it in response to |
| 36 // changes in the paint artifact. | 38 // changes in the paint artifact. |
| 37 // | 39 // |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 ExtraDataForTesting* getExtraDataForTesting() const { | 76 ExtraDataForTesting* getExtraDataForTesting() const { |
| 75 return m_extraDataForTesting.get(); | 77 return m_extraDataForTesting.get(); |
| 76 } | 78 } |
| 77 | 79 |
| 78 void setTracksRasterInvalidations(bool); | 80 void setTracksRasterInvalidations(bool); |
| 79 void resetTrackedRasterInvalidations(); | 81 void resetTrackedRasterInvalidations(); |
| 80 bool hasTrackedRasterInvalidations() const; | 82 bool hasTrackedRasterInvalidations() const; |
| 81 | 83 |
| 82 std::unique_ptr<JSONObject> layersAsJSON(LayerTreeFlags) const; | 84 std::unique_ptr<JSONObject> layersAsJSON(LayerTreeFlags) const; |
| 83 | 85 |
| 86 #ifndef NDEBUG |
| 87 void showDebugData(); |
| 88 #endif |
| 89 |
| 84 private: | 90 private: |
| 91 // A pending layer is a collection of paint chunks that will end up in |
| 92 // the same cc::Layer. |
| 93 struct PLATFORM_EXPORT PendingLayer { |
| 94 PendingLayer(const PaintChunk& firstPaintChunk); |
| 95 void add(const PaintChunk&, GeometryMapper*); |
| 96 FloatRect bounds; |
| 97 Vector<const PaintChunk*> paintChunks; |
| 98 bool knownToBeOpaque; |
| 99 bool backfaceHidden; |
| 100 PropertyTreeState propertyTreeState; |
| 101 }; |
| 102 |
| 85 PaintArtifactCompositor(); | 103 PaintArtifactCompositor(); |
| 86 | 104 |
| 87 class ContentLayerClientImpl; | 105 class ContentLayerClientImpl; |
| 88 | 106 |
| 107 // Collects the PaintChunks into groups which will end up in the same |
| 108 // cc layer. This includes testing PaintChunks for "merge" compatibility (e.g. |
| 109 // directly composited property tree states are separately composited) |
| 110 // and overlap testing (PaintChunks that overlap existing PaintLayers they |
| 111 // are not compatible with must be separately composited). |
| 112 void collectPendingLayers(const PaintArtifact&, |
| 113 Vector<PendingLayer>& pendingLayers, |
| 114 GeometryMapper&); |
| 115 |
| 89 // Builds a leaf layer that represents a single paint chunk. | 116 // Builds a leaf layer that represents a single paint chunk. |
| 90 // Note: cc::Layer API assumes the layer bounds start at (0, 0), but the | 117 // Note: cc::Layer API assumes the layer bounds start at (0, 0), but the |
| 91 // bounding box of a paint chunk does not necessarily start at (0, 0) (and | 118 // bounding box of a paint chunk does not necessarily start at (0, 0) (and |
| 92 // could even be negative). Internally the generated layer translates the | 119 // could even be negative). Internally the generated layer translates the |
| 93 // paint chunk to align the bounding box to (0, 0) and return the actual | 120 // paint chunk to align the bounding box to (0, 0) and return the actual |
| 94 // origin of the paint chunk in the |layerOffset| outparam. | 121 // origin of the paint chunk in the |layerOffset| outparam. |
| 95 scoped_refptr<cc::Layer> layerForPaintChunk( | 122 scoped_refptr<cc::Layer> compositedLayerForPendingLayer( |
| 96 const PaintArtifact&, | 123 const PaintArtifact&, |
| 97 const PaintChunk&, | 124 const PendingLayer&, |
| 98 gfx::Vector2dF& layerOffset, | 125 gfx::Vector2dF& layerOffset, |
| 99 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, | 126 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, |
| 100 RasterInvalidationTracking*, | 127 RasterInvalidationTrackingMap<const PaintChunk>*, |
| 101 bool storeDebugInfo); | 128 bool storeDebugInfo, |
| 129 GeometryMapper&); |
| 102 | 130 |
| 103 // Finds a client among the current vector of clients that matches the paint | 131 // Finds a client among the current vector of clients that matches the paint |
| 104 // chunk's id, or otherwise allocates a new one. | 132 // chunk's id, or otherwise allocates a new one. |
| 105 std::unique_ptr<ContentLayerClientImpl> clientForPaintChunk( | 133 std::unique_ptr<ContentLayerClientImpl> clientForPaintChunk( |
| 106 const PaintChunk&, | 134 const PaintChunk&, |
| 107 const PaintArtifact&); | 135 const PaintArtifact&); |
| 108 | 136 |
| 137 // This method is an implementation of Algorithm step 4 from goo.gl/6xP8Oe. |
| 138 static scoped_refptr<cc::DisplayItemList> recordPendingLayer( |
| 139 const PaintArtifact&, |
| 140 const PendingLayer&, |
| 141 const gfx::Rect& combinedBounds, |
| 142 GeometryMapper&); |
| 143 |
| 144 static bool canMergeInto(const PaintArtifact&, |
| 145 const PaintChunk& newChunk, |
| 146 const PendingLayer& candidatePendingLayer); |
| 147 |
| 148 // Returns true if |newChunk| might overlap |candidatePendingLayer| in the |
| 149 // root property tree space. If it does overlap, it will always return true. |
| 150 // If it doesn't overlap, it might return true in cases were we can't |
| 151 // efficiently determine a false value, or the truth depends on |
| 152 // compositor animations. |
| 153 static bool mightOverlap(const PaintChunk& newChunk, |
| 154 const PendingLayer& candidatePendingLayer, |
| 155 GeometryMapper&); |
| 156 |
| 109 scoped_refptr<cc::Layer> m_rootLayer; | 157 scoped_refptr<cc::Layer> m_rootLayer; |
| 110 std::unique_ptr<WebLayer> m_webLayer; | 158 std::unique_ptr<WebLayer> m_webLayer; |
| 111 Vector<std::unique_ptr<ContentLayerClientImpl>> m_contentLayerClients; | 159 Vector<std::unique_ptr<ContentLayerClientImpl>> m_contentLayerClients; |
| 112 | 160 |
| 113 bool m_extraDataForTestingEnabled = false; | 161 bool m_extraDataForTestingEnabled = false; |
| 114 std::unique_ptr<ExtraDataForTesting> m_extraDataForTesting; | 162 std::unique_ptr<ExtraDataForTesting> m_extraDataForTesting; |
| 115 friend class StubChromeClientForSPv2; | 163 friend class StubChromeClientForSPv2; |
| 116 | 164 |
| 117 bool m_isTrackingRasterInvalidations; | 165 bool m_isTrackingRasterInvalidations; |
| 166 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 167 ForeignLayerPassesThrough); |
| 168 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 169 MergeSimpleChunks); |
| 170 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 171 Merge2DTransform); |
| 172 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 173 MergeClip); |
| 174 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 175 MergeOpacity); |
| 176 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 177 MergeNested); |
| 178 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 179 ClipPushedUp); |
| 180 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 181 EffectPushedUp); |
| 182 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 183 EffectAndClipPushedUp); |
| 184 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 185 ClipAndEffectNoTransform); |
| 186 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 187 TwoClips); |
| 188 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 189 TwoEffects); |
| 190 |
| 191 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 192 PendingLayer); |
| 193 FRIEND_TEST_ALL_PREFIXES(PaintArtifactCompositorTestWithPropertyTrees, |
| 194 PendingLayerWithGeometry); |
| 118 }; | 195 }; |
| 119 | 196 |
| 120 } // namespace blink | 197 } // namespace blink |
| 121 | 198 |
| 122 #endif // PaintArtifactCompositor_h | 199 #endif // PaintArtifactCompositor_h |
| OLD | NEW |