diff options
Diffstat (limited to 'chromium/media/renderers/video_resource_updater_unittest.cc')
-rw-r--r-- | chromium/media/renderers/video_resource_updater_unittest.cc | 143 |
1 files changed, 112 insertions, 31 deletions
diff --git a/chromium/media/renderers/video_resource_updater_unittest.cc b/chromium/media/renderers/video_resource_updater_unittest.cc index 3cd5e2bdf89..b5b587e85f2 100644 --- a/chromium/media/renderers/video_resource_updater_unittest.cc +++ b/chromium/media/renderers/video_resource_updater_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -183,6 +183,26 @@ class VideoResourceUpdaterTest : public testing::Test { return video_frame; } + scoped_refptr<VideoFrame> CreateNV12TestFrame() { + const int kDimension = 10; + gfx::Size size(kDimension, kDimension); + + scoped_refptr<VideoFrame> video_frame(VideoFrame::CreateFrame( + PIXEL_FORMAT_NV12, size, gfx::Rect(size), size, base::TimeDelta())); + EXPECT_TRUE(video_frame); + return video_frame; + } + + scoped_refptr<VideoFrame> CreateP016TestFrame() { + const int kDimension = 10; + gfx::Size size(kDimension, kDimension); + + scoped_refptr<VideoFrame> video_frame(VideoFrame::CreateFrame( + PIXEL_FORMAT_P016LE, size, gfx::Rect(size), size, base::TimeDelta())); + EXPECT_TRUE(video_frame); + return video_frame; + } + void SetReleaseSyncToken(const gpu::SyncToken& sync_token) { release_sync_token_ = sync_token; } @@ -278,6 +298,29 @@ TEST_F(VideoResourceUpdaterTest, SoftwareFrame) { EXPECT_EQ(VideoFrameResourceType::YUV, resources.type); } +TEST_F(VideoResourceUpdaterTest, SoftwareFrameNV12) { + std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware(); + + VideoFrameExternalResources resources = + updater->CreateExternalResourcesFromVideoFrame(CreateNV12TestFrame()); + EXPECT_EQ(VideoFrameResourceType::RGBA, resources.type); + + // Use a different frame for this test since frames with the same unique_id() + // expect to use the same resources. + gl_->set_supports_texture_rg(true); + resources = + updater->CreateExternalResourcesFromVideoFrame(CreateNV12TestFrame()); + EXPECT_EQ(VideoFrameResourceType::YUV, resources.type); +} + +TEST_F(VideoResourceUpdaterTest, SoftwareFrameP016_NoR16Support) { + std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware(); + + VideoFrameExternalResources resources = + updater->CreateExternalResourcesFromVideoFrame(CreateP016TestFrame()); + EXPECT_EQ(VideoFrameResourceType::RGBA, resources.type); +} + TEST_F(VideoResourceUpdaterTest, SoftwareFrameRGB) { std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware(); for (const auto& fmt : {PIXEL_FORMAT_XBGR, PIXEL_FORMAT_XRGB, @@ -332,6 +375,14 @@ class VideoResourceUpdaterTestWithR16 : public VideoResourceUpdaterTest { } }; +TEST_F(VideoResourceUpdaterTestWithR16, SoftwareFrameP016) { + std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware(); + + VideoFrameExternalResources resources = + updater->CreateExternalResourcesFromVideoFrame(CreateP016TestFrame()); + EXPECT_EQ(VideoFrameResourceType::YUV, resources.type); +} + TEST_F(VideoResourceUpdaterTestWithR16, HighBitFrame) { std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware(); scoped_refptr<VideoFrame> video_frame = CreateTestHighBitFrame(); @@ -354,6 +405,24 @@ TEST_F(VideoResourceUpdaterTestWithR16, HighBitFrame) { EXPECT_NEAR(resources2.offset, 0.0, 0.1); } +TEST_F(VideoResourceUpdaterTest, NV12FrameSoftwareCompositor) { + std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware(); + scoped_refptr<VideoFrame> video_frame = CreateNV12TestFrame(); + + VideoFrameExternalResources resources = + updater->CreateExternalResourcesFromVideoFrame(video_frame); + EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type); +} + +TEST_F(VideoResourceUpdaterTest, P016FrameSoftwareCompositor) { + std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware(); + scoped_refptr<VideoFrame> video_frame = CreateP016TestFrame(); + + VideoFrameExternalResources resources = + updater->CreateExternalResourcesFromVideoFrame(video_frame); + EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type); +} + TEST_F(VideoResourceUpdaterTest, HighBitFrameSoftwareCompositor) { std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware(); scoped_refptr<VideoFrame> video_frame = CreateTestHighBitFrame(); @@ -411,6 +480,37 @@ TEST_F(VideoResourceUpdaterTest, ReuseResource) { EXPECT_EQ(0, gl_->UploadCount()); } +TEST_F(VideoResourceUpdaterTest, ReuseResourceNV12) { + std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware(); + scoped_refptr<VideoFrame> video_frame = CreateNV12TestFrame(); + video_frame->set_timestamp(base::Seconds(1234)); + gl_->set_supports_texture_rg(true); + + // Allocate the resources for a YUV video frame. + gl_->ResetUploadCount(); + VideoFrameExternalResources resources = + updater->CreateExternalResourcesFromVideoFrame(video_frame); + EXPECT_EQ(VideoFrameResourceType::YUV, resources.type); + EXPECT_EQ(2u, resources.resources.size()); + EXPECT_EQ(2u, resources.release_callbacks.size()); + // Expect exactly three texture uploads, one for each plane. + EXPECT_EQ(2, gl_->UploadCount()); + + // Simulate the ResourceProvider releasing the resources back to the video + // updater. + for (auto& release_callback : resources.release_callbacks) + std::move(release_callback).Run(gpu::SyncToken(), false); + + // Allocate resources for the same frame. + gl_->ResetUploadCount(); + resources = updater->CreateExternalResourcesFromVideoFrame(video_frame); + EXPECT_EQ(VideoFrameResourceType::YUV, resources.type); + EXPECT_EQ(2u, resources.resources.size()); + EXPECT_EQ(2u, resources.release_callbacks.size()); + // The data should be reused so expect no texture uploads. + EXPECT_EQ(0, gl_->UploadCount()); +} + TEST_F(VideoResourceUpdaterTest, ReuseResourceNoDelete) { std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware(); scoped_refptr<VideoFrame> video_frame = CreateTestYUVVideoFrame(); @@ -726,17 +826,8 @@ TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_SingleNV12) { EXPECT_EQ(1u, resources.resources.size()); EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES, resources.resources[0].mailbox_holder.texture_target); - EXPECT_EQ(viz::YUV_420_BIPLANAR, resources.resources[0].format); - - video_frame = CreateTestYuvHardwareVideoFrame(PIXEL_FORMAT_NV12, 1, - GL_TEXTURE_RECTANGLE_ARB); - resources = updater->CreateExternalResourcesFromVideoFrame(video_frame); - EXPECT_EQ(VideoFrameResourceType::RGB, resources.type); - EXPECT_EQ(1u, resources.resources.size()); - EXPECT_EQ((GLenum)GL_TEXTURE_RECTANGLE_ARB, - resources.resources[0].mailbox_holder.texture_target); - EXPECT_EQ(viz::YUV_420_BIPLANAR, resources.resources[0].format); - + EXPECT_EQ(viz::YUV_420_BIPLANAR, + resources.resources[0].format.resource_format()); EXPECT_EQ(0u, GetSharedImageCount()); } @@ -753,9 +844,11 @@ TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_DualNV12) { EXPECT_EQ(2u, resources.release_callbacks.size()); EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES, resources.resources[0].mailbox_holder.texture_target); + EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES, + resources.resources[1].mailbox_holder.texture_target); // |updater| doesn't set |buffer_format| in this case. - EXPECT_EQ(viz::RED_8, resources.resources[0].format); - EXPECT_EQ(viz::RG_88, resources.resources[1].format); + EXPECT_EQ(viz::RED_8, resources.resources[0].format.resource_format()); + EXPECT_EQ(viz::RG_88, resources.resources[1].format.resource_format()); video_frame = CreateTestYuvHardwareVideoFrame(PIXEL_FORMAT_NV12, 2, GL_TEXTURE_RECTANGLE_ARB); @@ -764,8 +857,10 @@ TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_DualNV12) { EXPECT_EQ(2u, resources.resources.size()); EXPECT_EQ((GLenum)GL_TEXTURE_RECTANGLE_ARB, resources.resources[0].mailbox_holder.texture_target); - EXPECT_EQ(viz::RED_8, resources.resources[0].format); - EXPECT_EQ(viz::RG_88, resources.resources[1].format); + EXPECT_EQ((GLenum)GL_TEXTURE_RECTANGLE_ARB, + resources.resources[1].mailbox_holder.texture_target); + EXPECT_EQ(viz::RED_8, resources.resources[0].format.resource_format()); + EXPECT_EQ(viz::RG_88, resources.resources[1].format.resource_format()); EXPECT_EQ(0u, GetSharedImageCount()); } @@ -786,23 +881,9 @@ TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_SingleP016HDR) { EXPECT_EQ(1u, resources.resources.size()); EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), resources.resources[0].mailbox_holder.texture_target); - EXPECT_EQ(viz::P010, resources.resources[0].format); + EXPECT_EQ(viz::P010, resources.resources[0].format.resource_format()); EXPECT_EQ(kHDR10ColorSpace, resources.resources[0].color_space); EXPECT_EQ(hdr_metadata, resources.resources[0].hdr_metadata); - - video_frame = CreateTestYuvHardwareVideoFrame(PIXEL_FORMAT_P016LE, 1, - GL_TEXTURE_RECTANGLE_ARB); - video_frame->set_color_space(kHDR10ColorSpace); - video_frame->set_hdr_metadata(hdr_metadata); - resources = updater->CreateExternalResourcesFromVideoFrame(video_frame); - EXPECT_EQ(VideoFrameResourceType::RGB, resources.type); - EXPECT_EQ(1u, resources.resources.size()); - EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_RECTANGLE_ARB), - resources.resources[0].mailbox_holder.texture_target); - EXPECT_EQ(viz::P010, resources.resources[0].format); - EXPECT_EQ(kHDR10ColorSpace, resources.resources[0].color_space); - EXPECT_EQ(hdr_metadata, resources.resources[0].hdr_metadata); - EXPECT_EQ(0u, GetSharedImageCount()); } |