OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/compositor/test/test_compositor_host.h" | 5 #include "ui/compositor/test/test_compositor_host.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "ui/base/x/x11_window_event_manager.h" |
17 #include "ui/compositor/compositor.h" | 18 #include "ui/compositor/compositor.h" |
18 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
19 #include "ui/gfx/x/x11_types.h" | 20 #include "ui/gfx/x/x11_types.h" |
20 | 21 |
21 namespace ui { | 22 namespace ui { |
22 | 23 |
23 class TestCompositorHostX11 : public TestCompositorHost { | 24 class TestCompositorHostX11 : public TestCompositorHost { |
24 public: | 25 public: |
25 TestCompositorHostX11(const gfx::Rect& bounds, | 26 TestCompositorHostX11(const gfx::Rect& bounds, |
26 ui::ContextFactory* context_factory); | 27 ui::ContextFactory* context_factory); |
27 ~TestCompositorHostX11() override; | 28 ~TestCompositorHostX11() override; |
28 | 29 |
29 private: | 30 private: |
30 // Overridden from TestCompositorHost: | 31 // Overridden from TestCompositorHost: |
31 void Show() override; | 32 void Show() override; |
32 ui::Compositor* GetCompositor() override; | 33 ui::Compositor* GetCompositor() override; |
33 | 34 |
34 gfx::Rect bounds_; | 35 gfx::Rect bounds_; |
35 | 36 |
36 ui::ContextFactory* context_factory_; | 37 ui::ContextFactory* context_factory_; |
37 | 38 |
38 ui::Compositor compositor_; | 39 ui::Compositor compositor_; |
39 | 40 |
40 XID window_; | 41 XID window_; |
41 | 42 |
| 43 std::unique_ptr<XScopedEventSelector> window_events_; |
| 44 |
42 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostX11); | 45 DISALLOW_COPY_AND_ASSIGN(TestCompositorHostX11); |
43 }; | 46 }; |
44 | 47 |
45 TestCompositorHostX11::TestCompositorHostX11( | 48 TestCompositorHostX11::TestCompositorHostX11( |
46 const gfx::Rect& bounds, | 49 const gfx::Rect& bounds, |
47 ui::ContextFactory* context_factory) | 50 ui::ContextFactory* context_factory) |
48 : bounds_(bounds), | 51 : bounds_(bounds), |
49 context_factory_(context_factory), | 52 context_factory_(context_factory), |
50 compositor_(context_factory_, base::ThreadTaskRunnerHandle::Get()) {} | 53 compositor_(context_factory_, base::ThreadTaskRunnerHandle::Get()) {} |
51 | 54 |
52 TestCompositorHostX11::~TestCompositorHostX11() { | 55 TestCompositorHostX11::~TestCompositorHostX11() {} |
53 } | |
54 | 56 |
55 void TestCompositorHostX11::Show() { | 57 void TestCompositorHostX11::Show() { |
56 XDisplay* display = gfx::GetXDisplay(); | 58 XDisplay* display = gfx::GetXDisplay(); |
57 XSetWindowAttributes swa; | 59 XSetWindowAttributes swa; |
58 swa.event_mask = StructureNotifyMask | ExposureMask; | |
59 swa.override_redirect = True; | 60 swa.override_redirect = True; |
60 window_ = XCreateWindow( | 61 window_ = XCreateWindow( |
61 display, | 62 display, |
62 RootWindow(display, DefaultScreen(display)), // parent | 63 RootWindow(display, DefaultScreen(display)), // parent |
63 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), | 64 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), |
64 0, // border width | 65 0, // border width |
65 CopyFromParent, // depth | 66 CopyFromParent, // depth |
66 InputOutput, | 67 InputOutput, |
67 CopyFromParent, // visual | 68 CopyFromParent, // visual |
68 CWEventMask | CWOverrideRedirect, &swa); | 69 CWOverrideRedirect, &swa); |
| 70 window_events_.reset( |
| 71 new XScopedEventSelector(window_, StructureNotifyMask | ExposureMask)); |
69 XMapWindow(display, window_); | 72 XMapWindow(display, window_); |
70 | 73 |
71 while (1) { | 74 while (1) { |
72 XEvent event; | 75 XEvent event; |
73 XNextEvent(display, &event); | 76 XNextEvent(display, &event); |
74 if (event.type == MapNotify && event.xmap.window == window_) | 77 if (event.type == MapNotify && event.xmap.window == window_) |
75 break; | 78 break; |
76 } | 79 } |
77 compositor_.SetAcceleratedWidget(window_); | 80 compositor_.SetAcceleratedWidget(window_); |
78 compositor_.SetScaleAndSize(1.0f, bounds_.size()); | 81 compositor_.SetScaleAndSize(1.0f, bounds_.size()); |
79 compositor_.SetVisible(true); | 82 compositor_.SetVisible(true); |
80 } | 83 } |
81 | 84 |
82 ui::Compositor* TestCompositorHostX11::GetCompositor() { | 85 ui::Compositor* TestCompositorHostX11::GetCompositor() { |
83 return &compositor_; | 86 return &compositor_; |
84 } | 87 } |
85 | 88 |
86 // static | 89 // static |
87 TestCompositorHost* TestCompositorHost::Create( | 90 TestCompositorHost* TestCompositorHost::Create( |
88 const gfx::Rect& bounds, | 91 const gfx::Rect& bounds, |
89 ui::ContextFactory* context_factory) { | 92 ui::ContextFactory* context_factory) { |
90 return new TestCompositorHostX11(bounds, context_factory); | 93 return new TestCompositorHostX11(bounds, context_factory); |
91 } | 94 } |
92 | 95 |
93 } // namespace ui | 96 } // namespace ui |
OLD | NEW |