Index: tools/viewer/sk_app/mac/main_mac.cpp |
diff --git a/tools/viewer/sk_app/mac/main_mac.cpp b/tools/viewer/sk_app/mac/main_mac.cpp |
index 94bc99e01e7f564353d8fdb29ebd050becd6949e..c7040b5adb6383b73efc44e8701953110ea6054c 100644 |
--- a/tools/viewer/sk_app/mac/main_mac.cpp |
+++ b/tools/viewer/sk_app/mac/main_mac.cpp |
@@ -7,69 +7,50 @@ |
#include "SkTypes.h" |
#include "SkTHash.h" |
+#include "SDL.h" |
#include "Timer.h" |
#include "Window_mac.h" |
#include "../Application.h" |
using sk_app::Application; |
-int main(int argc, char**argv) { |
-#if 0 |
- // TODO: use Mac main loop |
- |
- Display* display = XOpenDisplay(nullptr); |
- |
- Application* app = Application::Create(argc, argv, (void*)display); |
+int main(int argc, char* argv[]) { |
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) { |
+ SkDebugf("Could not initialize SDL!\n"); |
+ return 1; |
+ } |
- // Get the file descriptor for the X display |
- int x11_fd = ConnectionNumber(display); |
- fd_set in_fds; |
+ Application* app = Application::Create(argc, argv, nullptr); |
- SkTHashSet<sk_app::Window_mac*> pendingWindows; |
+ SDL_Event event; |
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_mac* win = sk_app::Window_mac::gWindowMap.find(event.xany.window); |
- // paint and resize events get collapsed |
+ while (SDL_PollEvent(&event)) { |
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)) { |
+ // events handled by the windows |
+ case SDL_WINDOWEVENT: |
+ case SDL_MOUSEMOTION: |
+ case SDL_MOUSEBUTTONDOWN: |
+ case SDL_MOUSEBUTTONUP: |
+ case SDL_KEYDOWN: |
+ case SDL_KEYUP: |
+ done = sk_app::Window_mac::HandleWindowEvent(event); |
+ break; |
+ |
+ case SDL_QUIT: |
done = true; |
- } |
- break; |
- } |
+ break; |
+ |
+ default: |
+ break; |
+ } |
} |
- } |
+ app->onIdle(); |
+ } |
delete app; |
- XCloseDisplay(display); |
-#endif |
- |
+ SDL_Quit(); |
+ |
return 0; |
} |