OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/video_layer_impl.h" | 5 #include "cc/layers/video_layer_impl.h" |
6 | 6 |
7 #include "cc/layers/video_frame_provider_client_impl.h" | 7 #include "cc/layers/video_frame_provider_client_impl.h" |
8 #include "cc/output/context_provider.h" | 8 #include "cc/output/context_provider.h" |
9 #include "cc/output/output_surface.h" | 9 #include "cc/output/output_surface.h" |
| 10 #include "cc/quads/draw_quad.h" |
10 #include "cc/test/fake_video_frame_provider.h" | 11 #include "cc/test/fake_video_frame_provider.h" |
11 #include "cc/test/layer_test_common.h" | 12 #include "cc/test/layer_test_common.h" |
12 #include "cc/trees/single_thread_proxy.h" | 13 #include "cc/trees/single_thread_proxy.h" |
13 #include "media/base/video_frame.h" | 14 #include "media/base/video_frame.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace cc { | 17 namespace cc { |
17 namespace { | 18 namespace { |
18 | 19 |
19 TEST(VideoLayerImplTest, Occlusion) { | 20 TEST(VideoLayerImplTest, Occlusion) { |
20 gfx::Size layer_size(1000, 1000); | 21 gfx::Size layer_size(1000, 1000); |
21 gfx::Size viewport_size(1000, 1000); | 22 gfx::Size viewport_size(1000, 1000); |
22 | 23 |
23 LayerTestCommon::LayerImplTest impl; | 24 LayerTestCommon::LayerImplTest impl; |
24 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | 25 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); |
25 | 26 |
26 scoped_refptr<media::VideoFrame> video_frame = | 27 scoped_refptr<media::VideoFrame> video_frame = |
27 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 28 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
28 gfx::Size(10, 10), | 29 gfx::Size(10, 10), |
29 gfx::Rect(10, 10), | 30 gfx::Rect(10, 10), |
30 gfx::Size(10, 10), | 31 gfx::Size(10, 10), |
31 base::TimeDelta()); | 32 base::TimeDelta()); |
32 FakeVideoFrameProvider provider; | 33 FakeVideoFrameProvider provider; |
33 provider.set_frame(video_frame); | 34 provider.set_frame(video_frame); |
34 | 35 |
35 VideoLayerImpl* video_layer_impl = | 36 VideoLayerImpl* video_layer_impl = |
36 impl.AddChildToRoot<VideoLayerImpl>(&provider); | 37 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_0); |
37 video_layer_impl->SetBounds(layer_size); | 38 video_layer_impl->SetBounds(layer_size); |
38 video_layer_impl->SetContentBounds(layer_size); | 39 video_layer_impl->SetContentBounds(layer_size); |
39 video_layer_impl->SetDrawsContent(true); | 40 video_layer_impl->SetDrawsContent(true); |
40 | 41 |
41 impl.CalcDrawProps(viewport_size); | 42 impl.CalcDrawProps(viewport_size); |
42 | 43 |
43 { | 44 { |
44 SCOPED_TRACE("No occlusion"); | 45 SCOPED_TRACE("No occlusion"); |
45 gfx::Rect occluded; | 46 gfx::Rect occluded; |
46 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); | 47 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); |
(...skipping 28 matching lines...) Expand all Loading... |
75 EXPECT_EQ(1u, partially_occluded_count); | 76 EXPECT_EQ(1u, partially_occluded_count); |
76 } | 77 } |
77 } | 78 } |
78 | 79 |
79 TEST(VideoLayerImplTest, DidBecomeActiveShouldSetActiveVideoLayer) { | 80 TEST(VideoLayerImplTest, DidBecomeActiveShouldSetActiveVideoLayer) { |
80 LayerTestCommon::LayerImplTest impl; | 81 LayerTestCommon::LayerImplTest impl; |
81 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | 82 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); |
82 | 83 |
83 FakeVideoFrameProvider provider; | 84 FakeVideoFrameProvider provider; |
84 VideoLayerImpl* video_layer_impl = | 85 VideoLayerImpl* video_layer_impl = |
85 impl.AddChildToRoot<VideoLayerImpl>(&provider); | 86 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_0); |
86 | 87 |
87 VideoFrameProviderClientImpl* client = | 88 VideoFrameProviderClientImpl* client = |
88 static_cast<VideoFrameProviderClientImpl*>(provider.client()); | 89 static_cast<VideoFrameProviderClientImpl*>(provider.client()); |
89 ASSERT_TRUE(client); | 90 ASSERT_TRUE(client); |
90 EXPECT_FALSE(client->active_video_layer()); | 91 EXPECT_FALSE(client->active_video_layer()); |
91 | 92 |
92 video_layer_impl->DidBecomeActive(); | 93 video_layer_impl->DidBecomeActive(); |
93 EXPECT_EQ(video_layer_impl, client->active_video_layer()); | 94 EXPECT_EQ(video_layer_impl, client->active_video_layer()); |
94 } | 95 } |
95 | 96 |
| 97 TEST(VideoLayerImplTest, Rotated0) { |
| 98 gfx::Size layer_size(100, 50); |
| 99 gfx::Size viewport_size(1000, 500); |
| 100 |
| 101 LayerTestCommon::LayerImplTest impl; |
| 102 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); |
| 103 |
| 104 scoped_refptr<media::VideoFrame> video_frame = |
| 105 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
| 106 gfx::Size(20, 10), |
| 107 gfx::Rect(20, 10), |
| 108 gfx::Size(20, 10), |
| 109 base::TimeDelta()); |
| 110 FakeVideoFrameProvider provider; |
| 111 provider.set_frame(video_frame); |
| 112 |
| 113 VideoLayerImpl* video_layer_impl = |
| 114 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_0); |
| 115 video_layer_impl->SetBounds(layer_size); |
| 116 video_layer_impl->SetContentBounds(layer_size); |
| 117 video_layer_impl->SetDrawsContent(true); |
| 118 |
| 119 impl.CalcDrawProps(viewport_size); |
| 120 gfx::Rect occluded; |
| 121 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); |
| 122 |
| 123 EXPECT_EQ(1u, impl.quad_list().size()); |
| 124 |
| 125 gfx::Point3F p1(0, impl.quad_list()[0]->rect.height(), 0); |
| 126 gfx::Point3F p2(impl.quad_list()[0]->rect.width(), 0, 0); |
| 127 impl.quad_list()[0]->quadTransform().TransformPoint(&p1); |
| 128 impl.quad_list()[0]->quadTransform().TransformPoint(&p2); |
| 129 EXPECT_EQ(gfx::Point3F(0, 50, 0), p1); |
| 130 EXPECT_EQ(gfx::Point3F(100, 0, 0), p2); |
| 131 } |
| 132 |
| 133 TEST(VideoLayerImplTest, Rotated90) { |
| 134 gfx::Size layer_size(100, 50); |
| 135 gfx::Size viewport_size(1000, 500); |
| 136 |
| 137 LayerTestCommon::LayerImplTest impl; |
| 138 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); |
| 139 |
| 140 scoped_refptr<media::VideoFrame> video_frame = |
| 141 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
| 142 gfx::Size(20, 10), |
| 143 gfx::Rect(20, 10), |
| 144 gfx::Size(20, 10), |
| 145 base::TimeDelta()); |
| 146 FakeVideoFrameProvider provider; |
| 147 provider.set_frame(video_frame); |
| 148 |
| 149 VideoLayerImpl* video_layer_impl = |
| 150 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_90); |
| 151 video_layer_impl->SetBounds(layer_size); |
| 152 video_layer_impl->SetContentBounds(layer_size); |
| 153 video_layer_impl->SetDrawsContent(true); |
| 154 |
| 155 impl.CalcDrawProps(viewport_size); |
| 156 gfx::Rect occluded; |
| 157 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); |
| 158 |
| 159 EXPECT_EQ(1u, impl.quad_list().size()); |
| 160 |
| 161 gfx::Point3F p1(0, impl.quad_list()[0]->rect.height(), 0); |
| 162 gfx::Point3F p2(impl.quad_list()[0]->rect.width(), 0, 0); |
| 163 impl.quad_list()[0]->quadTransform().TransformPoint(&p1); |
| 164 impl.quad_list()[0]->quadTransform().TransformPoint(&p2); |
| 165 EXPECT_EQ(gfx::Point3F(0, 0, 0), p1); |
| 166 EXPECT_EQ(gfx::Point3F(100, 50, 0), p2); |
| 167 } |
| 168 |
| 169 TEST(VideoLayerImplTest, Rotated180) { |
| 170 gfx::Size layer_size(100, 50); |
| 171 gfx::Size viewport_size(1000, 500); |
| 172 |
| 173 LayerTestCommon::LayerImplTest impl; |
| 174 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); |
| 175 |
| 176 scoped_refptr<media::VideoFrame> video_frame = |
| 177 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
| 178 gfx::Size(20, 10), |
| 179 gfx::Rect(20, 10), |
| 180 gfx::Size(20, 10), |
| 181 base::TimeDelta()); |
| 182 FakeVideoFrameProvider provider; |
| 183 provider.set_frame(video_frame); |
| 184 |
| 185 VideoLayerImpl* video_layer_impl = |
| 186 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_180); |
| 187 video_layer_impl->SetBounds(layer_size); |
| 188 video_layer_impl->SetContentBounds(layer_size); |
| 189 video_layer_impl->SetDrawsContent(true); |
| 190 |
| 191 impl.CalcDrawProps(viewport_size); |
| 192 gfx::Rect occluded; |
| 193 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); |
| 194 |
| 195 EXPECT_EQ(1u, impl.quad_list().size()); |
| 196 |
| 197 gfx::Point3F p1(0, impl.quad_list()[0]->rect.height(), 0); |
| 198 gfx::Point3F p2(impl.quad_list()[0]->rect.width(), 0, 0); |
| 199 impl.quad_list()[0]->quadTransform().TransformPoint(&p1); |
| 200 impl.quad_list()[0]->quadTransform().TransformPoint(&p2); |
| 201 EXPECT_EQ(gfx::Point3F(100, 0, 0), p1); |
| 202 EXPECT_EQ(gfx::Point3F(0, 50, 0), p2); |
| 203 } |
| 204 |
| 205 TEST(VideoLayerImplTest, Rotated270) { |
| 206 gfx::Size layer_size(100, 50); |
| 207 gfx::Size viewport_size(1000, 500); |
| 208 |
| 209 LayerTestCommon::LayerImplTest impl; |
| 210 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); |
| 211 |
| 212 scoped_refptr<media::VideoFrame> video_frame = |
| 213 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
| 214 gfx::Size(20, 10), |
| 215 gfx::Rect(20, 10), |
| 216 gfx::Size(20, 10), |
| 217 base::TimeDelta()); |
| 218 FakeVideoFrameProvider provider; |
| 219 provider.set_frame(video_frame); |
| 220 |
| 221 VideoLayerImpl* video_layer_impl = |
| 222 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_270); |
| 223 video_layer_impl->SetBounds(layer_size); |
| 224 video_layer_impl->SetContentBounds(layer_size); |
| 225 video_layer_impl->SetDrawsContent(true); |
| 226 |
| 227 impl.CalcDrawProps(viewport_size); |
| 228 gfx::Rect occluded; |
| 229 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); |
| 230 |
| 231 EXPECT_EQ(1u, impl.quad_list().size()); |
| 232 |
| 233 gfx::Point3F p1(0, impl.quad_list()[0]->rect.height(), 0); |
| 234 gfx::Point3F p2(impl.quad_list()[0]->rect.width(), 0, 0); |
| 235 impl.quad_list()[0]->quadTransform().TransformPoint(&p1); |
| 236 impl.quad_list()[0]->quadTransform().TransformPoint(&p2); |
| 237 EXPECT_EQ(gfx::Point3F(100, 50, 0), p1); |
| 238 EXPECT_EQ(gfx::Point3F(0, 0, 0), p2); |
| 239 } |
| 240 |
96 } // namespace | 241 } // namespace |
97 } // namespace cc | 242 } // namespace cc |
OLD | NEW |