Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/PaintController.cpp

Issue 2868283003: [SPv2] Renaming and refactor about raster invalidation tracking (Closed)
Patch Set: - Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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; 19 static constexpr int kMaxNumberOfSlowPathsBeforeVeto = 5;
20 20
21 namespace blink { 21 namespace blink {
22 22
23 void PaintController::SetTracksRasterInvalidations(bool value) { 23 void PaintController::SetTracksRasterInvalidations(bool value) {
24 if (value || 24 if (value ||
25 RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { 25 RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) {
26 paint_chunks_raster_invalidation_tracking_map_ = 26 raster_invalidation_tracking_map_ =
27 WTF::WrapUnique(new RasterInvalidationTrackingMap<const PaintChunk>); 27 WTF::WrapUnique(new RasterInvalidationTrackingMap<const PaintChunk>);
28 } else { 28 } else {
29 paint_chunks_raster_invalidation_tracking_map_ = nullptr; 29 raster_invalidation_tracking_map_ = nullptr;
30 } 30 }
31 } 31 }
32 32
33 const PaintArtifact& PaintController::GetPaintArtifact() const { 33 const PaintArtifact& PaintController::GetPaintArtifact() const {
34 DCHECK(new_display_item_list_.IsEmpty()); 34 DCHECK(new_display_item_list_.IsEmpty());
35 DCHECK(new_paint_chunks_.IsInInitialState()); 35 DCHECK(new_paint_chunks_.IsInInitialState());
36 return current_paint_artifact_; 36 return current_paint_artifact_;
37 } 37 }
38 38
39 bool PaintController::UseCachedDrawingIfPossible( 39 bool PaintController::UseCachedDrawingIfPossible(
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 245 }
246 #endif 246 #endif
247 247
248 if (IsSkippingCache()) 248 if (IsSkippingCache())
249 display_item.SetSkippedCache(); 249 display_item.SetSkippedCache();
250 250
251 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { 251 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
252 size_t last_chunk_index = new_paint_chunks_.LastChunkIndex(); 252 size_t last_chunk_index = new_paint_chunks_.LastChunkIndex();
253 if (new_paint_chunks_.IncrementDisplayItemIndex(display_item)) { 253 if (new_paint_chunks_.IncrementDisplayItemIndex(display_item)) {
254 DCHECK(last_chunk_index != new_paint_chunks_.LastChunkIndex()); 254 DCHECK(last_chunk_index != new_paint_chunks_.LastChunkIndex());
255 if (last_chunk_index != kNotFound) 255 if (last_chunk_index != kNotFound) {
256 GenerateChunkRasterInvalidationRects( 256 GenerateRasterInvalidations(
257 new_paint_chunks_.PaintChunkAt(last_chunk_index)); 257 new_paint_chunks_.PaintChunkAt(last_chunk_index));
258 }
258 } 259 }
259 } 260 }
260 261
261 #if DCHECK_IS_ON() 262 #if DCHECK_IS_ON()
262 // Verify noop begin/end pairs have been removed. 263 // Verify noop begin/end pairs have been removed.
263 if (new_display_item_list_.size() >= 2 && display_item.IsEnd()) { 264 if (new_display_item_list_.size() >= 2 && display_item.IsEnd()) {
264 const auto& begin_display_item = 265 const auto& begin_display_item =
265 new_display_item_list_[new_display_item_list_.size() - 2]; 266 new_display_item_list_[new_display_item_list_.size() - 2];
266 if (begin_display_item.IsBegin() && !begin_display_item.DrawsContent()) 267 if (begin_display_item.IsBegin() && !begin_display_item.DrawsContent())
267 DCHECK(!display_item.IsEndAndPairedWith(begin_display_item.GetType())); 268 DCHECK(!display_item.IsEndAndPairedWith(begin_display_item.GetType()));
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 (int)new_display_item_list_.size() - num_cached_new_items_); 534 (int)new_display_item_list_.size() - num_cached_new_items_);
534 num_cached_new_items_ = 0; 535 num_cached_new_items_ = 0;
535 // These data structures are used during painting only. 536 // These data structures are used during painting only.
536 DCHECK(!IsSkippingCache()); 537 DCHECK(!IsSkippingCache());
537 #if DCHECK_IS_ON() 538 #if DCHECK_IS_ON()
538 new_display_item_indices_by_client_.clear(); 539 new_display_item_indices_by_client_.clear();
539 #endif 540 #endif
540 541
541 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && 542 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() &&
542 !new_display_item_list_.IsEmpty()) 543 !new_display_item_list_.IsEmpty())
543 GenerateChunkRasterInvalidationRects(new_paint_chunks_.LastChunk()); 544 GenerateRasterInvalidations(new_paint_chunks_.LastChunk());
544 545
545 int num_slow_paths = 0; 546 int num_slow_paths = 0;
546 547
547 current_cache_generation_ = 548 current_cache_generation_ =
548 DisplayItemClient::CacheGenerationOrInvalidationReason::Next(); 549 DisplayItemClient::CacheGenerationOrInvalidationReason::Next();
549 550
550 new_cached_subsequences_.swap(current_cached_subsequences_); 551 new_cached_subsequences_.swap(current_cached_subsequences_);
551 new_cached_subsequences_.clear(); 552 new_cached_subsequences_.clear();
552 last_cached_subsequence_end_ = 0; 553 last_cached_subsequence_end_ = 0;
553 for (auto& item : current_cached_subsequences_) { 554 for (auto& item : current_cached_subsequences_) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 } 593 }
593 } 594 }
594 } 595 }
595 596
596 for (auto* client : skipped_cache_clients) 597 for (auto* client : skipped_cache_clients)
597 client->SetDisplayItemsUncached(); 598 client->SetDisplayItemsUncached();
598 599
599 // The new list will not be appended to again so we can release unused memory. 600 // The new list will not be appended to again so we can release unused memory.
600 new_display_item_list_.ShrinkToFit(); 601 new_display_item_list_.ShrinkToFit();
601 602
602 if (paint_chunks_raster_invalidation_tracking_map_) { 603 if (raster_invalidation_tracking_map_) {
603 for (const auto& chunk : current_paint_artifact_.PaintChunks()) 604 for (const auto& chunk : current_paint_artifact_.PaintChunks())
604 paint_chunks_raster_invalidation_tracking_map_->Remove(&chunk); 605 raster_invalidation_tracking_map_->Remove(&chunk);
605 } 606 }
606 current_paint_artifact_ = PaintArtifact( 607 current_paint_artifact_ = PaintArtifact(
607 std::move(new_display_item_list_), new_paint_chunks_.ReleasePaintChunks(), 608 std::move(new_display_item_list_), new_paint_chunks_.ReleasePaintChunks(),
608 num_slow_paths <= kMaxNumberOfSlowPathsBeforeVeto); 609 num_slow_paths <= kMaxNumberOfSlowPathsBeforeVeto);
609 610
610 ResetCurrentListIndices(); 611 ResetCurrentListIndices();
611 out_of_order_item_indices_.clear(); 612 out_of_order_item_indices_.clear();
612 out_of_order_chunk_indices_.clear(); 613 out_of_order_chunk_indices_.clear();
613 items_moved_into_new_list_.clear(); 614 items_moved_into_new_list_.clear();
614 615
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 current_paint_artifact_.GetDisplayItemList() 668 current_paint_artifact_.GetDisplayItemList()
668 .AllocateAndConstruct<DrawingDisplayItem>(display_item_client, 669 .AllocateAndConstruct<DrawingDisplayItem>(display_item_client,
669 DisplayItem::kDebugDrawing, 670 DisplayItem::kDebugDrawing,
670 std::move(record)); 671 std::move(record));
671 display_item.SetSkippedCache(); 672 display_item.SetSkippedCache();
672 // TODO(wkorman): Only compute and append visual rect for drawings. 673 // TODO(wkorman): Only compute and append visual rect for drawings.
673 current_paint_artifact_.GetDisplayItemList().AppendVisualRect( 674 current_paint_artifact_.GetDisplayItemList().AppendVisualRect(
674 VisualRectForDisplayItem(display_item, offset_from_layout_object)); 675 VisualRectForDisplayItem(display_item, offset_from_layout_object));
675 } 676 }
676 677
677 void PaintController::GenerateChunkRasterInvalidationRects( 678 void PaintController::GenerateRasterInvalidations(PaintChunk& new_chunk) {
678 PaintChunk& new_chunk) {
679 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 679 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled());
680 if (new_chunk.begin_index >= 680 if (new_chunk.begin_index >=
681 current_cached_subsequence_begin_index_in_new_list_) 681 current_cached_subsequence_begin_index_in_new_list_)
682 return; 682 return;
683 683
684 static FloatRect infinite_float_rect(LayoutRect::InfiniteIntRect()); 684 static FloatRect infinite_float_rect(LayoutRect::InfiniteIntRect());
685 if (!new_chunk.id) { 685 if (!new_chunk.id) {
686 AddRasterInvalidationInfo(nullptr, new_chunk, infinite_float_rect); 686 AddRasterInvalidation(nullptr, new_chunk, infinite_float_rect);
687 return; 687 return;
688 } 688 }
689 689
690 // Try to match old chunk sequentially first. 690 // Try to match old chunk sequentially first.
691 const auto& old_chunks = current_paint_artifact_.PaintChunks(); 691 const auto& old_chunks = current_paint_artifact_.PaintChunks();
692 while (next_chunk_to_match_ < old_chunks.size()) { 692 while (next_chunk_to_match_ < old_chunks.size()) {
693 const PaintChunk& old_chunk = old_chunks[next_chunk_to_match_]; 693 const PaintChunk& old_chunk = old_chunks[next_chunk_to_match_];
694 if (new_chunk.Matches(old_chunk)) { 694 if (new_chunk.Matches(old_chunk)) {
695 GenerateChunkRasterInvalidationRectsComparingOldChunk(new_chunk, 695 GenerateRasterInvalidationsComparingChunks(new_chunk, old_chunk);
696 old_chunk);
697 ++next_chunk_to_match_; 696 ++next_chunk_to_match_;
698 return; 697 return;
699 } 698 }
700 699
701 // Add skipped old chunks into the index. 700 // Add skipped old chunks into the index.
702 if (old_chunk.id) { 701 if (old_chunk.id) {
703 auto it = out_of_order_chunk_indices_.find(&old_chunk.id->client); 702 auto it = out_of_order_chunk_indices_.find(&old_chunk.id->client);
704 Vector<size_t>& indices = 703 Vector<size_t>& indices =
705 it == out_of_order_chunk_indices_.end() 704 it == out_of_order_chunk_indices_.end()
706 ? out_of_order_chunk_indices_ 705 ? out_of_order_chunk_indices_
707 .insert(&old_chunk.id->client, Vector<size_t>()) 706 .insert(&old_chunk.id->client, Vector<size_t>())
708 .stored_value->value 707 .stored_value->value
709 : it->value; 708 : it->value;
710 indices.push_back(next_chunk_to_match_); 709 indices.push_back(next_chunk_to_match_);
711 } 710 }
712 ++next_chunk_to_match_; 711 ++next_chunk_to_match_;
713 } 712 }
714 713
715 // Sequential matching reaches the end. Find from the out-of-order index. 714 // Sequential matching reaches the end. Find from the out-of-order index.
716 auto it = out_of_order_chunk_indices_.find(&new_chunk.id->client); 715 auto it = out_of_order_chunk_indices_.find(&new_chunk.id->client);
717 if (it != out_of_order_chunk_indices_.end()) { 716 if (it != out_of_order_chunk_indices_.end()) {
718 for (size_t i : it->value) { 717 for (size_t i : it->value) {
719 if (new_chunk.Matches(old_chunks[i])) { 718 if (new_chunk.Matches(old_chunks[i])) {
720 GenerateChunkRasterInvalidationRectsComparingOldChunk(new_chunk, 719 GenerateRasterInvalidationsComparingChunks(new_chunk, old_chunks[i]);
721 old_chunks[i]);
722 return; 720 return;
723 } 721 }
724 } 722 }
725 } 723 }
726 724
727 // We reach here because the chunk is new. 725 // We reach here because the chunk is new.
728 AddRasterInvalidationInfo(nullptr, new_chunk, infinite_float_rect); 726 AddRasterInvalidation(nullptr, new_chunk, infinite_float_rect);
729 } 727 }
730 728
731 void PaintController::AddRasterInvalidationInfo(const DisplayItemClient* client, 729 void PaintController::AddRasterInvalidation(const DisplayItemClient* client,
732 PaintChunk& chunk, 730 PaintChunk& chunk,
733 const FloatRect& rect) { 731 const FloatRect& rect) {
734 chunk.raster_invalidation_rects.push_back(rect); 732 chunk.raster_invalidation_rects.push_back(rect);
735 if (!paint_chunks_raster_invalidation_tracking_map_) 733 if (raster_invalidation_tracking_map_)
736 return; 734 TrackRasterInvalidation(client, chunk, rect);
735 }
736
737 void PaintController::TrackRasterInvalidation(const DisplayItemClient* client,
738 PaintChunk& chunk,
739 const FloatRect& rect) {
740 DCHECK(raster_invalidation_tracking_map_);
741
737 RasterInvalidationInfo info; 742 RasterInvalidationInfo info;
738 info.rect = EnclosingIntRect(rect); 743 info.rect = EnclosingIntRect(rect);
739 info.client = client; 744 info.client = client;
740 if (client) { 745 if (client) {
741 info.client_debug_name = client->DebugName(); 746 info.client_debug_name = client->DebugName();
742 info.reason = client->GetPaintInvalidationReason(); 747 info.reason = client->GetPaintInvalidationReason();
743 } 748 }
744 RasterInvalidationTracking& tracking = 749 raster_invalidation_tracking_map_->Add(&chunk).invalidations.push_back(info);
745 paint_chunks_raster_invalidation_tracking_map_->Add(&chunk);
746 tracking.tracked_raster_invalidations.push_back(info);
747 } 750 }
748 751
749 void PaintController::GenerateChunkRasterInvalidationRectsComparingOldChunk( 752 void PaintController::GenerateRasterInvalidationsComparingChunks(
750 PaintChunk& new_chunk, 753 PaintChunk& new_chunk,
751 const PaintChunk& old_chunk) { 754 const PaintChunk& old_chunk) {
752 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 755 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled());
753 756
754 // TODO(wangxianzhu): Handle PaintInvalidationIncremental. 757 // TODO(wangxianzhu): Handle PaintInvalidationIncremental.
755 // TODO(wangxianzhu): Optimize paint offset change. 758 // TODO(wangxianzhu): Optimize paint offset change.
756 759
757 HashSet<const DisplayItemClient*> invalidated_clients_in_old_chunk; 760 HashSet<const DisplayItemClient*> invalidated_clients_in_old_chunk;
758 size_t highest_moved_to_index = 0; 761 size_t highest_moved_to_index = 0;
759 for (size_t old_index = old_chunk.begin_index; 762 for (size_t old_index = old_chunk.begin_index;
760 old_index < old_chunk.end_index; ++old_index) { 763 old_index < old_chunk.end_index; ++old_index) {
761 const DisplayItem& old_item = 764 const DisplayItem& old_item =
762 current_paint_artifact_.GetDisplayItemList()[old_index]; 765 current_paint_artifact_.GetDisplayItemList()[old_index];
763 const DisplayItemClient* client_to_invalidate = nullptr; 766 const DisplayItemClient* client_to_invalidate = nullptr;
764 bool is_potentially_invalid_client = false; 767 bool is_potentially_invalid_client = false;
765 if (!old_item.HasValidClient()) { 768 if (!old_item.HasValidClient()) {
766 size_t moved_to_index = items_moved_into_new_list_[old_index]; 769 size_t moved_to_index = items_moved_into_new_list_[old_index];
767 if (new_display_item_list_[moved_to_index].DrawsContent()) { 770 if (new_display_item_list_[moved_to_index].DrawsContent()) {
768 if (moved_to_index < new_chunk.begin_index || 771 if (moved_to_index < new_chunk.begin_index ||
769 moved_to_index >= new_chunk.end_index) { 772 moved_to_index >= new_chunk.end_index) {
770 // The item has been moved into another chunk, so need to invalidate 773 // The item has been moved into another chunk, so need to invalidate
771 // it in the old chunk. 774 // it in the old chunk.
772 client_to_invalidate = 775 client_to_invalidate =
773 &new_display_item_list_[moved_to_index].Client(); 776 &new_display_item_list_[moved_to_index].Client();
774 // And invalidate in the new chunk into which the item was moved. 777 // And invalidate in the new chunk into which the item was moved.
775 PaintChunk& moved_to_chunk = 778 PaintChunk& moved_to_chunk =
776 new_paint_chunks_.FindChunkByDisplayItemIndex(moved_to_index); 779 new_paint_chunks_.FindChunkByDisplayItemIndex(moved_to_index);
777 AddRasterInvalidationInfo( 780 AddRasterInvalidation(client_to_invalidate, moved_to_chunk,
778 client_to_invalidate, moved_to_chunk, 781 FloatRect(client_to_invalidate->VisualRect()));
779 FloatRect(client_to_invalidate->VisualRect()));
780 } else if (moved_to_index < highest_moved_to_index) { 782 } else if (moved_to_index < highest_moved_to_index) {
781 // The item has been moved behind other cached items, so need to 783 // The item has been moved behind other cached items, so need to
782 // invalidate the area that is probably exposed by the item moved 784 // invalidate the area that is probably exposed by the item moved
783 // earlier. 785 // earlier.
784 client_to_invalidate = 786 client_to_invalidate =
785 &new_display_item_list_[moved_to_index].Client(); 787 &new_display_item_list_[moved_to_index].Client();
786 } else { 788 } else {
787 highest_moved_to_index = moved_to_index; 789 highest_moved_to_index = moved_to_index;
788 } 790 }
789 } 791 }
790 } else if (old_item.DrawsContent()) { 792 } else if (old_item.DrawsContent()) {
791 is_potentially_invalid_client = true; 793 is_potentially_invalid_client = true;
792 client_to_invalidate = &old_item.Client(); 794 client_to_invalidate = &old_item.Client();
793 } 795 }
794 if (client_to_invalidate && 796 if (client_to_invalidate &&
795 invalidated_clients_in_old_chunk.insert(client_to_invalidate) 797 invalidated_clients_in_old_chunk.insert(client_to_invalidate)
796 .is_new_entry) { 798 .is_new_entry) {
797 AddRasterInvalidationInfo( 799 AddRasterInvalidation(
798 is_potentially_invalid_client ? nullptr : client_to_invalidate, 800 is_potentially_invalid_client ? nullptr : client_to_invalidate,
799 new_chunk, 801 new_chunk,
800 FloatRect(current_paint_artifact_.GetDisplayItemList().VisualRect( 802 FloatRect(current_paint_artifact_.GetDisplayItemList().VisualRect(
801 old_index))); 803 old_index)));
802 } 804 }
803 } 805 }
804 806
805 HashSet<const DisplayItemClient*> invalidated_clients_in_new_chunk; 807 HashSet<const DisplayItemClient*> invalidated_clients_in_new_chunk;
806 for (size_t new_index = new_chunk.begin_index; 808 for (size_t new_index = new_chunk.begin_index;
807 new_index < new_chunk.end_index; ++new_index) { 809 new_index < new_chunk.end_index; ++new_index) {
808 const DisplayItem& new_item = new_display_item_list_[new_index]; 810 const DisplayItem& new_item = new_display_item_list_[new_index];
809 if (new_item.DrawsContent() && !ClientCacheIsValid(new_item.Client()) && 811 if (new_item.DrawsContent() && !ClientCacheIsValid(new_item.Client()) &&
810 invalidated_clients_in_new_chunk.insert(&new_item.Client()) 812 invalidated_clients_in_new_chunk.insert(&new_item.Client())
811 .is_new_entry) { 813 .is_new_entry) {
812 AddRasterInvalidationInfo(&new_item.Client(), new_chunk, 814 AddRasterInvalidation(&new_item.Client(), new_chunk,
813 FloatRect(new_item.Client().VisualRect())); 815 FloatRect(new_item.Client().VisualRect()));
814 } 816 }
815 } 817 }
816 } 818 }
817 819
818 void PaintController::ShowUnderInvalidationError( 820 void PaintController::ShowUnderInvalidationError(
819 const char* reason, 821 const char* reason,
820 const DisplayItem& new_item, 822 const DisplayItem& new_item,
821 const DisplayItem* old_item) const { 823 const DisplayItem* old_item) const {
822 LOG(ERROR) << under_invalidation_message_prefix_ << " " << reason; 824 LOG(ERROR) << under_invalidation_message_prefix_ << " " << reason;
823 #ifndef NDEBUG 825 #ifndef NDEBUG
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 show_paint_records 947 show_paint_records
946 ? (DisplayItemList::JsonOptions::kShowPaintRecords | 948 ? (DisplayItemList::JsonOptions::kShowPaintRecords |
947 DisplayItemList::JsonOptions::kShowClientDebugName) 949 DisplayItemList::JsonOptions::kShowClientDebugName)
948 : DisplayItemList::JsonOptions::kShowClientDebugName) 950 : DisplayItemList::JsonOptions::kShowClientDebugName)
949 ->ToPrettyJSONString() 951 ->ToPrettyJSONString()
950 .Utf8() 952 .Utf8()
951 .data()); 953 .data());
952 } 954 }
953 955
954 } // namespace blink 956 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698