Skip to content

Commit

Permalink
re-using the 'is_complex' flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdPaleLight committed Mar 23, 2022
1 parent c5bfc8b commit 0a4e7c0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions flow/layers/display_list_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ void DisplayListLayer::Preroll(PrerollContext* context,
if (auto* cache = context->raster_cache) {
TRACE_EVENT0("flutter", "DisplayListLayer::RasterCache (Preroll)");
if (context->cull_rect.intersects(bounds)) {
if (cache->Prepare(context, disp_list, is_complex_, will_change_, matrix,
offset_)) {
if (cache->Prepare(context, disp_list, /*for_testing=*/false,
will_change_, matrix, offset_, is_complex_)) {
context->subtree_can_inherit_opacity = true;
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions flow/layers/picture_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
if (auto* cache = context->raster_cache) {
TRACE_EVENT0("flutter", "PictureLayer::RasterCache (Preroll)");
if (context->cull_rect.intersects(bounds)) {
if (cache->Prepare(context, sk_picture, is_complex_, will_change_, matrix,
offset_)) {
if (cache->Prepare(context, sk_picture, /*for_testing=*/false,
will_change_, matrix, offset_, is_complex_)) {
context->subtree_can_inherit_opacity = true;
}
} else {
Expand Down
28 changes: 14 additions & 14 deletions flow/raster_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static bool CanRasterizeRect(const SkRect& cull_rect) {
static bool IsPictureWorthRasterizing(SkPicture* picture,
bool will_change,
bool is_complex,
bool is_high_priority) {
bool for_testing) {
if (will_change) {
// If the picture is going to change in the future, there is no point in
// doing to extra work to rasterize.
Expand All @@ -76,7 +76,7 @@ static bool IsPictureWorthRasterizing(SkPicture* picture,
return false;
}

if (is_complex || is_high_priority) {
if (is_complex || for_testing) {
// The caller seems to have extra information about the picture and thinks
// the picture is always worth rasterizing.
return true;
Expand All @@ -91,7 +91,7 @@ static bool IsDisplayListWorthRasterizing(
DisplayList* display_list,
bool will_change,
bool is_complex,
bool is_high_priority,
bool for_testing,
DisplayListComplexityCalculator* complexity_calculator) {
if (will_change) {
// If the display list is going to change in the future, there is no point
Expand All @@ -105,7 +105,7 @@ static bool IsDisplayListWorthRasterizing(
return false;
}

if (is_complex || is_high_priority) {
if (is_complex || for_testing) {
// The caller seems to have extra information about the display list and
// thinks the display list is always worth rasterizing.
return true;
Expand Down Expand Up @@ -222,17 +222,17 @@ std::unique_ptr<RasterCacheResult> RasterCache::RasterizeLayer(

bool RasterCache::Prepare(PrerollContext* context,
SkPicture* picture,
bool is_complex,
bool for_testing,
bool will_change,
const SkMatrix& untranslated_matrix,
const SkPoint& offset,
bool is_high_priority) {
bool is_complex) {
if (!GenerateNewCacheInThisFrame()) {
return false;
}

if (!IsPictureWorthRasterizing(picture, will_change, is_complex,
is_high_priority)) {
for_testing)) {
// We only deal with pictures that are worthy of rasterization.
return false;
}
Expand All @@ -250,8 +250,8 @@ bool RasterCache::Prepare(PrerollContext* context,

// Creates an entry, if not present prior.
Entry& entry = cache_[cache_key];
entry.is_high_priority = is_high_priority;
if (!is_high_priority && entry.access_count < access_threshold_) {
entry.is_complex = is_complex;
if (!is_complex && entry.access_count < access_threshold_) {
// Frame threshold has not yet been reached.
return false;
}
Expand All @@ -273,11 +273,11 @@ bool RasterCache::Prepare(PrerollContext* context,

bool RasterCache::Prepare(PrerollContext* context,
DisplayList* display_list,
bool is_complex,
bool for_testing,
bool will_change,
const SkMatrix& untranslated_matrix,
const SkPoint& offset,
bool is_high_priority) {
bool is_complex) {
if (!GenerateNewCacheInThisFrame()) {
return false;
}
Expand All @@ -288,7 +288,7 @@ bool RasterCache::Prepare(PrerollContext* context,
: DisplayListComplexityCalculator::GetForSoftware();

if (!IsDisplayListWorthRasterizing(display_list, will_change, is_complex,
is_high_priority, complexity_calculator)) {
for_testing, complexity_calculator)) {
// We only deal with display lists that are worthy of rasterization.
return false;
}
Expand All @@ -307,8 +307,8 @@ bool RasterCache::Prepare(PrerollContext* context,

// Creates an entry, if not present prior.
Entry& entry = cache_[cache_key];
entry.is_high_priority = is_high_priority;
if (!is_high_priority && entry.access_count < access_threshold_) {
entry.is_complex = is_complex;
if (!is_complex && entry.access_count < access_threshold_) {
// Frame threshold has not yet been reached.
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions flow/raster_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,18 @@ class RasterCache {
// 4. The picture is accessed too few times
bool Prepare(PrerollContext* context,
SkPicture* picture,
bool is_complex,
bool for_testing,
bool will_change,
const SkMatrix& untranslated_matrix,
const SkPoint& offset = SkPoint(),
bool is_high_priority = false);
bool is_complex = false);
bool Prepare(PrerollContext* context,
DisplayList* display_list,
bool is_complex,
bool for_testing,
bool will_change,
const SkMatrix& untranslated_matrix,
const SkPoint& offset = SkPoint(),
bool is_high_priority = false);
bool is_complex = false);

// If there is cache entry for this picture, display list or layer, mark it as
// used for this frame in order to not get evicted. This is needed during
Expand Down Expand Up @@ -303,14 +303,14 @@ class RasterCache {
struct Entry {
// If the entry is high priority, it will always cache on first usage and
// survive 3 frames without usage.
bool is_high_priority = false;
bool is_complex = false;
bool used_this_frame = false;
size_t access_count = 0;
size_t unused_count = 0;
std::unique_ptr<RasterCacheResult> image;
// Return the number of frames the entry survives if it is not used. If the
// number is 0, then it will be evicted when not in use.
size_t unused_threshold() const { return is_high_priority ? 3 : 0; }
size_t unused_threshold() const { return is_complex ? 3 : 0; }
};

void Touch(const RasterCacheKey& cache_key);
Expand Down

0 comments on commit 0a4e7c0

Please sign in to comment.