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

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

Issue 7457023: Adding a Wayland basic toolkit (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Removed the WaylandDisplay singleton 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_message_pump.h"
6
7 #include <wayland-client.h>
8
9 #include "ui/wayland/wayland_display.h"
10
11 WaylandMessagePump::WaylandMessagePump(WaylandDisplay* display)
12 : display_(display) {
13 static GSourceFuncs source_handlers = {
14 WaylandMessagePump::SourcePrepare,
15 WaylandMessagePump::SourceCheck,
16 WaylandMessagePump::SourceDispatch,
17 NULL
18 };
19
20 source_ = static_cast<WorkSource*>(
21 g_source_new(&source_handlers, sizeof(WorkSource)));
22 source_->pump = this;
23 pfd_.fd = wl_display_get_fd(display_->GetNativeDisplay(),
24 WaylandMessagePump::SourceUpdate,
25 source_);
26 pfd_.events = G_IO_IN | G_IO_ERR;
27 g_source_add_poll(source_, &pfd_);
28 g_source_attach(source_, NULL);
29 }
30
31 WaylandMessagePump::~WaylandMessagePump() {
32 g_source_destroy(source_);
33 g_source_unref(source_);
34 }
35
36 int WaylandMessagePump::HandlePrepare() {
37 while (mask_ & WL_DISPLAY_WRITABLE) {
38 wl_display_iterate(display_->GetNativeDisplay(), WL_DISPLAY_WRITABLE);
39 }
40 return -1;
41 }
42
43 bool WaylandMessagePump::HandleCheck() {
44 return pfd_.revents;
45 }
46
47 void WaylandMessagePump::HandleDispatch() {
48 wl_display_iterate(display_->GetNativeDisplay(), WL_DISPLAY_READABLE);
49 }
50
51 // static
52 gboolean WaylandMessagePump::SourcePrepare(GSource* source, gint* timeout) {
53 *timeout = static_cast<WorkSource*>(source)->pump->HandlePrepare();
54 return FALSE;
55 }
56
57 // static
58 gboolean WaylandMessagePump::SourceCheck(GSource* source) {
59 return static_cast<WorkSource*>(source)->pump->HandleCheck();
60 }
61
62 // static
63 gboolean WaylandMessagePump::SourceDispatch(GSource* source,
64 GSourceFunc callback,
65 gpointer data) {
66 static_cast<WorkSource*>(source)->pump->HandleDispatch();
67 return TRUE;
68 }
69
70 // static
71 int WaylandMessagePump::SourceUpdate(uint32_t mask, void* data) {
72 static_cast<WorkSource*>(data)->pump->mask_ = mask;
73 return 0;
74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698