Correct comment added on r267371
[chromium-blink-merge.git] / ui / compositor / test / test_compositor_host_x11.cc
blob4215e276d619e84eef3f25da533dbb65376150ba
1 // Copyright 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.
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/message_loop.h"
16 #include "ui/compositor/compositor.h"
17 #include "ui/gfx/rect.h"
18 #include "ui/gfx/x/x11_types.h"
20 namespace ui {
22 class TestCompositorHostX11 : public TestCompositorHost {
23 public:
24 TestCompositorHostX11(const gfx::Rect& bounds);
25 virtual ~TestCompositorHostX11();
27 private:
28 // Overridden from TestCompositorHost:
29 virtual void Show() OVERRIDE;
30 virtual ui::Compositor* GetCompositor() OVERRIDE;
32 void Draw();
34 gfx::Rect bounds_;
36 scoped_ptr<ui::Compositor> compositor_;
38 XID window_;
40 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostX11);
43 TestCompositorHostX11::TestCompositorHostX11(const gfx::Rect& bounds)
44 : bounds_(bounds) {
47 TestCompositorHostX11::~TestCompositorHostX11() {
50 void TestCompositorHostX11::Show() {
51 XDisplay* display = gfx::GetXDisplay();
52 XSetWindowAttributes swa;
53 swa.event_mask = StructureNotifyMask | ExposureMask;
54 swa.override_redirect = True;
55 window_ = XCreateWindow(
56 display,
57 RootWindow(display, DefaultScreen(display)), // parent
58 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(),
59 0, // border width
60 CopyFromParent, // depth
61 InputOutput,
62 CopyFromParent, // visual
63 CWEventMask | CWOverrideRedirect, &swa);
64 XMapWindow(display, window_);
66 while (1) {
67 XEvent event;
68 XNextEvent(display, &event);
69 if (event.type == MapNotify && event.xmap.window == window_)
70 break;
72 compositor_.reset(new ui::Compositor(window_));
73 compositor_->SetScaleAndSize(1.0f, bounds_.size());
76 ui::Compositor* TestCompositorHostX11::GetCompositor() {
77 return compositor_.get();
80 void TestCompositorHostX11::Draw() {
81 if (compositor_.get())
82 compositor_->Draw();
85 // static
86 TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) {
87 return new TestCompositorHostX11(bounds);
90 } // namespace ui