summaryrefslogtreecommitdiffstats
path: root/ui/gfx/compositor/test_compositor_host_win.cc
blob: 226ea8c0bbcafc351021a797a0ddbca036e58ebc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/gfx/compositor/test_compositor_host.h"

#include "base/compiler_specific.h"
#include "ui/base/win/window_impl.h"
#include "ui/gfx/compositor/compositor.h"

namespace ui {

class TestCompositorHostWin : public TestCompositorHost,
                              public WindowImpl,
                              public CompositorDelegate {
 public:
  TestCompositorHostWin(const gfx::Rect& bounds) {
    Init(NULL, bounds);
    compositor_ = ui::Compositor::Create(this, hwnd(), GetSize());
  }

  virtual ~TestCompositorHostWin() {
    DestroyWindow(hwnd());
  }

  // Overridden from MessageLoop::Dispatcher:
  virtual bool Dispatch(const MSG& msg) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    return true;
  }

  // Overridden from TestCompositorHost:
  virtual void Show() OVERRIDE {
    ShowWindow(hwnd(), SW_SHOWNORMAL);
  }
  virtual ui::Compositor* GetCompositor() OVERRIDE {
    return compositor_;
  }

  // Overridden from CompositorDelegate:
  virtual void ScheduleDraw() OVERRIDE {
    RECT rect;
    ::GetClientRect(hwnd(), &rect);
    InvalidateRect(hwnd(), &rect, FALSE);
  }

 private:
  BEGIN_MSG_MAP_EX(TestCompositorHostWin)
    MSG_WM_PAINT(OnPaint)
  END_MSG_MAP()

  void OnPaint(HDC dc) {
    compositor_->Draw(false);
    ValidateRect(hwnd(), NULL);
  }

  gfx::Size GetSize() {
    RECT r;
    GetClientRect(hwnd(), &r);
    return gfx::Rect(r).size();
  }

  scoped_refptr<ui::Compositor> compositor_;

  DISALLOW_COPY_AND_ASSIGN(TestCompositorHostWin);
};

TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) {
  return new TestCompositorHostWin(bounds);
}

}  // namespace ui