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,16 +402,17 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( ...@@ -402,16 +402,17 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
media::VideoFrame::Format frame_format = video_frame->format(); media::VideoFrame::Format frame_format = video_frame->format();
DCHECK_EQ(frame_format, media::VideoFrame::NATIVE_TEXTURE); DCHECK_EQ(frame_format, media::VideoFrame::NATIVE_TEXTURE);
if (frame_format != media::VideoFrame::NATIVE_TEXTURE)
return VideoFrameExternalResources();
if (!context_provider_) if (!context_provider_)
return VideoFrameExternalResources(); return VideoFrameExternalResources();
DCHECK_EQ(1u, media::VideoFrame::NumTextures(video_frame->texture_format())); size_t textures =
const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); media::VideoFrame::NumTextures(video_frame->texture_format());
DCHECK_GE(textures, 1u);
VideoFrameExternalResources external_resources; VideoFrameExternalResources external_resources;
switch (mailbox_holder.texture_target) { 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: case GL_TEXTURE_2D:
external_resources.type = VideoFrameExternalResources::RGB_RESOURCE; external_resources.type = VideoFrameExternalResources::RGB_RESOURCE;
break; break;
...@@ -426,7 +427,15 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( ...@@ -426,7 +427,15 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
NOTREACHED(); NOTREACHED();
return VideoFrameExternalResources(); return VideoFrameExternalResources();
} }
break;
case media::VideoFrame::TEXTURE_YUV_420:
external_resources.type = VideoFrameExternalResources::YUV_RESOURCE;
break;
}
DCHECK_NE(VideoFrameExternalResources::NONE, external_resources.type);
for (size_t i = 0; i < textures; ++i) {
const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i);
external_resources.mailboxes.push_back( external_resources.mailboxes.push_back(
TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target, TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target,
mailbox_holder.sync_point)); mailbox_holder.sync_point));
...@@ -434,6 +443,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( ...@@ -434,6 +443,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
video_frame->allow_overlay()); video_frame->allow_overlay());
external_resources.release_callbacks.push_back( external_resources.release_callbacks.push_back(
base::Bind(&ReturnTexture, AsWeakPtr(), video_frame)); base::Bind(&ReturnTexture, AsWeakPtr(), video_frame));
}
return external_resources; return external_resources;
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "cc/test/test_shared_bitmap_manager.h" #include "cc/test/test_shared_bitmap_manager.h"
#include "cc/test/test_web_graphics_context_3d.h" #include "cc/test/test_web_graphics_context_3d.h"
#include "cc/trees/blocking_task_runner.h" #include "cc/trees/blocking_task_runner.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -106,6 +107,53 @@ class VideoResourceUpdaterTest : public testing::Test { ...@@ -106,6 +107,53 @@ class VideoResourceUpdaterTest : public testing::Test {
base::Closure()); // no_longer_needed_cb 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_; WebGraphicsContext3DUploadCounter* context3d_;
FakeOutputSurfaceClient client_; FakeOutputSurfaceClient client_;
scoped_ptr<FakeOutputSurface> output_surface3d_; scoped_ptr<FakeOutputSurface> output_surface3d_;
...@@ -251,5 +299,27 @@ TEST_F(VideoResourceUpdaterTest, ReuseResourceNoDeleteSoftwareCompositor) { ...@@ -251,5 +299,27 @@ TEST_F(VideoResourceUpdaterTest, ReuseResourceNoDeleteSoftwareCompositor) {
EXPECT_EQ(0, shared_bitmap_manager_->AllocationCount()); 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
} // namespace cc } // 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