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

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: Updated trunk to HEAD 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
« no previous file with comments | « ui/wayland/wayland_display.h ('k') | ui/wayland/wayland_input_device.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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->buffer(), x, y);
84 }
85 }
86
87 std::list<WaylandScreen*> WaylandDisplay::GetScreenList() const {
88 return screen_list_;
89 }
90
91 // static
92 void WaylandDisplay::DisplayHandleGlobal(wl_display* display,
93 uint32_t id,
94 const char* interface,
95 uint32_t version,
96 void* data) {
97 WaylandDisplay* disp = static_cast<WaylandDisplay*>(data);
98
99 static const wl_compositor_listener kCompositorListener = {
100 WaylandDisplay::CompositorHandleVisual,
101 };
102 static const wl_shell_listener kShellListener = {
103 WaylandDisplay::ShellHandleConfigure,
104 };
105
106 if (strcmp(interface, "wl_compositor") == 0) {
107 disp->compositor_ = wl_compositor_create(display, id, 1);
108 wl_compositor_add_listener(disp->compositor_,
109 &kCompositorListener,
110 disp);
111 } else if (strcmp(interface, "wl_output") == 0) {
112 WaylandScreen* screen = new WaylandScreen(disp, id);
113 disp->screen_list_.push_back(screen);
114 } else if (strcmp(interface, "wl_input_device") == 0) {
115 WaylandInputDevice *input_device = new WaylandInputDevice(display, id);
116 disp->input_list_.push_back(input_device);
117 } else if (strcmp(interface, "wl_shell") == 0) {
118 disp->shell_ = wl_shell_create(display, id, 1);
119 wl_shell_add_listener(disp->shell_, &kShellListener, disp);
120 } else if (strcmp(interface, "wl_shm") == 0) {
121 disp->shm_ = wl_shm_create(display, id, 1);
122 }
123 }
124
125 // static
126 void WaylandDisplay::CompositorHandleVisual(void* data,
127 wl_compositor* compositor,
128 uint32_t id,
129 uint32_t token) {
130 WaylandDisplay* display = static_cast<WaylandDisplay*>(data);
131
132 // The compositor may support multiple types of visuals but we really only
133 // need one.
134 switch (token) {
135 case WL_COMPOSITOR_VISUAL_ARGB32:
136 break;
137 case WL_COMPOSITOR_VISUAL_PREMULTIPLIED_ARGB32:
138 display->visual_ = wl_visual_create(display->display_, id, 1);
139 break;
140 case WL_COMPOSITOR_VISUAL_XRGB32:
141 break;
142 }
143 }
144
145 // static
146 void WaylandDisplay::ShellHandleConfigure(void* data,
147 wl_shell* shell,
148 uint32_t time,
149 uint32_t edges,
150 wl_surface* surface,
151 int32_t width,
152 int32_t height) {
153 WaylandWindow* window = static_cast<WaylandWindow*>(
154 wl_surface_get_user_data(surface));
155 window->Configure(time, edges, 0, 0, width, height);
156 }
157
158 } // namespace ui
OLDNEW
« no previous file with comments | « ui/wayland/wayland_display.h ('k') | ui/wayland/wayland_input_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698