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

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: Inlined functions and styling changes Created 9 years, 4 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 i = input_list_.begin();
64 i != input_list_.end(); ++i) {
65 delete *i;
66 }
67 for (std::list<WaylandScreen*>::iterator i = screen_list_.begin();
68 i != screen_list_.end(); ++i) {
69 delete *i;
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 i = input_list_.begin();
82 i != input_list_.end(); ++i) {
83 (*i)->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 // static
96 void WaylandDisplay::DisplayHandleGlobal(wl_display* display,
97 uint32_t id,
98 const char* interface,
99 uint32_t version,
100 void* data) {
101 WaylandDisplay* disp = static_cast<WaylandDisplay*>(data);
102
103 static const wl_compositor_listener kCompositorListener = {
104 WaylandDisplay::CompositorHandleVisual,
105 };
106 static const wl_shell_listener kShellListener = {
107 WaylandDisplay::ShellHandleConfigure,
108 };
109
110 if (strcmp(interface, "wl_compositor") == 0) {
111 disp->compositor_ = wl_compositor_create(display, id, 1);
112 wl_compositor_add_listener(disp->compositor_,
113 &kCompositorListener,
114 disp);
115 } else if (strcmp(interface, "wl_output") == 0) {
116 WaylandScreen* screen = new WaylandScreen(disp, id);
117 disp->screen_list_.push_back(screen);
118 } else if (strcmp(interface, "wl_input_device") == 0) {
119 WaylandInputDevice *input_device = new WaylandInputDevice(display, id);
120 disp->input_list_.push_back(input_device);
121 } else if (strcmp(interface, "wl_shell") == 0) {
122 disp->shell_ = wl_shell_create(display, id, 1);
123 wl_shell_add_listener(disp->shell_, &kShellListener, disp);
124 } else if (strcmp(interface, "wl_shm") == 0) {
125 disp->shm_ = wl_shm_create(display, id, 1);
126 }
127 }
128
129 // static
130 void WaylandDisplay::CompositorHandleVisual(void* data,
131 wl_compositor* compositor,
132 uint32_t id,
133 uint32_t token) {
134 WaylandDisplay* display = static_cast<WaylandDisplay*>(data);
135
136 // The compositor may support multiple types of visuals but we really only
137 // need one.
138 switch (token) {
139 case WL_COMPOSITOR_VISUAL_ARGB32:
140 break;
141 case WL_COMPOSITOR_VISUAL_PREMULTIPLIED_ARGB32:
142 display->visual_ = wl_visual_create(display->display_, id, 1);
143 break;
144 case WL_COMPOSITOR_VISUAL_XRGB32:
145 break;
146 }
147 }
148
149 // static
150 void WaylandDisplay::ShellHandleConfigure(void* data,
151 wl_shell* shell,
152 uint32_t time,
153 uint32_t edges,
154 wl_surface* surface,
155 int32_t width,
156 int32_t height) {
157 WaylandWindow* window = static_cast<WaylandWindow*>(
158 wl_surface_get_user_data(surface));
159 window->Configure(time, edges, 0, 0, width, height);
160 }
161
162 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698