blob: 86f181496da42cd9488a0af441055ac49367475a [file] [log] [blame]
jvanverth9f372462016-04-06 06:08:59 -07001/*
2* Copyright 2016 Google Inc.
3*
4* Use of this source code is governed by a BSD-style license that can be
5* found in the LICENSE file.
6*/
7
8#include "Window.h"
9
10#include "SkSurface.h"
11#include "SkCanvas.h"
12#include "VulkanTestContext.h"
13
jvanverth9fab59d2016-04-06 12:08:51 -070014static bool default_char_func(SkUnichar c, uint32_t modifiers, void* userData) {
jvanverth9f372462016-04-06 06:08:59 -070015 return false;
16}
17
jvanverth9fab59d2016-04-06 12:08:51 -070018static bool default_key_func(Window::Key key, Window::InputState state, uint32_t modifiers,
19 void* userData) {
20 return false;
21}
22
23static bool default_mouse_func(int x, int y, Window::InputState state, uint32_t modifiers,
24 void* userData) {
jvanverth9f372462016-04-06 06:08:59 -070025 return false;
26}
27
28static void default_paint_func(SkCanvas*, void* userData) {}
29
jvanverth9fab59d2016-04-06 12:08:51 -070030Window::Window() : fCharFunc(default_char_func)
31 , fKeyFunc(default_key_func)
jvanverth9f372462016-04-06 06:08:59 -070032 , fMouseFunc(default_mouse_func)
33 , fPaintFunc(default_paint_func) {
34}
35
36void Window::detach() {
37 delete fTestContext;
38 fTestContext = nullptr;
39}
40
jvanverth9fab59d2016-04-06 12:08:51 -070041bool Window::onChar(SkUnichar c, uint32_t modifiers) {
42 return fCharFunc(c, modifiers, fCharUserData);
43}
44
45bool Window::onKey(Key key, InputState state, uint32_t modifiers) {
46 return fKeyFunc(key, state, modifiers, fKeyUserData);
47}
48
49bool Window::onMouse(int x, int y, InputState state, uint32_t modifiers) {
50 return fMouseFunc(x, y, state, modifiers, fMouseUserData);
51}
52
jvanverth9f372462016-04-06 06:08:59 -070053void Window::onPaint() {
54 SkSurface* backbuffer = fTestContext->getBackbufferSurface();
55 if (backbuffer) {
56 // draw into the canvas of this surface
57 SkCanvas* canvas = backbuffer->getCanvas();
58
59 fPaintFunc(canvas, fPaintUserData);
60
61 canvas->flush();
62
63 fTestContext->swapBuffers();
64 }
65
66}
67
68
jvanverth9fab59d2016-04-06 12:08:51 -070069void Window::onResize(uint32_t w, uint32_t h) {
70 fTestContext->resize(w, h);
jvanverth9f372462016-04-06 06:08:59 -070071}