Fix build break
[chromium-blink-merge.git] / ui / compositor / test / test_compositor_host_linux.cc
blob789ac1995b0920975dc5832fee3dfbc5bd635973
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
3 // found in the LICENSE file.
5 #include "ui/compositor/test/test_compositor_host.h"
7 #include <X11/Xlib.h>
9 #include "base/basictypes.h"
10 #include "base/bind.h"
11 #include "base/compiler_specific.h"
12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/message_loop.h"
16 #include "ui/base/x/x11_util.h"
17 #include "ui/compositor/compositor.h"
18 #include "ui/gfx/rect.h"
20 namespace ui {
22 class TestCompositorHostLinux : public TestCompositorHost,
23 public CompositorDelegate {
24 public:
25 TestCompositorHostLinux(const gfx::Rect& bounds);
26 virtual ~TestCompositorHostLinux();
28 private:
29 // Overridden from TestCompositorHost:
30 virtual void Show() OVERRIDE;
31 virtual ui::Compositor* GetCompositor() OVERRIDE;
33 // Overridden from CompositorDelegate:
34 virtual void ScheduleDraw() OVERRIDE;
36 void Draw();
38 gfx::Rect bounds_;
40 scoped_ptr<ui::Compositor> compositor_;
42 XID window_;
44 base::WeakPtrFactory<TestCompositorHostLinux> method_factory_;
46 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostLinux);
49 TestCompositorHostLinux::TestCompositorHostLinux(const gfx::Rect& bounds)
50 : bounds_(bounds),
51 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
54 TestCompositorHostLinux::~TestCompositorHostLinux() {
57 void TestCompositorHostLinux::Show() {
58 Display* display = GetXDisplay();
59 XSetWindowAttributes swa;
60 swa.event_mask = StructureNotifyMask | ExposureMask;
61 swa.override_redirect = True;
62 window_ = XCreateWindow(
63 display,
64 RootWindow(display, DefaultScreen(display)), // parent
65 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(),
66 0, // border width
67 CopyFromParent, // depth
68 InputOutput,
69 CopyFromParent, // visual
70 CWEventMask | CWOverrideRedirect, &swa);
71 XMapWindow(display, window_);
73 while (1) {
74 XEvent event;
75 XNextEvent(display, &event);
76 if (event.type == MapNotify && event.xmap.window == window_)
77 break;
79 compositor_.reset(new ui::Compositor(this, window_));
80 compositor_->SetScaleAndSize(1.0f, bounds_.size());
83 ui::Compositor* TestCompositorHostLinux::GetCompositor() {
84 return compositor_.get();
87 void TestCompositorHostLinux::ScheduleDraw() {
88 DCHECK(!ui::Compositor::WasInitializedWithThread());
89 if (!method_factory_.HasWeakPtrs()) {
90 MessageLoopForUI::current()->PostTask(
91 FROM_HERE,
92 base::Bind(&TestCompositorHostLinux::Draw,
93 method_factory_.GetWeakPtr()));
97 void TestCompositorHostLinux::Draw() {
98 if (compositor_.get())
99 compositor_->Draw();
102 // static
103 TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) {
104 return new TestCompositorHostLinux(bounds);
107 } // namespace ui