Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: tools/vulkan/VulkanViewer.cpp

Issue 1848833005: First pass at VulkanViewer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Revise setup and event handling Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
bsalomon 2016/04/05 14:24:43 Would it make since to put everything related to t
jvanverth1 2016/04/05 18:16:49 Done.
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 "VulkanViewer.h"
9
10 #include "SkCanvas.h"
11 #include "SkRandom.h"
12
13 Application* Application::Create(int argc, char** argv, void* platformData) {
14 return new VulkanViewer(argc, argv, platformData);
15 }
16
17 static bool on_key_handler(int key, bool keyDown, void* userData) {
18 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData);
19
20 return vv->onKey(key, keyDown);
21 }
22
23 static bool on_mouse_handler(int x, int y, bool mouseDown, void* userData) {
24 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData);
25
26 return vv->onMouse(x, y, mouseDown);
27 }
28
29 static void on_paint_handler(SkCanvas* canvas, void* userData) {
30 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData);
31
32 return vv->onPaint(canvas);
33 }
34
35 VulkanViewer::VulkanViewer(int argc, char** argv, void* platformData) {
36 fWindow = Window::CreateNativeWindow(platformData);
37 fWindow->attach(Window::kVulkan_BackendType, 0, nullptr);
38
39 // register callbacks
40 fWindow->registerKeyFunc(on_key_handler, this);
41 fWindow->registerMouseFunc(on_mouse_handler, this);
42 fWindow->registerPaintFunc(on_paint_handler, this);
43
44 fWindow->setTitle("VulkanViewer");
45 fWindow->show();
46 }
47
48 VulkanViewer::~VulkanViewer() {
49 fWindow->release();
50 delete fWindow;
51 }
52
53 bool VulkanViewer::onKey(int key, bool keyDown) {
54 return false;
55 }
56
57 bool VulkanViewer::onMouse(int x, int y, bool mouseDown) {
58 return false;
59 }
60
61 void VulkanViewer::onPaint(SkCanvas* canvas) {
62 canvas->scale(20, 20);
63 canvas->translate(13, 13);
64
65 SkPaint paint;
66 paint.setAntiAlias(true);
67 paint.setStyle(SkPaint::kStroke_Style);
68 paint.setStrokeWidth(SK_Scalar1 / 2);
69
70 const SkScalar delta = paint.getStrokeWidth() * 3 / 2;
71 SkRect r = SkRect::MakeXYWH(-12, -12, 24, 24);
72 SkRandom rand;
73
74 SkScalar sign = 1;
75 while (r.width() > paint.getStrokeWidth() * 2) {
76 SkAutoCanvasRestore acr(canvas, true);
77 // canvas->rotate(fRotate * sign);
78
79 paint.setColor(rand.nextU() | (0xFF << 24));
80 canvas->drawOval(r, paint);
81 r.inset(delta, delta);
82 sign = -sign;
83 }
84
85 }
86
87 void VulkanViewer::onIdle(float dt) {
88 fWindow->onPaint();
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698