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/quads/draw_quad.h" |
11 #include "cc/test/fake_video_frame_provider.h" | 11 #include "cc/test/fake_video_frame_provider.h" |
12 #include "cc/test/layer_test_common.h" | 12 #include "cc/test/layer_test_common.h" |
13 #include "cc/trees/single_thread_proxy.h" | 13 #include "cc/trees/single_thread_proxy.h" |
14 #include "media/base/video_frame.h" | 14 #include "media/base/video_frame.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 namespace { | 18 namespace { |
19 | 19 |
| 20 // NOTE: We cannot use DebugScopedSetImplThreadAndMainThreadBlocked in these |
| 21 // tests because it gets destroyed before the VideoLayerImpl is destroyed. This |
| 22 // causes a DCHECK in VideoLayerImpl's destructor to fail. |
| 23 static void DebugSetImplThreadAndMainThreadBlocked(Proxy* proxy) { |
| 24 #if DCHECK_IS_ON() |
| 25 proxy->SetCurrentThreadIsImplThread(true); |
| 26 proxy->SetMainThreadBlocked(true); |
| 27 #endif |
| 28 } |
| 29 |
20 TEST(VideoLayerImplTest, Occlusion) { | 30 TEST(VideoLayerImplTest, Occlusion) { |
21 gfx::Size layer_size(1000, 1000); | 31 gfx::Size layer_size(1000, 1000); |
22 gfx::Size viewport_size(1000, 1000); | 32 gfx::Size viewport_size(1000, 1000); |
23 | 33 |
24 LayerTestCommon::LayerImplTest impl; | 34 LayerTestCommon::LayerImplTest impl; |
25 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | 35 DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); |
26 | 36 |
27 scoped_refptr<media::VideoFrame> video_frame = | 37 scoped_refptr<media::VideoFrame> video_frame = |
28 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 38 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
29 gfx::Size(10, 10), | 39 gfx::Size(10, 10), |
30 gfx::Rect(10, 10), | 40 gfx::Rect(10, 10), |
31 gfx::Size(10, 10), | 41 gfx::Size(10, 10), |
32 base::TimeDelta()); | 42 base::TimeDelta()); |
33 FakeVideoFrameProvider provider; | 43 FakeVideoFrameProvider provider; |
34 provider.set_frame(video_frame); | 44 provider.set_frame(video_frame); |
35 | 45 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 LayerTestCommon::VerifyQuadsAreOccluded( | 79 LayerTestCommon::VerifyQuadsAreOccluded( |
70 impl.quad_list(), occluded, &partially_occluded_count); | 80 impl.quad_list(), occluded, &partially_occluded_count); |
71 // The layer outputs one quad, which is partially occluded. | 81 // The layer outputs one quad, which is partially occluded. |
72 EXPECT_EQ(1u, impl.quad_list().size()); | 82 EXPECT_EQ(1u, impl.quad_list().size()); |
73 EXPECT_EQ(1u, partially_occluded_count); | 83 EXPECT_EQ(1u, partially_occluded_count); |
74 } | 84 } |
75 } | 85 } |
76 | 86 |
77 TEST(VideoLayerImplTest, DidBecomeActiveShouldSetActiveVideoLayer) { | 87 TEST(VideoLayerImplTest, DidBecomeActiveShouldSetActiveVideoLayer) { |
78 LayerTestCommon::LayerImplTest impl; | 88 LayerTestCommon::LayerImplTest impl; |
79 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | 89 DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); |
80 | 90 |
81 FakeVideoFrameProvider provider; | 91 FakeVideoFrameProvider provider; |
82 VideoLayerImpl* video_layer_impl = | 92 VideoLayerImpl* video_layer_impl = |
83 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_0); | 93 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_0); |
84 | 94 |
85 VideoFrameProviderClientImpl* client = | 95 VideoFrameProviderClientImpl* client = |
86 static_cast<VideoFrameProviderClientImpl*>(provider.client()); | 96 static_cast<VideoFrameProviderClientImpl*>(provider.client()); |
87 ASSERT_TRUE(client); | 97 ASSERT_TRUE(client); |
88 EXPECT_FALSE(client->active_video_layer()); | |
89 | 98 |
| 99 EXPECT_FALSE(client->ActiveVideoLayer()); |
90 video_layer_impl->DidBecomeActive(); | 100 video_layer_impl->DidBecomeActive(); |
91 EXPECT_EQ(video_layer_impl, client->active_video_layer()); | 101 EXPECT_EQ(video_layer_impl, client->ActiveVideoLayer()); |
92 } | 102 } |
93 | 103 |
94 TEST(VideoLayerImplTest, Rotated0) { | 104 TEST(VideoLayerImplTest, Rotated0) { |
95 gfx::Size layer_size(100, 50); | 105 gfx::Size layer_size(100, 50); |
96 gfx::Size viewport_size(1000, 500); | 106 gfx::Size viewport_size(1000, 500); |
97 | 107 |
98 LayerTestCommon::LayerImplTest impl; | 108 LayerTestCommon::LayerImplTest impl; |
99 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | 109 DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); |
100 | 110 |
101 scoped_refptr<media::VideoFrame> video_frame = | 111 scoped_refptr<media::VideoFrame> video_frame = |
102 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 112 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
103 gfx::Size(20, 10), | 113 gfx::Size(20, 10), |
104 gfx::Rect(20, 10), | 114 gfx::Rect(20, 10), |
105 gfx::Size(20, 10), | 115 gfx::Size(20, 10), |
106 base::TimeDelta()); | 116 base::TimeDelta()); |
107 FakeVideoFrameProvider provider; | 117 FakeVideoFrameProvider provider; |
108 provider.set_frame(video_frame); | 118 provider.set_frame(video_frame); |
109 | 119 |
(...skipping 15 matching lines...) Expand all Loading... |
125 impl.quad_list().front()->quadTransform().TransformPoint(&p2); | 135 impl.quad_list().front()->quadTransform().TransformPoint(&p2); |
126 EXPECT_EQ(gfx::Point3F(0, 50, 0), p1); | 136 EXPECT_EQ(gfx::Point3F(0, 50, 0), p1); |
127 EXPECT_EQ(gfx::Point3F(100, 0, 0), p2); | 137 EXPECT_EQ(gfx::Point3F(100, 0, 0), p2); |
128 } | 138 } |
129 | 139 |
130 TEST(VideoLayerImplTest, Rotated90) { | 140 TEST(VideoLayerImplTest, Rotated90) { |
131 gfx::Size layer_size(100, 50); | 141 gfx::Size layer_size(100, 50); |
132 gfx::Size viewport_size(1000, 500); | 142 gfx::Size viewport_size(1000, 500); |
133 | 143 |
134 LayerTestCommon::LayerImplTest impl; | 144 LayerTestCommon::LayerImplTest impl; |
135 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | 145 DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); |
136 | 146 |
137 scoped_refptr<media::VideoFrame> video_frame = | 147 scoped_refptr<media::VideoFrame> video_frame = |
138 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 148 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
139 gfx::Size(20, 10), | 149 gfx::Size(20, 10), |
140 gfx::Rect(20, 10), | 150 gfx::Rect(20, 10), |
141 gfx::Size(20, 10), | 151 gfx::Size(20, 10), |
142 base::TimeDelta()); | 152 base::TimeDelta()); |
143 FakeVideoFrameProvider provider; | 153 FakeVideoFrameProvider provider; |
144 provider.set_frame(video_frame); | 154 provider.set_frame(video_frame); |
145 | 155 |
(...skipping 15 matching lines...) Expand all Loading... |
161 impl.quad_list().front()->quadTransform().TransformPoint(&p2); | 171 impl.quad_list().front()->quadTransform().TransformPoint(&p2); |
162 EXPECT_EQ(gfx::Point3F(0, 0, 0), p1); | 172 EXPECT_EQ(gfx::Point3F(0, 0, 0), p1); |
163 EXPECT_EQ(gfx::Point3F(100, 50, 0), p2); | 173 EXPECT_EQ(gfx::Point3F(100, 50, 0), p2); |
164 } | 174 } |
165 | 175 |
166 TEST(VideoLayerImplTest, Rotated180) { | 176 TEST(VideoLayerImplTest, Rotated180) { |
167 gfx::Size layer_size(100, 50); | 177 gfx::Size layer_size(100, 50); |
168 gfx::Size viewport_size(1000, 500); | 178 gfx::Size viewport_size(1000, 500); |
169 | 179 |
170 LayerTestCommon::LayerImplTest impl; | 180 LayerTestCommon::LayerImplTest impl; |
171 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | 181 DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); |
172 | 182 |
173 scoped_refptr<media::VideoFrame> video_frame = | 183 scoped_refptr<media::VideoFrame> video_frame = |
174 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 184 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
175 gfx::Size(20, 10), | 185 gfx::Size(20, 10), |
176 gfx::Rect(20, 10), | 186 gfx::Rect(20, 10), |
177 gfx::Size(20, 10), | 187 gfx::Size(20, 10), |
178 base::TimeDelta()); | 188 base::TimeDelta()); |
179 FakeVideoFrameProvider provider; | 189 FakeVideoFrameProvider provider; |
180 provider.set_frame(video_frame); | 190 provider.set_frame(video_frame); |
181 | 191 |
(...skipping 15 matching lines...) Expand all Loading... |
197 impl.quad_list().front()->quadTransform().TransformPoint(&p2); | 207 impl.quad_list().front()->quadTransform().TransformPoint(&p2); |
198 EXPECT_EQ(gfx::Point3F(100, 0, 0), p1); | 208 EXPECT_EQ(gfx::Point3F(100, 0, 0), p1); |
199 EXPECT_EQ(gfx::Point3F(0, 50, 0), p2); | 209 EXPECT_EQ(gfx::Point3F(0, 50, 0), p2); |
200 } | 210 } |
201 | 211 |
202 TEST(VideoLayerImplTest, Rotated270) { | 212 TEST(VideoLayerImplTest, Rotated270) { |
203 gfx::Size layer_size(100, 50); | 213 gfx::Size layer_size(100, 50); |
204 gfx::Size viewport_size(1000, 500); | 214 gfx::Size viewport_size(1000, 500); |
205 | 215 |
206 LayerTestCommon::LayerImplTest impl; | 216 LayerTestCommon::LayerImplTest impl; |
207 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | 217 DebugSetImplThreadAndMainThreadBlocked(impl.proxy()); |
208 | 218 |
209 scoped_refptr<media::VideoFrame> video_frame = | 219 scoped_refptr<media::VideoFrame> video_frame = |
210 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 220 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
211 gfx::Size(20, 10), | 221 gfx::Size(20, 10), |
212 gfx::Rect(20, 10), | 222 gfx::Rect(20, 10), |
213 gfx::Size(20, 10), | 223 gfx::Size(20, 10), |
214 base::TimeDelta()); | 224 base::TimeDelta()); |
215 FakeVideoFrameProvider provider; | 225 FakeVideoFrameProvider provider; |
216 provider.set_frame(video_frame); | 226 provider.set_frame(video_frame); |
217 | 227 |
(...skipping 12 matching lines...) Expand all Loading... |
230 gfx::Point3F p1(0, impl.quad_list().front()->rect.height(), 0); | 240 gfx::Point3F p1(0, impl.quad_list().front()->rect.height(), 0); |
231 gfx::Point3F p2(impl.quad_list().front()->rect.width(), 0, 0); | 241 gfx::Point3F p2(impl.quad_list().front()->rect.width(), 0, 0); |
232 impl.quad_list().front()->quadTransform().TransformPoint(&p1); | 242 impl.quad_list().front()->quadTransform().TransformPoint(&p1); |
233 impl.quad_list().front()->quadTransform().TransformPoint(&p2); | 243 impl.quad_list().front()->quadTransform().TransformPoint(&p2); |
234 EXPECT_EQ(gfx::Point3F(100, 50, 0), p1); | 244 EXPECT_EQ(gfx::Point3F(100, 50, 0), p1); |
235 EXPECT_EQ(gfx::Point3F(0, 0, 0), p2); | 245 EXPECT_EQ(gfx::Point3F(0, 0, 0), p2); |
236 } | 246 } |
237 | 247 |
238 } // namespace | 248 } // namespace |
239 } // namespace cc | 249 } // namespace cc |
OLD | NEW |