| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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/gfx/compositor/test_compositor_host.h" | |
| 6 | |
| 7 #include "base/compiler_specific.h" | |
| 8 #include "ui/base/win/window_impl.h" | |
| 9 #include "ui/gfx/compositor/compositor.h" | |
| 10 | |
| 11 namespace ui { | |
| 12 | |
| 13 class TestCompositorHostWin : public TestCompositorHost, | |
| 14 public WindowImpl, | |
| 15 public CompositorDelegate { | |
| 16 public: | |
| 17 TestCompositorHostWin(const gfx::Rect& bounds) { | |
| 18 Init(NULL, bounds); | |
| 19 compositor_ = ui::Compositor::Create(this, hwnd(), GetSize()); | |
| 20 } | |
| 21 | |
| 22 virtual ~TestCompositorHostWin() { | |
| 23 DestroyWindow(hwnd()); | |
| 24 } | |
| 25 | |
| 26 // Overridden from MessageLoop::Dispatcher: | |
| 27 virtual bool Dispatch(const MSG& msg) { | |
| 28 TranslateMessage(&msg); | |
| 29 DispatchMessage(&msg); | |
| 30 return true; | |
| 31 } | |
| 32 | |
| 33 // Overridden from TestCompositorHost: | |
| 34 virtual void Show() OVERRIDE { | |
| 35 ShowWindow(hwnd(), SW_SHOWNORMAL); | |
| 36 } | |
| 37 virtual ui::Compositor* GetCompositor() OVERRIDE { | |
| 38 return compositor_; | |
| 39 } | |
| 40 | |
| 41 // Overridden from CompositorDelegate: | |
| 42 virtual void ScheduleDraw() OVERRIDE { | |
| 43 RECT rect; | |
| 44 ::GetClientRect(hwnd(), &rect); | |
| 45 InvalidateRect(hwnd(), &rect, FALSE); | |
| 46 } | |
| 47 | |
| 48 private: | |
| 49 BEGIN_MSG_MAP_EX(TestCompositorHostWin) | |
| 50 MSG_WM_PAINT(OnPaint) | |
| 51 END_MSG_MAP() | |
| 52 | |
| 53 void OnPaint(HDC dc) { | |
| 54 compositor_->Draw(false); | |
| 55 ValidateRect(hwnd(), NULL); | |
| 56 } | |
| 57 | |
| 58 gfx::Size GetSize() { | |
| 59 RECT r; | |
| 60 GetClientRect(hwnd(), &r); | |
| 61 return gfx::Rect(r).size(); | |
| 62 } | |
| 63 | |
| 64 scoped_refptr<ui::Compositor> compositor_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostWin); | |
| 67 }; | |
| 68 | |
| 69 TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) { | |
| 70 return new TestCompositorHostWin(bounds); | |
| 71 } | |
| 72 | |
| 73 } // namespace ui | |
| OLD | NEW |