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/basictypes.h" | |
8 #include "base/compiler_specific.h" | |
9 #include "base/logging.h" | |
10 #include "ui/base/x/x11_util.h" | |
11 #include "ui/gfx/compositor/compositor.h" | |
12 #include "ui/gfx/rect.h" | |
13 | |
14 #include <X11/Xlib.h> | |
15 | |
16 #if defined(TOUCH_UI) || defined(USE_AURA) | |
17 #include "base/message_pump_x.h" | |
18 #endif | |
19 | |
20 namespace ui { | |
21 | |
22 class TestCompositorHostLinux : public TestCompositorHost, | |
23 public CompositorDelegate { | |
24 public: | |
25 TestCompositorHostLinux(const gfx::Rect& bounds); | |
26 virtual ~TestCompositorHostLinux(); | |
27 | |
28 private: | |
29 // Overridden from TestCompositorHost: | |
30 virtual void Show() OVERRIDE; | |
31 virtual ui::Compositor* GetCompositor() OVERRIDE; | |
32 | |
33 // Overridden from CompositorDelegate: | |
34 virtual void ScheduleDraw() OVERRIDE; | |
35 | |
36 // Overridden from MessagePumpDispatcher: | |
37 #if defined(TOUCH_UI) || defined(USE_AURA) | |
38 virtual base::MessagePumpDispatcher::DispatchStatus | |
39 Dispatch(XEvent* xev) OVERRIDE; | |
40 #elif defined(TOOLKIT_USES_GTK) | |
41 virtual bool Dispatch(GdkEvent* event) OVERRIDE; | |
42 #endif | |
43 | |
44 gfx::Rect bounds_; | |
45 | |
46 scoped_refptr<ui::Compositor> compositor_; | |
47 | |
48 Display* display_; | |
49 | |
50 XID window_; | |
51 | |
52 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostLinux); | |
53 }; | |
54 | |
55 TestCompositorHostLinux::TestCompositorHostLinux(const gfx::Rect& bounds) | |
56 : bounds_(bounds) { | |
57 } | |
58 | |
59 TestCompositorHostLinux::~TestCompositorHostLinux() { | |
60 XDestroyWindow(display_, window_); | |
61 } | |
62 | |
63 void TestCompositorHostLinux::Show() { | |
64 display_ = XOpenDisplay(NULL); | |
65 XSetWindowAttributes swa; | |
66 swa.event_mask = StructureNotifyMask | ExposureMask; | |
67 swa.override_redirect = True; | |
68 window_ = XCreateWindow( | |
69 display_, | |
70 RootWindow(display_, DefaultScreen(display_)), // parent | |
71 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), | |
72 0, // border width | |
73 CopyFromParent, // depth | |
74 InputOutput, | |
75 CopyFromParent, // visual | |
76 CWEventMask | CWOverrideRedirect, &swa); | |
77 XMapWindow(display_, window_); | |
78 | |
79 while (1) { | |
80 XEvent event; | |
81 XNextEvent(display_, &event); | |
82 if (event.type == MapNotify && event.xmap.window == window_) | |
83 break; | |
84 } | |
85 compositor_ = ui::Compositor::Create(this, window_, bounds_.size()); | |
86 } | |
87 | |
88 ui::Compositor* TestCompositorHostLinux::GetCompositor() { | |
89 return compositor_; | |
90 } | |
91 | |
92 void TestCompositorHostLinux::ScheduleDraw() { | |
93 if (compositor_) | |
94 compositor_->Draw(false); | |
95 } | |
96 | |
97 #if defined(TOUCH_UI) || defined(USE_AURA) | |
98 base::MessagePumpDispatcher::DispatchStatus TestCompositorHostLinux::Dispatch( | |
99 XEvent* xev) { | |
100 return MessagePumpDispatcher::EVENT_IGNORED; | |
101 } | |
102 #elif defined(TOOLKIT_USES_GTK) | |
103 bool TestCompositorHostLinux::Dispatch(GdkEvent*) { | |
104 return false; | |
105 } | |
106 #endif | |
107 | |
108 // static | |
109 TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) { | |
110 return new TestCompositorHostLinux(bounds); | |
111 } | |
112 | |
113 } // namespace ui | |
OLD | NEW |