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.
|
|
|
|
*/
|
|
|
|
|
2016-05-04 20:49:13 +00:00
|
|
|
#ifndef Viewer_DEFINED
|
|
|
|
#define Viewer_DEFINED
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-05-05 19:32:03 +00:00
|
|
|
#include "sk_app/Application.h"
|
2016-05-10 13:50:49 +00:00
|
|
|
#include "sk_app/CommandSet.h"
|
2016-05-05 19:32:03 +00:00
|
|
|
#include "sk_app/Window.h"
|
2016-04-06 13:08:59 +00:00
|
|
|
#include "gm.h"
|
2016-04-08 19:51:45 +00:00
|
|
|
#include "SkAnimTimer.h"
|
2016-06-10 14:50:00 +00:00
|
|
|
#include "SkTouchGesture.h"
|
2016-04-08 14:24:09 +00:00
|
|
|
#include "Slide.h"
|
2016-04-06 13:08:59 +00:00
|
|
|
|
|
|
|
class SkCanvas;
|
|
|
|
|
2016-05-04 20:49:13 +00:00
|
|
|
class Viewer : public sk_app::Application {
|
2016-04-06 13:08:59 +00:00
|
|
|
public:
|
2016-05-04 20:49:13 +00:00
|
|
|
Viewer(int argc, char** argv, void* platformData);
|
|
|
|
~Viewer() override;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2017-02-24 20:22:53 +00:00
|
|
|
void onBackendCreated();
|
2016-04-06 13:08:59 +00:00
|
|
|
void onPaint(SkCanvas* canvas);
|
2016-07-06 21:11:32 +00:00
|
|
|
void onIdle() override;
|
2016-06-06 15:48:47 +00:00
|
|
|
bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y);
|
2017-05-04 18:00:59 +00:00
|
|
|
bool onMouse(float x, float y, sk_app::Window::InputState state, uint32_t modifiers);
|
2016-05-27 15:52:52 +00:00
|
|
|
void onUIStateChanged(const SkString& stateName, const SkString& stateValue);
|
Integrate the ImGui library with viewer
Code and docs are at: https://github.com/ocornut/imgui
ImGui is an open source immediate mode GUI library that's
lightweight and fairly simply to integrate. Widget functions
return their state, and the library emits vertex and index
data to render everything. It's got a huge set of built-in
widgets and really robust layout control.
For the initial integration, I had to fix up event handling
in the viewer's app framework (to get mouse wheel and more
keys, etc...).
The new viewer 'Debug' window is toggled with the space bar.
For this change, I've added one feature to that window: the
slide picker. It's got a list of all slides, with filtering
support, and the ability to click to switch slides.
I also included the ImGui 'Demo' window (toggled with 'g').
This is nicely laid out, and includes examples of pretty
much everything the library can do. It also serves as good
documentation - find something that looks like what you want,
and then go look at the corresponding code (all of it is in
imgui_demo.cpp).
I have other CLs with other features (like directly editing
the primaries of the working color space), but I wanted to
land this chunk first, then start adding more features.
Other than adding new debugging features, there are few
more outstanding work items:
1) Raster doesn't render the GUI correctly, due to non-
invertible pos -> UV matrices. Florin is working on that.
2) Touch inputs aren't being routed yet, so the GUI isn't
usable on Android yet. Might also be tough to work with,
given the size.
3) ImGui has clipboard integration (that's why it wants
the C, X, and V keys), but we need to wire it up to the
OS' clipboard functions.
4) Draw commands can carry a void* payload to support
drawing images (using whatever mechanism the engine has).
I'd like to set that up (probably using SkImage*), which
makes it really easy to add visualization of off-screen
images in GMs, etc...
BUG=skia:
Change-Id: Iac2a63e37228d33141cb55b7e4d60bf11b7e9ae1
Reviewed-on: https://skia-review.googlesource.com/7702
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-02-10 18:36:16 +00:00
|
|
|
bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers);
|
|
|
|
bool onChar(SkUnichar c, uint32_t modifiers);
|
2016-04-06 13:08:59 +00:00
|
|
|
|
|
|
|
private:
|
2017-03-06 16:47:26 +00:00
|
|
|
enum class ColorMode {
|
|
|
|
kLegacy, // N32, no color management
|
|
|
|
kColorManagedSRGB8888_NonLinearBlending, // N32, sRGB transfer function, nonlinear blending
|
|
|
|
kColorManagedSRGB8888, // N32, sRGB transfer function, linear blending
|
|
|
|
kColorManagedLinearF16, // F16, linear transfer function, linear blending
|
|
|
|
};
|
|
|
|
|
2016-04-08 14:24:09 +00:00
|
|
|
void initSlides();
|
2016-05-06 20:28:57 +00:00
|
|
|
void updateTitle();
|
2017-02-28 20:45:01 +00:00
|
|
|
void setBackend(sk_app::Window::BackendType);
|
2017-03-06 16:47:26 +00:00
|
|
|
void setColorMode(ColorMode);
|
2017-02-14 20:16:46 +00:00
|
|
|
void setStartupSlide();
|
2016-04-08 19:51:45 +00:00
|
|
|
void setupCurrentSlide(int previousSlide);
|
2017-02-14 20:16:46 +00:00
|
|
|
void listNames();
|
2017-11-03 17:36:07 +00:00
|
|
|
void resetMeasurements();
|
2016-04-08 14:24:09 +00:00
|
|
|
|
2016-05-27 15:52:52 +00:00
|
|
|
void updateUIState();
|
|
|
|
|
2017-02-08 15:47:28 +00:00
|
|
|
void drawSlide(SkCanvas* canvs);
|
2016-04-07 18:09:51 +00:00
|
|
|
void drawStats(SkCanvas* canvas);
|
Integrate the ImGui library with viewer
Code and docs are at: https://github.com/ocornut/imgui
ImGui is an open source immediate mode GUI library that's
lightweight and fairly simply to integrate. Widget functions
return their state, and the library emits vertex and index
data to render everything. It's got a huge set of built-in
widgets and really robust layout control.
For the initial integration, I had to fix up event handling
in the viewer's app framework (to get mouse wheel and more
keys, etc...).
The new viewer 'Debug' window is toggled with the space bar.
For this change, I've added one feature to that window: the
slide picker. It's got a list of all slides, with filtering
support, and the ability to click to switch slides.
I also included the ImGui 'Demo' window (toggled with 'g').
This is nicely laid out, and includes examples of pretty
much everything the library can do. It also serves as good
documentation - find something that looks like what you want,
and then go look at the corresponding code (all of it is in
imgui_demo.cpp).
I have other CLs with other features (like directly editing
the primaries of the working color space), but I wanted to
land this chunk first, then start adding more features.
Other than adding new debugging features, there are few
more outstanding work items:
1) Raster doesn't render the GUI correctly, due to non-
invertible pos -> UV matrices. Florin is working on that.
2) Touch inputs aren't being routed yet, so the GUI isn't
usable on Android yet. Might also be tough to work with,
given the size.
3) ImGui has clipboard integration (that's why it wants
the C, X, and V keys), but we need to wire it up to the
OS' clipboard functions.
4) Draw commands can carry a void* payload to support
drawing images (using whatever mechanism the engine has).
I'd like to set that up (probably using SkImage*), which
makes it really easy to add visualization of off-screen
images in GMs, etc...
BUG=skia:
Change-Id: Iac2a63e37228d33141cb55b7e4d60bf11b7e9ae1
Reviewed-on: https://skia-review.googlesource.com/7702
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-02-10 18:36:16 +00:00
|
|
|
void drawImGui(SkCanvas* canvas);
|
2016-04-07 18:09:51 +00:00
|
|
|
|
2016-04-08 19:51:45 +00:00
|
|
|
void changeZoomLevel(float delta);
|
2016-05-17 19:44:20 +00:00
|
|
|
SkMatrix computeMatrix();
|
2016-04-08 19:51:45 +00:00
|
|
|
|
2016-05-04 20:49:13 +00:00
|
|
|
sk_app::Window* fWindow;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2017-11-03 17:36:07 +00:00
|
|
|
static const int kMeasurementCount = 1 << 6; // should be power of 2 for fast mod
|
2017-02-09 17:10:20 +00:00
|
|
|
double fPaintTimes[kMeasurementCount];
|
|
|
|
double fFlushTimes[kMeasurementCount];
|
|
|
|
double fAnimateTimes[kMeasurementCount];
|
2016-04-07 18:09:51 +00:00
|
|
|
int fCurrentMeasurement;
|
2017-11-03 17:36:07 +00:00
|
|
|
double fCumulativeMeasurementTime;
|
|
|
|
int fCumulativeMeasurementCount;
|
2016-04-07 18:09:51 +00:00
|
|
|
|
2016-04-08 19:51:45 +00:00
|
|
|
SkAnimTimer fAnimTimer;
|
2016-04-08 14:24:09 +00:00
|
|
|
SkTArray<sk_sp<Slide>> fSlides;
|
|
|
|
int fCurrentSlide;
|
2016-04-08 19:51:45 +00:00
|
|
|
|
|
|
|
bool fDisplayStats;
|
2016-07-06 21:11:32 +00:00
|
|
|
bool fRefresh; // whether to continuously refresh for measuring render time
|
2016-04-08 19:51:45 +00:00
|
|
|
|
2017-02-13 14:39:57 +00:00
|
|
|
SkPaint fImGuiFontPaint;
|
2017-02-24 14:49:14 +00:00
|
|
|
SkPaint fImGuiGamutPaint;
|
Integrate the ImGui library with viewer
Code and docs are at: https://github.com/ocornut/imgui
ImGui is an open source immediate mode GUI library that's
lightweight and fairly simply to integrate. Widget functions
return their state, and the library emits vertex and index
data to render everything. It's got a huge set of built-in
widgets and really robust layout control.
For the initial integration, I had to fix up event handling
in the viewer's app framework (to get mouse wheel and more
keys, etc...).
The new viewer 'Debug' window is toggled with the space bar.
For this change, I've added one feature to that window: the
slide picker. It's got a list of all slides, with filtering
support, and the ability to click to switch slides.
I also included the ImGui 'Demo' window (toggled with 'g').
This is nicely laid out, and includes examples of pretty
much everything the library can do. It also serves as good
documentation - find something that looks like what you want,
and then go look at the corresponding code (all of it is in
imgui_demo.cpp).
I have other CLs with other features (like directly editing
the primaries of the working color space), but I wanted to
land this chunk first, then start adding more features.
Other than adding new debugging features, there are few
more outstanding work items:
1) Raster doesn't render the GUI correctly, due to non-
invertible pos -> UV matrices. Florin is working on that.
2) Touch inputs aren't being routed yet, so the GUI isn't
usable on Android yet. Might also be tough to work with,
given the size.
3) ImGui has clipboard integration (that's why it wants
the C, X, and V keys), but we need to wire it up to the
OS' clipboard functions.
4) Draw commands can carry a void* payload to support
drawing images (using whatever mechanism the engine has).
I'd like to set that up (probably using SkImage*), which
makes it really easy to add visualization of off-screen
images in GMs, etc...
BUG=skia:
Change-Id: Iac2a63e37228d33141cb55b7e4d60bf11b7e9ae1
Reviewed-on: https://skia-review.googlesource.com/7702
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-02-10 18:36:16 +00:00
|
|
|
bool fShowImGuiDebugWindow;
|
|
|
|
bool fShowImGuiTestWindow;
|
|
|
|
|
2017-02-13 14:39:57 +00:00
|
|
|
bool fShowZoomWindow;
|
|
|
|
sk_sp<SkImage> fLastImage;
|
|
|
|
|
2016-05-20 13:01:06 +00:00
|
|
|
sk_app::Window::BackendType fBackendType;
|
|
|
|
|
2017-02-08 15:47:28 +00:00
|
|
|
// Color properties for slide rendering
|
2017-03-06 16:47:26 +00:00
|
|
|
ColorMode fColorMode;
|
2017-02-24 14:49:14 +00:00
|
|
|
SkColorSpacePrimaries fColorSpacePrimaries;
|
2017-02-08 15:47:28 +00:00
|
|
|
|
2016-04-08 19:51:45 +00:00
|
|
|
// transform data
|
|
|
|
SkScalar fZoomLevel;
|
|
|
|
|
2016-05-10 13:50:49 +00:00
|
|
|
sk_app::CommandSet fCommands;
|
2016-05-17 19:44:20 +00:00
|
|
|
|
2017-06-07 14:00:30 +00:00
|
|
|
enum class GestureDevice {
|
|
|
|
kNone,
|
|
|
|
kTouch,
|
|
|
|
kMouse,
|
|
|
|
};
|
|
|
|
|
2016-05-17 19:44:20 +00:00
|
|
|
SkTouchGesture fGesture;
|
2017-06-07 14:00:30 +00:00
|
|
|
GestureDevice fGestureDevice;
|
2016-05-20 14:32:19 +00:00
|
|
|
|
|
|
|
// identity unless the window initially scales the content to fit the screen.
|
|
|
|
SkMatrix fDefaultMatrix;
|
2016-06-07 13:57:40 +00:00
|
|
|
|
2017-02-24 16:57:23 +00:00
|
|
|
SkTArray<std::function<void(void)>> fDeferredActions;
|
|
|
|
|
2016-06-07 13:57:40 +00:00
|
|
|
Json::Value fAllSlideNames; // cache all slide names for fast updateUIState
|
2016-04-06 13:08:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|