Commit 0ff62a54 authored by dcastagna's avatar dcastagna Committed by Commit bot

cc: VideoResourceUpdater support for YUV native textures.

After crrev.com/1117423002 VideoFrames can carry three textures, each
one representing a different YUV plane.
VideResourceUpdater needs to create a YUV external resource in case the
VideoFrame contains three native texture representing a frame in YUV420.

BUG=485859

Review URL: https://codereview.chromium.org/1127423006

Cr-Commit-Position: refs/heads/master@{#329290}
parent def5bc67
......@@ -402,38 +402,48 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
media::VideoFrame::Format frame_format = video_frame->format();
DCHECK_EQ(frame_format, media::VideoFrame::NATIVE_TEXTURE);
if (frame_format != media::VideoFrame::NATIVE_TEXTURE)
return VideoFrameExternalResources();
if (!context_provider_)
return VideoFrameExternalResources();
DCHECK_EQ(1u, media::VideoFrame::NumTextures(video_frame->texture_format()));
const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0);
size_t textures =
media::VideoFrame::NumTextures(video_frame->texture_format());
DCHECK_GE(textures, 1u);
VideoFrameExternalResources external_resources;
switch (mailbox_holder.texture_target) {
case GL_TEXTURE_2D:
external_resources.type = VideoFrameExternalResources::RGB_RESOURCE;
break;
case GL_TEXTURE_EXTERNAL_OES:
external_resources.type =
VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE;
switch (video_frame->texture_format()) {
case media::VideoFrame::TEXTURE_RGBA:
DCHECK_EQ(1u, textures);
switch (video_frame->mailbox_holder(0).texture_target) {
case GL_TEXTURE_2D:
external_resources.type = VideoFrameExternalResources::RGB_RESOURCE;
break;
case GL_TEXTURE_EXTERNAL_OES:
external_resources.type =
VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE;
break;
case GL_TEXTURE_RECTANGLE_ARB:
external_resources.type = VideoFrameExternalResources::IO_SURFACE;
break;
default:
NOTREACHED();
return VideoFrameExternalResources();
}
break;
case GL_TEXTURE_RECTANGLE_ARB:
external_resources.type = VideoFrameExternalResources::IO_SURFACE;
case media::VideoFrame::TEXTURE_YUV_420:
external_resources.type = VideoFrameExternalResources::YUV_RESOURCE;
break;
default:
NOTREACHED();
return VideoFrameExternalResources();
}
DCHECK_NE(VideoFrameExternalResources::NONE, external_resources.type);
external_resources.mailboxes.push_back(
TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target,
mailbox_holder.sync_point));
external_resources.mailboxes.back().set_allow_overlay(
video_frame->allow_overlay());
external_resources.release_callbacks.push_back(
base::Bind(&ReturnTexture, AsWeakPtr(), video_frame));
for (size_t i = 0; i < textures; ++i) {
const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i);
external_resources.mailboxes.push_back(
TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target,
mailbox_holder.sync_point));
external_resources.mailboxes.back().set_allow_overlay(
video_frame->allow_overlay());
external_resources.release_callbacks.push_back(
base::Bind(&ReturnTexture, AsWeakPtr(), video_frame));
}
return external_resources;
}
......
......@@ -11,6 +11,7 @@
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/test/test_web_graphics_context_3d.h"
#include "cc/trees/blocking_task_runner.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "media/base/video_frame.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -106,6 +107,53 @@ class VideoResourceUpdaterTest : public testing::Test {
base::Closure()); // no_longer_needed_cb
}
static void ReleaseMailboxCB(unsigned sync_point) {}
scoped_refptr<media::VideoFrame> CreateTestRGBAHardwareVideoFrame() {
const int kDimension = 10;
gfx::Size size(kDimension, kDimension);
gpu::Mailbox mailbox;
mailbox.name[0] = 51;
const unsigned sync_point = 7;
const unsigned target = GL_TEXTURE_2D;
return media::VideoFrame::WrapNativeTexture(
gpu::MailboxHolder(mailbox, target, sync_point),
base::Bind(&ReleaseMailboxCB),
size, // coded_size
gfx::Rect(size), // visible_rect
size, // natural_size
base::TimeDelta(), // timestamp
false); // allow_overlay
}
scoped_refptr<media::VideoFrame> CreateTestYUVHardareVideoFrame() {
const int kDimension = 10;
gfx::Size size(kDimension, kDimension);
const int kPlanesNum = 3;
gpu::Mailbox mailbox[kPlanesNum];
for (int i = 0; i < kPlanesNum; ++i) {
mailbox[i].name[0] = 50 + 1;
}
const unsigned sync_point = 7;
const unsigned target = GL_TEXTURE_RECTANGLE_ARB;
return media::VideoFrame::WrapYUV420NativeTextures(
gpu::MailboxHolder(mailbox[media::VideoFrame::kYPlane], target,
sync_point),
gpu::MailboxHolder(mailbox[media::VideoFrame::kUPlane], target,
sync_point),
gpu::MailboxHolder(mailbox[media::VideoFrame::kVPlane], target,
sync_point),
base::Bind(&ReleaseMailboxCB),
size, // coded_size
gfx::Rect(size), // visible_rect
size, // natural_size
base::TimeDelta(), // timestamp
false); // allow_overlay
}
WebGraphicsContext3DUploadCounter* context3d_;
FakeOutputSurfaceClient client_;
scoped_ptr<FakeOutputSurface> output_surface3d_;
......@@ -251,5 +299,27 @@ TEST_F(VideoResourceUpdaterTest, ReuseResourceNoDeleteSoftwareCompositor) {
EXPECT_EQ(0, shared_bitmap_manager_->AllocationCount());
}
TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes) {
VideoResourceUpdater updater(output_surface3d_->context_provider(),
resource_provider3d_.get());
scoped_refptr<media::VideoFrame> video_frame =
CreateTestRGBAHardwareVideoFrame();
VideoFrameExternalResources resources =
updater.CreateExternalResourcesFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameExternalResources::RGB_RESOURCE, resources.type);
EXPECT_EQ(1u, resources.mailboxes.size());
EXPECT_EQ(1u, resources.release_callbacks.size());
EXPECT_EQ(0u, resources.software_resources.size());
video_frame = CreateTestYUVHardareVideoFrame();
resources = updater.CreateExternalResourcesFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
EXPECT_EQ(3u, resources.mailboxes.size());
EXPECT_EQ(3u, resources.release_callbacks.size());
EXPECT_EQ(0u, resources.software_resources.size());
}
} // namespace
} // namespace cc
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