Skip to content

Commit

Permalink
[media] Use ClientSharedImage in PaintCanvasVideoRenderer
Browse files Browse the repository at this point in the history
As part of the ClientSharedImage refactorization, this CL replaces the
Mailbox member of PaintCanvasVideoRenderer::YUVTextureCache with
ClientSharedImage, and uses this new ClientSharedImage member when
calling DestroySharedImage().

Bug: 1494911, 1499992
Change-Id: Ie959048dfa5047fe351a63a52b5af28256f23bb5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5106648
Commit-Queue: Mingjing Zhang <mjzhang@chromium.org>
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1236164}
  • Loading branch information
Mingjing Zhang authored and Chromium LUCI CQ committed Dec 12, 2023
1 parent 3344d1b commit 5eedea4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
20 changes: 9 additions & 11 deletions media/renderers/paint_canvas_video_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1829,8 +1829,7 @@ bool PaintCanvasVideoRenderer::CopyVideoFrameYUVDataToGLTexture(
// We need a shared image to receive the intermediate RGB result. Try to reuse
// one if compatible, otherwise create a new one.
gpu::SyncToken token;
if (!yuv_cache_.mailbox.IsZero() &&
yuv_cache_.size == video_frame->coded_size() &&
if (yuv_cache_.shared_image && yuv_cache_.size == video_frame->coded_size() &&
yuv_cache_.raster_context_provider == raster_context_provider) {
token = yuv_cache_.sync_token;
} else {
Expand All @@ -1844,19 +1843,18 @@ bool PaintCanvasVideoRenderer::CopyVideoFrameYUVDataToGLTexture(
gpu::SHARED_IMAGE_USAGE_OOP_RASTERIZATION;
}

auto client_shared_image = sii->CreateSharedImage(
yuv_cache_.shared_image = sii->CreateSharedImage(
SHARED_IMAGE_FORMAT, video_frame->coded_size(),
GetVideoFrameRGBColorSpacePreferringSRGB(video_frame.get()),
kTopLeft_GrSurfaceOrigin, kPremul_SkAlphaType, usage,
"PaintCanvasVideoRenderer", gpu::kNullSurfaceHandle);
CHECK(client_shared_image);
yuv_cache_.mailbox = client_shared_image->mailbox();
CHECK(yuv_cache_.shared_image);
token = sii->GenUnverifiedSyncToken();
}

// On the source Raster context, do the YUV->RGB conversion.
gpu::MailboxHolder dest_holder;
dest_holder.mailbox = yuv_cache_.mailbox;
dest_holder.mailbox = yuv_cache_.shared_image->mailbox();
dest_holder.texture_target = GL_TEXTURE_2D;
dest_holder.sync_token = token;
yuv_cache_.yuv_converter.ConvertYUVVideoFrame(
Expand All @@ -1870,8 +1868,8 @@ bool PaintCanvasVideoRenderer::CopyVideoFrameYUVDataToGLTexture(
// destination texture.
CopyMailboxToTexture(
destination_gl, video_frame->coded_size(), video_frame->visible_rect(),
yuv_cache_.mailbox, post_conversion_sync_token, target, texture,
internal_format, format, type, level, premultiply_alpha, flip_y);
yuv_cache_.shared_image->mailbox(), post_conversion_sync_token, target,
texture, internal_format, format, type, level, premultiply_alpha, flip_y);
destination_gl->GenUnverifiedSyncTokenCHROMIUM(
yuv_cache_.sync_token.GetData());

Expand Down Expand Up @@ -2219,17 +2217,17 @@ PaintCanvasVideoRenderer::YUVTextureCache::~YUVTextureCache() {
}

void PaintCanvasVideoRenderer::YUVTextureCache::Reset() {
if (mailbox.IsZero())
if (!shared_image) {
return;
}
DCHECK(raster_context_provider);

gpu::raster::RasterInterface* ri = raster_context_provider->RasterInterface();
ri->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
ri->OrderingBarrierCHROMIUM();

auto* sii = raster_context_provider->SharedImageInterface();
sii->DestroySharedImage(sync_token, mailbox);
mailbox.SetZero();
sii->DestroySharedImage(sync_token, std::move(shared_image));

yuv_converter.ReleaseCachedData();

Expand Down
3 changes: 2 additions & 1 deletion media/renderers/paint_canvas_video_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class RectF;

namespace gpu {
struct Capabilities;
class ClientSharedImage;

namespace gles2 {
class GLES2Interface;
Expand Down Expand Up @@ -297,7 +298,7 @@ class MEDIA_EXPORT PaintCanvasVideoRenderer {
gfx::Size size;

// The shared image backing the texture.
gpu::Mailbox mailbox;
scoped_refptr<gpu::ClientSharedImage> shared_image;

// Used to perform YUV->RGB conversion on video frames. Internally caches
// shared images that are created to upload CPU video frame data to the GPU.
Expand Down

0 comments on commit 5eedea4

Please sign in to comment.