OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/paint/PaintController.h" | 5 #include "platform/graphics/paint/PaintController.h" |
6 | 6 |
7 #include "platform/graphics/GraphicsLayer.h" | 7 #include "platform/graphics/GraphicsLayer.h" |
8 #include "platform/graphics/paint/DrawingDisplayItem.h" | 8 #include "platform/graphics/paint/DrawingDisplayItem.h" |
9 #include "platform/instrumentation/tracing/TraceEvent.h" | 9 #include "platform/instrumentation/tracing/TraceEvent.h" |
10 #include "platform/wtf/AutoReset.h" | 10 #include "platform/wtf/AutoReset.h" |
11 #include "platform/wtf/text/StringBuilder.h" | 11 #include "platform/wtf/text/StringBuilder.h" |
12 #include "third_party/skia/include/core/SkPictureAnalyzer.h" | 12 #include "third_party/skia/include/core/SkPictureAnalyzer.h" |
13 | 13 |
14 #ifndef NDEBUG | 14 #ifndef NDEBUG |
15 #include "platform/graphics/LoggingCanvas.h" | 15 #include "platform/graphics/LoggingCanvas.h" |
16 #include <stdio.h> | 16 #include <stdio.h> |
17 #endif | 17 #endif |
18 | 18 |
| 19 static constexpr int kMaxNumberOfSlowPathsBeforeVeto = 5; |
| 20 |
19 namespace blink { | 21 namespace blink { |
20 | 22 |
21 void PaintController::SetTracksRasterInvalidations(bool value) { | 23 void PaintController::SetTracksRasterInvalidations(bool value) { |
22 if (value) { | 24 if (value) { |
23 paint_chunks_raster_invalidation_tracking_map_ = | 25 paint_chunks_raster_invalidation_tracking_map_ = |
24 WTF::WrapUnique(new RasterInvalidationTrackingMap<const PaintChunk>); | 26 WTF::WrapUnique(new RasterInvalidationTrackingMap<const PaintChunk>); |
25 } else { | 27 } else { |
26 paint_chunks_raster_invalidation_tracking_map_ = nullptr; | 28 paint_chunks_raster_invalidation_tracking_map_ = nullptr; |
27 } | 29 } |
28 } | 30 } |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 // These data structures are used during painting only. | 530 // These data structures are used during painting only. |
529 DCHECK(!IsSkippingCache()); | 531 DCHECK(!IsSkippingCache()); |
530 #if DCHECK_IS_ON() | 532 #if DCHECK_IS_ON() |
531 new_display_item_indices_by_client_.Clear(); | 533 new_display_item_indices_by_client_.Clear(); |
532 #endif | 534 #endif |
533 | 535 |
534 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && | 536 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && |
535 !new_display_item_list_.IsEmpty()) | 537 !new_display_item_list_.IsEmpty()) |
536 GenerateChunkRasterInvalidationRects(new_paint_chunks_.LastChunk()); | 538 GenerateChunkRasterInvalidationRects(new_paint_chunks_.LastChunk()); |
537 | 539 |
538 SkPictureGpuAnalyzer gpu_analyzer; | 540 int num_slow_paths = 0; |
539 | 541 |
540 current_cache_generation_ = | 542 current_cache_generation_ = |
541 DisplayItemClient::CacheGenerationOrInvalidationReason::Next(); | 543 DisplayItemClient::CacheGenerationOrInvalidationReason::Next(); |
542 | 544 |
543 new_cached_subsequences_.Swap(current_cached_subsequences_); | 545 new_cached_subsequences_.Swap(current_cached_subsequences_); |
544 new_cached_subsequences_.Clear(); | 546 new_cached_subsequences_.Clear(); |
545 last_cached_subsequence_end_ = 0; | 547 last_cached_subsequence_end_ = 0; |
546 for (auto& item : current_cached_subsequences_) { | 548 for (auto& item : current_cached_subsequences_) { |
547 item.key->SetDisplayItemsCached(current_cache_generation_); | 549 item.key->SetDisplayItemsCached(current_cache_generation_); |
548 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS | 550 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS |
549 DisplayItemClient::EndShouldKeepAliveAllClients(item.key); | 551 DisplayItemClient::EndShouldKeepAliveAllClients(item.key); |
550 DCHECK(current_subsequence_clients_.IsEmpty()); | 552 DCHECK(current_subsequence_clients_.IsEmpty()); |
551 #endif | 553 #endif |
552 } | 554 } |
553 | 555 |
554 Vector<const DisplayItemClient*> skipped_cache_clients; | 556 Vector<const DisplayItemClient*> skipped_cache_clients; |
555 for (const auto& item : new_display_item_list_) { | 557 for (const auto& item : new_display_item_list_) { |
556 // No reason to continue the analysis once we have a veto. | 558 // No reason to continue the analysis once we have a veto. |
557 if (gpu_analyzer.suitableForGpuRasterization()) | 559 if (num_slow_paths <= kMaxNumberOfSlowPathsBeforeVeto) |
558 item.AnalyzeForGpuRasterization(gpu_analyzer); | 560 num_slow_paths += item.NumberOfSlowPaths(); |
559 | 561 |
560 // TODO(wkorman): Only compute and append visual rect for drawings. | 562 // TODO(wkorman): Only compute and append visual rect for drawings. |
561 new_display_item_list_.AppendVisualRect( | 563 new_display_item_list_.AppendVisualRect( |
562 VisualRectForDisplayItem(item, offset_from_layout_object)); | 564 VisualRectForDisplayItem(item, offset_from_layout_object)); |
563 | 565 |
564 if (item.IsCacheable()) { | 566 if (item.IsCacheable()) { |
565 item.Client().SetDisplayItemsCached(current_cache_generation_); | 567 item.Client().SetDisplayItemsCached(current_cache_generation_); |
566 } else { | 568 } else { |
567 if (item.Client().IsJustCreated()) | 569 if (item.Client().IsJustCreated()) |
568 item.Client().ClearIsJustCreated(); | 570 item.Client().ClearIsJustCreated(); |
(...skipping 17 matching lines...) Expand all Loading... |
586 } | 588 } |
587 } | 589 } |
588 | 590 |
589 for (auto* client : skipped_cache_clients) | 591 for (auto* client : skipped_cache_clients) |
590 client->SetDisplayItemsUncached(); | 592 client->SetDisplayItemsUncached(); |
591 | 593 |
592 // The new list will not be appended to again so we can release unused memory. | 594 // The new list will not be appended to again so we can release unused memory. |
593 new_display_item_list_.ShrinkToFit(); | 595 new_display_item_list_.ShrinkToFit(); |
594 current_paint_artifact_ = PaintArtifact( | 596 current_paint_artifact_ = PaintArtifact( |
595 std::move(new_display_item_list_), new_paint_chunks_.ReleasePaintChunks(), | 597 std::move(new_display_item_list_), new_paint_chunks_.ReleasePaintChunks(), |
596 gpu_analyzer.suitableForGpuRasterization()); | 598 num_slow_paths <= kMaxNumberOfSlowPathsBeforeVeto); |
597 ResetCurrentListIndices(); | 599 ResetCurrentListIndices(); |
598 out_of_order_item_indices_.Clear(); | 600 out_of_order_item_indices_.Clear(); |
599 out_of_order_chunk_indices_.Clear(); | 601 out_of_order_chunk_indices_.Clear(); |
600 items_moved_into_new_list_.Clear(); | 602 items_moved_into_new_list_.Clear(); |
601 | 603 |
602 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { | 604 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { |
603 for (const auto& chunk : current_paint_artifact_.PaintChunks()) { | 605 for (const auto& chunk : current_paint_artifact_.PaintChunks()) { |
604 if (chunk.id && chunk.id->client.IsJustCreated()) | 606 if (chunk.id && chunk.id->client.IsJustCreated()) |
605 chunk.id->client.ClearIsJustCreated(); | 607 chunk.id->client.ClearIsJustCreated(); |
606 } | 608 } |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 show_paint_records | 934 show_paint_records |
933 ? (DisplayItemList::JsonOptions::kShowPaintRecords | | 935 ? (DisplayItemList::JsonOptions::kShowPaintRecords | |
934 DisplayItemList::JsonOptions::kShowClientDebugName) | 936 DisplayItemList::JsonOptions::kShowClientDebugName) |
935 : DisplayItemList::JsonOptions::kShowClientDebugName) | 937 : DisplayItemList::JsonOptions::kShowClientDebugName) |
936 ->ToPrettyJSONString() | 938 ->ToPrettyJSONString() |
937 .Utf8() | 939 .Utf8() |
938 .Data()); | 940 .Data()); |
939 } | 941 } |
940 | 942 |
941 } // namespace blink | 943 } // namespace blink |
OLD | NEW |