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

Unified Diff: tools/viewer/sk_app/unix/main_unix.cpp

Issue 1999213002: Add Xlib support to viewer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove viewer hack Created 4 years, 7 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 | « tools/viewer/sk_app/unix/Window_unix.cpp ('k') | tools/viewer/sk_app/win/VulkanWindowContext_win.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/viewer/sk_app/unix/main_unix.cpp
diff --git a/tools/viewer/sk_app/unix/main_unix.cpp b/tools/viewer/sk_app/unix/main_unix.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d5953791746a39a5b9f0d51b1c431313895a1463
--- /dev/null
+++ b/tools/viewer/sk_app/unix/main_unix.cpp
@@ -0,0 +1,90 @@
+/*
+* Copyright 2016 Google Inc.
+*
+* Use of this source code is governed by a BSD-style license that can be
+* found in the LICENSE file.
+*/
+
+#include "SkTypes.h"
+#include "SkTHash.h"
+#include "Timer.h"
+#include "Window_unix.h"
+#include "../Application.h"
+
+using sk_app::Application;
+
+static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
+
+void finishWindow(sk_app::Window_unix* win) {
+ win->finishResize();
+ win->finishPaint();
+}
+
+int main(int argc, char**argv) {
+
+ Display* display = XOpenDisplay(nullptr);
+
+ Application* app = Application::Create(argc, argv, (void*)display);
+
+ double currentTime = 0.0;
+ double previousTime = 0.0;
+
+ // Get the file descriptor for the X display
+ int x11_fd = ConnectionNumber(display);
+ fd_set in_fds;
+
+ SkTHashSet<sk_app::Window_unix*> pendingWindows;
+ bool done = false;
+ while (!done) {
+ // Create a file description set containing x11_fd
+ FD_ZERO(&in_fds);
+ FD_SET(x11_fd, &in_fds);
+
+ // Set a sleep timer
+ struct timeval tv;
+ tv.tv_usec = 100;
+ tv.tv_sec = 0;
+
+ // Wait for an event on the file descriptor or for timer expiration
+ (void) select(1, &in_fds, NULL, NULL, &tv);
+
+ // Handle XEvents (if any) and flush the input
+ XEvent event;
+ while (XPending(display) && !done) {
+ XNextEvent(display, &event);
+
+ sk_app::Window_unix* win = sk_app::Window_unix::gWindowMap.find(event.xany.window);
+ // paint and resize events get collapsed
+ switch (event.type) {
+ case Expose:
+ win->markPendingPaint();
+ pendingWindows.add(win);
+ break;
+ case ConfigureNotify:
+ win->markPendingResize(event.xconfigurerequest.width,
+ event.xconfigurerequest.height);
+ pendingWindows.add(win);
+ break;
+ default:
+ if (win->handleEvent(event)) {
+ done = true;
+ }
+ break;
+ }
+ }
+
+ pendingWindows.foreach(finishWindow);
+ if (pendingWindows.count() > 0) {
+ previousTime = currentTime;
+ currentTime = now_ms();
+ app->onIdle(currentTime - previousTime);
+ }
+ pendingWindows.reset();
+ }
+
+ delete app;
+
+ XCloseDisplay(display);
+
+ return 0;
+}
« no previous file with comments | « tools/viewer/sk_app/unix/Window_unix.cpp ('k') | tools/viewer/sk_app/win/VulkanWindowContext_win.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698