2016-04-06 13:08:59 +00:00
|
|
|
/*
|
|
|
|
* 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 "Window.h"
|
|
|
|
|
|
|
|
#include "SkSurface.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "VulkanTestContext.h"
|
|
|
|
|
2016-05-04 20:49:13 +00:00
|
|
|
namespace sk_app {
|
|
|
|
|
2016-04-06 19:08:51 +00:00
|
|
|
static bool default_char_func(SkUnichar c, uint32_t modifiers, void* userData) {
|
2016-04-06 13:08:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-06 19:08:51 +00:00
|
|
|
static bool default_key_func(Window::Key key, Window::InputState state, uint32_t modifiers,
|
|
|
|
void* userData) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool default_mouse_func(int x, int y, Window::InputState state, uint32_t modifiers,
|
|
|
|
void* userData) {
|
2016-04-06 13:08:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void default_paint_func(SkCanvas*, void* userData) {}
|
|
|
|
|
2016-04-06 19:08:51 +00:00
|
|
|
Window::Window() : fCharFunc(default_char_func)
|
|
|
|
, fKeyFunc(default_key_func)
|
2016-04-06 13:08:59 +00:00
|
|
|
, fMouseFunc(default_mouse_func)
|
|
|
|
, fPaintFunc(default_paint_func) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::detach() {
|
|
|
|
delete fTestContext;
|
|
|
|
fTestContext = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-06 19:08:51 +00:00
|
|
|
bool Window::onChar(SkUnichar c, uint32_t modifiers) {
|
|
|
|
return fCharFunc(c, modifiers, fCharUserData);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::onKey(Key key, InputState state, uint32_t modifiers) {
|
|
|
|
return fKeyFunc(key, state, modifiers, fKeyUserData);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::onMouse(int x, int y, InputState state, uint32_t modifiers) {
|
|
|
|
return fMouseFunc(x, y, state, modifiers, fMouseUserData);
|
|
|
|
}
|
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
void Window::onPaint() {
|
|
|
|
SkSurface* backbuffer = fTestContext->getBackbufferSurface();
|
|
|
|
if (backbuffer) {
|
|
|
|
// draw into the canvas of this surface
|
|
|
|
SkCanvas* canvas = backbuffer->getCanvas();
|
|
|
|
|
|
|
|
fPaintFunc(canvas, fPaintUserData);
|
|
|
|
|
|
|
|
canvas->flush();
|
|
|
|
|
|
|
|
fTestContext->swapBuffers();
|
2016-04-07 18:09:51 +00:00
|
|
|
} else {
|
|
|
|
// try recreating testcontext
|
2016-04-06 13:08:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-04-06 19:08:51 +00:00
|
|
|
void Window::onResize(uint32_t w, uint32_t h) {
|
2016-04-08 19:51:45 +00:00
|
|
|
fWidth = w;
|
|
|
|
fHeight = h;
|
2016-04-06 19:08:51 +00:00
|
|
|
fTestContext->resize(w, h);
|
2016-04-06 13:08:59 +00:00
|
|
|
}
|
2016-05-04 20:49:13 +00:00
|
|
|
|
|
|
|
} // namespace sk_app
|