Commit ea0f3516 authored by dcastagna's avatar dcastagna Committed by Commit bot

cc: VideoLayerImpl VideoFrame::TEXTURE_YUV_420 support.

VideoFrame can carry YUV native textures.
After crrev.com/1127423006 VideoResoucesUpdater will create the
appropriate VideoFrameExternalResources.
This change makes VideoLayerImpl deal with a VideoFrame with a
NATIVE_TEXTURE format and a TEXTURE_YUV_420 texture format.

BUG=485859

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

Cr-Commit-Position: refs/heads/master@{#330017}
parent 11885698
...@@ -217,8 +217,7 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass, ...@@ -217,8 +217,7 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
} }
case VideoFrameExternalResources::YUV_RESOURCE: { case VideoFrameExternalResources::YUV_RESOURCE: {
DCHECK_GE(frame_resources_.size(), 3u); DCHECK_GE(frame_resources_.size(), 3u);
if (frame_resources_.size() < 3u)
break;
YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::REC_601; YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::REC_601;
if (frame_->format() == media::VideoFrame::YV12J) { if (frame_->format() == media::VideoFrame::YV12J) {
color_space = YUVVideoDrawQuad::JPEG; color_space = YUVVideoDrawQuad::JPEG;
...@@ -227,15 +226,26 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass, ...@@ -227,15 +226,26 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
} }
const gfx::Size ya_tex_size = coded_size; const gfx::Size ya_tex_size = coded_size;
const gfx::Size uv_tex_size = media::VideoFrame::PlaneSize( gfx::Size uv_tex_size;
frame_->format(), media::VideoFrame::kUPlane, coded_size);
DCHECK(uv_tex_size == if (frame_->format() == media::VideoFrame::NATIVE_TEXTURE) {
media::VideoFrame::PlaneSize( DCHECK_EQ(media::VideoFrame::TEXTURE_YUV_420, frame_->texture_format());
frame_->format(), media::VideoFrame::kVPlane, coded_size)); DCHECK_EQ(3u, frame_resources_.size()); // Alpha is not supported yet.
if (frame_resources_.size() > 3) { DCHECK(visible_rect.origin().IsOrigin());
DCHECK(ya_tex_size == DCHECK(visible_rect.size() == coded_size);
uv_tex_size.SetSize((ya_tex_size.width() + 1) / 2,
(ya_tex_size.height() + 1) / 2);
} else {
uv_tex_size = media::VideoFrame::PlaneSize(
frame_->format(), media::VideoFrame::kUPlane, coded_size);
DCHECK(uv_tex_size ==
media::VideoFrame::PlaneSize( media::VideoFrame::PlaneSize(
frame_->format(), media::VideoFrame::kAPlane, coded_size)); frame_->format(), media::VideoFrame::kVPlane, coded_size));
DCHECK_IMPLIES(
frame_resources_.size() > 3,
ya_tex_size ==
media::VideoFrame::PlaneSize(
frame_->format(), media::VideoFrame::kAPlane, coded_size));
} }
// Compute the UV sub-sampling factor based on the ratio between // Compute the UV sub-sampling factor based on the ratio between
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "cc/output/context_provider.h" #include "cc/output/context_provider.h"
#include "cc/output/output_surface.h" #include "cc/output/output_surface.h"
#include "cc/quads/draw_quad.h" #include "cc/quads/draw_quad.h"
#include "cc/quads/yuv_video_draw_quad.h"
#include "cc/test/fake_video_frame_provider.h" #include "cc/test/fake_video_frame_provider.h"
#include "cc/test/layer_test_common.h" #include "cc/test/layer_test_common.h"
#include "cc/trees/single_thread_proxy.h" #include "cc/trees/single_thread_proxy.h"
...@@ -245,5 +246,85 @@ TEST(VideoLayerImplTest, Rotated270) { ...@@ -245,5 +246,85 @@ TEST(VideoLayerImplTest, Rotated270) {
EXPECT_EQ(gfx::Point3F(0, 0, 0), p2); EXPECT_EQ(gfx::Point3F(0, 0, 0), p2);
} }
void EmptyCallback(unsigned sync_point) {
}
TEST(VideoLayerImplTest, SoftwareVideoFrameGeneratesYUVQuad) {
gfx::Size layer_size(1000, 1000);
gfx::Size viewport_size(1000, 1000);
LayerTestCommon::LayerImplTest impl;
DebugSetImplThreadAndMainThreadBlocked(impl.proxy());
gpu::MailboxHolder mailbox_holder;
mailbox_holder.mailbox.name[0] = 1;
scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame(
media::VideoFrame::YV12, gfx::Size(20, 10), gfx::Rect(20, 10),
gfx::Size(20, 10), base::TimeDelta());
FakeVideoFrameProvider provider;
provider.set_frame(video_frame);
VideoLayerImpl* video_layer_impl =
impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_0);
video_layer_impl->SetBounds(layer_size);
video_layer_impl->SetContentBounds(layer_size);
video_layer_impl->SetDrawsContent(true);
gfx::Rect occluded;
impl.AppendQuadsWithOcclusion(video_layer_impl, occluded);
EXPECT_EQ(1u, impl.quad_list().size());
const DrawQuad* draw_quad = impl.quad_list().ElementAt(0);
ASSERT_EQ(DrawQuad::YUV_VIDEO_CONTENT, draw_quad->material);
const YUVVideoDrawQuad* yuv_draw_quad =
static_cast<const YUVVideoDrawQuad*>(draw_quad);
EXPECT_EQ(yuv_draw_quad->uv_tex_size.height(),
(yuv_draw_quad->ya_tex_size.height() + 1) / 2);
EXPECT_EQ(yuv_draw_quad->uv_tex_size.width(),
(yuv_draw_quad->ya_tex_size.width() + 1) / 2);
}
TEST(VideoLayerImplTest, NativeYUVFrameGeneratesYUVQuad) {
gfx::Size layer_size(1000, 1000);
gfx::Size viewport_size(1000, 1000);
LayerTestCommon::LayerImplTest impl;
DebugSetImplThreadAndMainThreadBlocked(impl.proxy());
gpu::MailboxHolder mailbox_holder;
mailbox_holder.mailbox.name[0] = 1;
scoped_refptr<media::VideoFrame> video_frame =
media::VideoFrame::WrapYUV420NativeTextures(
mailbox_holder, mailbox_holder, mailbox_holder,
base::Bind(EmptyCallback), gfx::Size(10, 10), gfx::Rect(10, 10),
gfx::Size(10, 10), base::TimeDelta(), true);
FakeVideoFrameProvider provider;
provider.set_frame(video_frame);
VideoLayerImpl* video_layer_impl =
impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_0);
video_layer_impl->SetBounds(layer_size);
video_layer_impl->SetContentBounds(layer_size);
video_layer_impl->SetDrawsContent(true);
gfx::Rect occluded;
impl.AppendQuadsWithOcclusion(video_layer_impl, occluded);
EXPECT_EQ(1u, impl.quad_list().size());
const DrawQuad* draw_quad = impl.quad_list().ElementAt(0);
ASSERT_EQ(DrawQuad::YUV_VIDEO_CONTENT, draw_quad->material);
const YUVVideoDrawQuad* yuv_draw_quad =
static_cast<const YUVVideoDrawQuad*>(draw_quad);
EXPECT_EQ(yuv_draw_quad->uv_tex_size.height(),
(yuv_draw_quad->ya_tex_size.height() + 1) / 2);
EXPECT_EQ(yuv_draw_quad->uv_tex_size.width(),
(yuv_draw_quad->ya_tex_size.width() + 1) / 2);
}
} // 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