| 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 #include "platform/graphics/compositing/PaintArtifactCompositor.h" | 5 #include "platform/graphics/compositing/PaintArtifactCompositor.h" |
| 6 | 6 |
| 7 #include "cc/layers/content_layer_client.h" | 7 #include "cc/layers/content_layer_client.h" |
| 8 #include "cc/layers/layer.h" | 8 #include "cc/layers/layer.h" |
| 9 #include "cc/layers/picture_layer.h" | 9 #include "cc/layers/picture_layer.h" |
| 10 #include "cc/playback/display_item_list.h" | 10 #include "cc/playback/display_item_list.h" |
| 11 #include "cc/playback/display_item_list_settings.h" | 11 #include "cc/playback/display_item_list_settings.h" |
| 12 #include "cc/playback/drawing_display_item.h" | 12 #include "cc/playback/drawing_display_item.h" |
| 13 #include "cc/playback/transform_display_item.h" | 13 #include "cc/playback/transform_display_item.h" |
| 14 #include "cc/trees/clip_node.h" | 14 #include "cc/trees/clip_node.h" |
| 15 #include "cc/trees/effect_node.h" | 15 #include "cc/trees/effect_node.h" |
| 16 #include "cc/trees/layer_tree_host.h" | 16 #include "cc/trees/layer_tree_host.h" |
| 17 #include "cc/trees/property_tree.h" | 17 #include "cc/trees/property_tree.h" |
| 18 #include "cc/trees/scroll_node.h" | 18 #include "cc/trees/scroll_node.h" |
| 19 #include "cc/trees/transform_node.h" | 19 #include "cc/trees/transform_node.h" |
| 20 #include "core/paint/PaintPropertyTreePrinter.h" |
| 20 #include "platform/RuntimeEnabledFeatures.h" | 21 #include "platform/RuntimeEnabledFeatures.h" |
| 21 #include "platform/graphics/paint/ClipPaintPropertyNode.h" | 22 #include "platform/graphics/paint/ClipPaintPropertyNode.h" |
| 22 #include "platform/graphics/paint/DisplayItem.h" | 23 #include "platform/graphics/paint/DisplayItem.h" |
| 23 #include "platform/graphics/paint/DrawingDisplayItem.h" | 24 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 24 #include "platform/graphics/paint/ForeignLayerDisplayItem.h" | 25 #include "platform/graphics/paint/ForeignLayerDisplayItem.h" |
| 26 #include "platform/graphics/paint/GeometryMapper.h" |
| 25 #include "platform/graphics/paint/PaintArtifact.h" | 27 #include "platform/graphics/paint/PaintArtifact.h" |
| 28 #include "platform/graphics/paint/PropertyTreeState.h" |
| 26 #include "platform/graphics/paint/RasterInvalidationTracking.h" | 29 #include "platform/graphics/paint/RasterInvalidationTracking.h" |
| 27 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" | 30 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" |
| 28 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 31 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 29 #include "public/platform/Platform.h" | 32 #include "public/platform/Platform.h" |
| 30 #include "public/platform/WebCompositorSupport.h" | 33 #include "public/platform/WebCompositorSupport.h" |
| 31 #include "public/platform/WebLayer.h" | 34 #include "public/platform/WebLayer.h" |
| 32 #include "ui/gfx/geometry/point.h" | 35 #include "ui/gfx/geometry/point.h" |
| 33 #include "ui/gfx/geometry/point_f.h" | 36 #include "ui/gfx/geometry/point_f.h" |
| 34 #include "ui/gfx/geometry/rect.h" | 37 #include "ui/gfx/geometry/rect.h" |
| 35 #include "ui/gfx/geometry/rect_f.h" | 38 #include "ui/gfx/geometry/rect_f.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 62 } | 65 } |
| 63 | 66 |
| 64 class PaintArtifactCompositor::ContentLayerClientImpl | 67 class PaintArtifactCompositor::ContentLayerClientImpl |
| 65 : public cc::ContentLayerClient { | 68 : public cc::ContentLayerClient { |
| 66 WTF_MAKE_NONCOPYABLE(ContentLayerClientImpl); | 69 WTF_MAKE_NONCOPYABLE(ContentLayerClientImpl); |
| 67 USING_FAST_MALLOC(ContentLayerClientImpl); | 70 USING_FAST_MALLOC(ContentLayerClientImpl); |
| 68 | 71 |
| 69 public: | 72 public: |
| 70 ContentLayerClientImpl(DisplayItem::Id paintChunkId) | 73 ContentLayerClientImpl(DisplayItem::Id paintChunkId) |
| 71 : m_id(paintChunkId), | 74 : m_id(paintChunkId), |
| 72 m_debugName(paintChunkId.client.debugName()), | |
| 73 m_ccPictureLayer(cc::PictureLayer::Create(this)) {} | 75 m_ccPictureLayer(cc::PictureLayer::Create(this)) {} |
| 74 | 76 |
| 75 void SetDisplayList(scoped_refptr<cc::DisplayItemList> ccDisplayItemList) { | 77 void SetDisplayList(scoped_refptr<cc::DisplayItemList> ccDisplayItemList) { |
| 76 m_ccDisplayItemList = std::move(ccDisplayItemList); | 78 m_ccDisplayItemList = std::move(ccDisplayItemList); |
| 77 } | 79 } |
| 78 void SetPaintableRegion(gfx::Rect region) { m_paintableRegion = region; } | 80 void SetPaintableRegion(gfx::Rect region) { m_paintableRegion = region; } |
| 79 | 81 |
| 82 void addPaintChunkDebugData(std::unique_ptr<JSONArray> json) { |
| 83 m_paintChunkDebugData.append(std::move(json)); |
| 84 } |
| 85 |
| 86 void clearPaintChunkDebugData() { m_paintChunkDebugData.clear(); } |
| 87 |
| 80 // cc::ContentLayerClient | 88 // cc::ContentLayerClient |
| 81 gfx::Rect PaintableRegion() override { return m_paintableRegion; } | 89 gfx::Rect PaintableRegion() override { return m_paintableRegion; } |
| 82 scoped_refptr<cc::DisplayItemList> PaintContentsToDisplayList( | 90 scoped_refptr<cc::DisplayItemList> PaintContentsToDisplayList( |
| 83 PaintingControlSetting) override { | 91 PaintingControlSetting) override { |
| 84 return m_ccDisplayItemList; | 92 return m_ccDisplayItemList; |
| 85 } | 93 } |
| 86 bool FillsBoundsCompletely() const override { return false; } | 94 bool FillsBoundsCompletely() const override { return false; } |
| 87 size_t GetApproximateUnsharedMemoryUsage() const override { | 95 size_t GetApproximateUnsharedMemoryUsage() const override { |
| 88 // TODO(jbroman): Actually calculate memory usage. | 96 // TODO(jbroman): Actually calculate memory usage. |
| 89 return 0; | 97 return 0; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // TODO(crbug.com/496260): Some antialiasing effects overflow the paint | 133 // TODO(crbug.com/496260): Some antialiasing effects overflow the paint |
| 126 // invalidation rect. | 134 // invalidation rect. |
| 127 IntRect r = rasterInvalidationInfo->rect; | 135 IntRect r = rasterInvalidationInfo->rect; |
| 128 r.inflate(1); | 136 r.inflate(1); |
| 129 tracking.rasterInvalidationRegionSinceLastPaint.unite(r); | 137 tracking.rasterInvalidationRegionSinceLastPaint.unite(r); |
| 130 } | 138 } |
| 131 } | 139 } |
| 132 | 140 |
| 133 std::unique_ptr<JSONObject> layerAsJSON() { | 141 std::unique_ptr<JSONObject> layerAsJSON() { |
| 134 std::unique_ptr<JSONObject> json = JSONObject::create(); | 142 std::unique_ptr<JSONObject> json = JSONObject::create(); |
| 135 json->setString("name", m_debugName); | |
| 136 IntSize bounds(m_ccPictureLayer->bounds().width(), | 143 IntSize bounds(m_ccPictureLayer->bounds().width(), |
| 137 m_ccPictureLayer->bounds().height()); | 144 m_ccPictureLayer->bounds().height()); |
| 138 if (!bounds.isEmpty()) | 145 if (!bounds.isEmpty()) |
| 139 json->setArray("bounds", sizeAsJSONArray(bounds)); | 146 json->setArray("bounds", sizeAsJSONArray(bounds)); |
| 140 json->setBoolean("contentsOpaque", m_ccPictureLayer->contents_opaque()); | 147 json->setBoolean("contentsOpaque", m_ccPictureLayer->contents_opaque()); |
| 141 json->setBoolean("drawsContent", m_ccPictureLayer->DrawsContent()); | 148 json->setBoolean("drawsContent", m_ccPictureLayer->DrawsContent()); |
| 142 | 149 |
| 150 std::unique_ptr<JSONArray> paintChunkContentsArray = JSONArray::create(); |
| 151 for (const auto& debugData : m_paintChunkDebugData) { |
| 152 paintChunkContentsArray->pushValue(debugData->clone()); |
| 153 } |
| 154 json->setArray("paintChunkContents", std::move(paintChunkContentsArray)); |
| 155 |
| 143 ccLayersRasterInvalidationTrackingMap().asJSON(m_ccPictureLayer.get(), | 156 ccLayersRasterInvalidationTrackingMap().asJSON(m_ccPictureLayer.get(), |
| 144 json.get()); | 157 json.get()); |
| 145 return json; | 158 return json; |
| 146 } | 159 } |
| 147 | 160 |
| 148 scoped_refptr<cc::PictureLayer> ccPictureLayer() { return m_ccPictureLayer; } | 161 scoped_refptr<cc::PictureLayer> ccPictureLayer() { return m_ccPictureLayer; } |
| 149 | 162 |
| 150 bool matches(const PaintChunk& paintChunk) { | 163 bool matches(const PaintChunk& paintChunk) { |
| 151 return paintChunk.id && m_id == *paintChunk.id; | 164 return paintChunk.id && m_id == *paintChunk.id; |
| 152 } | 165 } |
| 153 | 166 |
| 154 private: | 167 private: |
| 155 PaintChunk::Id m_id; | 168 PaintChunk::Id m_id; |
| 156 String m_debugName; | |
| 157 scoped_refptr<cc::PictureLayer> m_ccPictureLayer; | 169 scoped_refptr<cc::PictureLayer> m_ccPictureLayer; |
| 158 scoped_refptr<cc::DisplayItemList> m_ccDisplayItemList; | 170 scoped_refptr<cc::DisplayItemList> m_ccDisplayItemList; |
| 159 gfx::Rect m_paintableRegion; | 171 gfx::Rect m_paintableRegion; |
| 172 |
| 173 Vector<std::unique_ptr<JSONArray>> m_paintChunkDebugData; |
| 160 }; | 174 }; |
| 161 | 175 |
| 162 PaintArtifactCompositor::PaintArtifactCompositor() { | 176 PaintArtifactCompositor::PaintArtifactCompositor() { |
| 163 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 177 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 164 return; | 178 return; |
| 165 m_rootLayer = cc::Layer::Create(); | 179 m_rootLayer = cc::Layer::Create(); |
| 166 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( | 180 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( |
| 167 m_rootLayer.get()); | 181 m_rootLayer.get()); |
| 168 m_isTrackingRasterInvalidations = false; | 182 m_isTrackingRasterInvalidations = false; |
| 169 } | 183 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // to raster in a different space than that of the visual rects. We'll be | 231 // to raster in a different space than that of the visual rects. We'll be |
| 218 // reworking visual rects further for SPv2, so for now we just pass a | 232 // reworking visual rects further for SPv2, so for now we just pass a |
| 219 // visual rect large enough to make sure items raster. | 233 // visual rect large enough to make sure items raster. |
| 220 list->CreateAndAppendDrawingItem<cc::DrawingDisplayItem>( | 234 list->CreateAndAppendDrawingItem<cc::DrawingDisplayItem>( |
| 221 largeRect, sk_ref_sp(picture)); | 235 largeRect, sk_ref_sp(picture)); |
| 222 } | 236 } |
| 223 } | 237 } |
| 224 | 238 |
| 225 static scoped_refptr<cc::DisplayItemList> recordPaintChunk( | 239 static scoped_refptr<cc::DisplayItemList> recordPaintChunk( |
| 226 const PaintArtifact& artifact, | 240 const PaintArtifact& artifact, |
| 227 const PaintChunk& chunk, | 241 const PendingLayer& pendingLayer, |
| 228 const gfx::Rect& combinedBounds) { | 242 const gfx::Rect& combinedBounds) { |
| 229 cc::DisplayItemListSettings settings; | 243 cc::DisplayItemListSettings settings; |
| 230 scoped_refptr<cc::DisplayItemList> list = | 244 scoped_refptr<cc::DisplayItemList> list = |
| 231 cc::DisplayItemList::Create(settings); | 245 cc::DisplayItemList::Create(settings); |
| 232 | 246 |
| 233 gfx::Transform translation; | 247 gfx::Transform translation; |
| 234 translation.Translate(-combinedBounds.x(), -combinedBounds.y()); | 248 translation.Translate(-combinedBounds.x(), -combinedBounds.y()); |
| 235 // Passing combinedBounds as the visual rect for the begin/end transform item | 249 // Passing combinedBounds as the visual rect for the begin/end transform item |
| 236 // would normally be the sensible thing to do, but see comment above re: | 250 // would normally be the sensible thing to do, but see comment above re: |
| 237 // visual rects for drawing items and further rework in flight. | 251 // visual rects for drawing items and further rework in flight. |
| 238 list->CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>(translation); | 252 list->CreateAndAppendPairedBeginItem<cc::TransformDisplayItem>(translation); |
| 239 | 253 |
| 240 const DisplayItemList& displayItems = artifact.getDisplayItemList(); | 254 const DisplayItemList& displayItems = artifact.getDisplayItemList(); |
| 241 for (const auto& displayItem : displayItems.itemsInPaintChunk(chunk)) | 255 for (const auto& paintChunk : pendingLayer.paintChunks) { |
| 242 appendDisplayItemToCcDisplayItemList(displayItem, list.get()); | 256 for (const auto& displayItem : displayItems.itemsInPaintChunk(paintChunk)) |
| 257 appendDisplayItemToCcDisplayItemList(displayItem, list.get()); |
| 258 } |
| 243 | 259 |
| 244 list->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); | 260 list->CreateAndAppendPairedEndItem<cc::EndTransformDisplayItem>(); |
| 245 | 261 |
| 246 list->Finalize(); | 262 list->Finalize(); |
| 247 return list; | 263 return list; |
| 248 } | 264 } |
| 249 | 265 |
| 250 scoped_refptr<cc::Layer> foreignLayerForPaintChunk( | 266 scoped_refptr<cc::Layer> foreignLayerForPaintChunk( |
| 251 const PaintArtifact& paintArtifact, | 267 const PaintArtifact& paintArtifact, |
| 252 const PaintChunk& paintChunk, | 268 const PaintChunk& paintChunk, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 if (client && client->matches(paintChunk)) | 305 if (client && client->matches(paintChunk)) |
| 290 return std::move(client); | 306 return std::move(client); |
| 291 } | 307 } |
| 292 | 308 |
| 293 return wrapUnique(new ContentLayerClientImpl( | 309 return wrapUnique(new ContentLayerClientImpl( |
| 294 paintChunk.id | 310 paintChunk.id |
| 295 ? *paintChunk.id | 311 ? *paintChunk.id |
| 296 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); | 312 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); |
| 297 } | 313 } |
| 298 | 314 |
| 299 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk( | 315 scoped_refptr<cc::Layer> |
| 316 PaintArtifactCompositor::compositedLayerForPendingLayer( |
| 300 const PaintArtifact& paintArtifact, | 317 const PaintArtifact& paintArtifact, |
| 301 const PaintChunk& paintChunk, | 318 const PendingLayer& pendingLayer, |
| 302 gfx::Vector2dF& layerOffset, | 319 gfx::Vector2dF& layerOffset, |
| 303 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, | 320 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, |
| 304 RasterInvalidationTracking* tracking) { | 321 RasterInvalidationTrackingMap<const PaintChunk>* trackingMap) { |
| 305 DCHECK(paintChunk.size()); | 322 DCHECK(pendingLayer.paintChunks.size()); |
| 323 const PaintChunk& firstPaintChunk = pendingLayer.paintChunks[0]; |
| 324 DCHECK(firstPaintChunk.size()); |
| 325 #if DCHECK_IS_ON |
| 326 for (const auto& paintChunk : pendingLayer.paintChunks) { |
| 327 DCHECK(paintChunk.properties == firstPaintChunk.properties); |
| 328 } |
| 329 #endif |
| 306 | 330 |
| 307 // If the paint chunk is a foreign layer, just return that layer. | 331 // If the paint chunk is a foreign layer, just return that layer. |
| 308 if (scoped_refptr<cc::Layer> foreignLayer = | 332 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk( |
| 309 foreignLayerForPaintChunk(paintArtifact, paintChunk, layerOffset)) | 333 paintArtifact, firstPaintChunk, layerOffset)) { |
| 334 DCHECK(pendingLayer.paintChunks.size() == 1); |
| 310 return foreignLayer; | 335 return foreignLayer; |
| 336 } |
| 311 | 337 |
| 312 // The common case: create or reuse a PictureLayer for painted content. | 338 // The common case: create or reuse a PictureLayer for painted content. |
| 313 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = | 339 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = |
| 314 clientForPaintChunk(paintChunk, paintArtifact); | 340 clientForPaintChunk(firstPaintChunk, paintArtifact); |
| 315 | 341 |
| 316 gfx::Rect combinedBounds = enclosingIntRect(paintChunk.bounds); | 342 IntRect combinedBounds = enclosingIntRect(pendingLayer.bounds); |
| 343 bool knownToBeOpaque = pendingLayer.knownToBeOpaque; |
| 344 gfx::Rect ccCombinedBounds(combinedBounds); |
| 345 |
| 317 scoped_refptr<cc::DisplayItemList> displayList = | 346 scoped_refptr<cc::DisplayItemList> displayList = |
| 318 recordPaintChunk(paintArtifact, paintChunk, combinedBounds); | 347 recordPaintChunk(paintArtifact, pendingLayer, ccCombinedBounds); |
| 319 contentLayerClient->SetDisplayList(std::move(displayList)); | 348 contentLayerClient->SetDisplayList(std::move(displayList)); |
| 320 contentLayerClient->SetPaintableRegion(gfx::Rect(combinedBounds.size())); | 349 contentLayerClient->SetPaintableRegion(gfx::Rect(ccCombinedBounds.size())); |
| 321 | 350 |
| 322 layerOffset = combinedBounds.OffsetFromOrigin(); | 351 layerOffset = ccCombinedBounds.OffsetFromOrigin(); |
| 323 scoped_refptr<cc::PictureLayer> ccPictureLayer = | 352 scoped_refptr<cc::PictureLayer> ccPictureLayer = |
| 324 contentLayerClient->ccPictureLayer(); | 353 contentLayerClient->ccPictureLayer(); |
| 325 ccPictureLayer->SetBounds(combinedBounds.size()); | 354 ccPictureLayer->SetBounds(ccCombinedBounds.size()); |
| 326 ccPictureLayer->SetIsDrawable(true); | 355 ccPictureLayer->SetIsDrawable(true); |
| 327 if (paintChunk.knownToBeOpaque) | 356 ccPictureLayer->SetContentsOpaque(knownToBeOpaque); |
| 328 ccPictureLayer->SetContentsOpaque(true); | 357 contentLayerClient->clearPaintChunkDebugData(); |
| 329 DCHECK(!tracking || | 358 |
| 330 tracking->trackedRasterInvalidations.size() == | 359 for (const auto& paintChunk : pendingLayer.paintChunks) { |
| 331 paintChunk.rasterInvalidationRects.size()); | 360 RasterInvalidationTracking* rasterTracking = |
| 332 for (unsigned index = 0; index < paintChunk.rasterInvalidationRects.size(); | 361 trackingMap ? trackingMap->find(&paintChunk) : nullptr; |
| 333 ++index) { | 362 DCHECK(!rasterTracking || |
| 334 IntRect rect(enclosingIntRect(paintChunk.rasterInvalidationRects[index])); | 363 rasterTracking->trackedRasterInvalidations.size() == |
| 335 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), std::max(0, rect.width()), | 364 paintChunk.rasterInvalidationRects.size()); |
| 336 std::max(0, rect.height())); | 365 for (unsigned index = 0; index < paintChunk.rasterInvalidationRects.size(); |
| 337 // Raster paintChunk.rasterInvalidationRects is in the space of the | 366 ++index) { |
| 338 // containing transform node, so need to subtract off the layer offset. | 367 IntRect rect(enclosingIntRect(paintChunk.rasterInvalidationRects[index])); |
| 339 ccInvalidationRect.Offset(-combinedBounds.OffsetFromOrigin()); | 368 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), |
| 340 contentLayerClient->setNeedsDisplayRect( | 369 std::max(0, rect.width()), |
| 341 ccInvalidationRect, | 370 std::max(0, rect.height())); |
| 342 tracking ? &tracking->trackedRasterInvalidations[index] : nullptr); | 371 // Raster paintChunk.rasterInvalidationRects is in the space of the |
| 372 // containing transform node, so need to subtract off the layer offset. |
| 373 ccInvalidationRect.Offset(-ccCombinedBounds.OffsetFromOrigin()); |
| 374 contentLayerClient->setNeedsDisplayRect( |
| 375 ccInvalidationRect, |
| 376 rasterTracking ? &rasterTracking->trackedRasterInvalidations[index] |
| 377 : nullptr); |
| 378 } |
| 379 contentLayerClient->addPaintChunkDebugData( |
| 380 paintArtifact.getDisplayItemList().subsequenceAsJSON( |
| 381 paintChunk.beginIndex, paintChunk.endIndex, false, true)); |
| 343 } | 382 } |
| 344 | 383 |
| 345 newContentLayerClients.append(std::move(contentLayerClient)); | 384 newContentLayerClients.append(std::move(contentLayerClient)); |
| 346 return ccPictureLayer; | 385 return ccPictureLayer; |
| 347 } | 386 } |
| 348 | 387 |
| 349 namespace { | 388 namespace { |
| 350 | 389 |
| 351 class PropertyTreeManager { | 390 class PropertyTreeManager { |
| 352 WTF_MAKE_NONCOPYABLE(PropertyTreeManager); | 391 WTF_MAKE_NONCOPYABLE(PropertyTreeManager); |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 | 787 |
| 749 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 788 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 750 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); | 789 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); |
| 751 dummyLayer->SetClipTreeIndex(outputClipId); | 790 dummyLayer->SetClipTreeIndex(outputClipId); |
| 752 dummyLayer->SetEffectTreeIndex(effectNode.id); | 791 dummyLayer->SetEffectTreeIndex(effectNode.id); |
| 753 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); | 792 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); |
| 754 } | 793 } |
| 755 | 794 |
| 756 } // namespace | 795 } // namespace |
| 757 | 796 |
| 797 static bool canMergeInto(const PaintChunk& newChunk, |
| 798 const PendingLayer& candidatePendingLayer) { |
| 799 DCHECK(candidatePendingLayer.paintChunks.size() >= 1); |
| 800 const PaintChunk& firstLayerChunk = candidatePendingLayer.paintChunks[0]; |
| 801 |
| 802 PropertyTreeState newChunkProperties( |
| 803 newChunk.properties.transform.get(), newChunk.properties.clip.get(), |
| 804 newChunk.properties.effect.get(), newChunk.properties.scroll.get()); |
| 805 |
| 806 PropertyTreeState currentLayerProperties( |
| 807 firstLayerChunk.properties.transform.get(), |
| 808 firstLayerChunk.properties.clip.get(), |
| 809 firstLayerChunk.properties.effect.get(), |
| 810 firstLayerChunk.properties.scroll.get()); |
| 811 |
| 812 if (firstLayerChunk.properties.hasDirectCompositingReasons() || |
| 813 newChunk.properties.hasDirectCompositingReasons()) |
| 814 return false; |
| 815 |
| 816 for (PropertyTreeStateIterator it(newChunkProperties); it.hasNext(); |
| 817 it.next()) { |
| 818 if (it.current().hasDirectCompositingReasons()) |
| 819 return false; |
| 820 |
| 821 if (it.current() == currentLayerProperties) |
| 822 return true; |
| 823 } |
| 824 return false; |
| 825 } |
| 826 |
| 827 static bool overlaps(const PaintChunk& paintChunk, |
| 828 const PendingLayer& candidatePendingLayer, |
| 829 GeometryMapper& geometryMapper) { |
| 830 PropertyTreeState rootPropertyTreeState( |
| 831 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 832 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); |
| 833 |
| 834 FloatRect paintChunkScreenVisualRect(paintChunk.bounds); |
| 835 PropertyTreeState paintChunkPropertyState( |
| 836 paintChunk.properties.transform.get(), paintChunk.properties.clip.get(), |
| 837 paintChunk.properties.effect.get(), paintChunk.properties.scroll.get()); |
| 838 bool success = false; |
| 839 geometryMapper.localToVisualRectInAncestorSpace( |
| 840 paintChunkScreenVisualRect, paintChunkPropertyState, |
| 841 rootPropertyTreeState, success); |
| 842 DCHECK(success); |
| 843 |
| 844 PropertyTreeState candidatePendingLayerPropertyState( |
| 845 candidatePendingLayer.paintChunks[0].properties.transform.get(), |
| 846 candidatePendingLayer.paintChunks[0].properties.clip.get(), |
| 847 candidatePendingLayer.paintChunks[0].properties.effect.get(), |
| 848 candidatePendingLayer.paintChunks[0].properties.scroll.get()); |
| 849 |
| 850 FloatRect pendingLayerScreenVisualRect(candidatePendingLayer.bounds); |
| 851 success = false; |
| 852 geometryMapper.localToVisualRectInAncestorSpace( |
| 853 pendingLayerScreenVisualRect, candidatePendingLayerPropertyState, |
| 854 rootPropertyTreeState, success); |
| 855 DCHECK(success); |
| 856 |
| 857 return paintChunkScreenVisualRect.intersects(pendingLayerScreenVisualRect); |
| 858 return true; |
| 859 } |
| 860 |
| 861 void PaintArtifactCompositor::collectPendingLayers( |
| 862 const Vector<PaintChunk>& paintChunks, |
| 863 Vector<PendingLayer>& pendingLayers) { |
| 864 GeometryMapper geometryMapper; |
| 865 for (const PaintChunk& paintChunk : paintChunks) { |
| 866 bool createNew = true; |
| 867 for (Vector<PendingLayer>::reverse_iterator candidatePendingLayer = |
| 868 pendingLayers.rbegin(); |
| 869 candidatePendingLayer != pendingLayers.rend(); |
| 870 ++candidatePendingLayer) { |
| 871 if (canMergeInto(paintChunk, *candidatePendingLayer)) { |
| 872 candidatePendingLayer->add(paintChunk); |
| 873 createNew = false; |
| 874 break; |
| 875 } |
| 876 if (overlaps(paintChunk, *candidatePendingLayer, geometryMapper)) { |
| 877 break; |
| 878 } |
| 879 } |
| 880 if (createNew) |
| 881 pendingLayers.append(PendingLayer(paintChunk)); |
| 882 } |
| 883 } |
| 884 |
| 758 void PaintArtifactCompositor::update( | 885 void PaintArtifactCompositor::update( |
| 759 const PaintArtifact& paintArtifact, | 886 const PaintArtifact& paintArtifact, |
| 760 RasterInvalidationTrackingMap<const PaintChunk>* rasterChunkInvalidations) { | 887 RasterInvalidationTrackingMap<const PaintChunk>* rasterChunkInvalidations) { |
| 761 DCHECK(m_rootLayer); | 888 DCHECK(m_rootLayer); |
| 762 | |
| 763 cc::LayerTree* layerTree = m_rootLayer->GetLayerTree(); | 889 cc::LayerTree* layerTree = m_rootLayer->GetLayerTree(); |
| 764 | 890 |
| 765 // The tree will be null after detaching and this update can be ignored. | 891 // The tree will be null after detaching and this update can be ignored. |
| 766 // See: WebViewImpl::detachPaintArtifactCompositor(). | 892 // See: WebViewImpl::detachPaintArtifactCompositor(). |
| 767 if (!layerTree) | 893 if (!layerTree) |
| 768 return; | 894 return; |
| 769 | 895 |
| 770 if (m_extraDataForTestingEnabled) | 896 if (m_extraDataForTestingEnabled) |
| 771 m_extraDataForTesting = wrapUnique(new ExtraDataForTesting); | 897 m_extraDataForTesting = wrapUnique(new ExtraDataForTesting); |
| 772 | 898 |
| 773 m_rootLayer->RemoveAllChildren(); | 899 m_rootLayer->RemoveAllChildren(); |
| 774 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 900 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 775 | 901 |
| 776 PropertyTreeManager propertyTreeManager(*layerTree->property_trees(), | 902 PropertyTreeManager propertyTreeManager(*layerTree->property_trees(), |
| 777 m_rootLayer.get()); | 903 m_rootLayer.get()); |
| 778 | 904 |
| 905 Vector<PendingLayer> pendingLayers; |
| 906 collectPendingLayers(paintArtifact.paintChunks(), pendingLayers); |
| 907 |
| 779 Vector<std::unique_ptr<ContentLayerClientImpl>> newContentLayerClients; | 908 Vector<std::unique_ptr<ContentLayerClientImpl>> newContentLayerClients; |
| 780 newContentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); | 909 newContentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); |
| 781 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { | 910 |
| 911 for (const PendingLayer& pendingLayer : pendingLayers) { |
| 782 gfx::Vector2dF layerOffset; | 912 gfx::Vector2dF layerOffset; |
| 783 scoped_refptr<cc::Layer> layer = layerForPaintChunk( | 913 scoped_refptr<cc::Layer> layer = compositedLayerForPendingLayer( |
| 784 paintArtifact, paintChunk, layerOffset, newContentLayerClients, | 914 paintArtifact, pendingLayer, layerOffset, newContentLayerClients, |
| 785 rasterChunkInvalidations ? rasterChunkInvalidations->find(&paintChunk) | 915 rasterChunkInvalidations); |
| 786 : nullptr); | |
| 787 | 916 |
| 788 int transformId = propertyTreeManager.compositorIdForTransformNode( | 917 int transformId = propertyTreeManager.compositorIdForTransformNode( |
| 789 paintChunk.properties.transform.get()); | 918 pendingLayer.paintChunks[0].properties.transform.get()); |
| 790 int scrollId = propertyTreeManager.compositorIdForScrollNode( | 919 int scrollId = propertyTreeManager.compositorIdForScrollNode( |
| 791 paintChunk.properties.scroll.get()); | 920 pendingLayer.paintChunks[0].properties.scroll.get()); |
| 792 int clipId = propertyTreeManager.compositorIdForClipNode( | 921 int clipId = propertyTreeManager.compositorIdForClipNode( |
| 793 paintChunk.properties.clip.get()); | 922 pendingLayer.paintChunks[0].properties.clip.get()); |
| 794 int effectId = propertyTreeManager.switchToEffectNode( | 923 int effectId = propertyTreeManager.switchToEffectNode( |
| 795 *paintChunk.properties.effect.get()); | 924 *pendingLayer.paintChunks[0].properties.effect.get()); |
| 796 | 925 |
| 797 propertyTreeManager.updateScrollOffset(layer->id(), scrollId); | 926 propertyTreeManager.updateScrollOffset(layer->id(), scrollId); |
| 798 | 927 |
| 799 layer->set_offset_to_transform_parent(layerOffset); | 928 layer->set_offset_to_transform_parent(layerOffset); |
| 800 | 929 |
| 801 m_rootLayer->AddChild(layer); | 930 m_rootLayer->AddChild(layer); |
| 802 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 931 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 803 layer->SetTransformTreeIndex(transformId); | 932 layer->SetTransformTreeIndex(transformId); |
| 804 layer->SetClipTreeIndex(clipId); | 933 layer->SetClipTreeIndex(clipId); |
| 805 layer->SetEffectTreeIndex(effectId); | 934 layer->SetEffectTreeIndex(effectId); |
| 806 layer->SetScrollTreeIndex(scrollId); | 935 layer->SetScrollTreeIndex(scrollId); |
| 807 | 936 |
| 808 // TODO(jbroman): This probably shouldn't be necessary, but it is still | 937 // TODO(jbroman): This probably shouldn't be necessary, but it is still |
| 809 // queried by RenderSurfaceImpl. | 938 // queried by RenderSurfaceImpl. |
| 810 layer->Set3dSortingContextId(layerTree->property_trees() | 939 layer->Set3dSortingContextId(layerTree->property_trees() |
| 811 ->transform_tree.Node(transformId) | 940 ->transform_tree.Node(transformId) |
| 812 ->sorting_context_id); | 941 ->sorting_context_id); |
| 813 | 942 |
| 814 layer->SetShouldCheckBackfaceVisibility( | 943 layer->SetShouldCheckBackfaceVisibility( |
| 815 paintChunk.properties.backfaceHidden); | 944 pendingLayer.paintChunks[0].properties.backfaceHidden); |
| 816 | 945 |
| 817 if (m_extraDataForTestingEnabled) | 946 if (m_extraDataForTestingEnabled) |
| 818 m_extraDataForTesting->contentLayers.append(layer); | 947 m_extraDataForTesting->contentLayers.append(layer); |
| 819 } | 948 } |
| 820 m_contentLayerClients.clear(); | 949 m_contentLayerClients.clear(); |
| 821 m_contentLayerClients.swap(newContentLayerClients); | 950 m_contentLayerClients.swap(newContentLayerClients); |
| 822 | 951 |
| 823 // Mark the property trees as having been rebuilt. | 952 // Mark the property trees as having been rebuilt. |
| 824 layerTree->property_trees()->sequence_number = kPropertyTreeSequenceNumber; | 953 layerTree->property_trees()->sequence_number = kPropertyTreeSequenceNumber; |
| 825 layerTree->property_trees()->needs_rebuild = false; | 954 layerTree->property_trees()->needs_rebuild = false; |
| 826 layerTree->property_trees()->ResetCachedData(); | 955 layerTree->property_trees()->ResetCachedData(); |
| 827 } | 956 } |
| 828 | 957 |
| 829 } // namespace blink | 958 } // namespace blink |
| OLD | NEW |