Commit c5fe11ca authored by Zhaoliang Ma's avatar Zhaoliang Ma Committed by Commit Bot

media/renderer: clean up |VideoResourceUpdater| ContextGL

This CL move the ContextGL to a member function of VideoResourceUpdater.

Bug: None
Change-Id: I0032cd5c766d6c0f3d798b8ca60259bf66d3057e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2415671
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808434}
parent c3fca2f9
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "components/viz/common/resources/resource_sizes.h" #include "components/viz/common/resources/resource_sizes.h"
#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/shared_image_interface.h" #include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/common/shared_image_trace_utils.h" #include "gpu/command_buffer/common/shared_image_trace_utils.h"
#include "gpu/command_buffer/common/shared_image_usage.h" #include "gpu/command_buffer/common/shared_image_usage.h"
...@@ -791,9 +790,7 @@ void VideoResourceUpdater::CopyHardwarePlane( ...@@ -791,9 +790,7 @@ void VideoResourceUpdater::CopyHardwarePlane(
DCHECK_EQ(hardware_resource->texture_target(), DCHECK_EQ(hardware_resource->texture_target(),
static_cast<GLenum>(GL_TEXTURE_2D)); static_cast<GLenum>(GL_TEXTURE_2D));
auto* gl = raster_context_provider_ ? raster_context_provider_->ContextGL() auto* gl = ContextGL();
: context_provider_->ContextGL();
gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData());
// This is only used on Android where all video mailboxes already use shared // This is only used on Android where all video mailboxes already use shared
...@@ -1070,10 +1067,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( ...@@ -1070,10 +1067,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
video_frame.get(), upload_pixels_.get(), bytes_per_row); video_frame.get(), upload_pixels_.get(), bytes_per_row);
// Copy pixels into texture. // Copy pixels into texture.
auto* gl = raster_context_provider_ auto* gl = ContextGL();
? raster_context_provider_->ContextGL()
: context_provider_->ContextGL();
const gfx::Size& plane_size = hardware_resource->resource_size(); const gfx::Size& plane_size = hardware_resource->resource_size();
{ {
HardwarePlaneResource::ScopedTexture scope(gl, hardware_resource); HardwarePlaneResource::ScopedTexture scope(gl, hardware_resource);
...@@ -1100,9 +1094,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( ...@@ -1100,9 +1094,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
HardwarePlaneResource* hardware_resource = plane_resource->AsHardware(); HardwarePlaneResource* hardware_resource = plane_resource->AsHardware();
external_resources.type = VideoFrameResourceType::RGBA; external_resources.type = VideoFrameResourceType::RGBA;
gpu::SyncToken sync_token; gpu::SyncToken sync_token;
auto* gl = raster_context_provider_ auto* gl = ContextGL();
? raster_context_provider_->ContextGL()
: context_provider_->ContextGL();
GenerateCompositorSyncToken(gl, &sync_token); GenerateCompositorSyncToken(gl, &sync_token);
transferable_resource = viz::TransferableResource::MakeGL( transferable_resource = viz::TransferableResource::MakeGL(
hardware_resource->mailbox(), GL_LINEAR, hardware_resource->mailbox(), GL_LINEAR,
...@@ -1139,6 +1131,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( ...@@ -1139,6 +1131,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
external_resources.offset = 0; external_resources.offset = 0;
} }
auto* gl = ContextGL();
// We need to transfer data from |video_frame| to the plane resources. // We need to transfer data from |video_frame| to the plane resources.
for (size_t i = 0; i < plane_resources.size(); ++i) { for (size_t i = 0; i < plane_resources.size(); ++i) {
HardwarePlaneResource* plane_resource = plane_resources[i]->AsHardware(); HardwarePlaneResource* plane_resource = plane_resources[i]->AsHardware();
...@@ -1244,8 +1237,6 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( ...@@ -1244,8 +1237,6 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
// Copy pixels into texture. TexSubImage2D() is applicable because // Copy pixels into texture. TexSubImage2D() is applicable because
// |yuv_resource_format| is LUMINANCE_F16, R16_EXT, LUMINANCE_8 or RED_8. // |yuv_resource_format| is LUMINANCE_F16, R16_EXT, LUMINANCE_8 or RED_8.
auto* gl = raster_context_provider_ ? raster_context_provider_->ContextGL()
: context_provider_->ContextGL();
DCHECK(GLSupportsFormat(plane_resource_format)); DCHECK(GLSupportsFormat(plane_resource_format));
{ {
HardwarePlaneResource::ScopedTexture scope(gl, plane_resource); HardwarePlaneResource::ScopedTexture scope(gl, plane_resource);
...@@ -1268,8 +1259,6 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( ...@@ -1268,8 +1259,6 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
// Set the sync token otherwise resource is assumed to be synchronized. // Set the sync token otherwise resource is assumed to be synchronized.
gpu::SyncToken sync_token; gpu::SyncToken sync_token;
auto* gl = raster_context_provider_ ? raster_context_provider_->ContextGL()
: context_provider_->ContextGL();
GenerateCompositorSyncToken(gl, &sync_token); GenerateCompositorSyncToken(gl, &sync_token);
for (size_t i = 0; i < plane_resources.size(); ++i) { for (size_t i = 0; i < plane_resources.size(); ++i) {
...@@ -1290,6 +1279,13 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( ...@@ -1290,6 +1279,13 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
return external_resources; return external_resources;
} }
gpu::gles2::GLES2Interface* VideoResourceUpdater::ContextGL() {
auto* gl = raster_context_provider_ ? raster_context_provider_->ContextGL()
: context_provider_->ContextGL();
DCHECK(gl);
return gl;
}
void VideoResourceUpdater::ReturnTexture(scoped_refptr<VideoFrame> video_frame, void VideoResourceUpdater::ReturnTexture(scoped_refptr<VideoFrame> video_frame,
const gpu::SyncToken& sync_token, const gpu::SyncToken& sync_token,
bool lost_resource) { bool lost_resource) {
...@@ -1298,10 +1294,8 @@ void VideoResourceUpdater::ReturnTexture(scoped_refptr<VideoFrame> video_frame, ...@@ -1298,10 +1294,8 @@ void VideoResourceUpdater::ReturnTexture(scoped_refptr<VideoFrame> video_frame,
return; return;
// The video frame will insert a wait on the previous release sync token. // The video frame will insert a wait on the previous release sync token.
auto* gl = raster_context_provider_ ? raster_context_provider_->ContextGL() SyncTokenClientImpl client(
: context_provider_->ContextGL(); ContextGL(), nullptr /* gpu::SharedImageInterface* */, sync_token);
SyncTokenClientImpl client(gl, nullptr /* gpu::SharedImageInterface* */,
sync_token);
video_frame->UpdateReleaseSyncToken(&client); video_frame->UpdateReleaseSyncToken(&client);
} }
...@@ -1331,9 +1325,7 @@ void VideoResourceUpdater::RecycleResource(uint32_t plane_resource_id, ...@@ -1331,9 +1325,7 @@ void VideoResourceUpdater::RecycleResource(uint32_t plane_resource_id,
return; return;
if ((raster_context_provider_ || context_provider_) && sync_token.HasData()) { if ((raster_context_provider_ || context_provider_) && sync_token.HasData()) {
auto* gl = raster_context_provider_ ? raster_context_provider_->ContextGL() ContextGL()->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
: context_provider_->ContextGL();
gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
} }
if (lost_resource) { if (lost_resource) {
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "components/viz/common/resources/resource_format.h" #include "components/viz/common/resources/resource_format.h"
#include "components/viz/common/resources/resource_id.h" #include "components/viz/common/resources/resource_id.h"
#include "components/viz/common/resources/transferable_resource.h" #include "components/viz/common/resources/transferable_resource.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "media/base/media_export.h" #include "media/base/media_export.h"
#include "ui/gfx/buffer_types.h" #include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -186,6 +187,8 @@ class MEDIA_EXPORT VideoResourceUpdater ...@@ -186,6 +187,8 @@ class MEDIA_EXPORT VideoResourceUpdater
VideoFrameExternalResources CreateForSoftwarePlanes( VideoFrameExternalResources CreateForSoftwarePlanes(
scoped_refptr<VideoFrame> video_frame); scoped_refptr<VideoFrame> video_frame);
gpu::gles2::GLES2Interface* ContextGL();
void RecycleResource(uint32_t plane_resource_id, void RecycleResource(uint32_t plane_resource_id,
const gpu::SyncToken& sync_token, const gpu::SyncToken& sync_token,
bool lost_resource); bool lost_resource);
......
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