Skip to content

Commit

Permalink
Move generation of GeneratorClientId to ctors of image decode caches.
Browse files Browse the repository at this point in the history
This is CL a preparation to share a decode cache instances between cc
instances to reduce memory used by decoded ui images.

Bug: 1279568
Change-Id: I402d6a0048fcba039407d3e93548eb1b82de54c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3818944
Reviewed-by: Khushal Sagar <khushalsagar@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/main@{#1034449}
  • Loading branch information
msisov authored and Chromium LUCI CQ committed Aug 12, 2022
1 parent c5a8070 commit 7a5139e
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 40 deletions.
3 changes: 1 addition & 2 deletions cc/paint/oop_pixeltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ class OopPixelTest : public testing::Test,
raster_context_provider_->ContextCapabilities().max_texture_size;
oop_image_cache_ = std::make_unique<GpuImageDecodeCache>(
raster_context_provider_.get(), true, kRGBA_8888_SkColorType,
kWorkingSetSize, raster_max_texture_size,
PaintImage::GetNextGeneratorClientId(), nullptr);
kWorkingSetSize, raster_max_texture_size, nullptr);
}

class RasterOptions {
Expand Down
3 changes: 1 addition & 2 deletions cc/test/fake_tile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ FakeTileManager::FakeTileManager(TileManagerClient* client,
TileManagerSettings()),
image_decode_cache_(
kN32_SkColorType,
LayerTreeSettings().decoded_image_working_set_budget_bytes,
PaintImage::GetNextGeneratorClientId()) {
LayerTreeSettings().decoded_image_working_set_budget_bytes) {
SetResources(resource_pool, &image_decode_cache_, GetGlobalTaskGraphRunner(),
GetGlobalRasterBufferProvider(),
/*use_gpu_rasterization=*/false, nullptr);
Expand Down
3 changes: 1 addition & 2 deletions cc/tiles/gpu_image_decode_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -988,13 +988,12 @@ GpuImageDecodeCache::GpuImageDecodeCache(
SkColorType color_type,
size_t max_working_set_bytes,
int max_texture_size,
PaintImage::GeneratorClientId generator_client_id,
RasterDarkModeFilter* const dark_mode_filter)
: color_type_(color_type),
use_transfer_cache_(use_transfer_cache),
context_(context),
max_texture_size_(max_texture_size),
generator_client_id_(generator_client_id),
generator_client_id_(PaintImage::GetNextGeneratorClientId()),
enable_clipped_image_scaling_(
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableClippedImageScaling)),
Expand Down
1 change: 0 additions & 1 deletion cc/tiles/gpu_image_decode_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ class CC_EXPORT GpuImageDecodeCache
SkColorType color_type,
size_t max_working_set_bytes,
int max_texture_size,
PaintImage::GeneratorClientId client_id,
RasterDarkModeFilter* const dark_mode_filter);
~GpuImageDecodeCache() override;

Expand Down
3 changes: 1 addition & 2 deletions cc/tiles/gpu_image_decode_cache_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class GpuImageDecodeCachePerfTest
ASSERT_EQ(result, gpu::ContextResult::kSuccess);
cache_ = std::make_unique<GpuImageDecodeCache>(
context_provider_.get(), UseTransferCache(), kRGBA_8888_SkColorType,
kCacheSize, MaxTextureSize(), PaintImage::GetNextGeneratorClientId(),
nullptr);
kCacheSize, MaxTextureSize(), nullptr);
}

protected:
Expand Down
3 changes: 1 addition & 2 deletions cc/tiles/gpu_image_decode_cache_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ class GpuImageDecodeCacheTest
RasterDarkModeFilter* const dark_mode_filter = nullptr) {
return std::make_unique<GpuImageDecodeCache>(
context_provider_.get(), use_transfer_cache_, color_type_,
memory_limit_bytes, max_texture_size_,
PaintImage::GetNextGeneratorClientId(), dark_mode_filter);
memory_limit_bytes, max_texture_size_, dark_mode_filter);
}

