eff04b5ec2
There is still a large amount of views code that could be trimmed down, but which is used to implement samples (in viewer). Seemed simpler to remove some of this code in pieces. Bug: skia: Change-Id: Ia3415060d03c8de604a154e3dc38379b754daab6 Reviewed-on: https://skia-review.googlesource.com/72801 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
95 lines
2.4 KiB
C++
95 lines
2.4 KiB
C++
/*
|
|
|
|
* 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;
|
|
|
|
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);
|
|
|
|
// Get the file descriptor for the X display
|
|
int x11_fd = ConnectionNumber(display);
|
|
int count = x11_fd + 1;
|
|
|
|
SkTHashSet<sk_app::Window_unix*> pendingWindows;
|
|
bool done = false;
|
|
while (!done) {
|
|
// Create a file description set containing x11_fd
|
|
fd_set in_fds;
|
|
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;
|
|
|
|
while (!XPending(display)) {
|
|
// Wait for an event on the file descriptor or for timer expiration
|
|
(void) select(count, &in_fds, nullptr, nullptr, &tv);
|
|
}
|
|
|
|
// Handle XEvents (if any) and flush the input
|
|
int count = XPending(display);
|
|
while (count-- && !done) {
|
|
XEvent event;
|
|
XNextEvent(display, &event);
|
|
|
|
sk_app::Window_unix* win = sk_app::Window_unix::gWindowMap.find(event.xany.window);
|
|
if (!win) {
|
|
continue;
|
|
}
|
|
|
|
// 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) {
|
|
app->onIdle();
|
|
}
|
|
pendingWindows.reset();
|
|
|
|
XFlush(display);
|
|
}
|
|
|
|
delete app;
|
|
|
|
XCloseDisplay(display);
|
|
|
|
return 0;
|
|
}
|