Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b91cde5

Browse files
committed
use CacheInfo struct to simplify return values
1 parent 90fa1bb commit b91cde5

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

flow/layers/display_list_layer_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ TEST_F(DisplayListLayerTest, OverflowCachedDisplayListOpacityInheritance) {
540540
offset, SkiaGPUObject(display_list, unref_queue()), true, false);
541541
opacity_layer->Add(layers[i]);
542542
}
543-
for (int j = 0; j < context->raster_cache->access_threshold(); j++) {
543+
for (size_t j = 0; j < context->raster_cache->access_threshold(); j++) {
544544
context->raster_cache->BeginFrame();
545545
for (int i = 0; i < layer_count; i++) {
546546
context->renderable_state_flags = 0;

flow/layers/display_list_raster_cache_item.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ void DisplayListRasterCacheItem::PrerollFinalize(PrerollContext* context,
105105
auto* raster_cache = context->raster_cache;
106106
SkRect bounds = display_list_->bounds().makeOffset(offset_.x(), offset_.y());
107107
bool visible = !context->state_stack.content_culled(bounds);
108-
bool has_image = false;
109-
int accesses = raster_cache->MarkSeen(key_id_, matrix, visible, &has_image);
110-
if (!visible || accesses <= raster_cache->access_threshold()) {
108+
RasterCache::CacheInfo cache_info =
109+
raster_cache->MarkSeen(key_id_, matrix, visible);
110+
if (!visible ||
111+
cache_info.accesses_since_visible <= raster_cache->access_threshold()) {
111112
cache_state_ = kNone;
112113
} else {
113-
if (has_image) {
114+
if (cache_info.has_image) {
114115
context->renderable_state_flags |=
115116
LayerStateStack::kCallerCanApplyOpacity;
116117
}

flow/raster_cache.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,17 @@ bool RasterCache::UpdateCacheEntry(
110110
return entry.image != nullptr;
111111
}
112112

113-
int RasterCache::MarkSeen(const RasterCacheKeyID& id,
114-
const SkMatrix& matrix,
115-
bool visible,
116-
bool* has_image) const {
113+
RasterCache::CacheInfo RasterCache::MarkSeen(const RasterCacheKeyID& id,
114+
const SkMatrix& matrix,
115+
bool visible) const {
117116
RasterCacheKey key = RasterCacheKey(id, matrix);
118117
Entry& entry = cache_[key];
119118
entry.encountered_this_frame = true;
120119
entry.visible_this_frame = visible;
121120
if (visible || entry.accesses_since_visible > 0) {
122121
entry.accesses_since_visible++;
123122
}
124-
if (has_image) {
125-
*has_image = (entry.image != nullptr);
126-
}
127-
return entry.accesses_since_visible;
123+
return {entry.accesses_since_visible, entry.image != nullptr};
128124
}
129125

130126
int RasterCache::GetAccessCount(const RasterCacheKeyID& id,

flow/raster_cache.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ class RasterCache {
121121
const SkRect& logical_rect;
122122
const char* flow_type;
123123
};
124+
struct CacheInfo {
125+
const size_t accesses_since_visible;
126+
const bool has_image;
127+
};
124128

125129
std::unique_ptr<RasterCacheResult> Rasterize(
126130
const RasterCache::Context& context,
@@ -203,7 +207,7 @@ class RasterCache {
203207
* If the number is one, then it must be prepared and drawn on 1 frame
204208
* and it will then be cached on the next frame if it is prepared.
205209
*/
206-
int access_threshold() const { return access_threshold_; }
210+
size_t access_threshold() const { return access_threshold_; }
207211

208212
bool GenerateNewCacheInThisFrame() const {
209213
// Disabling caching when access_threshold is zero is historic behavior.
@@ -221,10 +225,9 @@ class RasterCache {
221225
* @return the number of times the entry has been hit since it was created.
222226
* For a new entry that will be 1 if it is visible, or zero if non-visible.
223227
*/
224-
int MarkSeen(const RasterCacheKeyID& id,
225-
const SkMatrix& matrix,
226-
bool visible,
227-
bool* has_image = nullptr) const;
228+
CacheInfo MarkSeen(const RasterCacheKeyID& id,
229+
const SkMatrix& matrix,
230+
bool visible) const;
228231

229232
/**
230233
* Returns the access count (i.e. accesses_since_visible) for the given

flow/testing/mock_raster_cache.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void MockRasterCache::AddMockPicture(int width, int height) {
6565

6666
DisplayListRasterCacheItem display_list_item(display_list.get(), SkPoint(),
6767
true, false);
68-
for (int i = 0; i < access_threshold(); i++) {
68+
for (size_t i = 0; i < access_threshold(); i++) {
6969
AutoCache(&display_list_item, &preroll_context_, ctm);
7070
}
7171
RasterCache::Context r_context = {

0 commit comments

Comments
 (0)