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

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

Issue 2776973004: Remove CompositorObserver::OnCompositingEnded() (Closed)
Patch Set: 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/compositor_unittest.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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 const gfx::Rect& bounds, DrawStringLayerDelegate* delegate) { 203 const gfx::Rect& bounds, DrawStringLayerDelegate* delegate) {
204 std::unique_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); 204 std::unique_ptr<Layer> layer(new Layer(LAYER_TEXTURED));
205 layer->SetBounds(bounds); 205 layer->SetBounds(bounds);
206 layer->set_delegate(delegate); 206 layer->set_delegate(delegate);
207 return layer; 207 return layer;
208 } 208 }
209 209
210 void DrawTree(Layer* root) { 210 void DrawTree(Layer* root) {
211 GetCompositor()->SetRootLayer(root); 211 GetCompositor()->SetRootLayer(root);
212 GetCompositor()->ScheduleDraw(); 212 GetCompositor()->ScheduleDraw();
213 WaitForSwap(); 213 WaitForDraw();
214 } 214 }
215 215
216 void ReadPixels(SkBitmap* bitmap) { 216 void ReadPixels(SkBitmap* bitmap) {
217 ReadPixels(bitmap, gfx::Rect(GetCompositor()->size())); 217 ReadPixels(bitmap, gfx::Rect(GetCompositor()->size()));
218 } 218 }
219 219
220 void ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) { 220 void ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) {
221 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder); 221 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder);
222 std::unique_ptr<cc::CopyOutputRequest> request = 222 std::unique_ptr<cc::CopyOutputRequest> request =
223 cc::CopyOutputRequest::CreateBitmapRequest( 223 cc::CopyOutputRequest::CreateBitmapRequest(
(...skipping 13 matching lines...) Expand all
237 // Waits for the callback to finish run and return result. 237 // Waits for the callback to finish run and return result.
238 holder->WaitForReadback(); 238 holder->WaitForReadback();
239 239
240 *bitmap = holder->result(); 240 *bitmap = holder->result();
241 } 241 }
242 242
243 void WaitForDraw() { 243 void WaitForDraw() {
244 ui::DrawWaiterForTest::WaitForCompositingStarted(GetCompositor()); 244 ui::DrawWaiterForTest::WaitForCompositingStarted(GetCompositor());
245 } 245 }
246 246
247 void WaitForSwap() { 247 // void WaitForSwap() {
Fady Samuel 2017/03/27 18:36:18 Delete this?
Alex Z. 2017/03/27 18:52:38 Done.
248 DrawWaiterForTest::WaitForCompositingEnded(GetCompositor()); 248 // DrawWaiterForTest::WaitForCompositingEnded(GetCompositor());
249 } 249 // }
250 250
251 void WaitForCommit() { 251 void WaitForCommit() {
252 ui::DrawWaiterForTest::WaitForCommit(GetCompositor()); 252 ui::DrawWaiterForTest::WaitForCommit(GetCompositor());
253 } 253 }
254 254
255 // Invalidates the entire contents of the layer. 255 // Invalidates the entire contents of the layer.
256 void SchedulePaintForLayer(Layer* layer) { 256 void SchedulePaintForLayer(Layer* layer) {
257 layer->SchedulePaint( 257 layer->SchedulePaint(
258 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 258 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
259 } 259 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 383
384 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); 384 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate);
385 }; 385 };
386 386
387 // Remembers if it has been notified. 387 // Remembers if it has been notified.
388 class TestCompositorObserver : public CompositorObserver { 388 class TestCompositorObserver : public CompositorObserver {
389 public: 389 public:
390 TestCompositorObserver() = default; 390 TestCompositorObserver() = default;
391 391
392 bool committed() const { return committed_; } 392 bool committed() const { return committed_; }
393 bool notified() const { return started_ && ended_; } 393 bool started() const { return started_; }
394 394
395 void Reset() { 395 void Reset() {
396 committed_ = false; 396 committed_ = false;
397 started_ = false; 397 started_ = false;
398 ended_ = false;
399 } 398 }
400 399
401 private: 400 private:
402 void OnCompositingDidCommit(Compositor* compositor) override { 401 void OnCompositingDidCommit(Compositor* compositor) override {
403 committed_ = true; 402 committed_ = true;
404 } 403 }
405 404
406 void OnCompositingStarted(Compositor* compositor, 405 void OnCompositingStarted(Compositor* compositor,
407 base::TimeTicks start_time) override { 406 base::TimeTicks start_time) override {
408 started_ = true; 407 started_ = true;
409 } 408 }
410 409
411 void OnCompositingEnded(Compositor* compositor) override { ended_ = true; }
412
413 void OnCompositingLockStateChanged(Compositor* compositor) override {} 410 void OnCompositingLockStateChanged(Compositor* compositor) override {}
414 411
415 void OnCompositingShuttingDown(Compositor* compositor) override {} 412 void OnCompositingShuttingDown(Compositor* compositor) override {}
416 413
417 bool committed_ = false; 414 bool committed_ = false;
418 bool started_ = false; 415 bool started_ = false;
419 bool ended_ = false;
420 416
421 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver); 417 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver);
422 }; 418 };
423 419
424 class TestCompositorAnimationObserver : public CompositorAnimationObserver { 420 class TestCompositorAnimationObserver : public CompositorAnimationObserver {
425 public: 421 public:
426 explicit TestCompositorAnimationObserver(ui::Compositor* compositor) 422 explicit TestCompositorAnimationObserver(ui::Compositor* compositor)
427 : compositor_(compositor), 423 : compositor_(compositor),
428 animation_step_count_(0), 424 animation_step_count_(0),
429 shutdown_(false) { 425 shutdown_(false) {
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); 1328 CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400)));
1333 std::unique_ptr<Layer> l2( 1329 std::unique_ptr<Layer> l2(
1334 CreateColorLayer(SK_ColorBLUE, gfx::Rect(10, 10, 350, 350))); 1330 CreateColorLayer(SK_ColorBLUE, gfx::Rect(10, 10, 350, 350)));
1335 l1->Add(l2.get()); 1331 l1->Add(l2.get());
1336 TestCompositorObserver observer; 1332 TestCompositorObserver observer;
1337 GetCompositor()->AddObserver(&observer); 1333 GetCompositor()->AddObserver(&observer);
1338 1334
1339 // Explicitly called DrawTree should cause the observers to be notified. 1335 // Explicitly called DrawTree should cause the observers to be notified.
1340 // NOTE: this call to DrawTree sets l1 to be the compositor's root layer. 1336 // NOTE: this call to DrawTree sets l1 to be the compositor's root layer.
1341 DrawTree(l1.get()); 1337 DrawTree(l1.get());
1342 EXPECT_TRUE(observer.notified()); 1338 EXPECT_TRUE(observer.started());
1343 1339
1344 // ScheduleDraw without any visible change should cause a commit. 1340 // ScheduleDraw without any visible change should cause a commit.
1345 observer.Reset(); 1341 observer.Reset();
1346 l1->ScheduleDraw(); 1342 l1->ScheduleDraw();
1347 WaitForCommit(); 1343 WaitForCommit();
1348 EXPECT_TRUE(observer.committed()); 1344 EXPECT_TRUE(observer.committed());
1349 1345
1350 // Moving, but not resizing, a layer should alert the observers. 1346 // Moving, but not resizing, a layer should alert the observers.
1351 observer.Reset(); 1347 observer.Reset();
1352 l2->SetBounds(gfx::Rect(0, 0, 350, 350)); 1348 l2->SetBounds(gfx::Rect(0, 0, 350, 350));
1353 WaitForSwap(); 1349 WaitForDraw();
1354 EXPECT_TRUE(observer.notified()); 1350 EXPECT_TRUE(observer.started());
1355 1351
1356 // So should resizing a layer. 1352 // So should resizing a layer.
1357 observer.Reset(); 1353 observer.Reset();
1358 l2->SetBounds(gfx::Rect(0, 0, 400, 400)); 1354 l2->SetBounds(gfx::Rect(0, 0, 400, 400));
1359 WaitForSwap(); 1355 WaitForDraw();
1360 EXPECT_TRUE(observer.notified()); 1356 EXPECT_TRUE(observer.started());
1361 1357
1362 // Opacity changes should alert the observers. 1358 // Opacity changes should alert the observers.
1363 observer.Reset(); 1359 observer.Reset();
1364 l2->SetOpacity(0.5f); 1360 l2->SetOpacity(0.5f);
1365 WaitForSwap(); 1361 WaitForDraw();
1366 EXPECT_TRUE(observer.notified()); 1362 EXPECT_TRUE(observer.started());
1367 1363
1368 // So should setting the opacity back. 1364 // So should setting the opacity back.
1369 observer.Reset(); 1365 observer.Reset();
1370 l2->SetOpacity(1.0f); 1366 l2->SetOpacity(1.0f);
1371 WaitForSwap(); 1367 WaitForDraw();
1372 EXPECT_TRUE(observer.notified()); 1368 EXPECT_TRUE(observer.started());
1373 1369
1374 // Setting the transform of a layer should alert the observers. 1370 // Setting the transform of a layer should alert the observers.
1375 observer.Reset(); 1371 observer.Reset();
1376 gfx::Transform transform; 1372 gfx::Transform transform;
1377 transform.Translate(200.0, 200.0); 1373 transform.Translate(200.0, 200.0);
1378 transform.Rotate(90.0); 1374 transform.Rotate(90.0);
1379 transform.Translate(-200.0, -200.0); 1375 transform.Translate(-200.0, -200.0);
1380 l2->SetTransform(transform); 1376 l2->SetTransform(transform);
1381 WaitForSwap(); 1377 WaitForDraw();
1382 EXPECT_TRUE(observer.notified()); 1378 EXPECT_TRUE(observer.started());
1383 1379
1384 GetCompositor()->RemoveObserver(&observer); 1380 GetCompositor()->RemoveObserver(&observer);
1385 1381
1386 // Opacity changes should no longer alert the removed observer. 1382 // Opacity changes should no longer alert the removed observer.
1387 observer.Reset(); 1383 observer.Reset();
1388 l2->SetOpacity(0.5f); 1384 l2->SetOpacity(0.5f);
1389 WaitForSwap(); 1385 WaitForDraw();
1390 1386
1391 EXPECT_FALSE(observer.notified()); 1387 EXPECT_FALSE(observer.started());
1392 } 1388 }
1393 1389
1394 // Checks that modifying the hierarchy correctly affects final composite. 1390 // Checks that modifying the hierarchy correctly affects final composite.
1395 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { 1391 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) {
1396 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); 1392 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50));
1397 1393
1398 // l0 1394 // l0
1399 // +-l11 1395 // +-l11
1400 // | +-l21 1396 // | +-l21
1401 // +-l12 1397 // +-l12
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 2226
2231 TEST_F(LayerWithRealCompositorTest, CompositorAnimationObserverTest) { 2227 TEST_F(LayerWithRealCompositorTest, CompositorAnimationObserverTest) {
2232 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); 2228 std::unique_ptr<Layer> root(CreateLayer(LAYER_TEXTURED));
2233 2229
2234 root->SetAnimator(LayerAnimator::CreateImplicitAnimator()); 2230 root->SetAnimator(LayerAnimator::CreateImplicitAnimator());
2235 2231
2236 TestCompositorAnimationObserver animation_observer(GetCompositor()); 2232 TestCompositorAnimationObserver animation_observer(GetCompositor());
2237 EXPECT_EQ(0u, animation_observer.animation_step_count()); 2233 EXPECT_EQ(0u, animation_observer.animation_step_count());
2238 2234
2239 root->SetOpacity(0.5f); 2235 root->SetOpacity(0.5f);
2240 WaitForSwap(); 2236 WaitForDraw();
2241 EXPECT_EQ(1u, animation_observer.animation_step_count()); 2237 EXPECT_EQ(1u, animation_observer.animation_step_count());
2242 2238
2243 EXPECT_FALSE(animation_observer.shutdown()); 2239 EXPECT_FALSE(animation_observer.shutdown());
2244 ResetCompositor(); 2240 ResetCompositor();
2245 EXPECT_TRUE(animation_observer.shutdown()); 2241 EXPECT_TRUE(animation_observer.shutdown());
2246 } 2242 }
2247 2243
2248 // A simple AnimationMetricsReporter class that remembers smoothness metric 2244 // A simple AnimationMetricsReporter class that remembers smoothness metric
2249 // when animation completes. 2245 // when animation completes.
2250 class TestMetricsReporter : public ui::AnimationMetricsReporter { 2246 class TestMetricsReporter : public ui::AnimationMetricsReporter {
(...skipping 25 matching lines...) Expand all
2276 LayerAnimator* animator = root->GetAnimator(); 2272 LayerAnimator* animator = root->GetAnimator();
2277 std::unique_ptr<ui::LayerAnimationElement> animation_element = 2273 std::unique_ptr<ui::LayerAnimationElement> animation_element =
2278 ui::LayerAnimationElement::CreateColorElement( 2274 ui::LayerAnimationElement::CreateColorElement(
2279 SK_ColorRED, base::TimeDelta::FromMilliseconds(100)); 2275 SK_ColorRED, base::TimeDelta::FromMilliseconds(100));
2280 ui::LayerAnimationSequence* animation_sequence = 2276 ui::LayerAnimationSequence* animation_sequence =
2281 new ui::LayerAnimationSequence(std::move(animation_element)); 2277 new ui::LayerAnimationSequence(std::move(animation_element));
2282 TestMetricsReporter reporter; 2278 TestMetricsReporter reporter;
2283 animation_sequence->SetAnimationMetricsReporter(&reporter); 2279 animation_sequence->SetAnimationMetricsReporter(&reporter);
2284 animator->StartAnimation(animation_sequence); 2280 animator->StartAnimation(animation_sequence);
2285 while (!reporter.report_called()) 2281 while (!reporter.report_called())
2286 WaitForSwap(); 2282 WaitForDraw();
2287 ResetCompositor(); 2283 ResetCompositor();
2288 // Even though most of the time 100% smooth animations are expected, on the 2284 // Even though most of the time 100% smooth animations are expected, on the
2289 // test bots this cannot be guaranteed. Therefore simply check that some 2285 // test bots this cannot be guaranteed. Therefore simply check that some
2290 // value was reported. 2286 // value was reported.
2291 EXPECT_GT(reporter.value(), 0); 2287 EXPECT_GT(reporter.value(), 0);
2292 } 2288 }
2293 2289
2294 TEST(LayerDebugInfoTest, LayerNameDoesNotClobber) { 2290 TEST(LayerDebugInfoTest, LayerNameDoesNotClobber) {
2295 Layer layer(LAYER_NOT_DRAWN); 2291 Layer layer(LAYER_NOT_DRAWN);
2296 layer.set_name("foo"); 2292 layer.set_name("foo");
2297 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info = 2293 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info =
2298 layer.TakeDebugInfo(nullptr); 2294 layer.TakeDebugInfo(nullptr);
2299 std::string trace_format("bar,"); 2295 std::string trace_format("bar,");
2300 debug_info->AppendAsTraceFormat(&trace_format); 2296 debug_info->AppendAsTraceFormat(&trace_format);
2301 std::string expected("bar,{\"layer_name\":\"foo\"}"); 2297 std::string expected("bar,{\"layer_name\":\"foo\"}");
2302 EXPECT_EQ(expected, trace_format); 2298 EXPECT_EQ(expected, trace_format);
2303 } 2299 }
2304 2300
2305 } // namespace ui 2301 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/compositor_unittest.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