Commit 35454c17 authored by Antoine Labour's avatar Antoine Labour Committed by Commit Bot

Use shared images in CopyVideoFrameYUVDataToGLTexture

Use an explicit shared image allocation for the intermediate texture
that is used in both the source and destination GL contexts.

Bug: 882547
Change-Id: Ibd37bb16a1a43860976c9b35feadd576e099df4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1633530
Auto-Submit: Antoine Labour <piman@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Commit-Queue: Antoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664539}
parent 0738403e
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
#include "gpu/GLES2/gl2extchromium.h" #include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/context_support.h" #include "gpu/command_buffer/client/context_support.h"
#include "gpu/command_buffer/client/gles2_interface.h" #include "gpu/command_buffer/client/gles2_interface.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/common/capabilities.h" #include "gpu/command_buffer/common/capabilities.h"
#include "gpu/command_buffer/common/mailbox_holder.h" #include "gpu/command_buffer/common/mailbox_holder.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "media/base/data_buffer.h" #include "media/base/data_buffer.h"
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
#include "third_party/libyuv/include/libyuv.h" #include "third_party/libyuv/include/libyuv.h"
...@@ -1327,43 +1329,69 @@ bool PaintCanvasVideoRenderer::CopyVideoFrameYUVDataToGLTexture( ...@@ -1327,43 +1329,69 @@ bool PaintCanvasVideoRenderer::CopyVideoFrameYUVDataToGLTexture(
yuv_textures[plane] = yuv_images[plane]->getBackendTexture(false); yuv_textures[plane] = yuv_images[plane]->getBackendTexture(false);
} }
// Decode 3 GPU-side Y,U,V SkImages into a GPU-side RGB SkImage. auto* sii = context_provider->SharedImageInterface();
sk_sp<SkImage> yuv_image = YUVGrBackendTexturesToSkImage(
gr_context, video_frame.ColorSpace(), video_frame.format(), yuv_textures);
if (!yuv_image) {
return false;
}
GrGLTextureInfo src_texture_info{};
yuv_image->getBackendTexture(true).getGLTextureInfo(&src_texture_info);
gpu::gles2::GLES2Interface* source_gl = context_provider->ContextGL(); gpu::gles2::GLES2Interface* source_gl = context_provider->ContextGL();
gpu::MailboxHolder mailbox_holder;
mailbox_holder.texture_target = src_texture_info.fTarget;
source_gl->ProduceTextureDirectCHROMIUM(src_texture_info.fID,
mailbox_holder.mailbox.name);
// Wait for mailbox creation on source context before consuming it and // Create a shared image to receive the intermediate RGB result.
// copying from it on the consumer context. gpu::Mailbox mailbox = sii->CreateSharedImage(
source_gl->GenUnverifiedSyncTokenCHROMIUM( viz::ResourceFormat::RGBA_8888, video_frame.coded_size(),
mailbox_holder.sync_token.GetData()); gfx::ColorSpace(), gpu::SHARED_IMAGE_USAGE_GLES2);
gpu::SyncToken creation_sync_token = sii->GenUnverifiedSyncToken();
// On the source GL context, do the YUV->RGB conversion using Skia.
gpu::SyncToken post_conversion_sync_token;
{
source_gl->WaitSyncTokenCHROMIUM(creation_sync_token.GetConstData());
GLuint intermediate_texture =
source_gl->CreateAndTexStorage2DSharedImageCHROMIUM(mailbox.name);
source_gl->BeginSharedImageAccessDirectCHROMIUM(
intermediate_texture, GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM);
GrGLTextureInfo backend_texture = {intermediate_texture, GL_TEXTURE_2D,
GL_RGBA8};
GrBackendTexture result_texture(video_frame.coded_size().width(),
video_frame.coded_size().height(),
GrMipMapped::kNo, backend_texture);
sk_sp<SkImage> yuv_image = YUVGrBackendTexturesToSkImage(
gr_context, video_frame.ColorSpace(), video_frame.format(),
yuv_textures, &result_texture);
gr_context->flush();
source_gl->EndSharedImageAccessDirectCHROMIUM(intermediate_texture);
source_gl->DeleteTextures(1, &intermediate_texture);
source_gl->GenUnverifiedSyncTokenCHROMIUM(
post_conversion_sync_token.GetData());
if (!yuv_image) {
sii->DestroySharedImage(post_conversion_sync_token, mailbox);
return false;
}
}
destination_gl->WaitSyncTokenCHROMIUM( // On the destination GL context, do a copy (with cropping) into the
mailbox_holder.sync_token.GetConstData()); // destination texture.
uint32_t intermediate_texture = gpu::SyncToken post_copy_sync_token;
destination_gl->CreateAndConsumeTextureCHROMIUM( {
mailbox_holder.mailbox.name); destination_gl->WaitSyncTokenCHROMIUM(
VideoFrameCopyTextureOrSubTexture( post_conversion_sync_token.GetConstData());
destination_gl, video_frame.coded_size(), video_frame.visible_rect(), GLuint intermediate_texture =
intermediate_texture, target, texture, internal_format, format, type, destination_gl->CreateAndTexStorage2DSharedImageCHROMIUM(mailbox.name);
level, premultiply_alpha, flip_y); destination_gl->BeginSharedImageAccessDirectCHROMIUM(
destination_gl->DeleteTextures(1, &intermediate_texture); intermediate_texture, GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM);
// Wait for destination context to consume mailbox before deleting it in VideoFrameCopyTextureOrSubTexture(
// source context. destination_gl, video_frame.coded_size(), video_frame.visible_rect(),
gpu::SyncToken dest_sync_token; intermediate_texture, target, texture, internal_format, format, type,
destination_gl->GenUnverifiedSyncTokenCHROMIUM(dest_sync_token.GetData()); level, premultiply_alpha, flip_y);
source_gl->WaitSyncTokenCHROMIUM(dest_sync_token.GetConstData());
destination_gl->EndSharedImageAccessDirectCHROMIUM(intermediate_texture);
destination_gl->DeleteTextures(1, &intermediate_texture);
destination_gl->GenUnverifiedSyncTokenCHROMIUM(
post_copy_sync_token.GetData());
}
sii->DestroySharedImage(post_copy_sync_token, mailbox);
// video_frame->UpdateReleaseSyncToken is not necessary since the video frame // video_frame->UpdateReleaseSyncToken is not necessary since the video frame
// data we used was CPU-side (IsMappable) to begin with. If there were any // data we used was CPU-side (IsMappable) to begin with. If there were any
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment