Skip to content

Commit

Permalink
Multiplanar: Implement RasterDecoder::ReadbackARGB with plane index
Browse files Browse the repository at this point in the history
This change updates the RasterDecoder::ReadbackARGBImagePixels
to take in a plane index and use the SkImage and SkImagePromiseTexture
for readback using the given plane index. This is done for multiplanar
formats and shared images where we have a single mailbox used to
represent multiple textures for multiple planes (YUV).

Bug: 1417022
Change-Id: I42243fc43904a17a267c966868faaaf6c8b9debe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4265176
Reviewed-by: Kyle Charbonneau <kylechar@chromium.org>
Commit-Queue: Saifuddin Hitawala <hitawala@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1108895}
  • Loading branch information
Saifuddin Hitawala authored and Chromium LUCI CQ committed Feb 23, 2023
1 parent 9393fdd commit 3db13d0
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions gpu/command_buffer/service/raster_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,8 @@ void RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL(
return;
}

viz::SharedImageFormat source_format = source_shared_image->format();

// If present, the color space is serialized into shared memory after the
// result and before the pixel data.
if (color_space_offset > pixels_offset) {
Expand All @@ -2149,6 +2151,13 @@ void RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL(

sk_sp<SkColorSpace> dst_color_space;
if (color_space_size) {
// For multiplanar formats readback is per plane, and destination color
// space must be nullptr to allow letting Skia assume srgb color space.
if (source_format.is_multi_plane()) {
LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels",
"Unexpected color space for multiplanar shared image");
return;
}
void* color_space_bytes = GetSharedMemoryAs<void*>(
shm_id, shm_offset + color_space_offset, color_space_size);
if (!color_space_bytes) {
Expand Down Expand Up @@ -2201,6 +2210,12 @@ void RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL(
return;
}

if (!source_format.IsValidPlaneIndex(plane_index)) {
LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels",
"Invalid plane_index");
return;
}

std::vector<GrBackendSemaphore> begin_semaphores;
std::vector<GrBackendSemaphore> end_semaphores;

Expand All @@ -2221,8 +2236,18 @@ void RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL(
DCHECK(wait_result);
}

auto sk_image =
source_scoped_access->CreateSkImage(shared_context_state_->gr_context());
sk_sp<SkImage> sk_image;
if (source_format.is_single_plane()) {
// Create SkImage without plane index for single planar formats or legacy
// multiplanar formats with external sampler.
sk_image = source_scoped_access->CreateSkImage(
shared_context_state_->gr_context());
} else {
// Pass plane index for creating an SkImage for multiplanar formats.
sk_image = source_scoped_access->CreateSkImageForPlane(
plane_index, shared_context_state_->gr_context());
}

if (sk_image) {
bool success =
sk_image->readPixels(dst_info, pixel_address, row_bytes, src_x, src_y);
Expand All @@ -2239,7 +2264,8 @@ void RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL(

if (auto end_state = source_scoped_access->TakeEndState()) {
gr_context()->setBackendTextureState(
source_scoped_access->promise_image_texture()->backendTexture(),
source_scoped_access->promise_image_texture(plane_index)
->backendTexture(),
*end_state);
}

Expand Down

0 comments on commit 3db13d0

Please sign in to comment.