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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
// 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/basictypes.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/rect.h"
#include <X11/Xlib.h>
#if defined(TOUCH_UI) || defined(USE_AURA)
#include "base/message_pump_x.h"
#endif
namespace ui {
class TestCompositorHostLinux : public TestCompositorHost,
public CompositorDelegate {
public:
TestCompositorHostLinux(const gfx::Rect& bounds);
virtual ~TestCompositorHostLinux();
private:
// Overridden from TestCompositorHost:
virtual void Show() OVERRIDE;
virtual ui::Compositor* GetCompositor() OVERRIDE;
// Overridden from CompositorDelegate:
virtual void ScheduleDraw() OVERRIDE;
// Overridden from MessagePumpDispatcher:
#if defined(TOUCH_UI) || defined(USE_AURA)
virtual base::MessagePumpDispatcher::DispatchStatus
Dispatch(XEvent* xev) OVERRIDE;
#elif defined(TOOLKIT_USES_GTK)
virtual bool Dispatch(GdkEvent* event) OVERRIDE;
#endif
gfx::Rect bounds_;
scoped_refptr<ui::Compositor> compositor_;
Display* display_;
XID window_;
DISALLOW_COPY_AND_ASSIGN(TestCompositorHostLinux);
};
TestCompositorHostLinux::TestCompositorHostLinux(const gfx::Rect& bounds)
: bounds_(bounds) {
}
TestCompositorHostLinux::~TestCompositorHostLinux() {
XDestroyWindow(display_, window_);
}
void TestCompositorHostLinux::Show() {
display_ = XOpenDisplay(NULL);
XSetWindowAttributes swa;
swa.event_mask = StructureNotifyMask | ExposureMask;
swa.override_redirect = True;
window_ = XCreateWindow(
display_,
RootWindow(display_, DefaultScreen(display_)), // parent
bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(),
0, // border width
CopyFromParent, // depth
InputOutput,
CopyFromParent, // visual
CWEventMask | CWOverrideRedirect, &swa);
XMapWindow(display_, window_);
while (1) {
XEvent event;
XNextEvent(display_, &event);
if (event.type == MapNotify && event.xmap.window == window_)
break;
}
compositor_ = ui::Compositor::Create(this, window_, bounds_.size());
}
ui::Compositor* TestCompositorHostLinux::GetCompositor() {
return compositor_;
}
void TestCompositorHostLinux::ScheduleDraw() {
compositor_->Draw(false);
}
#if defined(TOUCH_UI) || defined(USE_AURA)
base::MessagePumpDispatcher::DispatchStatus TestCompositorHostLinux::Dispatch(
XEvent* xev) {
return MessagePumpDispatcher::EVENT_IGNORED;
}
#elif defined(TOOLKIT_USES_GTK)
bool TestCompositorHostLinux::Dispatch(GdkEvent*) {
return false;
}
#endif
// static
TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) {
return new TestCompositorHostLinux(bounds);
}
} // namespace ui
|