0

Fix a crash in RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL

Bug: 1227008
Change-Id: I3e5437c78495a647007860e8a2bad0c4d3507026
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3021687
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#901021}
This commit is contained in:
Peng Huang
2021-07-13 15:40:14 +00:00
committed by Chromium LUCI CQ
parent 168ed5dbb1
commit d677d8f715

@ -2819,33 +2819,6 @@ void RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL(
return;
}
std::vector<GrBackendSemaphore> begin_semaphores;
std::unique_ptr<SharedImageRepresentationSkia::ScopedReadAccess>
source_scoped_access = source_shared_image->BeginScopedReadAccess(
&begin_semaphores, nullptr);
if (!begin_semaphores.empty()) {
bool result = shared_context_state_->gr_context()->wait(
begin_semaphores.size(), begin_semaphores.data(),
/*deleteSemaphoresAfterWait=*/false);
DCHECK(result);
}
if (!source_scoped_access) {
LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels",
"Source shared image is not accessible");
return;
}
auto sk_image =
source_scoped_access->CreateSkImage(shared_context_state_->gr_context());
if (!sk_image) {
LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels",
"Couldn't create SkImage for reading.");
return;
}
size_t byte_size = dst_info.computeByteSize(row_bytes);
if (byte_size > UINT32_MAX) {
LOCAL_SET_GL_ERROR(
@ -2871,6 +2844,47 @@ void RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL(
return;
}
std::vector<GrBackendSemaphore> begin_semaphores;
std::vector<GrBackendSemaphore> end_semaphores;
std::unique_ptr<SharedImageRepresentationSkia::ScopedReadAccess>
source_scoped_access = source_shared_image->BeginScopedReadAccess(
&begin_semaphores, &end_semaphores);
if (!source_scoped_access) {
LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels",
"Source shared image is not accessible");
return;
}
if (!begin_semaphores.empty()) {
bool wait_result = shared_context_state_->gr_context()->wait(
begin_semaphores.size(), begin_semaphores.data(),
/*deleteSemaphoresAfterWait=*/false);
DCHECK(wait_result);
}
if (!end_semaphores.empty()) {
// Ask skia to signal |end_semaphores| here, since we will synchronized
// read pixels from the shared image.
GrFlushInfo flush_info = {
.fNumSemaphores = end_semaphores.size(),
.fSignalSemaphores = end_semaphores.data(),
};
AddVulkanCleanupTaskForSkiaFlush(
shared_context_state_->vk_context_provider(), &flush_info);
auto flush_result = shared_context_state_->gr_context()->flush(flush_info);
DCHECK(flush_result == GrSemaphoresSubmitted::kYes);
}
auto sk_image =
source_scoped_access->CreateSkImage(shared_context_state_->gr_context());
if (!sk_image) {
LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels",
"Couldn't create SkImage for reading.");
return;
}
bool success =
sk_image->readPixels(dst_info, pixel_address, row_bytes, src_x, src_y);
if (!success) {