video_layer_impl_unittest.cc revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "cc/layers/video_layer_impl.h" 6 7#include "cc/layers/video_frame_provider_client_impl.h" 8#include "cc/output/context_provider.h" 9#include "cc/output/output_surface.h" 10#include "cc/test/fake_video_frame_provider.h" 11#include "cc/test/layer_test_common.h" 12#include "cc/trees/single_thread_proxy.h" 13#include "media/base/video_frame.h" 14#include "testing/gtest/include/gtest/gtest.h" 15 16namespace cc { 17namespace { 18 19TEST(VideoLayerImplTest, Occlusion) { 20 gfx::Size layer_size(1000, 1000); 21 gfx::Size viewport_size(1000, 1000); 22 23 LayerTestCommon::LayerImplTest impl; 24 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); 25 26 scoped_refptr<media::VideoFrame> video_frame = 27 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, 28 gfx::Size(10, 10), 29 gfx::Rect(10, 10), 30 gfx::Size(10, 10), 31 base::TimeDelta()); 32 FakeVideoFrameProvider provider; 33 provider.set_frame(video_frame); 34 35 VideoLayerImpl* video_layer_impl = 36 impl.AddChildToRoot<VideoLayerImpl>(&provider); 37 video_layer_impl->SetBounds(layer_size); 38 video_layer_impl->SetContentBounds(layer_size); 39 video_layer_impl->SetDrawsContent(true); 40 41 impl.CalcDrawProps(viewport_size); 42 43 { 44 SCOPED_TRACE("No occlusion"); 45 gfx::Rect occluded; 46 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); 47 48 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), 49 gfx::Rect(layer_size)); 50 EXPECT_EQ(1u, impl.quad_list().size()); 51 } 52 53 { 54 SCOPED_TRACE("Full occlusion"); 55 gfx::Rect occluded(video_layer_impl->visible_content_rect()); 56 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); 57 58 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect()); 59 EXPECT_EQ(impl.quad_list().size(), 0u); 60 } 61 62 { 63 SCOPED_TRACE("Partial occlusion"); 64 gfx::Rect occluded(200, 0, 800, 1000); 65 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); 66 67 size_t partially_occluded_count = 0; 68 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion( 69 impl.quad_list(), 70 gfx::Rect(layer_size), 71 occluded, 72 &partially_occluded_count); 73 // The layer outputs one quad, which is partially occluded. 74 EXPECT_EQ(1u, impl.quad_list().size()); 75 EXPECT_EQ(1u, partially_occluded_count); 76 } 77} 78 79TEST(VideoLayerImplTest, DidBecomeActiveShouldSetActiveVideoLayer) { 80 LayerTestCommon::LayerImplTest impl; 81 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); 82 83 FakeVideoFrameProvider provider; 84 VideoLayerImpl* video_layer_impl = 85 impl.AddChildToRoot<VideoLayerImpl>(&provider); 86 87 VideoFrameProviderClientImpl* client = 88 static_cast<VideoFrameProviderClientImpl*>(provider.client()); 89 ASSERT_TRUE(client); 90 EXPECT_FALSE(client->active_video_layer()); 91 92 video_layer_impl->DidBecomeActive(); 93 EXPECT_EQ(video_layer_impl, client->active_video_layer()); 94} 95 96} // namespace 97} // namespace cc 98