| 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/cancelable_callback.h" | |
| 8 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 9 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 11 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 13 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 14 #include "base/run_loop.h" | |
| 15 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 17 #include "cc/layers/layer.h" | 15 #include "cc/layers/layer.h" |
| 18 #include "cc/output/delegated_frame_data.h" | 16 #include "cc/output/delegated_frame_data.h" |
| 19 #include "cc/test/pixel_test_utils.h" | 17 #include "cc/test/pixel_test_utils.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/compositor/compositor_observer.h" | 19 #include "ui/compositor/compositor_observer.h" |
| 22 #include "ui/compositor/compositor_setup.h" | 20 #include "ui/compositor/compositor_setup.h" |
| 23 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
| 24 #include "ui/compositor/layer_animation_sequence.h" | 22 #include "ui/compositor/layer_animation_sequence.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 75 } |
| 78 | 76 |
| 79 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { | 77 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { |
| 80 return base::Closure(); | 78 return base::Closure(); |
| 81 } | 79 } |
| 82 | 80 |
| 83 private: | 81 private: |
| 84 SkColor color_; | 82 SkColor color_; |
| 85 }; | 83 }; |
| 86 | 84 |
| 87 const int kDrawWaitTimeOutMs = 1000; | |
| 88 | |
| 89 class DrawWaiter : public ui::CompositorObserver { | |
| 90 public: | |
| 91 DrawWaiter() : did_draw_(false) {} | |
| 92 | |
| 93 bool Wait(ui::Compositor* compositor) { | |
| 94 did_draw_ = false; | |
| 95 compositor->AddObserver(this); | |
| 96 wait_run_loop_.reset(new base::RunLoop()); | |
| 97 base::CancelableClosure timeout( | |
| 98 base::Bind(&DrawWaiter::TimedOutWhileWaiting, | |
| 99 base::Unretained(this))); | |
| 100 MessageLoop::current()->PostDelayedTask( | |
| 101 FROM_HERE, timeout.callback(), | |
| 102 base::TimeDelta::FromMilliseconds(kDrawWaitTimeOutMs)); | |
| 103 wait_run_loop_->Run(); | |
| 104 compositor->RemoveObserver(this); | |
| 105 return did_draw_; | |
| 106 } | |
| 107 | |
| 108 private: | |
| 109 void TimedOutWhileWaiting() { | |
| 110 LOG(ERROR) << "Timed out waiting for draw."; | |
| 111 wait_run_loop_->Quit(); | |
| 112 } | |
| 113 | |
| 114 // ui::CompositorObserver implementation. | |
| 115 virtual void OnCompositingDidCommit(Compositor* compositor) OVERRIDE {} | |
| 116 virtual void OnCompositingStarted(Compositor* compositor, | |
| 117 base::TimeTicks start_time) OVERRIDE {} | |
| 118 virtual void OnCompositingEnded(Compositor* compositor) OVERRIDE { | |
| 119 did_draw_ = true; | |
| 120 wait_run_loop_->Quit(); | |
| 121 } | |
| 122 virtual void OnCompositingAborted(Compositor* compositor) OVERRIDE {} | |
| 123 virtual void OnCompositingLockStateChanged(Compositor* compositor) OVERRIDE {} | |
| 124 virtual void OnUpdateVSyncParameters(Compositor* compositor, | |
| 125 base::TimeTicks timebase, | |
| 126 base::TimeDelta interval) OVERRIDE {} | |
| 127 | |
| 128 scoped_ptr<base::RunLoop> wait_run_loop_; | |
| 129 bool did_draw_; | |
| 130 | |
| 131 DISALLOW_COPY_AND_ASSIGN(DrawWaiter); | |
| 132 }; | |
| 133 | |
| 134 class LayerWithRealCompositorTest : public testing::Test { | 85 class LayerWithRealCompositorTest : public testing::Test { |
| 135 public: | 86 public: |
| 136 LayerWithRealCompositorTest() { | 87 LayerWithRealCompositorTest() { |
| 137 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { | 88 if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) { |
| 138 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); | 89 test_data_directory_ = test_data_directory_.AppendASCII("compositor"); |
| 139 } else { | 90 } else { |
| 140 LOG(ERROR) << "Could not open test data directory."; | 91 LOG(ERROR) << "Could not open test data directory."; |
| 141 } | 92 } |
| 142 } | 93 } |
| 143 virtual ~LayerWithRealCompositorTest() {} | 94 virtual ~LayerWithRealCompositorTest() {} |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 GetCompositor()->ScheduleDraw(); | 129 GetCompositor()->ScheduleDraw(); |
| 179 WaitForDraw(); | 130 WaitForDraw(); |
| 180 } | 131 } |
| 181 | 132 |
| 182 bool ReadPixels(SkBitmap* bitmap) { | 133 bool ReadPixels(SkBitmap* bitmap) { |
| 183 return GetCompositor()->ReadPixels(bitmap, | 134 return GetCompositor()->ReadPixels(bitmap, |
| 184 gfx::Rect(GetCompositor()->size())); | 135 gfx::Rect(GetCompositor()->size())); |
| 185 } | 136 } |
| 186 | 137 |
| 187 bool WaitForDraw() { | 138 bool WaitForDraw() { |
| 188 DrawWaiter draw_waiter; | 139 return ui::DrawWaiterForTest::Wait(GetCompositor()); |
| 189 return draw_waiter.Wait(GetCompositor()); | |
| 190 } | 140 } |
| 191 | 141 |
| 192 // Invalidates the entire contents of the layer. | 142 // Invalidates the entire contents of the layer. |
| 193 void SchedulePaintForLayer(Layer* layer) { | 143 void SchedulePaintForLayer(Layer* layer) { |
| 194 layer->SchedulePaint( | 144 layer->SchedulePaint( |
| 195 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); | 145 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); |
| 196 } | 146 } |
| 197 | 147 |
| 198 const base::FilePath& test_data_directory() const { | 148 const base::FilePath& test_data_directory() const { |
| 199 return test_data_directory_; | 149 return test_data_directory_; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); | 421 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); |
| 472 } | 422 } |
| 473 | 423 |
| 474 // Invokes DrawTree on the compositor. | 424 // Invokes DrawTree on the compositor. |
| 475 void Draw() { | 425 void Draw() { |
| 476 compositor()->ScheduleDraw(); | 426 compositor()->ScheduleDraw(); |
| 477 WaitForDraw(); | 427 WaitForDraw(); |
| 478 } | 428 } |
| 479 | 429 |
| 480 bool WaitForDraw() { | 430 bool WaitForDraw() { |
| 481 DrawWaiter draw_waiter; | 431 return DrawWaiterForTest::Wait(compositor()); |
| 482 return draw_waiter.Wait(compositor()); | |
| 483 } | 432 } |
| 484 | 433 |
| 485 // CompositorDelegate overrides. | 434 // CompositorDelegate overrides. |
| 486 virtual void ScheduleDraw() OVERRIDE { | 435 virtual void ScheduleDraw() OVERRIDE { |
| 487 DCHECK(!ui::Compositor::WasInitializedWithThread()); | 436 DCHECK(!ui::Compositor::WasInitializedWithThread()); |
| 488 if (compositor_) { | 437 if (compositor_) { |
| 489 MessageLoop::current()->PostTask( | 438 MessageLoop::current()->PostTask( |
| 490 FROM_HERE, | 439 FROM_HERE, |
| 491 base::Bind(&Compositor::Draw, compositor_->AsWeakPtr(), false)); | 440 base::Bind(&Compositor::Draw, compositor_->AsWeakPtr(), false)); |
| 492 } | 441 } |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 l1->SetOpacity(0.5f); | 1373 l1->SetOpacity(0.5f); |
| 1425 | 1374 |
| 1426 // Change l1's cc::Layer. | 1375 // Change l1's cc::Layer. |
| 1427 l1->SwitchCCLayerForTest(); | 1376 l1->SwitchCCLayerForTest(); |
| 1428 | 1377 |
| 1429 // Ensure that the opacity animation completed. | 1378 // Ensure that the opacity animation completed. |
| 1430 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); | 1379 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); |
| 1431 } | 1380 } |
| 1432 | 1381 |
| 1433 } // namespace ui | 1382 } // namespace ui |
| OLD | NEW |