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 TEST(VideoLayerImplTest, Occlusion) { | 20 // We can't use DebugScopedSetImplThreadAndMainThreadBlocked for these tests |
danakj
2015/03/24 17:38:01
What if you SetRootLayer(nullptr) before exiting t
sunnyps
2015/03/24 19:43:38
I didn't use SetRootLayer(nullptr) but changed thi
| |
21 // because it gets destroyed before the layer tree. VideoLayerImpl triggers a | |
22 // DCHECK in it's destructor that checks if we're on impl thread and main thread | |
23 // is blocked. | |
24 class VideoLayerImplTest : public testing::Test { | |
25 public: | |
26 VideoLayerImplTest() { | |
27 #if DCHECK_IS_ON() | |
28 impl.proxy()->SetCurrentThreadIsImplThread(true); | |
29 impl.proxy()->SetMainThreadBlocked(true); | |
30 #endif | |
31 } | |
32 | |
33 protected: | |
34 LayerTestCommon::LayerImplTest impl; | |
35 }; | |
36 | |
37 TEST_F(VideoLayerImplTest, Occlusion) { | |
21 gfx::Size layer_size(1000, 1000); | 38 gfx::Size layer_size(1000, 1000); |
22 gfx::Size viewport_size(1000, 1000); | 39 gfx::Size viewport_size(1000, 1000); |
23 | 40 |
24 LayerTestCommon::LayerImplTest impl; | |
25 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | |
26 | |
27 scoped_refptr<media::VideoFrame> video_frame = | 41 scoped_refptr<media::VideoFrame> video_frame = |
28 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 42 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
29 gfx::Size(10, 10), | 43 gfx::Size(10, 10), |
30 gfx::Rect(10, 10), | 44 gfx::Rect(10, 10), |
31 gfx::Size(10, 10), | 45 gfx::Size(10, 10), |
32 base::TimeDelta()); | 46 base::TimeDelta()); |
33 FakeVideoFrameProvider provider; | 47 FakeVideoFrameProvider provider; |
34 provider.set_frame(video_frame); | 48 provider.set_frame(video_frame); |
35 | 49 |
36 VideoLayerImpl* video_layer_impl = | 50 VideoLayerImpl* video_layer_impl = |
(...skipping 30 matching lines...) Expand all Loading... | |
67 | 81 |
68 size_t partially_occluded_count = 0; | 82 size_t partially_occluded_count = 0; |
69 LayerTestCommon::VerifyQuadsAreOccluded( | 83 LayerTestCommon::VerifyQuadsAreOccluded( |
70 impl.quad_list(), occluded, &partially_occluded_count); | 84 impl.quad_list(), occluded, &partially_occluded_count); |
71 // The layer outputs one quad, which is partially occluded. | 85 // The layer outputs one quad, which is partially occluded. |
72 EXPECT_EQ(1u, impl.quad_list().size()); | 86 EXPECT_EQ(1u, impl.quad_list().size()); |
73 EXPECT_EQ(1u, partially_occluded_count); | 87 EXPECT_EQ(1u, partially_occluded_count); |
74 } | 88 } |
75 } | 89 } |
76 | 90 |
77 TEST(VideoLayerImplTest, DidBecomeActiveShouldSetActiveVideoLayer) { | 91 TEST_F(VideoLayerImplTest, DidBecomeActiveShouldStartProviderClient) { |
78 LayerTestCommon::LayerImplTest impl; | |
79 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | |
80 | |
81 FakeVideoFrameProvider provider; | 92 FakeVideoFrameProvider provider; |
82 VideoLayerImpl* video_layer_impl = | 93 VideoLayerImpl* video_layer_impl = |
83 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_0); | 94 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_0); |
84 | 95 |
85 VideoFrameProviderClientImpl* client = | 96 VideoFrameProviderClientImpl* client = |
86 static_cast<VideoFrameProviderClientImpl*>(provider.client()); | 97 static_cast<VideoFrameProviderClientImpl*>(provider.client()); |
87 ASSERT_TRUE(client); | 98 ASSERT_TRUE(client); |
88 EXPECT_FALSE(client->active_video_layer()); | |
89 | 99 |
100 EXPECT_FALSE(client->Started()); | |
90 video_layer_impl->DidBecomeActive(); | 101 video_layer_impl->DidBecomeActive(); |
91 EXPECT_EQ(video_layer_impl, client->active_video_layer()); | 102 EXPECT_TRUE(client->Started()); |
92 } | 103 } |
93 | 104 |
94 TEST(VideoLayerImplTest, Rotated0) { | 105 TEST_F(VideoLayerImplTest, Rotated0) { |
95 gfx::Size layer_size(100, 50); | 106 gfx::Size layer_size(100, 50); |
96 gfx::Size viewport_size(1000, 500); | 107 gfx::Size viewport_size(1000, 500); |
97 | 108 |
98 LayerTestCommon::LayerImplTest impl; | |
99 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | |
100 | |
101 scoped_refptr<media::VideoFrame> video_frame = | 109 scoped_refptr<media::VideoFrame> video_frame = |
102 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 110 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
103 gfx::Size(20, 10), | 111 gfx::Size(20, 10), |
104 gfx::Rect(20, 10), | 112 gfx::Rect(20, 10), |
105 gfx::Size(20, 10), | 113 gfx::Size(20, 10), |
106 base::TimeDelta()); | 114 base::TimeDelta()); |
107 FakeVideoFrameProvider provider; | 115 FakeVideoFrameProvider provider; |
108 provider.set_frame(video_frame); | 116 provider.set_frame(video_frame); |
109 | 117 |
110 VideoLayerImpl* video_layer_impl = | 118 VideoLayerImpl* video_layer_impl = |
111 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_0); | 119 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_0); |
112 video_layer_impl->SetBounds(layer_size); | 120 video_layer_impl->SetBounds(layer_size); |
113 video_layer_impl->SetContentBounds(layer_size); | 121 video_layer_impl->SetContentBounds(layer_size); |
114 video_layer_impl->SetDrawsContent(true); | 122 video_layer_impl->SetDrawsContent(true); |
115 | 123 |
116 impl.CalcDrawProps(viewport_size); | 124 impl.CalcDrawProps(viewport_size); |
117 gfx::Rect occluded; | 125 gfx::Rect occluded; |
118 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); | 126 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); |
119 | 127 |
120 EXPECT_EQ(1u, impl.quad_list().size()); | 128 EXPECT_EQ(1u, impl.quad_list().size()); |
121 | 129 |
122 gfx::Point3F p1(0, impl.quad_list().front()->rect.height(), 0); | 130 gfx::Point3F p1(0, impl.quad_list().front()->rect.height(), 0); |
123 gfx::Point3F p2(impl.quad_list().front()->rect.width(), 0, 0); | 131 gfx::Point3F p2(impl.quad_list().front()->rect.width(), 0, 0); |
124 impl.quad_list().front()->quadTransform().TransformPoint(&p1); | 132 impl.quad_list().front()->quadTransform().TransformPoint(&p1); |
125 impl.quad_list().front()->quadTransform().TransformPoint(&p2); | 133 impl.quad_list().front()->quadTransform().TransformPoint(&p2); |
126 EXPECT_EQ(gfx::Point3F(0, 50, 0), p1); | 134 EXPECT_EQ(gfx::Point3F(0, 50, 0), p1); |
127 EXPECT_EQ(gfx::Point3F(100, 0, 0), p2); | 135 EXPECT_EQ(gfx::Point3F(100, 0, 0), p2); |
128 } | 136 } |
129 | 137 |
130 TEST(VideoLayerImplTest, Rotated90) { | 138 TEST_F(VideoLayerImplTest, Rotated90) { |
131 gfx::Size layer_size(100, 50); | 139 gfx::Size layer_size(100, 50); |
132 gfx::Size viewport_size(1000, 500); | 140 gfx::Size viewport_size(1000, 500); |
133 | 141 |
134 LayerTestCommon::LayerImplTest impl; | |
135 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | |
136 | |
137 scoped_refptr<media::VideoFrame> video_frame = | 142 scoped_refptr<media::VideoFrame> video_frame = |
138 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 143 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
139 gfx::Size(20, 10), | 144 gfx::Size(20, 10), |
140 gfx::Rect(20, 10), | 145 gfx::Rect(20, 10), |
141 gfx::Size(20, 10), | 146 gfx::Size(20, 10), |
142 base::TimeDelta()); | 147 base::TimeDelta()); |
143 FakeVideoFrameProvider provider; | 148 FakeVideoFrameProvider provider; |
144 provider.set_frame(video_frame); | 149 provider.set_frame(video_frame); |
145 | 150 |
146 VideoLayerImpl* video_layer_impl = | 151 VideoLayerImpl* video_layer_impl = |
147 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_90); | 152 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_90); |
148 video_layer_impl->SetBounds(layer_size); | 153 video_layer_impl->SetBounds(layer_size); |
149 video_layer_impl->SetContentBounds(layer_size); | 154 video_layer_impl->SetContentBounds(layer_size); |
150 video_layer_impl->SetDrawsContent(true); | 155 video_layer_impl->SetDrawsContent(true); |
151 | 156 |
152 impl.CalcDrawProps(viewport_size); | 157 impl.CalcDrawProps(viewport_size); |
153 gfx::Rect occluded; | 158 gfx::Rect occluded; |
154 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); | 159 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); |
155 | 160 |
156 EXPECT_EQ(1u, impl.quad_list().size()); | 161 EXPECT_EQ(1u, impl.quad_list().size()); |
157 | 162 |
158 gfx::Point3F p1(0, impl.quad_list().front()->rect.height(), 0); | 163 gfx::Point3F p1(0, impl.quad_list().front()->rect.height(), 0); |
159 gfx::Point3F p2(impl.quad_list().front()->rect.width(), 0, 0); | 164 gfx::Point3F p2(impl.quad_list().front()->rect.width(), 0, 0); |
160 impl.quad_list().front()->quadTransform().TransformPoint(&p1); | 165 impl.quad_list().front()->quadTransform().TransformPoint(&p1); |
161 impl.quad_list().front()->quadTransform().TransformPoint(&p2); | 166 impl.quad_list().front()->quadTransform().TransformPoint(&p2); |
162 EXPECT_EQ(gfx::Point3F(0, 0, 0), p1); | 167 EXPECT_EQ(gfx::Point3F(0, 0, 0), p1); |
163 EXPECT_EQ(gfx::Point3F(100, 50, 0), p2); | 168 EXPECT_EQ(gfx::Point3F(100, 50, 0), p2); |
164 } | 169 } |
165 | 170 |
166 TEST(VideoLayerImplTest, Rotated180) { | 171 TEST_F(VideoLayerImplTest, Rotated180) { |
167 gfx::Size layer_size(100, 50); | 172 gfx::Size layer_size(100, 50); |
168 gfx::Size viewport_size(1000, 500); | 173 gfx::Size viewport_size(1000, 500); |
169 | 174 |
170 LayerTestCommon::LayerImplTest impl; | |
171 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | |
172 | |
173 scoped_refptr<media::VideoFrame> video_frame = | 175 scoped_refptr<media::VideoFrame> video_frame = |
174 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 176 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
175 gfx::Size(20, 10), | 177 gfx::Size(20, 10), |
176 gfx::Rect(20, 10), | 178 gfx::Rect(20, 10), |
177 gfx::Size(20, 10), | 179 gfx::Size(20, 10), |
178 base::TimeDelta()); | 180 base::TimeDelta()); |
179 FakeVideoFrameProvider provider; | 181 FakeVideoFrameProvider provider; |
180 provider.set_frame(video_frame); | 182 provider.set_frame(video_frame); |
181 | 183 |
182 VideoLayerImpl* video_layer_impl = | 184 VideoLayerImpl* video_layer_impl = |
183 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_180); | 185 impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_180); |
184 video_layer_impl->SetBounds(layer_size); | 186 video_layer_impl->SetBounds(layer_size); |
185 video_layer_impl->SetContentBounds(layer_size); | 187 video_layer_impl->SetContentBounds(layer_size); |
186 video_layer_impl->SetDrawsContent(true); | 188 video_layer_impl->SetDrawsContent(true); |
187 | 189 |
188 impl.CalcDrawProps(viewport_size); | 190 impl.CalcDrawProps(viewport_size); |
189 gfx::Rect occluded; | 191 gfx::Rect occluded; |
190 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); | 192 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded); |
191 | 193 |
192 EXPECT_EQ(1u, impl.quad_list().size()); | 194 EXPECT_EQ(1u, impl.quad_list().size()); |
193 | 195 |
194 gfx::Point3F p1(0, impl.quad_list().front()->rect.height(), 0); | 196 gfx::Point3F p1(0, impl.quad_list().front()->rect.height(), 0); |
195 gfx::Point3F p2(impl.quad_list().front()->rect.width(), 0, 0); | 197 gfx::Point3F p2(impl.quad_list().front()->rect.width(), 0, 0); |
196 impl.quad_list().front()->quadTransform().TransformPoint(&p1); | 198 impl.quad_list().front()->quadTransform().TransformPoint(&p1); |
197 impl.quad_list().front()->quadTransform().TransformPoint(&p2); | 199 impl.quad_list().front()->quadTransform().TransformPoint(&p2); |
198 EXPECT_EQ(gfx::Point3F(100, 0, 0), p1); | 200 EXPECT_EQ(gfx::Point3F(100, 0, 0), p1); |
199 EXPECT_EQ(gfx::Point3F(0, 50, 0), p2); | 201 EXPECT_EQ(gfx::Point3F(0, 50, 0), p2); |
200 } | 202 } |
201 | 203 |
202 TEST(VideoLayerImplTest, Rotated270) { | 204 TEST_F(VideoLayerImplTest, Rotated270) { |
203 gfx::Size layer_size(100, 50); | 205 gfx::Size layer_size(100, 50); |
204 gfx::Size viewport_size(1000, 500); | 206 gfx::Size viewport_size(1000, 500); |
205 | 207 |
206 LayerTestCommon::LayerImplTest impl; | |
207 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy()); | |
208 | |
209 scoped_refptr<media::VideoFrame> video_frame = | 208 scoped_refptr<media::VideoFrame> video_frame = |
210 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, | 209 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, |
211 gfx::Size(20, 10), | 210 gfx::Size(20, 10), |
212 gfx::Rect(20, 10), | 211 gfx::Rect(20, 10), |
213 gfx::Size(20, 10), | 212 gfx::Size(20, 10), |
214 base::TimeDelta()); | 213 base::TimeDelta()); |
215 FakeVideoFrameProvider provider; | 214 FakeVideoFrameProvider provider; |
216 provider.set_frame(video_frame); | 215 provider.set_frame(video_frame); |
217 | 216 |
218 VideoLayerImpl* video_layer_impl = | 217 VideoLayerImpl* video_layer_impl = |
(...skipping 11 matching lines...) Expand all Loading... | |
230 gfx::Point3F p1(0, impl.quad_list().front()->rect.height(), 0); | 229 gfx::Point3F p1(0, impl.quad_list().front()->rect.height(), 0); |
231 gfx::Point3F p2(impl.quad_list().front()->rect.width(), 0, 0); | 230 gfx::Point3F p2(impl.quad_list().front()->rect.width(), 0, 0); |
232 impl.quad_list().front()->quadTransform().TransformPoint(&p1); | 231 impl.quad_list().front()->quadTransform().TransformPoint(&p1); |
233 impl.quad_list().front()->quadTransform().TransformPoint(&p2); | 232 impl.quad_list().front()->quadTransform().TransformPoint(&p2); |
234 EXPECT_EQ(gfx::Point3F(100, 50, 0), p1); | 233 EXPECT_EQ(gfx::Point3F(100, 50, 0), p1); |
235 EXPECT_EQ(gfx::Point3F(0, 0, 0), p2); | 234 EXPECT_EQ(gfx::Point3F(0, 0, 0), p2); |
236 } | 235 } |
237 | 236 |
238 } // namespace | 237 } // namespace |
239 } // namespace cc | 238 } // namespace cc |
OLD | NEW |