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

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

Issue 2210603003: Get Mac viewer working with SDL (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix patch 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 | « 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 "SDL.h"
10 #include "Timer.h" 11 #include "Timer.h"
11 #include "Window_mac.h" 12 #include "Window_mac.h"
12 #include "../Application.h" 13 #include "../Application.h"
13 14
14 using sk_app::Application; 15 using sk_app::Application;
15 16
16 int main(int argc, char**argv) { 17 int main(int argc, char* argv[]) {
17 #if 0 18 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) {
18 // TODO: use Mac main loop 19 SkDebugf("Could not initialize SDL!\n");
20 return 1;
21 }
19 22
20 Display* display = XOpenDisplay(nullptr); 23 Application* app = Application::Create(argc, argv, nullptr);
21 24
22 Application* app = Application::Create(argc, argv, (void*)display); 25 SDL_Event event;
23
24 // Get the file descriptor for the X display
25 int x11_fd = ConnectionNumber(display);
26 fd_set in_fds;
27
28 SkTHashSet<sk_app::Window_mac*> pendingWindows;
29 bool done = false; 26 bool done = false;
30 while (!done) { 27 while (!done) {
31 // Create a file description set containing x11_fd 28 while (SDL_PollEvent(&event)) {
32 FD_ZERO(&in_fds); 29 switch (event.type) {
33 FD_SET(x11_fd, &in_fds); 30 // events handled by the windows
31 case SDL_WINDOWEVENT:
32 case SDL_MOUSEMOTION:
33 case SDL_MOUSEBUTTONDOWN:
34 case SDL_MOUSEBUTTONUP:
35 case SDL_KEYDOWN:
36 case SDL_KEYUP:
37 done = sk_app::Window_mac::HandleWindowEvent(event);
38 break;
39
40 case SDL_QUIT:
41 done = true;
42 break;
43
44 default:
45 break;
46 }
47 }
34 48
35 // Set a sleep timer 49 app->onIdle();
36 struct timeval tv;
37 tv.tv_usec = 100;
38 tv.tv_sec = 0;
39
40 // Wait for an event on the file descriptor or for timer expiration
41 (void) select(1, &in_fds, NULL, NULL, &tv);
42
43 // Handle XEvents (if any) and flush the input
44 XEvent event;
45 while (XPending(display) && !done) {
46 XNextEvent(display, &event);
47
48 sk_app::Window_mac* win = sk_app::Window_mac::gWindowMap.find(event. xany.window);
49 // paint and resize events get collapsed
50 switch (event.type) {
51 case Expose:
52 win->markPendingPaint();
53 pendingWindows.add(win);
54 break;
55 case ConfigureNotify:
56 win->markPendingResize(event.xconfigurerequest.width,
57 event.xconfigurerequest.height);
58 pendingWindows.add(win);
59 break;
60 default:
61 if (win->handleEvent(event)) {
62 done = true;
63 }
64 break;
65 }
66 }
67 } 50 }
68
69 delete app; 51 delete app;
70 52
71 XCloseDisplay(display); 53 SDL_Quit();
72 #endif 54
73
74 return 0; 55 return 0;
75 } 56 }
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