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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/x/x11_window_cache_event_source.cc
diff --git a/ui/base/x/x11_window_cache_event_source.cc b/ui/base/x/x11_window_cache_event_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2a5ce752d544d7b442ce67ae445011b405b01f45
--- /dev/null
+++ b/ui/base/x/x11_window_cache_event_source.cc
@@ -0,0 +1,68 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/base/x/x11_window_cache_event_source.h"
+
+#include <glib.h>
+
+#include "base/logging.h"
+#include "ui/base/x/x11_window_cache.h"
+
+namespace ui {
+
+namespace {
+
+struct GLibXcbSource : public GSource {
+ GPollFD* poll_fd;
+};
+
+gboolean callback(gpointer data) {
+ XWindowCache* cache = reinterpret_cast<XWindowCache*>(data);
+ cache->OnConnectionReadable();
+ return !cache->ConnectionHasError();
+}
+
+gboolean prepare(GSource* source, gint* timeout) {
+ *timeout = -1;
+ return FALSE;
+}
+
+gboolean check(GSource* source) {
+ return static_cast<GLibXcbSource*>(source)->poll_fd->revents & G_IO_IN;
+}
+
+gboolean dispatch(GSource* source, GSourceFunc callback, gpointer data) {
+ return callback(data);
+}
+
+GSourceFuncs source_funcs {prepare, check, dispatch, nullptr};
+
+} // anonymous namespace
+
+XWindowCacheEventSource::XWindowCacheEventSource(XWindowCache* cache) {
+ DCHECK(!cache->ConnectionHasError());
+ int fd = cache->ConnectionFd();
+
+ GPollFD* poll = new GPollFD();
+ g_poll_.reset(poll);
+ poll->fd = fd;
+ poll->events = G_IO_IN;
+ poll->revents = 0;
+
+ GLibXcbSource* g_source = static_cast<GLibXcbSource*>(
+ g_source_new(&source_funcs, sizeof(GLibXcbSource)));
+ g_source_ = g_source;
+ g_source->poll_fd = poll;
+ g_source_add_poll(g_source, poll);
+ g_source_set_can_recurse(g_source, TRUE);
+ g_source_set_callback(g_source, callback, cache, nullptr);
+ g_source_attach(g_source, g_main_context_default());
+}
+
+XWindowCacheEventSource::~XWindowCacheEventSource() {
+ g_source_destroy(g_source_);
+ g_source_unref(g_source_);
+}
+
+} // namespace ui
« 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