Skip to content

Commit

Permalink
[cc] Make "no_cache" only accessible through PaintImageBuilder
Browse files Browse the repository at this point in the history
This was suggested as a cleanup in
https://chromium-review.googlesource.com/c/chromium/src/+/4683446. Let's
do it, it's cleaner.

Bug: 1464610
Change-Id: I375e65d38f4c9338d9c2aa43348596648109a52b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4907029
Reviewed-by: ccameron chromium <ccameron@chromium.org>
Reviewed-by: K. Moon <kmoon@chromium.org>
Commit-Queue: Benoit Lize <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1205172}
  • Loading branch information
Benoit Lize authored and Chromium LUCI CQ committed Oct 4, 2023
1 parent f398c68 commit a706558
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
1 change: 0 additions & 1 deletion cc/paint/paint_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ class CC_PAINT_EXPORT PaintImage {
bool is_high_bit_depth() const { return is_high_bit_depth_; }
bool may_be_lcp_candidate() const { return may_be_lcp_candidate_; }
bool no_cache() const { return no_cache_; }
void set_no_cache(bool no_cache) { no_cache_ = no_cache; }
int repetition_count() const { return repetition_count_; }
bool ShouldAnimate() const;
AnimationSequenceId reset_animation_sequence_id() const {
Expand Down
4 changes: 4 additions & 0 deletions cc/paint/paint_image_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class CC_PAINT_EXPORT PaintImageBuilder {
paint_image_.may_be_lcp_candidate_ = may_be_lcp_candidate;
return std::move(*this);
}
PaintImageBuilder&& set_no_cache(bool no_cache) {
paint_image_.no_cache_ = no_cache;
return std::move(*this);
}
PaintImageBuilder&& set_repetition_count(int count) {
paint_image_.repetition_count_ = count;
return std::move(*this);
Expand Down
10 changes: 7 additions & 3 deletions cc/tiles/gpu_image_decode_cache_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "cc/paint/color_filter.h"
#include "cc/paint/draw_image.h"
#include "cc/paint/image_transfer_cache_entry.h"
#include "cc/paint/paint_image.h"
#include "cc/paint/paint_image_builder.h"
#include "cc/paint/paint_op_writer.h"
#include "cc/test/fake_paint_image_generator.h"
Expand Down Expand Up @@ -4882,9 +4883,12 @@ TEST_P(GpuImageDecodeCachePurgeOnTimerTest, NoDeadlock) {

TEST_P(GpuImageDecodeCachePurgeOnTimerTest, NoCache) {
const uint32_t client_id = cache_->GenerateClientId();
PaintImage image = CreatePaintImageInternal(GetNormalImageSize());
image.set_no_cache(true);
DrawImage draw_image = CreateDrawImageInternal(image);
PaintImage image_no_cache =
PaintImageBuilder::WithCopy(
CreatePaintImageInternal(GetNormalImageSize()))
.set_no_cache(true)
.TakePaintImage();
DrawImage draw_image = CreateDrawImageInternal(image_no_cache);

ImageDecodeCache::TaskResult result = cache_->GetTaskForImageAndRef(
client_id, draw_image, ImageDecodeCache::TracingInfo());
Expand Down
13 changes: 6 additions & 7 deletions pdf/pdf_view_web_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1883,12 +1883,6 @@ void PdfViewWebPlugin::ClearDeferredInvalidates() {
}

void PdfViewWebPlugin::UpdateSnapshot(sk_sp<SkImage> snapshot) {
snapshot_ =
cc::PaintImageBuilder::WithDefault()
.set_image(std::move(snapshot), cc::PaintImage::GetNextContentId())
.set_id(cc::PaintImage::GetNextId())
.TakePaintImage();

// Every time something changes (e.g. scale or scroll position),
// `UpdateSnapshot()` is called, so the snapshot is effectively used only
// once. Make it "no-cache" so that the old snapshots are not cached
Expand All @@ -1899,7 +1893,12 @@ void PdfViewWebPlugin::UpdateSnapshot(sk_sp<SkImage> snapshot) {
// service transfer cache. The size of the service transfer cache is bounded,
// so on desktop this "only" causes a 256MiB memory spike, but it's completely
// wasted memory nonetheless.
snapshot_.set_no_cache(true);
snapshot_ =
cc::PaintImageBuilder::WithDefault()
.set_image(std::move(snapshot), cc::PaintImage::GetNextContentId())
.set_id(cc::PaintImage::GetNextId())
.set_no_cache(true)
.TakePaintImage();

if (!plugin_rect_.IsEmpty())
InvalidatePluginContainer();
Expand Down

0 comments on commit a706558

Please sign in to comment.