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

Side by Side Diff: ui/base/x/x11_window_cache_event_source.cc

Issue 2199063003: Linux: Add xcb FD to glib event loop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor Created 4 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
« no previous file with comments | « ui/base/x/x11_window_cache_event_source.h ('k') | ui/base/x/x11_window_cache_unittest.cc » ('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 2016 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/base/x/x11_window_cache_event_source.h"
6
7 #include <glib.h>
8
9 #include "base/logging.h"
10 #include "ui/base/x/x11_window_cache.h"
11
12 namespace ui {
13
14 namespace {
15
16 struct GLibXcbSource : public GSource {
17 GPollFD* poll_fd;
18 };
19
20 gboolean callback(gpointer data) {
21 XWindowCache* cache = reinterpret_cast<XWindowCache*>(data);
22 cache->OnConnectionReadable();
23 return !cache->ConnectionHasError();
24 }
25
26 gboolean prepare(GSource* source, gint* timeout) {
27 *timeout = -1;
28 return FALSE;
29 }
30
31 gboolean check(GSource* source) {
32 return static_cast<GLibXcbSource*>(source)->poll_fd->revents & G_IO_IN;
33 }
34
35 gboolean dispatch(GSource* source, GSourceFunc callback, gpointer data) {
36 return callback(data);
37 }
38
39 GSourceFuncs source_funcs {prepare, check, dispatch, nullptr};
40
41 } // anonymous namespace
42
43 XWindowCacheEventSource::XWindowCacheEventSource(XWindowCache* cache) {
44 DCHECK(!cache->ConnectionHasError());
45 int fd = cache->ConnectionFd();
46
47 GPollFD* poll = new GPollFD();
48 g_poll_.reset(poll);
49 poll->fd = fd;
50 poll->events = G_IO_IN;
51 poll->revents = 0;
52
53 GLibXcbSource* g_source = static_cast<GLibXcbSource*>(
54 g_source_new(&source_funcs, sizeof(GLibXcbSource)));
55 g_source_ = g_source;
56 g_source->poll_fd = poll;
57 g_source_add_poll(g_source, poll);
58 g_source_set_can_recurse(g_source, TRUE);
59 g_source_set_callback(g_source, callback, cache, nullptr);
60 g_source_attach(g_source, g_main_context_default());
61 }
62
63 XWindowCacheEventSource::~XWindowCacheEventSource() {
64 g_source_destroy(g_source_);
65 g_source_unref(g_source_);
66 }
67
68 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/x/x11_window_cache_event_source.h ('k') | ui/base/x/x11_window_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698