| Index: tools/vulkan/VulkanViewer.cpp
|
| diff --git a/tools/vulkan/VulkanViewer.cpp b/tools/vulkan/VulkanViewer.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f08283f2956e529fae5ef87b50df35f4ddbbbfa1
|
| --- /dev/null
|
| +++ b/tools/vulkan/VulkanViewer.cpp
|
| @@ -0,0 +1,89 @@
|
| +/*
|
| +* 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 "VulkanViewer.h"
|
| +
|
| +#include "SkCanvas.h"
|
| +#include "SkRandom.h"
|
| +
|
| +Application* Application::Create(int argc, char** argv, void* platformData) {
|
| + return new VulkanViewer(argc, argv, platformData);
|
| +}
|
| +
|
| +static bool on_key_handler(int key, bool keyDown, void* userData) {
|
| + VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData);
|
| +
|
| + return vv->onKey(key, keyDown);
|
| +}
|
| +
|
| +static bool on_mouse_handler(int x, int y, bool mouseDown, void* userData) {
|
| + VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData);
|
| +
|
| + return vv->onMouse(x, y, mouseDown);
|
| +}
|
| +
|
| +static void on_paint_handler(SkCanvas* canvas, void* userData) {
|
| + VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData);
|
| +
|
| + return vv->onPaint(canvas);
|
| +}
|
| +
|
| +VulkanViewer::VulkanViewer(int argc, char** argv, void* platformData) {
|
| + fWindow = Window::CreateNativeWindow(platformData);
|
| + fWindow->attach(Window::kVulkan_BackendType, 0, nullptr);
|
| +
|
| + // register callbacks
|
| + fWindow->registerKeyFunc(on_key_handler, this);
|
| + fWindow->registerMouseFunc(on_mouse_handler, this);
|
| + fWindow->registerPaintFunc(on_paint_handler, this);
|
| +
|
| + fWindow->setTitle("VulkanViewer");
|
| + fWindow->show();
|
| +}
|
| +
|
| +VulkanViewer::~VulkanViewer() {
|
| + fWindow->release();
|
| + delete fWindow;
|
| +}
|
| +
|
| +bool VulkanViewer::onKey(int key, bool keyDown) {
|
| + return false;
|
| +}
|
| +
|
| +bool VulkanViewer::onMouse(int x, int y, bool mouseDown) {
|
| + return false;
|
| +}
|
| +
|
| +void VulkanViewer::onPaint(SkCanvas* canvas) {
|
| + canvas->scale(20, 20);
|
| + canvas->translate(13, 13);
|
| +
|
| + SkPaint paint;
|
| + paint.setAntiAlias(true);
|
| + paint.setStyle(SkPaint::kStroke_Style);
|
| + paint.setStrokeWidth(SK_Scalar1 / 2);
|
| +
|
| + const SkScalar delta = paint.getStrokeWidth() * 3 / 2;
|
| + SkRect r = SkRect::MakeXYWH(-12, -12, 24, 24);
|
| + SkRandom rand;
|
| +
|
| + SkScalar sign = 1;
|
| + while (r.width() > paint.getStrokeWidth() * 2) {
|
| + SkAutoCanvasRestore acr(canvas, true);
|
| + // canvas->rotate(fRotate * sign);
|
| +
|
| + paint.setColor(rand.nextU() | (0xFF << 24));
|
| + canvas->drawOval(r, paint);
|
| + r.inset(delta, delta);
|
| + sign = -sign;
|
| + }
|
| +
|
| +}
|
| +
|
| +void VulkanViewer::onIdle(float dt) {
|
| + fWindow->onPaint();
|
| +}
|
|
|