OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/compositor/test/test_compositor_host.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/message_loop.h" |
| 14 #include "ui/compositor/compositor.h" |
| 15 #include "ui/gfx/rect.h" |
| 16 |
| 17 namespace ui { |
| 18 |
| 19 class TestCompositorHostOzone : public TestCompositorHost, |
| 20 public CompositorDelegate { |
| 21 public: |
| 22 TestCompositorHostOzone(const gfx::Rect& bounds); |
| 23 virtual ~TestCompositorHostOzone(); |
| 24 |
| 25 private: |
| 26 // Overridden from TestCompositorHost: |
| 27 virtual void Show() OVERRIDE; |
| 28 virtual ui::Compositor* GetCompositor() OVERRIDE; |
| 29 |
| 30 // Overridden from CompositorDelegate: |
| 31 virtual void ScheduleDraw() OVERRIDE; |
| 32 |
| 33 void Draw(); |
| 34 |
| 35 gfx::Rect bounds_; |
| 36 |
| 37 scoped_ptr<ui::Compositor> compositor_; |
| 38 |
| 39 base::WeakPtrFactory<TestCompositorHostOzone> method_factory_; |
| 40 |
| 41 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostOzone); |
| 42 }; |
| 43 |
| 44 TestCompositorHostOzone::TestCompositorHostOzone(const gfx::Rect& bounds) |
| 45 : bounds_(bounds), method_factory_(this) {} |
| 46 |
| 47 TestCompositorHostOzone::~TestCompositorHostOzone() {} |
| 48 |
| 49 void TestCompositorHostOzone::Show() { |
| 50 // Ozone should rightly have a backing native framebuffer |
| 51 // An in-memory array draw into by OSMesa is a reasonble |
| 52 // fascimile of a dumb framebuffer at present. |
| 53 // GLSurface will allocate the array so long as it is provided |
| 54 // with a non-0 widget. |
| 55 // TODO(rjkroege): Use a "real" ozone widget when it is |
| 56 // available: http://crbug.com/255128 |
| 57 compositor_.reset(new ui::Compositor(this, 1)); |
| 58 compositor_->SetScaleAndSize(1.0f, bounds_.size()); |
| 59 } |
| 60 |
| 61 ui::Compositor* TestCompositorHostOzone::GetCompositor() { |
| 62 return compositor_.get(); |
| 63 } |
| 64 |
| 65 void TestCompositorHostOzone::ScheduleDraw() { |
| 66 DCHECK(!ui::Compositor::WasInitializedWithThread()); |
| 67 if (!method_factory_.HasWeakPtrs()) { |
| 68 base::MessageLoopForUI::current()->PostTask( |
| 69 FROM_HERE, |
| 70 base::Bind(&TestCompositorHostOzone::Draw, |
| 71 method_factory_.GetWeakPtr())); |
| 72 } |
| 73 } |
| 74 |
| 75 void TestCompositorHostOzone::Draw() { |
| 76 if (compositor_.get()) |
| 77 compositor_->Draw(); |
| 78 } |
| 79 |
| 80 // static |
| 81 TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) { |
| 82 return new TestCompositorHostOzone(bounds); |
| 83 } |
| 84 |
| 85 } // namespace ui |
OLD | NEW |