| 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" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 ContentLayerClientImpl(DisplayItem::Id paintChunkId) | 70 ContentLayerClientImpl(DisplayItem::Id paintChunkId) |
| 71 : m_id(paintChunkId), | 71 : m_id(paintChunkId), |
| 72 m_debugName(paintChunkId.client.debugName()), | 72 m_debugName(paintChunkId.client.debugName()), |
| 73 m_ccPictureLayer(cc::PictureLayer::Create(this)) {} | 73 m_ccPictureLayer(cc::PictureLayer::Create(this)) {} |
| 74 | 74 |
| 75 void SetDisplayList(scoped_refptr<cc::DisplayItemList> ccDisplayItemList) { | 75 void SetDisplayList(scoped_refptr<cc::DisplayItemList> ccDisplayItemList) { |
| 76 m_ccDisplayItemList = std::move(ccDisplayItemList); | 76 m_ccDisplayItemList = std::move(ccDisplayItemList); |
| 77 } | 77 } |
| 78 void SetPaintableRegion(gfx::Rect region) { m_paintableRegion = region; } | 78 void SetPaintableRegion(gfx::Rect region) { m_paintableRegion = region; } |
| 79 | 79 |
| 80 void addPaintChunkDebugData(std::unique_ptr<JSONArray> json) { |
| 81 m_paintChunkDebugData.append(std::move(json)); |
| 82 } |
| 83 void clearPaintChunkDebugData() { m_paintChunkDebugData.clear(); } |
| 84 |
| 80 // cc::ContentLayerClient | 85 // cc::ContentLayerClient |
| 81 gfx::Rect PaintableRegion() override { return m_paintableRegion; } | 86 gfx::Rect PaintableRegion() override { return m_paintableRegion; } |
| 82 scoped_refptr<cc::DisplayItemList> PaintContentsToDisplayList( | 87 scoped_refptr<cc::DisplayItemList> PaintContentsToDisplayList( |
| 83 PaintingControlSetting) override { | 88 PaintingControlSetting) override { |
| 84 return m_ccDisplayItemList; | 89 return m_ccDisplayItemList; |
| 85 } | 90 } |
| 86 bool FillsBoundsCompletely() const override { return false; } | 91 bool FillsBoundsCompletely() const override { return false; } |
| 87 size_t GetApproximateUnsharedMemoryUsage() const override { | 92 size_t GetApproximateUnsharedMemoryUsage() const override { |
| 88 // TODO(jbroman): Actually calculate memory usage. | 93 // TODO(jbroman): Actually calculate memory usage. |
| 89 return 0; | 94 return 0; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 128 |
| 124 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { | 129 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { |
| 125 // TODO(crbug.com/496260): Some antialiasing effects overflow the paint | 130 // TODO(crbug.com/496260): Some antialiasing effects overflow the paint |
| 126 // invalidation rect. | 131 // invalidation rect. |
| 127 IntRect r = rasterInvalidationInfo->rect; | 132 IntRect r = rasterInvalidationInfo->rect; |
| 128 r.inflate(1); | 133 r.inflate(1); |
| 129 tracking.rasterInvalidationRegionSinceLastPaint.unite(r); | 134 tracking.rasterInvalidationRegionSinceLastPaint.unite(r); |
| 130 } | 135 } |
| 131 } | 136 } |
| 132 | 137 |
| 133 std::unique_ptr<JSONObject> layerAsJSON() { | 138 std::unique_ptr<JSONObject> layerAsJSON(LayerTreeFlags flags) { |
| 134 std::unique_ptr<JSONObject> json = JSONObject::create(); | 139 std::unique_ptr<JSONObject> json = JSONObject::create(); |
| 135 json->setString("name", m_debugName); | 140 json->setString("name", m_debugName); |
| 136 IntSize bounds(m_ccPictureLayer->bounds().width(), | 141 IntSize bounds(m_ccPictureLayer->bounds().width(), |
| 137 m_ccPictureLayer->bounds().height()); | 142 m_ccPictureLayer->bounds().height()); |
| 138 if (!bounds.isEmpty()) | 143 if (!bounds.isEmpty()) |
| 139 json->setArray("bounds", sizeAsJSONArray(bounds)); | 144 json->setArray("bounds", sizeAsJSONArray(bounds)); |
| 140 json->setBoolean("contentsOpaque", m_ccPictureLayer->contents_opaque()); | 145 json->setBoolean("contentsOpaque", m_ccPictureLayer->contents_opaque()); |
| 141 json->setBoolean("drawsContent", m_ccPictureLayer->DrawsContent()); | 146 json->setBoolean("drawsContent", m_ccPictureLayer->DrawsContent()); |
| 142 | 147 |
| 148 if (flags & LayerTreeIncludesDebugInfo) { |
| 149 std::unique_ptr<JSONArray> paintChunkContentsArray = JSONArray::create(); |
| 150 for (const auto& debugData : m_paintChunkDebugData) { |
| 151 paintChunkContentsArray->pushValue(debugData->clone()); |
| 152 } |
| 153 json->setArray("paintChunkContents", std::move(paintChunkContentsArray)); |
| 154 } |
| 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; | 169 String m_debugName; |
| 157 scoped_refptr<cc::PictureLayer> m_ccPictureLayer; | 170 scoped_refptr<cc::PictureLayer> m_ccPictureLayer; |
| 158 scoped_refptr<cc::DisplayItemList> m_ccDisplayItemList; | 171 scoped_refptr<cc::DisplayItemList> m_ccDisplayItemList; |
| 159 gfx::Rect m_paintableRegion; | 172 gfx::Rect m_paintableRegion; |
| 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 16 matching lines...) Expand all Loading... |
| 186 if (client->hasTrackedRasterInvalidations()) | 200 if (client->hasTrackedRasterInvalidations()) |
| 187 return true; | 201 return true; |
| 188 } | 202 } |
| 189 return false; | 203 return false; |
| 190 } | 204 } |
| 191 | 205 |
| 192 std::unique_ptr<JSONObject> PaintArtifactCompositor::layersAsJSON( | 206 std::unique_ptr<JSONObject> PaintArtifactCompositor::layersAsJSON( |
| 193 LayerTreeFlags flags) const { | 207 LayerTreeFlags flags) const { |
| 194 std::unique_ptr<JSONArray> layersJSON = JSONArray::create(); | 208 std::unique_ptr<JSONArray> layersJSON = JSONArray::create(); |
| 195 for (const auto& client : m_contentLayerClients) { | 209 for (const auto& client : m_contentLayerClients) { |
| 196 layersJSON->pushObject(client->layerAsJSON()); | 210 layersJSON->pushObject(client->layerAsJSON(flags)); |
| 197 } | 211 } |
| 198 std::unique_ptr<JSONObject> json = JSONObject::create(); | 212 std::unique_ptr<JSONObject> json = JSONObject::create(); |
| 199 json->setArray("layers", std::move(layersJSON)); | 213 json->setArray("layers", std::move(layersJSON)); |
| 200 return json; | 214 return json; |
| 201 } | 215 } |
| 202 | 216 |
| 203 namespace { | 217 namespace { |
| 204 | 218 |
| 205 static gfx::Rect largeRect(-200000, -200000, 400000, 400000); | 219 static gfx::Rect largeRect(-200000, -200000, 400000, 400000); |
| 206 | 220 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 paintChunk.id | 308 paintChunk.id |
| 295 ? *paintChunk.id | 309 ? *paintChunk.id |
| 296 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); | 310 : paintArtifact.getDisplayItemList()[paintChunk.beginIndex].getId())); |
| 297 } | 311 } |
| 298 | 312 |
| 299 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk( | 313 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk( |
| 300 const PaintArtifact& paintArtifact, | 314 const PaintArtifact& paintArtifact, |
| 301 const PaintChunk& paintChunk, | 315 const PaintChunk& paintChunk, |
| 302 gfx::Vector2dF& layerOffset, | 316 gfx::Vector2dF& layerOffset, |
| 303 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, | 317 Vector<std::unique_ptr<ContentLayerClientImpl>>& newContentLayerClients, |
| 304 RasterInvalidationTracking* tracking) { | 318 RasterInvalidationTracking* tracking, |
| 319 bool storeDebugInfo) { |
| 305 DCHECK(paintChunk.size()); | 320 DCHECK(paintChunk.size()); |
| 306 | 321 |
| 307 // If the paint chunk is a foreign layer, just return that layer. | 322 // If the paint chunk is a foreign layer, just return that layer. |
| 308 if (scoped_refptr<cc::Layer> foreignLayer = | 323 if (scoped_refptr<cc::Layer> foreignLayer = |
| 309 foreignLayerForPaintChunk(paintArtifact, paintChunk, layerOffset)) | 324 foreignLayerForPaintChunk(paintArtifact, paintChunk, layerOffset)) |
| 310 return foreignLayer; | 325 return foreignLayer; |
| 311 | 326 |
| 312 // The common case: create or reuse a PictureLayer for painted content. | 327 // The common case: create or reuse a PictureLayer for painted content. |
| 313 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = | 328 std::unique_ptr<ContentLayerClientImpl> contentLayerClient = |
| 314 clientForPaintChunk(paintChunk, paintArtifact); | 329 clientForPaintChunk(paintChunk, paintArtifact); |
| 315 | 330 |
| 316 gfx::Rect combinedBounds = enclosingIntRect(paintChunk.bounds); | 331 gfx::Rect combinedBounds = enclosingIntRect(paintChunk.bounds); |
| 317 scoped_refptr<cc::DisplayItemList> displayList = | 332 scoped_refptr<cc::DisplayItemList> displayList = |
| 318 recordPaintChunk(paintArtifact, paintChunk, combinedBounds); | 333 recordPaintChunk(paintArtifact, paintChunk, combinedBounds); |
| 319 contentLayerClient->SetDisplayList(std::move(displayList)); | 334 contentLayerClient->SetDisplayList(std::move(displayList)); |
| 320 contentLayerClient->SetPaintableRegion(gfx::Rect(combinedBounds.size())); | 335 contentLayerClient->SetPaintableRegion(gfx::Rect(combinedBounds.size())); |
| 321 | 336 |
| 322 layerOffset = combinedBounds.OffsetFromOrigin(); | 337 layerOffset = combinedBounds.OffsetFromOrigin(); |
| 323 scoped_refptr<cc::PictureLayer> ccPictureLayer = | 338 scoped_refptr<cc::PictureLayer> ccPictureLayer = |
| 324 contentLayerClient->ccPictureLayer(); | 339 contentLayerClient->ccPictureLayer(); |
| 325 ccPictureLayer->SetBounds(combinedBounds.size()); | 340 ccPictureLayer->SetBounds(combinedBounds.size()); |
| 326 ccPictureLayer->SetIsDrawable(true); | 341 ccPictureLayer->SetIsDrawable(true); |
| 327 if (paintChunk.knownToBeOpaque) | 342 if (paintChunk.knownToBeOpaque) |
| 328 ccPictureLayer->SetContentsOpaque(true); | 343 ccPictureLayer->SetContentsOpaque(true); |
| 329 DCHECK(!tracking || | 344 DCHECK(!tracking || |
| 330 tracking->trackedRasterInvalidations.size() == | 345 tracking->trackedRasterInvalidations.size() == |
| 331 paintChunk.rasterInvalidationRects.size()); | 346 paintChunk.rasterInvalidationRects.size()); |
| 347 |
| 348 contentLayerClient->clearPaintChunkDebugData(); |
| 349 if (storeDebugInfo) { |
| 350 contentLayerClient->addPaintChunkDebugData( |
| 351 paintArtifact.getDisplayItemList().subsequenceAsJSON( |
| 352 paintChunk.beginIndex, paintChunk.endIndex, |
| 353 DisplayItemList::SkipNonDrawings | |
| 354 DisplayItemList::ShownOnlyDisplayItemTypes)); |
| 355 } |
| 356 |
| 332 for (unsigned index = 0; index < paintChunk.rasterInvalidationRects.size(); | 357 for (unsigned index = 0; index < paintChunk.rasterInvalidationRects.size(); |
| 333 ++index) { | 358 ++index) { |
| 334 IntRect rect(enclosingIntRect(paintChunk.rasterInvalidationRects[index])); | 359 IntRect rect(enclosingIntRect(paintChunk.rasterInvalidationRects[index])); |
| 335 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), std::max(0, rect.width()), | 360 gfx::Rect ccInvalidationRect(rect.x(), rect.y(), std::max(0, rect.width()), |
| 336 std::max(0, rect.height())); | 361 std::max(0, rect.height())); |
| 337 // Raster paintChunk.rasterInvalidationRects is in the space of the | 362 // Raster paintChunk.rasterInvalidationRects is in the space of the |
| 338 // containing transform node, so need to subtract off the layer offset. | 363 // containing transform node, so need to subtract off the layer offset. |
| 339 ccInvalidationRect.Offset(-combinedBounds.OffsetFromOrigin()); | 364 ccInvalidationRect.Offset(-combinedBounds.OffsetFromOrigin()); |
| 340 contentLayerClient->setNeedsDisplayRect( | 365 contentLayerClient->setNeedsDisplayRect( |
| 341 ccInvalidationRect, | 366 ccInvalidationRect, |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); | 786 dummyLayer->SetTransformTreeIndex(kSecondaryRootNodeId); |
| 762 dummyLayer->SetClipTreeIndex(outputClipId); | 787 dummyLayer->SetClipTreeIndex(outputClipId); |
| 763 dummyLayer->SetEffectTreeIndex(effectNode.id); | 788 dummyLayer->SetEffectTreeIndex(effectNode.id); |
| 764 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); | 789 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); |
| 765 } | 790 } |
| 766 | 791 |
| 767 } // namespace | 792 } // namespace |
| 768 | 793 |
| 769 void PaintArtifactCompositor::update( | 794 void PaintArtifactCompositor::update( |
| 770 const PaintArtifact& paintArtifact, | 795 const PaintArtifact& paintArtifact, |
| 771 RasterInvalidationTrackingMap<const PaintChunk>* rasterChunkInvalidations) { | 796 RasterInvalidationTrackingMap<const PaintChunk>* rasterChunkInvalidations, |
| 797 bool storeDebugInfo) { |
| 772 DCHECK(m_rootLayer); | 798 DCHECK(m_rootLayer); |
| 773 | 799 |
| 774 cc::LayerTree* layerTree = m_rootLayer->GetLayerTree(); | 800 cc::LayerTree* layerTree = m_rootLayer->GetLayerTree(); |
| 775 | 801 |
| 776 // The tree will be null after detaching and this update can be ignored. | 802 // The tree will be null after detaching and this update can be ignored. |
| 777 // See: WebViewImpl::detachPaintArtifactCompositor(). | 803 // See: WebViewImpl::detachPaintArtifactCompositor(). |
| 778 if (!layerTree) | 804 if (!layerTree) |
| 779 return; | 805 return; |
| 780 | 806 |
| 781 if (m_extraDataForTestingEnabled) | 807 if (m_extraDataForTestingEnabled) |
| 782 m_extraDataForTesting = WTF::wrapUnique(new ExtraDataForTesting); | 808 m_extraDataForTesting = WTF::wrapUnique(new ExtraDataForTesting); |
| 783 | 809 |
| 784 m_rootLayer->RemoveAllChildren(); | 810 m_rootLayer->RemoveAllChildren(); |
| 785 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 811 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 786 | 812 |
| 787 PropertyTreeManager propertyTreeManager(*layerTree->property_trees(), | 813 PropertyTreeManager propertyTreeManager(*layerTree->property_trees(), |
| 788 m_rootLayer.get()); | 814 m_rootLayer.get()); |
| 789 | 815 |
| 790 Vector<std::unique_ptr<ContentLayerClientImpl>> newContentLayerClients; | 816 Vector<std::unique_ptr<ContentLayerClientImpl>> newContentLayerClients; |
| 791 newContentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); | 817 newContentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); |
| 792 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { | 818 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { |
| 793 gfx::Vector2dF layerOffset; | 819 gfx::Vector2dF layerOffset; |
| 794 scoped_refptr<cc::Layer> layer = layerForPaintChunk( | 820 scoped_refptr<cc::Layer> layer = layerForPaintChunk( |
| 795 paintArtifact, paintChunk, layerOffset, newContentLayerClients, | 821 paintArtifact, paintChunk, layerOffset, newContentLayerClients, |
| 796 rasterChunkInvalidations ? rasterChunkInvalidations->find(&paintChunk) | 822 rasterChunkInvalidations ? rasterChunkInvalidations->find(&paintChunk) |
| 797 : nullptr); | 823 : nullptr, |
| 824 storeDebugInfo); |
| 798 | 825 |
| 799 int transformId = propertyTreeManager.compositorIdForTransformNode( | 826 int transformId = propertyTreeManager.compositorIdForTransformNode( |
| 800 paintChunk.properties.propertyTreeState.transform()); | 827 paintChunk.properties.propertyTreeState.transform()); |
| 801 int scrollId = propertyTreeManager.compositorIdForScrollNode( | 828 int scrollId = propertyTreeManager.compositorIdForScrollNode( |
| 802 paintChunk.properties.propertyTreeState.scroll()); | 829 paintChunk.properties.propertyTreeState.scroll()); |
| 803 int clipId = propertyTreeManager.compositorIdForClipNode( | 830 int clipId = propertyTreeManager.compositorIdForClipNode( |
| 804 paintChunk.properties.propertyTreeState.clip()); | 831 paintChunk.properties.propertyTreeState.clip()); |
| 805 int effectId = propertyTreeManager.switchToEffectNode( | 832 int effectId = propertyTreeManager.switchToEffectNode( |
| 806 *paintChunk.properties.propertyTreeState.effect()); | 833 *paintChunk.properties.propertyTreeState.effect()); |
| 807 | 834 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 831 m_contentLayerClients.clear(); | 858 m_contentLayerClients.clear(); |
| 832 m_contentLayerClients.swap(newContentLayerClients); | 859 m_contentLayerClients.swap(newContentLayerClients); |
| 833 | 860 |
| 834 // Mark the property trees as having been rebuilt. | 861 // Mark the property trees as having been rebuilt. |
| 835 layerTree->property_trees()->sequence_number = kPropertyTreeSequenceNumber; | 862 layerTree->property_trees()->sequence_number = kPropertyTreeSequenceNumber; |
| 836 layerTree->property_trees()->needs_rebuild = false; | 863 layerTree->property_trees()->needs_rebuild = false; |
| 837 layerTree->property_trees()->ResetCachedData(); | 864 layerTree->property_trees()->ResetCachedData(); |
| 838 } | 865 } |
| 839 | 866 |
| 840 } // namespace blink | 867 } // namespace blink |
| OLD | NEW |