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

Side by Side Diff: tools/viewer/sk_app/mac/main_mac.cpp

Issue 2167503002: Stub in Mac viewer code. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Exclude Mac files from other Viewer builds Created 4 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
« no previous file with comments | « tools/viewer/sk_app/mac/Window_mac.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkTypes.h" 8 #include "SkTypes.h"
9 #include "SkTHash.h" 9 #include "SkTHash.h"
10 #include "Timer.h" 10 #include "Timer.h"
11 #include "Window_unix.h" 11 #include "Window_mac.h"
12 #include "../Application.h" 12 #include "../Application.h"
13 13
14 using sk_app::Application; 14 using sk_app::Application;
15 15
16 void finishWindow(sk_app::Window_unix* win) {
17 win->finishResize();
18 win->finishPaint();
19 }
20
21 int main(int argc, char**argv) { 16 int main(int argc, char**argv) {
17 #if 0
18 // TODO: use Mac main loop
22 19
23 Display* display = XOpenDisplay(nullptr); 20 Display* display = XOpenDisplay(nullptr);
24 21
25 Application* app = Application::Create(argc, argv, (void*)display); 22 Application* app = Application::Create(argc, argv, (void*)display);
26 23
27 // Get the file descriptor for the X display 24 // Get the file descriptor for the X display
28 int x11_fd = ConnectionNumber(display); 25 int x11_fd = ConnectionNumber(display);
29 fd_set in_fds; 26 fd_set in_fds;
30 27
31 SkTHashSet<sk_app::Window_unix*> pendingWindows; 28 SkTHashSet<sk_app::Window_mac*> pendingWindows;
32 bool done = false; 29 bool done = false;
33 while (!done) { 30 while (!done) {
34 // Create a file description set containing x11_fd 31 // Create a file description set containing x11_fd
35 FD_ZERO(&in_fds); 32 FD_ZERO(&in_fds);
36 FD_SET(x11_fd, &in_fds); 33 FD_SET(x11_fd, &in_fds);
37 34
38 // Set a sleep timer 35 // Set a sleep timer
39 struct timeval tv; 36 struct timeval tv;
40 tv.tv_usec = 100; 37 tv.tv_usec = 100;
41 tv.tv_sec = 0; 38 tv.tv_sec = 0;
42 39
43 // Wait for an event on the file descriptor or for timer expiration 40 // Wait for an event on the file descriptor or for timer expiration
44 (void) select(1, &in_fds, NULL, NULL, &tv); 41 (void) select(1, &in_fds, NULL, NULL, &tv);
45 42
46 // Handle XEvents (if any) and flush the input 43 // Handle XEvents (if any) and flush the input
47 XEvent event; 44 XEvent event;
48 while (XPending(display) && !done) { 45 while (XPending(display) && !done) {
49 XNextEvent(display, &event); 46 XNextEvent(display, &event);
50 47
51 sk_app::Window_unix* win = sk_app::Window_unix::gWindowMap.find(even t.xany.window); 48 sk_app::Window_mac* win = sk_app::Window_mac::gWindowMap.find(event. xany.window);
52 // paint and resize events get collapsed 49 // paint and resize events get collapsed
53 switch (event.type) { 50 switch (event.type) {
54 case Expose: 51 case Expose:
55 win->markPendingPaint(); 52 win->markPendingPaint();
56 pendingWindows.add(win); 53 pendingWindows.add(win);
57 break; 54 break;
58 case ConfigureNotify: 55 case ConfigureNotify:
59 win->markPendingResize(event.xconfigurerequest.width, 56 win->markPendingResize(event.xconfigurerequest.width,
60 event.xconfigurerequest.height); 57 event.xconfigurerequest.height);
61 pendingWindows.add(win); 58 pendingWindows.add(win);
62 break; 59 break;
63 default: 60 default:
64 if (win->handleEvent(event)) { 61 if (win->handleEvent(event)) {
65 done = true; 62 done = true;
66 } 63 }
67 break; 64 break;
68 } 65 }
69 } 66 }
70
71 pendingWindows.foreach(finishWindow);
72 if (pendingWindows.count() > 0) {
73 app->onIdle();
74 }
75 pendingWindows.reset();
76 } 67 }
77 68
78 delete app; 69 delete app;
79 70
80 XCloseDisplay(display); 71 XCloseDisplay(display);
81 72 #endif
73
82 return 0; 74 return 0;
83 } 75 }
OLDNEW
« no previous file with comments | « tools/viewer/sk_app/mac/Window_mac.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698