// Returns dimensions for an image that will not fit in GPU memory and hence
Expand Down
5 changes: 2 additions & 3 deletions cc/tiles/software_image_decode_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,11 @@ PaintFlags::FilterQuality GetDecodedFilterQuality(

SoftwareImageDecodeCache::SoftwareImageDecodeCache(
SkColorType color_type,
size_t locked_memory_limit_bytes,
PaintImage::GeneratorClientId generator_client_id)
size_t locked_memory_limit_bytes)
: decoded_images_(ImageLRUCache::NO_AUTO_EVICT),
locked_images_budget_(locked_memory_limit_bytes),
color_type_(color_type),
generator_client_id_(generator_client_id),
generator_client_id_(PaintImage::GetNextGeneratorClientId()),
max_items_in_cache_(kNormalMaxItemsInCacheForSoftware) {
DCHECK_NE(generator_client_id_, PaintImage::kDefaultGeneratorClientId);
// In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview).
Expand Down
3 changes: 1 addition & 2 deletions cc/tiles/software_image_decode_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class CC_EXPORT SoftwareImageDecodeCache
enum class TaskProcessingResult { kFullDecode, kLockOnly, kCancelled };

SoftwareImageDecodeCache(SkColorType color_type,
size_t locked_memory_limit_bytes,
PaintImage::GeneratorClientId generator_client_id);
size_t locked_memory_limit_bytes);
~SoftwareImageDecodeCache() override;

// ImageDecodeCache overrides.
Expand Down
4 changes: 1 addition & 3 deletions cc/tiles/software_image_decode_cache_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ size_t kLockedMemoryLimitBytes = 128 * 1024 * 1024;
class TestSoftwareImageDecodeCache : public SoftwareImageDecodeCache {
public:
TestSoftwareImageDecodeCache()
: SoftwareImageDecodeCache(kN32_SkColorType,
kLockedMemoryLimitBytes,
PaintImage::GetNextGeneratorClientId()) {}
: SoftwareImageDecodeCache(kN32_SkColorType, kLockedMemoryLimitBytes) {}
};

