| 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/paint/display_item_list.h" | 10 #include "cc/paint/display_item_list.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 return 0; | 84 return 0; |
| 85 } | 85 } |
| 86 | 86 |
| 87 void ResetTrackedRasterInvalidations() { | 87 void ResetTrackedRasterInvalidations() { |
| 88 RasterInvalidationTracking* tracking = | 88 RasterInvalidationTracking* tracking = |
| 89 CcLayersRasterInvalidationTrackingMap().Find(cc_picture_layer_.get()); | 89 CcLayersRasterInvalidationTrackingMap().Find(cc_picture_layer_.get()); |
| 90 if (!tracking) | 90 if (!tracking) |
| 91 return; | 91 return; |
| 92 | 92 |
| 93 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) | 93 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) |
| 94 tracking->tracked_raster_invalidations.clear(); | 94 tracking->invalidations.clear(); |
| 95 else | 95 else |
| 96 CcLayersRasterInvalidationTrackingMap().Remove(cc_picture_layer_.get()); | 96 CcLayersRasterInvalidationTrackingMap().Remove(cc_picture_layer_.get()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool HasTrackedRasterInvalidations() const { | 99 bool HasTrackedRasterInvalidations() const { |
| 100 RasterInvalidationTracking* tracking = | 100 RasterInvalidationTracking* tracking = |
| 101 CcLayersRasterInvalidationTrackingMap().Find(cc_picture_layer_.get()); | 101 CcLayersRasterInvalidationTrackingMap().Find(cc_picture_layer_.get()); |
| 102 if (tracking) | 102 if (tracking) |
| 103 return !tracking->tracked_raster_invalidations.IsEmpty(); | 103 return !tracking->invalidations.IsEmpty(); |
| 104 return false; | 104 return false; |
| 105 } | 105 } |
| 106 | 106 |
| 107 void SetNeedsDisplayRect(const gfx::Rect& rect, | 107 void SetNeedsDisplayRect(const gfx::Rect& rect) { |
| 108 RasterInvalidationInfo* raster_invalidation_info) { | |
| 109 cc_picture_layer_->SetNeedsDisplayRect(rect); | 108 cc_picture_layer_->SetNeedsDisplayRect(rect); |
| 109 } |
| 110 | 110 |
| 111 if (!raster_invalidation_info || rect.IsEmpty()) | 111 void AddTrackedRasterInvalidations( |
| 112 const RasterInvalidationTracking& tracking) { |
| 113 auto& cc_tracking = |
| 114 CcLayersRasterInvalidationTrackingMap().Add(cc_picture_layer_.get()); |
| 115 cc_tracking.invalidations.AppendVector(tracking.invalidations); |
| 116 |
| 117 if (!RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) |
| 112 return; | 118 return; |
| 113 | 119 for (const auto& info : tracking.invalidations) { |
| 114 RasterInvalidationTracking& tracking = | |
| 115 CcLayersRasterInvalidationTrackingMap().Add(cc_picture_layer_.get()); | |
| 116 | |
| 117 tracking.tracked_raster_invalidations.push_back(*raster_invalidation_info); | |
| 118 | |
| 119 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { | |
| 120 // TODO(crbug.com/496260): Some antialiasing effects overflow the paint | 120 // TODO(crbug.com/496260): Some antialiasing effects overflow the paint |
| 121 // invalidation rect. | 121 // invalidation rect. |
| 122 IntRect r = raster_invalidation_info->rect; | 122 IntRect r = info.rect; |
| 123 r.Inflate(1); | 123 r.Inflate(1); |
| 124 tracking.raster_invalidation_region_since_last_paint.Unite(r); | 124 cc_tracking.invalidation_region_since_last_paint.Unite(r); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 std::unique_ptr<JSONObject> LayerAsJSON(LayerTreeFlags flags) { | 128 std::unique_ptr<JSONObject> LayerAsJSON(LayerTreeFlags flags) { |
| 129 std::unique_ptr<JSONObject> json = JSONObject::Create(); | 129 std::unique_ptr<JSONObject> json = JSONObject::Create(); |
| 130 json->SetString("name", debug_name_); | 130 json->SetString("name", debug_name_); |
| 131 IntSize bounds(cc_picture_layer_->bounds().width(), | 131 IntSize bounds(cc_picture_layer_->bounds().width(), |
| 132 cc_picture_layer_->bounds().height()); | 132 cc_picture_layer_->bounds().height()); |
| 133 if (!bounds.IsEmpty()) | 133 if (!bounds.IsEmpty()) |
| 134 json->SetArray("bounds", SizeAsJSONArray(bounds)); | 134 json->SetArray("bounds", SizeAsJSONArray(bounds)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 164 gfx::Rect paintable_region_; | 164 gfx::Rect paintable_region_; |
| 165 Vector<std::unique_ptr<JSONArray>> paint_chunk_debug_data_; | 165 Vector<std::unique_ptr<JSONArray>> paint_chunk_debug_data_; |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 PaintArtifactCompositor::PaintArtifactCompositor() { | 168 PaintArtifactCompositor::PaintArtifactCompositor() { |
| 169 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 169 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 170 return; | 170 return; |
| 171 root_layer_ = cc::Layer::Create(); | 171 root_layer_ = cc::Layer::Create(); |
| 172 web_layer_ = Platform::Current()->CompositorSupport()->CreateLayerFromCCLayer( | 172 web_layer_ = Platform::Current()->CompositorSupport()->CreateLayerFromCCLayer( |
| 173 root_layer_.get()); | 173 root_layer_.get()); |
| 174 is_tracking_raster_invalidations_ = false; | |
| 175 } | 174 } |
| 176 | 175 |
| 177 PaintArtifactCompositor::~PaintArtifactCompositor() {} | 176 PaintArtifactCompositor::~PaintArtifactCompositor() {} |
| 178 | 177 |
| 179 void PaintArtifactCompositor::SetTracksRasterInvalidations( | |
| 180 bool tracks_paint_invalidations) { | |
| 181 ResetTrackedRasterInvalidations(); | |
| 182 is_tracking_raster_invalidations_ = tracks_paint_invalidations; | |
| 183 } | |
| 184 | |
| 185 void PaintArtifactCompositor::ResetTrackedRasterInvalidations() { | 178 void PaintArtifactCompositor::ResetTrackedRasterInvalidations() { |
| 186 for (auto& client : content_layer_clients_) | 179 for (auto& client : content_layer_clients_) |
| 187 client->ResetTrackedRasterInvalidations(); | 180 client->ResetTrackedRasterInvalidations(); |
| 188 } | 181 } |
| 189 | 182 |
| 190 bool PaintArtifactCompositor::HasTrackedRasterInvalidations() const { | 183 bool PaintArtifactCompositor::HasTrackedRasterInvalidations() const { |
| 191 for (auto& client : content_layer_clients_) { | 184 for (auto& client : content_layer_clients_) { |
| 192 if (client->HasTrackedRasterInvalidations()) | 185 if (client->HasTrackedRasterInvalidations()) |
| 193 return true; | 186 return true; |
| 194 } | 187 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 gfx::Rect(cc_combined_bounds.size())); | 275 gfx::Rect(cc_combined_bounds.size())); |
| 283 | 276 |
| 284 scoped_refptr<cc::PictureLayer> cc_picture_layer = | 277 scoped_refptr<cc::PictureLayer> cc_picture_layer = |
| 285 content_layer_client->CcPictureLayer(); | 278 content_layer_client->CcPictureLayer(); |
| 286 cc_picture_layer->SetBounds(cc_combined_bounds.size()); | 279 cc_picture_layer->SetBounds(cc_combined_bounds.size()); |
| 287 cc_picture_layer->SetIsDrawable(true); | 280 cc_picture_layer->SetIsDrawable(true); |
| 288 cc_picture_layer->SetContentsOpaque(pending_layer.known_to_be_opaque); | 281 cc_picture_layer->SetContentsOpaque(pending_layer.known_to_be_opaque); |
| 289 content_layer_client->ClearPaintChunkDebugData(); | 282 content_layer_client->ClearPaintChunkDebugData(); |
| 290 | 283 |
| 291 for (const auto& paint_chunk : pending_layer.paint_chunks) { | 284 for (const auto& paint_chunk : pending_layer.paint_chunks) { |
| 292 RasterInvalidationTracking* raster_tracking = | |
| 293 tracking_map ? tracking_map->Find(paint_chunk) : nullptr; | |
| 294 DCHECK(!raster_tracking || | |
| 295 raster_tracking->tracked_raster_invalidations.size() == | |
| 296 paint_chunk->raster_invalidation_rects.size()); | |
| 297 | |
| 298 if (store_debug_info) { | 285 if (store_debug_info) { |
| 299 content_layer_client->AddPaintChunkDebugData( | 286 content_layer_client->AddPaintChunkDebugData( |
| 300 paint_artifact.GetDisplayItemList().SubsequenceAsJSON( | 287 paint_artifact.GetDisplayItemList().SubsequenceAsJSON( |
| 301 paint_chunk->begin_index, paint_chunk->end_index, | 288 paint_chunk->begin_index, paint_chunk->end_index, |
| 302 DisplayItemList::kSkipNonDrawings | | 289 DisplayItemList::kSkipNonDrawings | |
| 303 DisplayItemList::kShownOnlyDisplayItemTypes)); | 290 DisplayItemList::kShownOnlyDisplayItemTypes)); |
| 304 } | 291 } |
| 305 | 292 |
| 306 for (unsigned index = 0; | 293 for (const auto& r : paint_chunk->raster_invalidation_rects) { |
| 307 index < paint_chunk->raster_invalidation_rects.size(); ++index) { | 294 IntRect rect(EnclosingIntRect(r)); |
| 308 IntRect rect( | |
| 309 EnclosingIntRect(paint_chunk->raster_invalidation_rects[index])); | |
| 310 gfx::Rect cc_invalidation_rect(rect.X(), rect.Y(), | 295 gfx::Rect cc_invalidation_rect(rect.X(), rect.Y(), |
| 311 std::max(0, rect.Width()), | 296 std::max(0, rect.Width()), |
| 312 std::max(0, rect.Height())); | 297 std::max(0, rect.Height())); |
| 313 if (cc_invalidation_rect.IsEmpty()) | 298 if (cc_invalidation_rect.IsEmpty()) |
| 314 continue; | 299 continue; |
| 315 // Raster paintChunk.rasterInvalidationRects is in the space of the | 300 // Raster paintChunk.rasterInvalidationRects is in the space of the |
| 316 // containing transform node, so need to subtract off the layer offset. | 301 // containing transform node, so need to subtract off the layer offset. |
| 317 cc_invalidation_rect.Offset(-cc_combined_bounds.OffsetFromOrigin()); | 302 cc_invalidation_rect.Offset(-cc_combined_bounds.OffsetFromOrigin()); |
| 318 content_layer_client->SetNeedsDisplayRect( | 303 content_layer_client->SetNeedsDisplayRect(cc_invalidation_rect); |
| 319 cc_invalidation_rect, | |
| 320 raster_tracking | |
| 321 ? &raster_tracking->tracked_raster_invalidations[index] | |
| 322 : nullptr); | |
| 323 } | 304 } |
| 305 |
| 306 if (auto* raster_tracking = |
| 307 tracking_map ? tracking_map->Find(paint_chunk) : nullptr) |
| 308 content_layer_client->AddTrackedRasterInvalidations(*raster_tracking); |
| 324 } | 309 } |
| 325 | 310 |
| 326 new_content_layer_clients.push_back(std::move(content_layer_client)); | 311 new_content_layer_clients.push_back(std::move(content_layer_client)); |
| 327 return cc_picture_layer; | 312 return cc_picture_layer; |
| 328 } | 313 } |
| 329 | 314 |
| 330 PaintArtifactCompositor::PendingLayer::PendingLayer( | 315 PaintArtifactCompositor::PendingLayer::PendingLayer( |
| 331 const PaintChunk& first_paint_chunk, | 316 const PaintChunk& first_paint_chunk, |
| 332 bool chunk_is_foreign) | 317 bool chunk_is_foreign) |
| 333 : bounds(first_paint_chunk.bounds), | 318 : bounds(first_paint_chunk.bounds), |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 #ifndef NDEBUG | 682 #ifndef NDEBUG |
| 698 void PaintArtifactCompositor::ShowDebugData() { | 683 void PaintArtifactCompositor::ShowDebugData() { |
| 699 LOG(ERROR) << LayersAsJSON(kLayerTreeIncludesDebugInfo) | 684 LOG(ERROR) << LayersAsJSON(kLayerTreeIncludesDebugInfo) |
| 700 ->ToPrettyJSONString() | 685 ->ToPrettyJSONString() |
| 701 .Utf8() | 686 .Utf8() |
| 702 .data(); | 687 .data(); |
| 703 } | 688 } |
| 704 #endif | 689 #endif |
| 705 | 690 |
| 706 } // namespace blink | 691 } // namespace blink |
| OLD | NEW |