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"
|
2016-06-15 21:23:40 +00:00
|
|
|
#include "VulkanWindowContext.h"
|
2016-04-06 13:08:59 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-06-06 15:48:47 +00:00
|
|
|
static bool default_touch_func(intptr_t owner, Window::InputState state, float x, float y,
|
2016-05-17 19:44:20 +00:00
|
|
|
void* userData) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-27 15:52:52 +00:00
|
|
|
static void default_ui_state_changed_func(
|
|
|
|
const SkString& stateName, const SkString& stateValue, void* userData) {}
|
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
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)
|
2016-05-17 19:44:20 +00:00
|
|
|
, fTouchFunc(default_touch_func)
|
2016-05-27 15:52:52 +00:00
|
|
|
, fUIStateChangedFunc(default_ui_state_changed_func)
|
2016-04-06 13:08:59 +00:00
|
|
|
, fPaintFunc(default_paint_func) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::detach() {
|
2016-05-05 19:32:03 +00:00
|
|
|
delete fWindowContext;
|
|
|
|
fWindowContext = nullptr;
|
2016-04-06 13:08:59 +00:00
|
|
|
}
|
|
|
|
|
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-06-06 15:48:47 +00:00
|
|
|
bool Window::onTouch(intptr_t owner, InputState state, float x, float y) {
|
2016-05-17 19:44:20 +00:00
|
|
|
return fTouchFunc(owner, state, x, y, fTouchUserData);
|
|
|
|
}
|
|
|
|
|
2016-05-27 15:52:52 +00:00
|
|
|
void Window::onUIStateChanged(const SkString& stateName, const SkString& stateValue) {
|
|
|
|
return fUIStateChangedFunc(stateName, stateValue, fUIStateChangedUserData);
|
|
|
|
}
|
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
void Window::onPaint() {
|
2016-05-23 17:52:34 +00:00
|
|
|
markInvalProcessed();
|
2016-05-20 13:01:06 +00:00
|
|
|
sk_sp<SkSurface> backbuffer = fWindowContext->getBackbufferSurface();
|
2016-04-06 13:08:59 +00:00
|
|
|
if (backbuffer) {
|
|
|
|
// draw into the canvas of this surface
|
|
|
|
SkCanvas* canvas = backbuffer->getCanvas();
|
|
|
|
|
|
|
|
fPaintFunc(canvas, fPaintUserData);
|
|
|
|
|
|
|
|
canvas->flush();
|
|
|
|
|
2016-05-05 19:32:03 +00:00
|
|
|
fWindowContext->swapBuffers();
|
2016-04-07 18:09:51 +00:00
|
|
|
} else {
|
2016-05-27 13:47:08 +00:00
|
|
|
printf("no backbuffer!?\n");
|
2016-04-07 18:09:51 +00:00
|
|
|
// 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-05-05 19:32:03 +00:00
|
|
|
fWindowContext->resize(w, h);
|
2016-04-06 13:08:59 +00:00
|
|
|
}
|
2016-05-04 20:49:13 +00:00
|
|
|
|
2016-05-06 20:28:57 +00:00
|
|
|
const DisplayParams& Window::getDisplayParams() {
|
|
|
|
return fWindowContext->getDisplayParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::setDisplayParams(const DisplayParams& params) {
|
|
|
|
fWindowContext->setDisplayParams(params);
|
|
|
|
}
|
|
|
|
|
2016-05-23 17:52:34 +00:00
|
|
|
void Window::inval() {
|
|
|
|
if (!fIsContentInvalidated) {
|
|
|
|
fIsContentInvalidated = true;
|
|
|
|
onInval();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::markInvalProcessed() {
|
|
|
|
fIsContentInvalidated = false;
|
|
|
|
}
|
|
|
|
|
2016-05-04 20:49:13 +00:00
|
|
|
} // namespace sk_app
|