Commit 43a94cb5 authored by Miguel Casas-Sanchez's avatar Miguel Casas-Sanchez Committed by Commit Bot

Use VideoFrame::NumTextures ISO NumPlanes where needed

This CL sorts out a few points to clear the way for
crrev.com/c/784330 to be landed again; these changes
are, in a nutshell using NumTextures() ISO NumPlanes()
where appropriate, and rewriting the service function
NumGpuMemoryBuffers() for clarity and to allow for
removing FinalVideoFormat().

TEST=all unittests working as before, Video playback
in all platforms and with/without video deco acceleration
running as on ToT.

Bug: 791676
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Ic8f0a646a7a0d9271d7233681cb0383e3f6f64ba
Reviewed-on: https://chromium-review.googlesource.com/807366
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarFredrik Hubinette <hubbe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521999}
parent 27a36d41
......@@ -38,7 +38,7 @@ namespace {
const viz::ResourceFormat kRGBResourceFormat = viz::RGBA_8888;
VideoFrameExternalResources::ResourceType ExternalResourceTypeForHardwarePlanes(
GLuint format,
media::VideoPixelFormat format,
GLuint target,
int num_textures,
gfx::BufferFormat* buffer_format,
......@@ -67,22 +67,16 @@ VideoFrameExternalResources::ResourceType ExternalResourceTypeForHardwarePlanes(
return VideoFrameExternalResources::YUV_RESOURCE;
break;
case media::PIXEL_FORMAT_NV12:
switch (target) {
case GL_TEXTURE_EXTERNAL_OES:
case GL_TEXTURE_2D:
// Single plane textures can be sampled as RGB.
if (num_textures > 1) {
return VideoFrameExternalResources::YUV_RESOURCE;
} else {
*buffer_format = gfx::BufferFormat::YUV_420_BIPLANAR;
return VideoFrameExternalResources::RGB_RESOURCE;
}
case GL_TEXTURE_RECTANGLE_ARB:
return VideoFrameExternalResources::RGB_RESOURCE;
default:
NOTREACHED();
break;
}
DCHECK(target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_2D ||
target == GL_TEXTURE_RECTANGLE_ARB)
<< "Unsupported texture target " << std::hex << std::showbase
<< target;
// Single plane textures can be sampled as RGB.
if (num_textures > 1)
return VideoFrameExternalResources::YUV_RESOURCE;
*buffer_format = gfx::BufferFormat::YUV_420_BIPLANAR;
return VideoFrameExternalResources::RGB_RESOURCE;
break;
case media::PIXEL_FORMAT_YV12:
case media::PIXEL_FORMAT_YV16:
......@@ -886,8 +880,8 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
if (external_resources.type == VideoFrameExternalResources::RGB_RESOURCE)
resource_color_space = resource_color_space.GetAsFullRangeRGB();
const size_t num_planes = media::VideoFrame::NumPlanes(video_frame->format());
for (size_t i = 0; i < num_planes; ++i) {
const size_t num_textures = video_frame->NumTextures();
for (size_t i = 0; i < num_textures; ++i) {
const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i);
if (mailbox_holder.mailbox.IsZero())
break;
......
......@@ -726,6 +726,17 @@ TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_SingleNV12) {
resources.resources[0].mailbox_holder.texture_target);
EXPECT_EQ(gfx::BufferFormat::YUV_420_BIPLANAR,
resources.resources[0].buffer_format);
video_frame = CreateTestYuvHardwareVideoFrame(media::PIXEL_FORMAT_NV12, 1,
GL_TEXTURE_RECTANGLE_ARB);
resources = updater.CreateExternalResourcesFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameExternalResources::RGB_RESOURCE, resources.type);
EXPECT_EQ(1u, resources.resources.size());
EXPECT_EQ((GLenum)GL_TEXTURE_RECTANGLE_ARB,
resources.resources[0].mailbox_holder.texture_target);
EXPECT_EQ(gfx::BufferFormat::YUV_420_BIPLANAR,
resources.resources[0].buffer_format);
EXPECT_EQ(0, context3d_->TextureCreationCount());
}
......@@ -749,6 +760,16 @@ TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_DualNV12) {
resources.resources[0].mailbox_holder.texture_target);
// |updater| doesn't set |buffer_format| in this case.
EXPECT_EQ(gfx::BufferFormat::RGBA_8888, resources.resources[0].buffer_format);
video_frame = CreateTestYuvHardwareVideoFrame(media::PIXEL_FORMAT_NV12, 2,
GL_TEXTURE_RECTANGLE_ARB);
resources = updater.CreateExternalResourcesFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
EXPECT_EQ(2u, resources.resources.size());
EXPECT_EQ((GLenum)GL_TEXTURE_RECTANGLE_ARB,
resources.resources[0].mailbox_holder.texture_target);
EXPECT_EQ(gfx::BufferFormat::RGBA_8888, resources.resources[0].buffer_format);
EXPECT_EQ(0, context3d_->TextureCreationCount());
}
......
......@@ -102,13 +102,14 @@ sk_sp<SkImage> NewSkImageFromVideoFrameYUVTextures(
GrGLTextureInfo source_textures[] = {{0, 0}, {0, 0}, {0, 0}};
GLint min_mag_filter[][2] = {{0, 0}, {0, 0}, {0, 0}};
for (size_t i = 0; i < media::VideoFrame::NumPlanes(video_frame->format());
++i) {
for (size_t i = 0; i < video_frame->NumTextures(); ++i) {
// Get the texture from the mailbox and wrap it in a GrTexture.
const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i);
DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D ||
mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES ||
mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB);
mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB)
<< "Unsupported texture target " << std::hex << std::showbase
<< mailbox_holder.texture_target;
gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData());
source_textures[i].fID =
gl->CreateAndConsumeTextureCHROMIUM(mailbox_holder.mailbox.name);
......@@ -164,8 +165,7 @@ sk_sp<SkImage> NewSkImageFromVideoFrameYUVTextures(
handles, yuvSizes,
kTopLeft_GrSurfaceOrigin);
}
for (size_t i = 0; i < media::VideoFrame::NumPlanes(video_frame->format());
++i) {
for (size_t i = 0; i < video_frame->NumTextures(); ++i) {
gl->BindTexture(source_textures[i].fTarget, source_textures[i].fID);
gl->TexParameteri(source_textures[i].fTarget, GL_TEXTURE_MIN_FILTER,
min_mag_filter[i][0]);
......@@ -190,6 +190,7 @@ sk_sp<SkImage> NewSkImageFromVideoFrameNative(VideoFrame* video_frame,
DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D ||
mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB ||
mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES)
<< "Unsupported texture target " << std::hex << std::showbase
<< mailbox_holder.texture_target;
gpu::gles2::GLES2Interface* gl = context_3d.gl;
......@@ -881,7 +882,7 @@ bool PaintCanvasVideoRenderer::CopyVideoFrameTexturesToGLTexture(
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(video_frame);
DCHECK(video_frame->HasTextures());
if (media::VideoFrame::NumPlanes(video_frame->format()) > 1) {
if (video_frame->NumTextures() > 1) {
if (!context_3d.gr_context)
return false;
if (!UpdateLastImage(video_frame, context_3d))
......@@ -1040,7 +1041,7 @@ bool PaintCanvasVideoRenderer::UpdateLastImage(
if (video_frame->HasTextures()) {
DCHECK(context_3d.gr_context);
DCHECK(context_3d.gl);
if (media::VideoFrame::NumPlanes(video_frame->format()) > 1) {
if (video_frame->NumTextures() > 1) {
paint_image_builder.set_image(
NewSkImageFromVideoFrameYUVTextures(video_frame.get(), context_3d));
} else {
......
......@@ -271,17 +271,23 @@ VideoPixelFormat VideoFormat(
return PIXEL_FORMAT_UNKNOWN;
}
VideoPixelFormat FinalVideoFormat(
GpuVideoAcceleratorFactories::OutputFormat format) {
// Consumers should sample from NV12 textures as if they're XRGB.
if (format == GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB)
return PIXEL_FORMAT_XRGB;
return VideoFormat(format);
}
// The number of output planes to be copied in each iteration.
size_t NumGpuMemoryBuffers(GpuVideoAcceleratorFactories::OutputFormat format) {
return VideoFrame::NumPlanes(FinalVideoFormat(format));
switch (format) {
case GpuVideoAcceleratorFactories::OutputFormat::I420:
return 3;
case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB:
return 1;
case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB:
return 2;
case GpuVideoAcceleratorFactories::OutputFormat::UYVY:
return 1;
case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED:
NOTREACHED();
break;
}
NOTREACHED();
return 0;
}
// The number of output rows to be copied in each iteration.
......@@ -688,7 +694,7 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::
auto release_mailbox_callback = BindToCurrentLoop(
base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources));
VideoPixelFormat frame_format = FinalVideoFormat(output_format_);
VideoPixelFormat frame_format = VideoFormat(output_format_);
// Create the VideoFrame backed by native textures.
gfx::Size visible_size = video_frame->visible_rect().size();
......
......@@ -176,6 +176,8 @@ TEST_F(GpuMemoryBufferVideoFramePoolTest, CreateOneHardwareFrame) {
RunUntilIdle();
EXPECT_NE(software_frame.get(), frame.get());
EXPECT_EQ(PIXEL_FORMAT_I420, frame->format());
EXPECT_EQ(3u, frame->NumTextures());
EXPECT_EQ(3u, gles2_->gen_textures_count());
}
......@@ -243,6 +245,8 @@ TEST_F(GpuMemoryBufferVideoFramePoolTest, CreateOneHardwareUYUVFrame) {
RunUntilIdle();
EXPECT_NE(software_frame.get(), frame.get());
EXPECT_EQ(PIXEL_FORMAT_UYVY, frame->format());
EXPECT_EQ(1u, frame->NumTextures());
EXPECT_EQ(1u, gles2_->gen_textures_count());
EXPECT_TRUE(frame->metadata()->IsTrue(
media::VideoFrameMetadata::READ_LOCK_FENCES_ENABLED));
......@@ -259,6 +263,8 @@ TEST_F(GpuMemoryBufferVideoFramePoolTest, CreateOneHardwareNV12Frame) {
RunUntilIdle();
EXPECT_NE(software_frame.get(), frame.get());
EXPECT_EQ(PIXEL_FORMAT_NV12, frame->format());
EXPECT_EQ(1u, frame->NumTextures());
EXPECT_EQ(1u, gles2_->gen_textures_count());
EXPECT_TRUE(frame->metadata()->IsTrue(
media::VideoFrameMetadata::READ_LOCK_FENCES_ENABLED));
......@@ -275,6 +281,8 @@ TEST_F(GpuMemoryBufferVideoFramePoolTest, CreateOneHardwareNV12Frame2) {
RunUntilIdle();
EXPECT_NE(software_frame.get(), frame.get());
EXPECT_EQ(PIXEL_FORMAT_NV12, frame->format());
EXPECT_EQ(2u, frame->NumTextures());
EXPECT_EQ(2u, gles2_->gen_textures_count());
EXPECT_TRUE(frame->metadata()->IsTrue(
media::VideoFrameMetadata::READ_LOCK_FENCES_ENABLED));
......
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