This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[WIP]RasterCache adds a new mechanism for particularly complex pictures or display lists #31925
Closed
ColdPaleLight
wants to merge
11
commits into
flutter:main
from
ColdPaleLight:particularly_complex_cache_entry
Closed
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b8f53ff
RasterCache adds a new mechanism for particularly complex pictures or…
ColdPaleLight e2194eb
fix typo
ColdPaleLight c5bfc8b
Tweak the code and add some comments
ColdPaleLight 0a4e7c0
re-using the 'is_complex' flag
ColdPaleLight 35b8982
tweak comment
ColdPaleLight c3401b6
Revert "tweak comment"
ColdPaleLight 5842cc8
Revert "re-using the 'is_complex' flag"
ColdPaleLight 18dc81b
Keep 'is_complex' and 'is_high_priority' orthogonal
ColdPaleLight c99c52f
Tweak some code in raster cache
ColdPaleLight 36a7f86
Merge branch 'flutter:main' into particularly_complex_cache_entry
ColdPaleLight 7537885
Merge branch 'flutter:main' into particularly_complex_cache_entry
ColdPaleLight File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
RasterCache adds a new mechanism for particularly complex pictures or…
… display lists
- Loading branch information
commit b8f53ff475ea3337eb72781bedf71747e90aff53
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,8 @@ static bool CanRasterizeRect(const SkRect& cull_rect) { | |
|
|
||
| static bool IsPictureWorthRasterizing(SkPicture* picture, | ||
| bool will_change, | ||
| bool is_complex) { | ||
| bool is_complex, | ||
| bool is_high_priority) { | ||
| if (will_change) { | ||
| // If the picture is going to change in the future, there is no point in | ||
| // doing to extra work to rasterize. | ||
|
|
@@ -75,7 +76,7 @@ static bool IsPictureWorthRasterizing(SkPicture* picture, | |
| return false; | ||
| } | ||
|
|
||
| if (is_complex) { | ||
| if (is_complex || is_high_priority) { | ||
| // The caller seems to have extra information about the picture and thinks | ||
| // the picture is always worth rasterizing. | ||
| return true; | ||
|
|
@@ -90,6 +91,7 @@ static bool IsDisplayListWorthRasterizing( | |
| DisplayList* display_list, | ||
| bool will_change, | ||
| bool is_complex, | ||
| bool is_high_priority, | ||
| DisplayListComplexityCalculator* complexity_calculator) { | ||
| if (will_change) { | ||
| // If the display list is going to change in the future, there is no point | ||
|
|
@@ -103,7 +105,7 @@ static bool IsDisplayListWorthRasterizing( | |
| return false; | ||
| } | ||
|
|
||
| if (is_complex) { | ||
| if (is_complex || is_high_priority) { | ||
| // The caller seems to have extra information about the display list and | ||
| // thinks the display list is always worth rasterizing. | ||
| return true; | ||
|
|
@@ -180,6 +182,7 @@ void RasterCache::Prepare(PrerollContext* context, | |
| Entry& entry = cache_[cache_key]; | ||
| entry.access_count++; | ||
| entry.used_this_frame = true; | ||
| entry.unused_count = 0; | ||
| if (!entry.image) { | ||
| entry.image = RasterizeLayer(context, layer, ctm, checkerboard_images_); | ||
| } | ||
|
|
@@ -222,12 +225,14 @@ bool RasterCache::Prepare(PrerollContext* context, | |
| bool is_complex, | ||
| bool will_change, | ||
| const SkMatrix& untranslated_matrix, | ||
| const SkPoint& offset) { | ||
| const SkPoint& offset, | ||
| bool is_high_priority) { | ||
| if (!GenerateNewCacheInThisFrame()) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!IsPictureWorthRasterizing(picture, will_change, is_complex)) { | ||
| if (!IsPictureWorthRasterizing(picture, will_change, is_complex, | ||
| is_high_priority)) { | ||
| // We only deal with pictures that are worthy of rasterization. | ||
| return false; | ||
| } | ||
|
|
@@ -245,7 +250,8 @@ bool RasterCache::Prepare(PrerollContext* context, | |
|
|
||
| // Creates an entry, if not present prior. | ||
| Entry& entry = cache_[cache_key]; | ||
| if (entry.access_count < access_threshold_) { | ||
| entry.is_high_priority = is_high_priority; | ||
| if (!is_high_priority && entry.access_count < access_threshold_) { | ||
| // Frame threshold has not yet been reached. | ||
| return false; | ||
| } | ||
|
|
@@ -270,7 +276,8 @@ bool RasterCache::Prepare(PrerollContext* context, | |
| bool is_complex, | ||
| bool will_change, | ||
| const SkMatrix& untranslated_matrix, | ||
| const SkPoint& offset) { | ||
| const SkPoint& offset, | ||
| bool is_high_priority) { | ||
| if (!GenerateNewCacheInThisFrame()) { | ||
| return false; | ||
| } | ||
|
|
@@ -281,7 +288,7 @@ bool RasterCache::Prepare(PrerollContext* context, | |
| : DisplayListComplexityCalculator::GetForSoftware(); | ||
|
|
||
| if (!IsDisplayListWorthRasterizing(display_list, will_change, is_complex, | ||
| complexity_calculator)) { | ||
| is_high_priority, complexity_calculator)) { | ||
| // We only deal with display lists that are worthy of rasterization. | ||
| return false; | ||
| } | ||
|
|
@@ -300,7 +307,8 @@ bool RasterCache::Prepare(PrerollContext* context, | |
|
|
||
| // Creates an entry, if not present prior. | ||
| Entry& entry = cache_[cache_key]; | ||
| if (entry.access_count < access_threshold_) { | ||
| entry.is_high_priority = is_high_priority; | ||
| if (!is_high_priority && entry.access_count < access_threshold_) { | ||
| // Frame threshold has not yet been reached. | ||
| return false; | ||
| } | ||
|
|
@@ -345,6 +353,7 @@ void RasterCache::Touch(const RasterCacheKey& cache_key) { | |
| if (it != cache_.end()) { | ||
| it->second.used_this_frame = true; | ||
| it->second.access_count++; | ||
| it->second.unused_count = 0; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -384,6 +393,7 @@ bool RasterCache::Draw(const RasterCacheKey& cache_key, | |
| Entry& entry = it->second; | ||
| entry.access_count++; | ||
| entry.used_this_frame = true; | ||
| entry.unused_count = 0; | ||
|
|
||
| if (entry.image) { | ||
| entry.image->draw(canvas, paint); | ||
|
|
@@ -405,9 +415,25 @@ void RasterCache::SweepOneCacheAfterFrame(RasterCacheKey::Map<Entry>& cache, | |
|
|
||
| for (auto it = cache.begin(); it != cache.end(); ++it) { | ||
| Entry& entry = it->second; | ||
|
|
||
| if (!entry.used_this_frame) { | ||
| dead.push_back(it); | ||
| entry.unused_count++; | ||
| if (entry.unused_count < entry.unused_threshold()) { | ||
| if (entry.image) { | ||
| RasterCacheKeyKind kind = it->first.kind(); | ||
|
||
| switch (kind) { | ||
| case RasterCacheKeyKind::kPictureMetrics: | ||
| picture_metrics.unused_count++; | ||
| picture_metrics.unused_bytes += entry.image->image_bytes(); | ||
| break; | ||
| case RasterCacheKeyKind::kLayerMetrics: | ||
| layer_metrics.unused_count++; | ||
| layer_metrics.unused_bytes += entry.image->image_bytes(); | ||
| break; | ||
| } | ||
| } | ||
| } else { | ||
| dead.push_back(it); | ||
| } | ||
| } else if (entry.image) { | ||
| RasterCacheKeyKind kind = it->first.kind(); | ||
| switch (kind) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have entry.is_high_priority be a one-way latch, or a most-recently-specified flag? This might depend on what the recent request for empirical evidence turns up.