Reland "Refactor DestroySharedImage() for raster buffer providers"
This CL is a manually created reland of https://crrev.com/c/5003181
and includes a fix for a HasOneRef() assertion failure caused by
CL5003181 (see https://crbug.com/1501374 for more details of the
failure).
Original change's commit message:
> As part of a large scale refactorization that aims at introducing
> ClientSharedImage, this CL refactors several raster buffer providers
> to 1. use the new version of DestroySharedImage() (that accepts a
> ClientSharedImage parameter instead of a mailbox), and 2. make sure
> the ClientSharedImage created by CreateSharedImage() could persist
> until the calling of DestroySharedImage().
Bug: 1494911, 1499992
Change-Id: I6f92e6147fd0dcfcf88445707a4deed23d276548
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029514
Commit-Queue: Mingjing Zhang <mjzhang@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1228027}
diff --git a/cc/raster/gpu_raster_buffer_provider.cc b/cc/raster/gpu_raster_buffer_provider.cc
index 11711b4..4e6ef4f6 100644
--- a/cc/raster/gpu_raster_buffer_provider.cc
+++ b/cc/raster/gpu_raster_buffer_provider.cc
@@ -50,14 +50,14 @@
: public ResourcePool::GpuBacking {
public:
~GpuRasterBacking() override {
- if (mailbox.IsZero()) {
+ if (!shared_image) {
return;
}
auto* sii = worker_context_provider->SharedImageInterface();
if (returned_sync_token.HasData())
- sii->DestroySharedImage(returned_sync_token, mailbox);
+ sii->DestroySharedImage(returned_sync_token, std::move(shared_image));
else if (mailbox_sync_token.HasData())
- sii->DestroySharedImage(mailbox_sync_token, mailbox);
+ sii->DestroySharedImage(mailbox_sync_token, std::move(shared_image));
}
void OnMemoryDump(
@@ -65,11 +65,11 @@
const base::trace_event::MemoryAllocatorDumpGuid& buffer_dump_guid,
uint64_t tracing_process_id,
int importance) const override {
- if (mailbox.IsZero()) {
+ if (!shared_image) {
return;
}
- auto tracing_guid = gpu::GetSharedImageGUIDForTracing(mailbox);
+ auto tracing_guid = shared_image->GetGUIDForTracing();
pmd->CreateSharedGlobalAllocatorDump(tracing_guid);
pmd->AddOwnershipEdge(buffer_dump_guid, tracing_guid, importance);
}
@@ -370,7 +370,7 @@
gpu::raster::RasterInterface* ri =
client_->worker_context_provider_->RasterInterface();
bool mailbox_needs_clear = false;
- if (backing_->mailbox.IsZero()) {
+ if (!backing_->shared_image) {
DCHECK(!backing_->returned_sync_token.HasData());
auto* sii = client_->worker_context_provider_->SharedImageInterface();
uint32_t flags = gpu::SHARED_IMAGE_USAGE_DISPLAY_READ |
@@ -383,12 +383,11 @@
} else if (client_->is_using_raw_draw_) {
flags |= gpu::SHARED_IMAGE_USAGE_RAW_DRAW;
}
- auto client_shared_image = sii->CreateSharedImage(
+ backing_->shared_image = sii->CreateSharedImage(
shared_image_format_, resource_size_, color_space_,
kTopLeft_GrSurfaceOrigin, kPremul_SkAlphaType, flags, "GpuRasterTile",
gpu::kNullSurfaceHandle);
- CHECK(client_shared_image);
- backing_->mailbox = client_shared_image->mailbox();
+ CHECK(backing_->shared_image);
mailbox_needs_clear = true;
ri->WaitSyncTokenCHROMIUM(sii->GenUnverifiedSyncToken().GetConstData());
} else {
@@ -420,7 +419,7 @@
raster_source->background_color(), mailbox_needs_clear,
playback_settings.msaa_sample_count, msaa_mode, use_lcd_text,
playback_settings.visible, color_space_, playback_settings.hdr_headroom,
- backing_->mailbox.name);
+ backing_->shared_image->mailbox().name);
gfx::Vector2dF recording_to_raster_scale = transform.scale();
recording_to_raster_scale.InvScale(raster_source->recording_scale_factor());