Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: ui/compositor/layer_unittest.cc

Issue 2776973004: Remove CompositorObserver::OnCompositingEnded() (Closed)
Patch Set: Rename commited_frame_number_ to activated_frame_count_ and move increments back to DidReceiveCompo… Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/compositor/layer.cc ('k') | ui/compositor/test/draw_waiter_for_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/layer.h" 5 #include "ui/compositor/layer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 DrawFadedStringLayerDelegate* delegate) { 181 DrawFadedStringLayerDelegate* delegate) {
182 std::unique_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); 182 std::unique_ptr<Layer> layer(new Layer(LAYER_TEXTURED));
183 layer->SetBounds(bounds); 183 layer->SetBounds(bounds);
184 layer->set_delegate(delegate); 184 layer->set_delegate(delegate);
185 return layer; 185 return layer;
186 } 186 }
187 187
188 void DrawTree(Layer* root) { 188 void DrawTree(Layer* root) {
189 GetCompositor()->SetRootLayer(root); 189 GetCompositor()->SetRootLayer(root);
190 GetCompositor()->ScheduleDraw(); 190 GetCompositor()->ScheduleDraw();
191 WaitForSwap(); 191 WaitForDraw();
192 } 192 }
193 193
194 void ReadPixels(SkBitmap* bitmap) { 194 void ReadPixels(SkBitmap* bitmap) {
195 ReadPixels(bitmap, gfx::Rect(GetCompositor()->size())); 195 ReadPixels(bitmap, gfx::Rect(GetCompositor()->size()));
196 } 196 }
197 197
198 void ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) { 198 void ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) {
199 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder); 199 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder);
200 std::unique_ptr<cc::CopyOutputRequest> request = 200 std::unique_ptr<cc::CopyOutputRequest> request =
201 cc::CopyOutputRequest::CreateBitmapRequest( 201 cc::CopyOutputRequest::CreateBitmapRequest(
(...skipping 13 matching lines...) Expand all
215 // Waits for the callback to finish run and return result. 215 // Waits for the callback to finish run and return result.
216 holder->WaitForReadback(); 216 holder->WaitForReadback();
217 217
218 *bitmap = holder->result(); 218 *bitmap = holder->result();
219 } 219 }
220 220
221 void WaitForDraw() { 221 void WaitForDraw() {
222 ui::DrawWaiterForTest::WaitForCompositingStarted(GetCompositor()); 222 ui::DrawWaiterForTest::WaitForCompositingStarted(GetCompositor());
223 } 223 }
224 224
225 void WaitForSwap() {
226 DrawWaiterForTest::WaitForCompositingEnded(GetCompositor());
227 }
228
229 void WaitForCommit() { 225 void WaitForCommit() {
230 ui::DrawWaiterForTest::WaitForCommit(GetCompositor()); 226 ui::DrawWaiterForTest::WaitForCommit(GetCompositor());
231 } 227 }
232 228
233 // Invalidates the entire contents of the layer. 229 // Invalidates the entire contents of the layer.
234 void SchedulePaintForLayer(Layer* layer) { 230 void SchedulePaintForLayer(Layer* layer) {
235 layer->SchedulePaint( 231 layer->SchedulePaint(
236 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 232 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
237 } 233 }
238 234
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 357
362 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); 358 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate);
363 }; 359 };
364 360
365 // Remembers if it has been notified. 361 // Remembers if it has been notified.
366 class TestCompositorObserver : public CompositorObserver { 362 class TestCompositorObserver : public CompositorObserver {
367 public: 363 public:
368 TestCompositorObserver() = default; 364 TestCompositorObserver() = default;
369 365
370 bool committed() const { return committed_; } 366 bool committed() const { return committed_; }
371 bool notified() const { return started_ && ended_; } 367 bool started() const { return started_; }
372 368
373 void Reset() { 369 void Reset() {
374 committed_ = false; 370 committed_ = false;
375 started_ = false; 371 started_ = false;
376 ended_ = false;
377 } 372 }
378 373
379 private: 374 private:
380 void OnCompositingDidCommit(Compositor* compositor) override { 375 void OnCompositingDidCommit(Compositor* compositor) override {
381 committed_ = true; 376 committed_ = true;
382 } 377 }
383 378
384 void OnCompositingStarted(Compositor* compositor, 379 void OnCompositingStarted(Compositor* compositor,
385 base::TimeTicks start_time) override { 380 base::TimeTicks start_time) override {
386 started_ = true; 381 started_ = true;
387 } 382 }
388 383
389 void OnCompositingEnded(Compositor* compositor) override { ended_ = true; }
390
391 void OnCompositingLockStateChanged(Compositor* compositor) override {} 384 void OnCompositingLockStateChanged(Compositor* compositor) override {}
392 385
393 void OnCompositingShuttingDown(Compositor* compositor) override {} 386 void OnCompositingShuttingDown(Compositor* compositor) override {}
394 387
395 bool committed_ = false; 388 bool committed_ = false;
396 bool started_ = false; 389 bool started_ = false;
397 bool ended_ = false;
398 390
399 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver); 391 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver);
400 }; 392 };
401 393
402 class TestCompositorAnimationObserver : public CompositorAnimationObserver { 394 class TestCompositorAnimationObserver : public CompositorAnimationObserver {
403 public: 395 public:
404 explicit TestCompositorAnimationObserver(ui::Compositor* compositor) 396 explicit TestCompositorAnimationObserver(ui::Compositor* compositor)
405 : compositor_(compositor), 397 : compositor_(compositor),
406 animation_step_count_(0), 398 animation_step_count_(0),
407 shutdown_(false) { 399 shutdown_(false) {
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); 1302 CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400)));
1311 std::unique_ptr<Layer> l2( 1303 std::unique_ptr<Layer> l2(
1312 CreateColorLayer(SK_ColorBLUE, gfx::Rect(10, 10, 350, 350))); 1304 CreateColorLayer(SK_ColorBLUE, gfx::Rect(10, 10, 350, 350)));
1313 l1->Add(l2.get()); 1305 l1->Add(l2.get());
1314 TestCompositorObserver observer; 1306 TestCompositorObserver observer;
1315 GetCompositor()->AddObserver(&observer); 1307 GetCompositor()->AddObserver(&observer);
1316 1308
1317 // Explicitly called DrawTree should cause the observers to be notified. 1309 // Explicitly called DrawTree should cause the observers to be notified.
1318 // NOTE: this call to DrawTree sets l1 to be the compositor's root layer. 1310 // NOTE: this call to DrawTree sets l1 to be the compositor's root layer.
1319 DrawTree(l1.get()); 1311 DrawTree(l1.get());
1320 EXPECT_TRUE(observer.notified()); 1312 EXPECT_TRUE(observer.started());
1321 1313
1322 // ScheduleDraw without any visible change should cause a commit. 1314 // ScheduleDraw without any visible change should cause a commit.
1323 observer.Reset(); 1315 observer.Reset();
1324 l1->ScheduleDraw(); 1316 l1->ScheduleDraw();
1325 WaitForCommit(); 1317 WaitForCommit();
1326 EXPECT_TRUE(observer.committed()); 1318 EXPECT_TRUE(observer.committed());
1327 1319
1328 // Moving, but not resizing, a layer should alert the observers. 1320 // Moving, but not resizing, a layer should alert the observers.
1329 observer.Reset(); 1321 observer.Reset();
1330 l2->SetBounds(gfx::Rect(0, 0, 350, 350)); 1322 l2->SetBounds(gfx::Rect(0, 0, 350, 350));
1331 WaitForSwap(); 1323 WaitForDraw();
1332 EXPECT_TRUE(observer.notified()); 1324 EXPECT_TRUE(observer.started());
1333 1325
1334 // So should resizing a layer. 1326 // So should resizing a layer.
1335 observer.Reset(); 1327 observer.Reset();
1336 l2->SetBounds(gfx::Rect(0, 0, 400, 400)); 1328 l2->SetBounds(gfx::Rect(0, 0, 400, 400));
1337 WaitForSwap(); 1329 WaitForDraw();
1338 EXPECT_TRUE(observer.notified()); 1330 EXPECT_TRUE(observer.started());
1339 1331
1340 // Opacity changes should alert the observers. 1332 // Opacity changes should alert the observers.
1341 observer.Reset(); 1333 observer.Reset();
1342 l2->SetOpacity(0.5f); 1334 l2->SetOpacity(0.5f);
1343 WaitForSwap(); 1335 WaitForDraw();
1344 EXPECT_TRUE(observer.notified()); 1336 EXPECT_TRUE(observer.started());
1345 1337
1346 // So should setting the opacity back. 1338 // So should setting the opacity back.
1347 observer.Reset(); 1339 observer.Reset();
1348 l2->SetOpacity(1.0f); 1340 l2->SetOpacity(1.0f);
1349 WaitForSwap(); 1341 WaitForDraw();
1350 EXPECT_TRUE(observer.notified()); 1342 EXPECT_TRUE(observer.started());
1351 1343
1352 // Setting the transform of a layer should alert the observers. 1344 // Setting the transform of a layer should alert the observers.
1353 observer.Reset(); 1345 observer.Reset();
1354 gfx::Transform transform; 1346 gfx::Transform transform;
1355 transform.Translate(200.0, 200.0); 1347 transform.Translate(200.0, 200.0);
1356 transform.Rotate(90.0); 1348 transform.Rotate(90.0);
1357 transform.Translate(-200.0, -200.0); 1349 transform.Translate(-200.0, -200.0);
1358 l2->SetTransform(transform); 1350 l2->SetTransform(transform);
1359 WaitForSwap(); 1351 WaitForDraw();
1360 EXPECT_TRUE(observer.notified()); 1352 EXPECT_TRUE(observer.started());
1361 1353
1362 GetCompositor()->RemoveObserver(&observer); 1354 GetCompositor()->RemoveObserver(&observer);
1363 1355
1364 // Opacity changes should no longer alert the removed observer. 1356 // Opacity changes should no longer alert the removed observer.
1365 observer.Reset(); 1357 observer.Reset();
1366 l2->SetOpacity(0.5f); 1358 l2->SetOpacity(0.5f);
1367 WaitForSwap(); 1359 WaitForDraw();
1368 1360
1369 EXPECT_FALSE(observer.notified()); 1361 EXPECT_FALSE(observer.started());
1370 } 1362 }
1371 1363
1372 // Checks that modifying the hierarchy correctly affects final composite. 1364 // Checks that modifying the hierarchy correctly affects final composite.
1373 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { 1365 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) {
1374 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); 1366 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50));
1375 1367
1376 // l0 1368 // l0
1377 // +-l11 1369 // +-l11
1378 // | +-l21 1370 // | +-l21
1379 // +-l12 1371 // +-l12
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
2172 2164
2173 TEST_F(LayerWithRealCompositorTest, CompositorAnimationObserverTest) { 2165 TEST_F(LayerWithRealCompositorTest, CompositorAnimationObserverTest) {
2174 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); 2166 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED));
2175 2167
2176 root->SetAnimator(LayerAnimator::CreateImplicitAnimator()); 2168 root->SetAnimator(LayerAnimator::CreateImplicitAnimator());
2177 2169
2178 TestCompositorAnimationObserver animation_observer(GetCompositor()); 2170 TestCompositorAnimationObserver animation_observer(GetCompositor());
2179 EXPECT_EQ(0u, animation_observer.animation_step_count()); 2171 EXPECT_EQ(0u, animation_observer.animation_step_count());
2180 2172
2181 root->SetOpacity(0.5f); 2173 root->SetOpacity(0.5f);
2182 WaitForSwap(); 2174 WaitForDraw();
2183 EXPECT_EQ(1u, animation_observer.animation_step_count()); 2175 EXPECT_EQ(1u, animation_observer.animation_step_count());
2184 2176
2185 EXPECT_FALSE(animation_observer.shutdown()); 2177 EXPECT_FALSE(animation_observer.shutdown());
2186 ResetCompositor(); 2178 ResetCompositor();
2187 EXPECT_TRUE(animation_observer.shutdown()); 2179 EXPECT_TRUE(animation_observer.shutdown());
2188 } 2180 }
2189 2181
2190 // A simple AnimationMetricsReporter class that remembers smoothness metric 2182 // A simple AnimationMetricsReporter class that remembers smoothness metric
2191 // when animation completes. 2183 // when animation completes.
2192 class TestMetricsReporter : public ui::AnimationMetricsReporter { 2184 class TestMetricsReporter : public ui::AnimationMetricsReporter {
(...skipping 25 matching lines...) Expand all
2218 LayerAnimator* animator = root->GetAnimator(); 2210 LayerAnimator* animator = root->GetAnimator();
2219 std::unique_ptr<ui::LayerAnimationElement> animation_element = 2211 std::unique_ptr<ui::LayerAnimationElement> animation_element =
2220 ui::LayerAnimationElement::CreateColorElement( 2212 ui::LayerAnimationElement::CreateColorElement(
2221 SK_ColorRED, base::TimeDelta::FromMilliseconds(100)); 2213 SK_ColorRED, base::TimeDelta::FromMilliseconds(100));
2222 ui::LayerAnimationSequence* animation_sequence = 2214 ui::LayerAnimationSequence* animation_sequence =
2223 new ui::LayerAnimationSequence(std::move(animation_element)); 2215 new ui::LayerAnimationSequence(std::move(animation_element));
2224 TestMetricsReporter reporter; 2216 TestMetricsReporter reporter;
2225 animation_sequence->SetAnimationMetricsReporter(&reporter); 2217 animation_sequence->SetAnimationMetricsReporter(&reporter);
2226 animator->StartAnimation(animation_sequence); 2218 animator->StartAnimation(animation_sequence);
2227 while (!reporter.report_called()) 2219 while (!reporter.report_called())
2228 WaitForSwap(); 2220 WaitForDraw();
2229 ResetCompositor(); 2221 ResetCompositor();
2230 // Even though most of the time 100% smooth animations are expected, on the 2222 // Even though most of the time 100% smooth animations are expected, on the
2231 // test bots this cannot be guaranteed. Therefore simply check that some 2223 // test bots this cannot be guaranteed. Therefore simply check that some
2232 // value was reported. 2224 // value was reported.
2233 EXPECT_GT(reporter.value(), 0); 2225 EXPECT_GT(reporter.value(), 0);
2234 } 2226 }
2235 2227
2236 TEST(LayerDebugInfoTest, LayerNameDoesNotClobber) { 2228 TEST(LayerDebugInfoTest, LayerNameDoesNotClobber) {
2237 Layer layer(LAYER_NOT_DRAWN); 2229 Layer layer(LAYER_NOT_DRAWN);
2238 layer.set_name("foo"); 2230 layer.set_name("foo");
2239 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = 2231 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info =
2240 layer.TakeDebugInfo(nullptr); 2232 layer.TakeDebugInfo(nullptr);
2241 std::string trace_format("bar,"); 2233 std::string trace_format("bar,");
2242 debug_info->AppendAsTraceFormat(&trace_format); 2234 debug_info->AppendAsTraceFormat(&trace_format);
2243 std::string expected("bar,{\"layer_name\":\"foo\"}"); 2235 std::string expected("bar,{\"layer_name\":\"foo\"}");
2244 EXPECT_EQ(expected, trace_format); 2236 EXPECT_EQ(expected, trace_format);
2245 } 2237 }
2246 2238
2247 } // namespace ui 2239 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer.cc ('k') | ui/compositor/test/draw_waiter_for_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698