| Index: ui/compositor/layer_unittest.cc
|
| diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc
|
| index 3ca1b3e62b58b9557d00888d2601da87c0d6c635..30f376a427b7ef423698bb4423d5d0355583d037 100644
|
| --- a/ui/compositor/layer_unittest.cc
|
| +++ b/ui/compositor/layer_unittest.cc
|
| @@ -4,14 +4,12 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/bind.h"
|
| -#include "base/cancelable_callback.h"
|
| #include "base/compiler_specific.h"
|
| #include "base/file_util.h"
|
| #include "base/files/file_path.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/message_loop.h"
|
| #include "base/path_service.h"
|
| -#include "base/run_loop.h"
|
| #include "base/string_util.h"
|
| #include "base/stringprintf.h"
|
| #include "cc/layers/layer.h"
|
| @@ -84,130 +82,6 @@ class ColoredLayer : public Layer, public LayerDelegate {
|
| SkColor color_;
|
| };
|
|
|
| -const int kDrawWaitTimeOutMs = 1000;
|
| -
|
| -class DrawWaiter : public ui::CompositorObserver {
|
| - public:
|
| - DrawWaiter() : did_draw_(false) {}
|
| -
|
| - bool Wait(ui::Compositor* compositor) {
|
| - did_draw_ = false;
|
| - compositor->AddObserver(this);
|
| - wait_run_loop_.reset(new base::RunLoop());
|
| - base::CancelableClosure timeout(
|
| - base::Bind(&DrawWaiter::TimedOutWhileWaiting,
|
| - base::Unretained(this)));
|
| - MessageLoop::current()->PostDelayedTask(
|
| - FROM_HERE, timeout.callback(),
|
| - base::TimeDelta::FromMilliseconds(kDrawWaitTimeOutMs));
|
| - wait_run_loop_->Run();
|
| - compositor->RemoveObserver(this);
|
| - return did_draw_;
|
| - }
|
| -
|
| - private:
|
| - void TimedOutWhileWaiting() {
|
| - LOG(ERROR) << "Timed out waiting for draw.";
|
| - wait_run_loop_->Quit();
|
| - }
|
| -
|
| - // ui::CompositorObserver implementation.
|
| - virtual void OnCompositingDidCommit(Compositor* compositor) OVERRIDE {}
|
| - virtual void OnCompositingStarted(Compositor* compositor,
|
| - base::TimeTicks start_time) OVERRIDE {}
|
| - virtual void OnCompositingEnded(Compositor* compositor) OVERRIDE {
|
| - did_draw_ = true;
|
| - wait_run_loop_->Quit();
|
| - }
|
| - virtual void OnCompositingAborted(Compositor* compositor) OVERRIDE {}
|
| - virtual void OnCompositingLockStateChanged(Compositor* compositor) OVERRIDE {}
|
| - virtual void OnUpdateVSyncParameters(Compositor* compositor,
|
| - base::TimeTicks timebase,
|
| - base::TimeDelta interval) OVERRIDE {}
|
| -
|
| - scoped_ptr<base::RunLoop> wait_run_loop_;
|
| - bool did_draw_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(DrawWaiter);
|
| -};
|
| -
|
| -class LayerWithRealCompositorTest : public testing::Test {
|
| - public:
|
| - LayerWithRealCompositorTest() {
|
| - if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) {
|
| - test_data_directory_ = test_data_directory_.AppendASCII("compositor");
|
| - } else {
|
| - LOG(ERROR) << "Could not open test data directory.";
|
| - }
|
| - }
|
| - virtual ~LayerWithRealCompositorTest() {}
|
| -
|
| - // Overridden from testing::Test:
|
| - virtual void SetUp() OVERRIDE {
|
| - DisableTestCompositor();
|
| - const gfx::Rect host_bounds(10, 10, 500, 500);
|
| - window_.reset(TestCompositorHost::Create(host_bounds));
|
| - window_->Show();
|
| - }
|
| -
|
| - virtual void TearDown() OVERRIDE {
|
| - }
|
| -
|
| - Compositor* GetCompositor() {
|
| - return window_->GetCompositor();
|
| - }
|
| -
|
| - Layer* CreateLayer(LayerType type) {
|
| - return new Layer(type);
|
| - }
|
| -
|
| - Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
|
| - Layer* layer = new ColoredLayer(color);
|
| - layer->SetBounds(bounds);
|
| - return layer;
|
| - }
|
| -
|
| - Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
|
| - Layer* layer = CreateLayer(LAYER_NOT_DRAWN);
|
| - layer->SetBounds(bounds);
|
| - return layer;
|
| - }
|
| -
|
| - void DrawTree(Layer* root) {
|
| - GetCompositor()->SetRootLayer(root);
|
| - GetCompositor()->ScheduleDraw();
|
| - WaitForDraw();
|
| - }
|
| -
|
| - bool ReadPixels(SkBitmap* bitmap) {
|
| - return GetCompositor()->ReadPixels(bitmap,
|
| - gfx::Rect(GetCompositor()->size()));
|
| - }
|
| -
|
| - bool WaitForDraw() {
|
| - DrawWaiter draw_waiter;
|
| - return draw_waiter.Wait(GetCompositor());
|
| - }
|
| -
|
| - // Invalidates the entire contents of the layer.
|
| - void SchedulePaintForLayer(Layer* layer) {
|
| - layer->SchedulePaint(
|
| - gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
|
| - }
|
| -
|
| - const base::FilePath& test_data_directory() const {
|
| - return test_data_directory_;
|
| - }
|
| -
|
| - private:
|
| - scoped_ptr<TestCompositorHost> window_;
|
| -
|
| - // The root directory for test files.
|
| - base::FilePath test_data_directory_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest);
|
| -};
|
| -
|
| // LayerDelegate that paints colors to the layer.
|
| class TestLayerDelegate : public LayerDelegate {
|
| public:
|
| @@ -362,6 +236,82 @@ class TestCompositorObserver : public CompositorObserver {
|
|
|
| } // namespace
|
|
|
| +class LayerWithRealCompositorTest : public testing::Test {
|
| + public:
|
| + LayerWithRealCompositorTest() {
|
| + if (PathService::Get(gfx::DIR_TEST_DATA, &test_data_directory_)) {
|
| + test_data_directory_ = test_data_directory_.AppendASCII("compositor");
|
| + } else {
|
| + LOG(ERROR) << "Could not open test data directory.";
|
| + }
|
| + }
|
| + virtual ~LayerWithRealCompositorTest() {}
|
| +
|
| + // Overridden from testing::Test:
|
| + virtual void SetUp() OVERRIDE {
|
| + DisableTestCompositor();
|
| + const gfx::Rect host_bounds(10, 10, 500, 500);
|
| + window_.reset(TestCompositorHost::Create(host_bounds));
|
| + window_->Show();
|
| + }
|
| +
|
| + virtual void TearDown() OVERRIDE {
|
| + }
|
| +
|
| + Compositor* GetCompositor() {
|
| + return window_->GetCompositor();
|
| + }
|
| +
|
| + Layer* CreateLayer(LayerType type) {
|
| + return new Layer(type);
|
| + }
|
| +
|
| + Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
|
| + Layer* layer = new ColoredLayer(color);
|
| + layer->SetBounds(bounds);
|
| + return layer;
|
| + }
|
| +
|
| + Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
|
| + Layer* layer = CreateLayer(LAYER_NOT_DRAWN);
|
| + layer->SetBounds(bounds);
|
| + return layer;
|
| + }
|
| +
|
| + void DrawTree(Layer* root) {
|
| + GetCompositor()->SetRootLayer(root);
|
| + GetCompositor()->ScheduleDraw();
|
| + WaitForDraw();
|
| + }
|
| +
|
| + bool WaitForDraw() {
|
| + return GetCompositor()->WaitForDraw();
|
| + }
|
| +
|
| + bool ReadPixels(SkBitmap* bitmap) {
|
| + return GetCompositor()->ReadPixels(bitmap,
|
| + gfx::Rect(GetCompositor()->size()));
|
| + }
|
| +
|
| + // Invalidates the entire contents of the layer.
|
| + void SchedulePaintForLayer(Layer* layer) {
|
| + layer->SchedulePaint(
|
| + gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
|
| + }
|
| +
|
| + const base::FilePath& test_data_directory() const {
|
| + return test_data_directory_;
|
| + }
|
| +
|
| + private:
|
| + scoped_ptr<TestCompositorHost> window_;
|
| +
|
| + // The root directory for test files.
|
| + base::FilePath test_data_directory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest);
|
| +};
|
| +
|
| #if defined(OS_WIN)
|
| // These are disabled on windows as they don't run correctly on the buildbot.
|
| // Reenable once we move to the real compositor.
|
| @@ -478,8 +428,7 @@ class LayerWithDelegateTest : public testing::Test, public CompositorDelegate {
|
| }
|
|
|
| bool WaitForDraw() {
|
| - DrawWaiter draw_waiter;
|
| - return draw_waiter.Wait(compositor());
|
| + return compositor()->WaitForDraw();
|
| }
|
|
|
| // CompositorDelegate overrides.
|
|
|