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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkTypes.h"
9 #include "SkTHash.h"
10 #include "Timer.h"
11 #include "Window_unix.h"
12 #include "../Application.h"
13
14 using sk_app::Application;
15
16 static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
17
18 void finishWindow(sk_app::Window_unix* win) {
19 win->finishResize();
20 win->finishPaint();
21 }
22
23 int main(int argc, char**argv) {
24
25 Display* display = XOpenDisplay(nullptr);
26
27 Application* app = Application::Create(argc, argv, (void*)display);
28
29 double currentTime = 0.0;
30 double previousTime = 0.0;
31
32 // Get the file descriptor for the X display
33 int x11_fd = ConnectionNumber(display);
34 fd_set in_fds;
35
36 SkTHashSet<sk_app::Window_unix*> pendingWindows;
37 bool done = false;
38 while (!done) {
39 // Create a file description set containing x11_fd
40 FD_ZERO(&in_fds);
41 FD_SET(x11_fd, &in_fds);
42
43 // Set a sleep timer
44 struct timeval tv;
45 tv.tv_usec = 100;
46 tv.tv_sec = 0;
47
48 // Wait for an event on the file descriptor or for timer expiration
49 (void) select(1, &in_fds, NULL, NULL, &tv);
50
51 // Handle XEvents (if any) and flush the input
52 XEvent event;
53 while (XPending(display) && !done) {
54 XNextEvent(display, &event);
55
56 sk_app::Window_unix* win = sk_app::Window_unix::gWindowMap.find(even t.xany.window);
57 // paint and resize events get collapsed
58 switch (event.type) {
59 case Expose:
60 win->markPendingPaint();
61 pendingWindows.add(win);
62 break;
63 case ConfigureNotify:
64 win->markPendingResize(event.xconfigurerequest.width,
65 event.xconfigurerequest.height);
66 pendingWindows.add(win);
67 break;
68 default:
69 if (win->handleEvent(event)) {
70 done = true;
71 }
72 break;
73 }
74 }
75
76 pendingWindows.foreach(finishWindow);
77 if (pendingWindows.count() > 0) {
78 previousTime = currentTime;
79 currentTime = now_ms();
80 app->onIdle(currentTime - previousTime);
81 }
82 pendingWindows.reset();
83 }
84
85 delete app;
86
87 XCloseDisplay(display);
88
89 return 0;
90 }
OLDNEW
« 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