SkM44 CreateMatrix(const SkSize& scale, bool is_decomposable) {
Expand Down
15 changes: 6 additions & 9 deletions cc/tiles/software_image_decode_cache_unittest_combinations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,24 @@ class BaseTest : public testing::Test {
class N32Cache : public virtual BaseTest {
protected:
std::unique_ptr<SoftwareImageDecodeCache> CreateCache() override {
return std::make_unique<SoftwareImageDecodeCache>(
kN32_SkColorType, kLockedMemoryLimitBytes,
PaintImage::GetNextGeneratorClientId());
return std::make_unique<SoftwareImageDecodeCache>(kN32_SkColorType,
kLockedMemoryLimitBytes);
}
};

class RGBA4444Cache : public virtual BaseTest {
protected:
std::unique_ptr<SoftwareImageDecodeCache> CreateCache() override {
return std::make_unique<SoftwareImageDecodeCache>(
kARGB_4444_SkColorType, kLockedMemoryLimitBytes,
PaintImage::GetNextGeneratorClientId());
return std::make_unique<SoftwareImageDecodeCache>(kARGB_4444_SkColorType,
kLockedMemoryLimitBytes);
}
};

class RGBA_F16Cache : public virtual BaseTest {
protected:
std::unique_ptr<SoftwareImageDecodeCache> CreateCache() override {
return std::make_unique<SoftwareImageDecodeCache>(
kRGBA_F16_SkColorType, kLockedMemoryLimitBytes,
PaintImage::GetNextGeneratorClientId());
return std::make_unique<SoftwareImageDecodeCache>(kRGBA_F16_SkColorType,
kLockedMemoryLimitBytes);
}
};

Expand Down
6 changes: 2 additions & 4 deletions cc/trees/layer_tree_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ LayerTreeHostImpl::LayerTreeHostImpl(
image_animation_controller_(GetTaskRunner(),
this,
settings_.enable_image_animation_resync),
paint_image_generator_client_id_(PaintImage::GetNextGeneratorClientId()),
compositor_frame_reporting_controller_(
std::make_unique<CompositorFrameReportingController>(
/*should_report_histograms=*/!settings
Expand Down Expand Up @@ -3562,7 +3561,7 @@ void LayerTreeHostImpl::CreateTileManagerResources() {
viz::ResourceFormatToClosestSkColorType(/*gpu_compositing=*/true,
tile_format),
settings_.decoded_image_working_set_budget_bytes, max_texture_size_,
paint_image_generator_client_id_, dark_mode_filter_);
dark_mode_filter_);

pending_raster_queries_ = std::make_unique<RasterQueryQueue>(
layer_tree_frame_sink_->worker_context_provider());
Expand All @@ -3571,8 +3570,7 @@ void LayerTreeHostImpl::CreateTileManagerResources() {
bool gpu_compositing = !!layer_tree_frame_sink_->context_provider();
image_decode_cache_ = std::make_unique<SoftwareImageDecodeCache>(
viz::ResourceFormatToClosestSkColorType(gpu_compositing, tile_format),
settings_.decoded_image_working_set_budget_bytes,
paint_image_generator_client_id_);
settings_.decoded_image_working_set_budget_bytes);
}

raster_buffer_provider_ = CreateRasterBufferProvider();
Expand Down
2 changes: 0 additions & 2 deletions cc/trees/layer_tree_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1244,8 +1244,6 @@ class CC_EXPORT LayerTreeHostImpl : public TileManagerClient,

PresentationTimeCallbackBuffer presentation_time_callbacks_;

const PaintImage::GeneratorClientId paint_image_generator_client_id_;

// `compositor_frame_reporting_controller_` has a dependency on
// `dropped_frame_counter_` so it must be declared last and deleted first;
std::unique_ptr<CompositorFrameReportingController>
Expand Down
3 changes: 1 addition & 2 deletions content/renderer/webgraphicscontext3d_provider_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ cc::ImageDecodeCache* WebGraphicsContext3DProviderImpl::ImageDecodeCache(
color_type,
std::make_unique<cc::GpuImageDecodeCache>(
provider_.get(), use_transfer_cache, color_type, kMaxWorkingSetBytes,
provider_->ContextCapabilities().max_texture_size,
cc::PaintImage::GetNextGeneratorClientId(), nullptr));
provider_->ContextCapabilities().max_texture_size, nullptr));
DCHECK(insertion_result.second);
cache_iterator = insertion_result.first;
return cache_iterator->second.get();
Expand Down
6 changes: 2 additions & 4 deletions third_party/blink/renderer/platform/graphics/image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@ cc::ImageDecodeCache& Image::SharedCCDecodeCache(SkColorType color_type) {
if (color_type == kRGBA_F16_SkColorType) {
DEFINE_THREAD_SAFE_STATIC_LOCAL(
cc::SoftwareImageDecodeCache, image_decode_cache,
(kRGBA_F16_SkColorType, kLockedMemoryLimitBytes,
PaintImage::GetNextGeneratorClientId()));
(kRGBA_F16_SkColorType, kLockedMemoryLimitBytes));
return image_decode_cache;
}
DEFINE_THREAD_SAFE_STATIC_LOCAL(cc::SoftwareImageDecodeCache,
image_decode_cache,
(kN32_SkColorType, kLockedMemoryLimitBytes,
PaintImage::GetNextGeneratorClientId()));
(kN32_SkColorType, kLockedMemoryLimitBytes));
return image_decode_cache;
}

Expand Down

0 comments on commit 7a5139e

Please sign in to comment.