Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: ui/ozone/platform/wayland/fake_server.h

Issue 2042503002: ozone/platform/wayland: Add support for wl_output_interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [For landding] update comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/platform/wayland/BUILD.gn ('k') | ui/ozone/platform/wayland/fake_server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef UI_OZONE_PLATFORM_WAYLAND_FAKE_SERVER_H_ 5 #ifndef UI_OZONE_PLATFORM_WAYLAND_FAKE_SERVER_H_
6 #define UI_OZONE_PLATFORM_WAYLAND_FAKE_SERVER_H_ 6 #define UI_OZONE_PLATFORM_WAYLAND_FAKE_SERVER_H_
7 7
8 #include <wayland-server-core.h> 8 #include <wayland-server-core.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/message_loop/message_pump_libevent.h" 11 #include "base/message_loop/message_pump_libevent.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "ui/gfx/geometry/rect.h"
15 16
16 struct wl_client; 17 struct wl_client;
17 struct wl_display; 18 struct wl_display;
18 struct wl_event_loop; 19 struct wl_event_loop;
19 struct wl_global; 20 struct wl_global;
20 struct wl_resource; 21 struct wl_resource;
21 22
22 namespace wl { 23 namespace wl {
23 24
25 // Base class for managing the life cycle of server objects.
24 class ServerObject { 26 class ServerObject {
25 public: 27 public:
26 ServerObject(wl_resource* resource); 28 ServerObject(wl_resource* resource);
27 virtual ~ServerObject(); 29 virtual ~ServerObject();
28 30
29 wl_resource* resource() { return resource_; } 31 wl_resource* resource() { return resource_; }
30 32
31 static void OnResourceDestroyed(wl_resource* resource); 33 static void OnResourceDestroyed(wl_resource* resource);
32 34
33 private: 35 private:
34 wl_resource* resource_; 36 wl_resource* resource_;
35 37
36 DISALLOW_COPY_AND_ASSIGN(ServerObject); 38 DISALLOW_COPY_AND_ASSIGN(ServerObject);
37 }; 39 };
38 40
41 // Manage xdg_surface for providing desktop UI.
39 class MockXdgSurface : public ServerObject { 42 class MockXdgSurface : public ServerObject {
40 public: 43 public:
41 MockXdgSurface(wl_resource* resource); 44 MockXdgSurface(wl_resource* resource);
42 ~MockXdgSurface() override; 45 ~MockXdgSurface() override;
43 46
44 MOCK_METHOD1(SetParent, void(wl_resource* parent)); 47 MOCK_METHOD1(SetParent, void(wl_resource* parent));
45 MOCK_METHOD1(SetTitle, void(const char* title)); 48 MOCK_METHOD1(SetTitle, void(const char* title));
46 MOCK_METHOD1(SetAppId, void(const char* app_id)); 49 MOCK_METHOD1(SetAppId, void(const char* app_id));
47 MOCK_METHOD1(AckConfigure, void(uint32_t serial)); 50 MOCK_METHOD1(AckConfigure, void(uint32_t serial));
48 MOCK_METHOD0(SetMaximized, void()); 51 MOCK_METHOD0(SetMaximized, void());
49 MOCK_METHOD0(UnsetMaximized, void()); 52 MOCK_METHOD0(UnsetMaximized, void());
50 MOCK_METHOD0(SetMinimized, void()); 53 MOCK_METHOD0(SetMinimized, void());
51 54
52 private: 55 private:
53 DISALLOW_COPY_AND_ASSIGN(MockXdgSurface); 56 DISALLOW_COPY_AND_ASSIGN(MockXdgSurface);
54 }; 57 };
55 58
59 // Manage client surface
56 class MockSurface : public ServerObject { 60 class MockSurface : public ServerObject {
57 public: 61 public:
58 MockSurface(wl_resource* resource); 62 MockSurface(wl_resource* resource);
59 ~MockSurface() override; 63 ~MockSurface() override;
60 64
61 static MockSurface* FromResource(wl_resource* resource); 65 static MockSurface* FromResource(wl_resource* resource);
62 66
63 MOCK_METHOD3(Attach, void(wl_resource* buffer, int32_t x, int32_t y)); 67 MOCK_METHOD3(Attach, void(wl_resource* buffer, int32_t x, int32_t y));
64 MOCK_METHOD4(Damage, 68 MOCK_METHOD4(Damage,
65 void(int32_t x, int32_t y, int32_t width, int32_t height)); 69 void(int32_t x, int32_t y, int32_t width, int32_t height));
(...skipping 11 matching lines...) Expand all
77 ~MockPointer() override; 81 ~MockPointer() override;
78 82
79 private: 83 private:
80 DISALLOW_COPY_AND_ASSIGN(MockPointer); 84 DISALLOW_COPY_AND_ASSIGN(MockPointer);
81 }; 85 };
82 86
83 struct GlobalDeleter { 87 struct GlobalDeleter {
84 void operator()(wl_global* global); 88 void operator()(wl_global* global);
85 }; 89 };
86 90
91 // Base class for managing the life cycle of global objects:
92 // It presents a global object used to emit global events to all clients.
87 class Global { 93 class Global {
88 public: 94 public:
89 Global(const wl_interface* interface, 95 Global(const wl_interface* interface,
90 const void* implementation, 96 const void* implementation,
91 uint32_t version); 97 uint32_t version);
92 virtual ~Global(); 98 virtual ~Global();
93 99
100 // Create a global object.
94 bool Initialize(wl_display* display); 101 bool Initialize(wl_display* display);
102 // Called from Bind() to send additional information to clients.
103 virtual void OnBind() {}
95 104
96 // The first bound resource to this global, which is usually all that is 105 // The first bound resource to this global, which is usually all that is
97 // useful when testing a simple client. 106 // useful when testing a simple client.
98 wl_resource* resource() { return resource_; } 107 wl_resource* resource() { return resource_; }
99 108
109 // Send the global event to clients.
100 static void Bind(wl_client* client, 110 static void Bind(wl_client* client,
101 void* data, 111 void* data,
102 uint32_t version, 112 uint32_t version,
103 uint32_t id); 113 uint32_t id);
104 static void OnResourceDestroyed(wl_resource* resource); 114 static void OnResourceDestroyed(wl_resource* resource);
105 115
106 private: 116 private:
107 std::unique_ptr<wl_global, GlobalDeleter> global_; 117 std::unique_ptr<wl_global, GlobalDeleter> global_;
108 118
109 const wl_interface* interface_; 119 const wl_interface* interface_;
110 const void* implementation_; 120 const void* implementation_;
111 const uint32_t version_; 121 const uint32_t version_;
112 wl_resource* resource_ = nullptr; 122 wl_resource* resource_ = nullptr;
113 123
114 DISALLOW_COPY_AND_ASSIGN(Global); 124 DISALLOW_COPY_AND_ASSIGN(Global);
115 }; 125 };
116 126
127 // Manage wl_compositor object.
117 class MockCompositor : public Global { 128 class MockCompositor : public Global {
118 public: 129 public:
119 MockCompositor(); 130 MockCompositor();
120 ~MockCompositor() override; 131 ~MockCompositor() override;
121 132
122 void AddSurface(std::unique_ptr<MockSurface> surface); 133 void AddSurface(std::unique_ptr<MockSurface> surface);
123 134
124 private: 135 private:
125 std::vector<std::unique_ptr<MockSurface>> surfaces_; 136 std::vector<std::unique_ptr<MockSurface>> surfaces_;
126 137
127 DISALLOW_COPY_AND_ASSIGN(MockCompositor); 138 DISALLOW_COPY_AND_ASSIGN(MockCompositor);
128 }; 139 };
129 140
141 // Handle wl_output object.
142 class MockOutput : public Global {
143 public:
144 MockOutput();
145 ~MockOutput() override;
146 void SetRect(const gfx::Rect rect) { rect_ = rect; }
147 const gfx::Rect GetRect() { return rect_; }
148 void OnBind() override;
149
150 private:
151 gfx::Rect rect_;
152
153 DISALLOW_COPY_AND_ASSIGN(MockOutput);
154 };
155
156 // Manage wl_seat object: group of input devices.
130 class MockSeat : public Global { 157 class MockSeat : public Global {
131 public: 158 public:
132 MockSeat(); 159 MockSeat();
133 ~MockSeat() override; 160 ~MockSeat() override;
134 161
135 std::unique_ptr<MockPointer> pointer; 162 std::unique_ptr<MockPointer> pointer;
136 163
137 private: 164 private:
138 DISALLOW_COPY_AND_ASSIGN(MockSeat); 165 DISALLOW_COPY_AND_ASSIGN(MockSeat);
139 }; 166 };
140 167
168 // Manage xdg_shell object.
141 class MockXdgShell : public Global { 169 class MockXdgShell : public Global {
142 public: 170 public:
143 MockXdgShell(); 171 MockXdgShell();
144 ~MockXdgShell() override; 172 ~MockXdgShell() override;
145 173
146 MOCK_METHOD1(UseUnstableVersion, void(int32_t version)); 174 MOCK_METHOD1(UseUnstableVersion, void(int32_t version));
147 MOCK_METHOD1(Pong, void(uint32_t serial)); 175 MOCK_METHOD1(Pong, void(uint32_t serial));
148 176
149 private: 177 private:
150 DISALLOW_COPY_AND_ASSIGN(MockXdgShell); 178 DISALLOW_COPY_AND_ASSIGN(MockXdgShell);
(...skipping 22 matching lines...) Expand all
173 void Resume(); 201 void Resume();
174 202
175 template <typename T> 203 template <typename T>
176 T* GetObject(uint32_t id) { 204 T* GetObject(uint32_t id) {
177 wl_resource* resource = wl_client_get_object(client_, id); 205 wl_resource* resource = wl_client_get_object(client_, id);
178 return resource ? T::FromResource(resource) : nullptr; 206 return resource ? T::FromResource(resource) : nullptr;
179 } 207 }
180 208
181 MockSeat* seat() { return &seat_; } 209 MockSeat* seat() { return &seat_; }
182 MockXdgShell* xdg_shell() { return &xdg_shell_; } 210 MockXdgShell* xdg_shell() { return &xdg_shell_; }
211 MockOutput* output() { return &output_; }
183 212
184 private: 213 private:
185 void DoPause(); 214 void DoPause();
186 215
187 std::unique_ptr<base::MessagePump> CreateMessagePump(); 216 std::unique_ptr<base::MessagePump> CreateMessagePump();
188 217
189 // base::MessagePumpLibevent::Watcher 218 // base::MessagePumpLibevent::Watcher
190 void OnFileCanReadWithoutBlocking(int fd) override; 219 void OnFileCanReadWithoutBlocking(int fd) override;
191 void OnFileCanWriteWithoutBlocking(int fd) override; 220 void OnFileCanWriteWithoutBlocking(int fd) override;
192 221
193 std::unique_ptr<wl_display, DisplayDeleter> display_; 222 std::unique_ptr<wl_display, DisplayDeleter> display_;
194 wl_client* client_ = nullptr; 223 wl_client* client_ = nullptr;
195 wl_event_loop* event_loop_ = nullptr; 224 wl_event_loop* event_loop_ = nullptr;
196 225
197 base::WaitableEvent pause_event_; 226 base::WaitableEvent pause_event_;
198 base::WaitableEvent resume_event_; 227 base::WaitableEvent resume_event_;
199 228
229 // Represent Wayland global objects
200 MockCompositor compositor_; 230 MockCompositor compositor_;
231 MockOutput output_;
201 MockSeat seat_; 232 MockSeat seat_;
202 MockXdgShell xdg_shell_; 233 MockXdgShell xdg_shell_;
203 234
204 base::MessagePumpLibevent::FileDescriptorWatcher controller_; 235 base::MessagePumpLibevent::FileDescriptorWatcher controller_;
205 236
206 DISALLOW_COPY_AND_ASSIGN(FakeServer); 237 DISALLOW_COPY_AND_ASSIGN(FakeServer);
207 }; 238 };
208 239
209 } // namespace wl 240 } // namespace wl
210 241
211 #endif // UI_OZONE_PLATFORM_WAYLAND_FAKE_SERVER_H_ 242 #endif // UI_OZONE_PLATFORM_WAYLAND_FAKE_SERVER_H_
OLDNEW
« no previous file with comments | « ui/ozone/platform/wayland/BUILD.gn ('k') | ui/ozone/platform/wayland/fake_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698