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

Side by Side Diff: ui/wayland/wayland_display.cc

Issue 7457023: Adding a Wayland basic toolkit (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed argument layout Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
(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/wayland/wayland_display.h"
6
7 #include <string.h>
8 #include <wayland-client.h>
9
10 #include "ui/wayland/wayland_buffer.h"
11 #include "ui/wayland/wayland_input_device.h"
12 #include "ui/wayland/wayland_screen.h"
13 #include "ui/wayland/wayland_window.h"
14
15 namespace ui {
16
17 // static
18 WaylandDisplay* WaylandDisplay::Connect(char* name) {
19 WaylandDisplay* display = new WaylandDisplay(name);
20 if (!display->display_) {
21 delete display;
22 return NULL;
23 }
24
25 wl_display_set_user_data(display->display_, display);
26 // Register the display initialization handler and iterate over the initial
27 // connection events sent by the server. This is required since the display
28 // will send registration events needed to initialize everything else. This
29 // will create the compositor, visuals, etc.., which are required in creating
30 // a drawing context.
31 wl_display_add_global_listener(display->display_,
32 WaylandDisplay::DisplayHandleGlobal,
33 display);
34 wl_display_iterate(display->display_, WL_DISPLAY_READABLE);
35
36 return display;
37 }
38
39 // static
40 WaylandDisplay* WaylandDisplay::GetDisplay(wl_display* display) {
41 return static_cast<WaylandDisplay*>(wl_display_get_user_data(display));
42 }
43
44 WaylandDisplay::WaylandDisplay(char* name) : display_(NULL),
45 compositor_(NULL),
46 shell_(NULL),
47 shm_(NULL),
48 visual_(NULL) {
49 display_ = wl_display_connect(name);
50 }
51
52 WaylandDisplay::~WaylandDisplay() {
53 if (display_)
54 wl_display_destroy(display_);
55 if (compositor_)
56 wl_compositor_destroy(compositor_);
57 if (visual_)
58 wl_visual_destroy(visual_);
59 if (shell_)
60 wl_shell_destroy(shell_);
61 if (shm_)
62 wl_shm_destroy(shm_);
63 for (std::list<WaylandInputDevice*>::iterator it = input_list_.begin();
64 it != input_list_.end(); it++) {
65 delete *it;
66 }
67 for (std::list<WaylandScreen*>::iterator it = screen_list_.begin();
68 it != screen_list_.end(); it++) {
tfarina 2011/07/25 18:34:27 ++i
69 delete *it;
70 }
71 }
72
73 wl_surface* WaylandDisplay::CreateSurface() {
74 return wl_compositor_create_surface(compositor_);
75 }
76
77 void WaylandDisplay::SetCursor(WaylandBuffer* buffer,
78 int32_t x, int32_t y) {
79 // Currently there is no way of knowing which input device should have the
80 // buffer attached, so we just attach to every input device.
81 for (std::list<WaylandInputDevice*>::iterator it = input_list_.begin();
82 it != input_list_.end(); it++) {
83 (*it)->Attach(buffer->GetBuffer(), x, y);
84 }
85 }
86
87 wl_display* WaylandDisplay::GetNativeDisplay() const {
88 return display_;
89 }
90
91 std::list<WaylandScreen*> WaylandDisplay::GetScreenList() const {
92 return screen_list_;
93 }
94
95 wl_shell* WaylandDisplay::GetShell() const {
96 return shell_;
97 }
98
99 wl_shm* WaylandDisplay::GetShm() const {
100 return shm_;
101 }
102
103 wl_visual* WaylandDisplay::GetVisual() const {
104 return visual_;
105 }
106
107 // static
108 void WaylandDisplay::DisplayHandleGlobal(wl_display* display,
109 uint32_t id,
110 const char* interface,
111 uint32_t version,
112 void* data) {
113 WaylandDisplay* disp = static_cast<WaylandDisplay*>(data);
114
115 static const wl_compositor_listener kCompositorListener = {
116 WaylandDisplay::CompositorHandleVisual,
117 };
118 static const wl_shell_listener kShellListener = {
119 WaylandDisplay::ShellHandleConfigure,
120 };
121
122 if (strcmp(interface, "wl_compositor") == 0) {
123 disp->compositor_ = wl_compositor_create(display, id, 1);
124 wl_compositor_add_listener(disp->compositor_,
125 &kCompositorListener,
126 disp);
127 } else if (strcmp(interface, "wl_output") == 0) {
128 WaylandScreen* screen = new WaylandScreen(disp, id);
129 disp->screen_list_.push_back(screen);
130 } else if (strcmp(interface, "wl_input_device") == 0) {
131 WaylandInputDevice *input_device = new WaylandInputDevice(display, id);
132 disp->input_list_.push_back(input_device);
133 } else if (strcmp(interface, "wl_shell") == 0) {
134 disp->shell_ = wl_shell_create(display, id, 1);
135 wl_shell_add_listener(disp->shell_, &kShellListener, disp);
136 } else if (strcmp(interface, "wl_shm") == 0) {
137 disp->shm_ = wl_shm_create(display, id, 1);
138 }
139 }
140
141 // static
142 void WaylandDisplay::CompositorHandleVisual(void* data,
143 wl_compositor* compositor,
144 uint32_t id,
145 uint32_t token) {
146 WaylandDisplay* display = static_cast<WaylandDisplay*>(data);
147
148 // The compositor may support multiple types of visuals but we really only
149 // need one.
150 switch (token) {
151 case WL_COMPOSITOR_VISUAL_ARGB32:
152 break;
153 case WL_COMPOSITOR_VISUAL_PREMULTIPLIED_ARGB32:
154 display->visual_ = wl_visual_create(display->display_, id, 1);
155 break;
156 case WL_COMPOSITOR_VISUAL_XRGB32:
157 break;
158 }
tfarina 2011/07/25 18:34:27 do you need a default case here?
159 }
160
161 // static
162 void WaylandDisplay::ShellHandleConfigure(void* data,
163 wl_shell* shell,
164 uint32_t time,
165 uint32_t edges,
166 wl_surface* surface,
167 int32_t width,
168 int32_t height) {
169 WaylandWindow* window = static_cast<WaylandWindow*>(
170 wl_surface_get_user_data(surface));
171 window->Configure(time, edges, 0, 0, width, height);
172 }
173
174 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698