OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/compositor/test/test_compositor_host.h" | 5 #include "ui/gfx/compositor/test/test_compositor_host.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" |
10 #include "ui/base/x/x11_util.h" | 11 #include "ui/base/x/x11_util.h" |
11 #include "ui/gfx/compositor/compositor.h" | 12 #include "ui/gfx/compositor/compositor.h" |
12 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
13 | 14 |
14 #include <X11/Xlib.h> | 15 #include <X11/Xlib.h> |
15 | 16 |
16 #if defined(USE_AURA) | 17 #if defined(USE_AURA) |
17 #include "base/message_pump_x.h" | 18 #include "base/message_pump_x.h" |
18 #endif | 19 #endif |
19 | 20 |
(...skipping 18 matching lines...) Expand all Loading... |
38 virtual base::MessagePumpDispatcher::DispatchStatus | 39 virtual base::MessagePumpDispatcher::DispatchStatus |
39 Dispatch(XEvent* xev) OVERRIDE; | 40 Dispatch(XEvent* xev) OVERRIDE; |
40 #elif defined(TOOLKIT_USES_GTK) | 41 #elif defined(TOOLKIT_USES_GTK) |
41 virtual bool Dispatch(GdkEvent* event) OVERRIDE; | 42 virtual bool Dispatch(GdkEvent* event) OVERRIDE; |
42 #endif | 43 #endif |
43 | 44 |
44 gfx::Rect bounds_; | 45 gfx::Rect bounds_; |
45 | 46 |
46 scoped_refptr<ui::Compositor> compositor_; | 47 scoped_refptr<ui::Compositor> compositor_; |
47 | 48 |
48 Display* display_; | |
49 | |
50 XID window_; | 49 XID window_; |
51 | 50 |
52 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostLinux); | 51 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostLinux); |
53 }; | 52 }; |
54 | 53 |
55 TestCompositorHostLinux::TestCompositorHostLinux(const gfx::Rect& bounds) | 54 TestCompositorHostLinux::TestCompositorHostLinux(const gfx::Rect& bounds) |
56 : bounds_(bounds) { | 55 : bounds_(bounds) { |
57 } | 56 } |
58 | 57 |
59 TestCompositorHostLinux::~TestCompositorHostLinux() { | 58 TestCompositorHostLinux::~TestCompositorHostLinux() { |
60 XDestroyWindow(display_, window_); | |
61 } | 59 } |
62 | 60 |
63 void TestCompositorHostLinux::Show() { | 61 void TestCompositorHostLinux::Show() { |
64 display_ = XOpenDisplay(NULL); | 62 Display* display = base::MessagePumpForUI::GetDefaultXDisplay(); |
65 XSetWindowAttributes swa; | 63 XSetWindowAttributes swa; |
66 swa.event_mask = StructureNotifyMask | ExposureMask; | 64 swa.event_mask = StructureNotifyMask | ExposureMask; |
67 swa.override_redirect = True; | 65 swa.override_redirect = True; |
68 window_ = XCreateWindow( | 66 window_ = XCreateWindow( |
69 display_, | 67 display, |
70 RootWindow(display_, DefaultScreen(display_)), // parent | 68 RootWindow(display, DefaultScreen(display)), // parent |
71 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), | 69 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), |
72 0, // border width | 70 0, // border width |
73 CopyFromParent, // depth | 71 CopyFromParent, // depth |
74 InputOutput, | 72 InputOutput, |
75 CopyFromParent, // visual | 73 CopyFromParent, // visual |
76 CWEventMask | CWOverrideRedirect, &swa); | 74 CWEventMask | CWOverrideRedirect, &swa); |
77 XMapWindow(display_, window_); | 75 XMapWindow(display, window_); |
78 | 76 |
79 while (1) { | 77 while (1) { |
80 XEvent event; | 78 XEvent event; |
81 XNextEvent(display_, &event); | 79 XNextEvent(display, &event); |
82 if (event.type == MapNotify && event.xmap.window == window_) | 80 if (event.type == MapNotify && event.xmap.window == window_) |
83 break; | 81 break; |
84 } | 82 } |
85 compositor_ = ui::Compositor::Create(this, window_, bounds_.size()); | 83 compositor_ = ui::Compositor::Create(this, window_, bounds_.size()); |
86 } | 84 } |
87 | 85 |
88 ui::Compositor* TestCompositorHostLinux::GetCompositor() { | 86 ui::Compositor* TestCompositorHostLinux::GetCompositor() { |
89 return compositor_; | 87 return compositor_; |
90 } | 88 } |
91 | 89 |
(...skipping 12 matching lines...) Expand all Loading... |
104 return false; | 102 return false; |
105 } | 103 } |
106 #endif | 104 #endif |
107 | 105 |
108 // static | 106 // static |
109 TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) { | 107 TestCompositorHost* TestCompositorHost::Create(const gfx::Rect& bounds) { |
110 return new TestCompositorHostLinux(bounds); | 108 return new TestCompositorHostLinux(bounds); |
111 } | 109 } |
112 | 110 |
113 } // namespace ui | 111 } // namespace ui |
OLD | NEW |