OLD | NEW |
---|---|
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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 ui::ContextFactory* context_factory = | 100 ui::ContextFactory* context_factory = |
101 InitializeContextFactoryForTests(enable_pixel_output); | 101 InitializeContextFactoryForTests(enable_pixel_output); |
102 | 102 |
103 const gfx::Rect host_bounds(10, 10, 500, 500); | 103 const gfx::Rect host_bounds(10, 10, 500, 500); |
104 compositor_host_.reset( | 104 compositor_host_.reset( |
105 TestCompositorHost::Create(host_bounds, context_factory)); | 105 TestCompositorHost::Create(host_bounds, context_factory)); |
106 compositor_host_->Show(); | 106 compositor_host_->Show(); |
107 } | 107 } |
108 | 108 |
109 void TearDown() override { | 109 void TearDown() override { |
110 compositor_host_.reset(); | 110 ResetCompositor(); |
111 TerminateContextFactoryForTests(); | 111 TerminateContextFactoryForTests(); |
112 } | 112 } |
113 | 113 |
114 Compositor* GetCompositor() { return compositor_host_->GetCompositor(); } | 114 Compositor* GetCompositor() { return compositor_host_->GetCompositor(); } |
115 | 115 |
116 void ResetCompositor() { | |
117 compositor_host_.reset(); | |
118 } | |
119 | |
116 Layer* CreateLayer(LayerType type) { | 120 Layer* CreateLayer(LayerType type) { |
117 return new Layer(type); | 121 return new Layer(type); |
118 } | 122 } |
119 | 123 |
120 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { | 124 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { |
121 Layer* layer = new ColoredLayer(color); | 125 Layer* layer = new ColoredLayer(color); |
122 layer->SetBounds(bounds); | 126 layer->SetBounds(bounds); |
123 return layer; | 127 return layer; |
124 } | 128 } |
125 | 129 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 void OnCompositingShuttingDown(Compositor* compositor) override {} | 351 void OnCompositingShuttingDown(Compositor* compositor) override {} |
348 | 352 |
349 bool committed_; | 353 bool committed_; |
350 bool started_; | 354 bool started_; |
351 bool ended_; | 355 bool ended_; |
352 bool aborted_; | 356 bool aborted_; |
353 | 357 |
354 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver); | 358 DISALLOW_COPY_AND_ASSIGN(TestCompositorObserver); |
355 }; | 359 }; |
356 | 360 |
361 class TestCompositorAnimationObserver : public CompositorAnimationObserver { | |
362 public: | |
363 explicit TestCompositorAnimationObserver(ui::Compositor* compositor) | |
364 : compositor_(compositor), | |
365 animation_step_count_(0), | |
366 shutdown_(false) { | |
367 DCHECK(compositor_); | |
368 compositor_->AddAnimationObserver(this); | |
369 } | |
370 | |
371 ~TestCompositorAnimationObserver() override { | |
372 if (compositor_) | |
373 compositor_->RemoveAnimationObserver(this); | |
374 } | |
375 | |
376 size_t animation_step_count() const { return animation_step_count_; } | |
377 bool shutdown() const { return shutdown_; } | |
378 | |
379 private: | |
380 void OnAnimationStep(base::TimeTicks timestamp) override { | |
381 ++animation_step_count_; | |
382 } | |
383 | |
384 void OnCompositingShuttingDown(Compositor* compositor) override { | |
385 if (compositor_) | |
danakj
2015/06/02 18:24:15
how can it be null?
| |
386 compositor_->RemoveAnimationObserver(this); | |
387 compositor_ = nullptr; | |
388 shutdown_ = true; | |
389 } | |
390 | |
391 ui::Compositor* compositor_; | |
392 size_t animation_step_count_; | |
393 bool shutdown_; | |
394 | |
395 DISALLOW_COPY_AND_ASSIGN(TestCompositorAnimationObserver); | |
396 }; | |
397 | |
357 } // namespace | 398 } // namespace |
358 | 399 |
359 TEST_F(LayerWithRealCompositorTest, Draw) { | 400 TEST_F(LayerWithRealCompositorTest, Draw) { |
360 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, | 401 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, |
361 gfx::Rect(20, 20, 50, 50))); | 402 gfx::Rect(20, 20, 50, 50))); |
362 DrawTree(layer.get()); | 403 DrawTree(layer.get()); |
363 } | 404 } |
364 | 405 |
365 // Create this hierarchy: | 406 // Create this hierarchy: |
366 // L1 - red | 407 // L1 - red |
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1803 new cc::DelegatedFrameProvider(resource_collection.get(), | 1844 new cc::DelegatedFrameProvider(resource_collection.get(), |
1804 MakeFrameData(gfx::Size(10, 10)))); | 1845 MakeFrameData(gfx::Size(10, 10)))); |
1805 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); | 1846 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); |
1806 | 1847 |
1807 EXPECT_FALSE(delegate.delegated_frame_damage_called()); | 1848 EXPECT_FALSE(delegate.delegated_frame_damage_called()); |
1808 layer->OnDelegatedFrameDamage(damage_rect); | 1849 layer->OnDelegatedFrameDamage(damage_rect); |
1809 EXPECT_TRUE(delegate.delegated_frame_damage_called()); | 1850 EXPECT_TRUE(delegate.delegated_frame_damage_called()); |
1810 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); | 1851 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
1811 } | 1852 } |
1812 | 1853 |
1854 TEST_F(LayerWithRealCompositorTest, CompositorAnimationObserverTest) { | |
1855 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | |
1856 | |
1857 root->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | |
1858 | |
1859 TestCompositorAnimationObserver animation_observer(GetCompositor()); | |
1860 EXPECT_EQ(0u, animation_observer.animation_step_count()); | |
1861 | |
1862 root->SetOpacity(0.5f); | |
1863 WaitForSwap(); | |
1864 EXPECT_EQ(1u, animation_observer.animation_step_count()); | |
1865 | |
1866 EXPECT_EQ(false, animation_observer.shutdown()); | |
1867 ResetCompositor(); | |
1868 EXPECT_EQ(true, animation_observer.shutdown()); | |
1869 } | |
1870 | |
1813 } // namespace ui | 1871 } // namespace ui |
OLD | NEW |