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"
|
2017-12-08 21:46:09 +00:00
|
|
|
#include "ImGuiLayer.h"
|
2016-04-08 19:51:45 +00:00
|
|
|
#include "SkAnimTimer.h"
|
2017-11-22 17:07:41 +00:00
|
|
|
#include "SkExecutor.h"
|
2018-04-17 15:16:32 +00:00
|
|
|
#include "SkScan.h"
|
2016-04-08 14:24:09 +00:00
|
|
|
#include "Slide.h"
|
2017-12-19 16:15:16 +00:00
|
|
|
#include "StatsLayer.h"
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "TouchGesture.h"
|
2016-04-06 13:08:59 +00:00
|
|
|
|
|
|
|
class SkCanvas;
|
|
|
|
|
2017-12-08 21:45:43 +00:00
|
|
|
class Viewer : public sk_app::Application, sk_app::Window::Layer {
|
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
|
|
|
|
2016-07-06 21:11:32 +00:00
|
|
|
void onIdle() override;
|
2017-12-08 21:45:43 +00:00
|
|
|
|
|
|
|
void onBackendCreated() override;
|
|
|
|
void onPaint(SkCanvas* canvas) override;
|
2018-08-09 19:06:19 +00:00
|
|
|
void onResize(int width, int height) override;
|
2017-12-08 21:45:43 +00:00
|
|
|
bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y) override;
|
|
|
|
bool onMouse(int x, int y, sk_app::Window::InputState state, uint32_t modifiers) override;
|
|
|
|
void onUIStateChanged(const SkString& stateName, const SkString& stateValue) override;
|
|
|
|
bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers) override;
|
|
|
|
bool onChar(SkUnichar c, uint32_t modifiers) override;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2018-02-12 21:37:28 +00:00
|
|
|
struct SkPaintFields {
|
|
|
|
bool fTypeface = false;
|
|
|
|
bool fPathEffect = false;
|
|
|
|
bool fShader = false;
|
|
|
|
bool fMaskFilter = false;
|
|
|
|
bool fColorFilter = false;
|
|
|
|
bool fDrawLooper = false;
|
|
|
|
bool fImageFilter = false;
|
|
|
|
|
|
|
|
bool fTextSize = false;
|
2018-06-07 21:54:07 +00:00
|
|
|
SkScalar fTextSizeRange[2] = { 0, 20 };
|
2018-02-12 21:37:28 +00:00
|
|
|
bool fTextScaleX = false;
|
|
|
|
bool fTextSkewX = false;
|
|
|
|
bool fColor = false;
|
|
|
|
bool fWidth = false;
|
|
|
|
bool fMiterLimit = false;
|
|
|
|
bool fBlendMode = false;
|
|
|
|
|
|
|
|
uint32_t fFlags = 0;
|
|
|
|
enum class AntiAliasState {
|
|
|
|
Alias,
|
|
|
|
Normal,
|
|
|
|
AnalyticAAEnabled,
|
|
|
|
AnalyticAAForced,
|
|
|
|
DeltaAAEnabled,
|
|
|
|
DeltaAAForced,
|
|
|
|
} fAntiAlias = AntiAliasState::Alias;
|
2018-04-17 15:16:32 +00:00
|
|
|
const bool fOriginalSkUseAnalyticAA = gSkUseAnalyticAA;
|
|
|
|
const bool fOriginalSkForceAnalyticAA = gSkForceAnalyticAA;
|
|
|
|
const bool fOriginalSkUseDeltaAA = gSkUseDeltaAA;
|
|
|
|
const bool fOriginalSkForceDeltaAA = gSkForceDeltaAA;
|
2018-02-12 21:37:28 +00:00
|
|
|
|
|
|
|
bool fTextAlign = false;
|
|
|
|
bool fCapType = false;
|
|
|
|
bool fJoinType = false;
|
|
|
|
bool fStyle = false;
|
|
|
|
bool fTextEncoding = false;
|
|
|
|
bool fHinting = false;
|
|
|
|
bool fFilterQuality = false;
|
|
|
|
};
|
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);
|
2018-01-16 21:23:03 +00:00
|
|
|
int startupSlide() const;
|
|
|
|
void setCurrentSlide(int);
|
|
|
|
void setupCurrentSlide();
|
|
|
|
void listNames() const;
|
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);
|
2017-12-08 21:46:09 +00:00
|
|
|
void drawImGui();
|
2016-04-07 18:09:51 +00:00
|
|
|
|
2016-04-08 19:51:45 +00:00
|
|
|
void changeZoomLevel(float delta);
|
2018-04-23 16:55:06 +00:00
|
|
|
void preTouchMatrixChanged();
|
2018-03-28 20:23:31 +00:00
|
|
|
SkMatrix computePreTouchMatrix();
|
2018-05-02 19:40:20 +00:00
|
|
|
SkMatrix computePerspectiveMatrix();
|
2016-05-17 19:44:20 +00:00
|
|
|
SkMatrix computeMatrix();
|
2018-02-20 02:43:47 +00:00
|
|
|
SkPoint mapEvent(float x, float y);
|
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-12-19 16:15:16 +00:00
|
|
|
StatsLayer fStatsLayer;
|
|
|
|
StatsLayer::Timer fPaintTimer;
|
|
|
|
StatsLayer::Timer fFlushTimer;
|
|
|
|
StatsLayer::Timer fAnimateTimer;
|
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
|
|
|
|
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-12-01 16:23:53 +00:00
|
|
|
bool fSaveToSKP;
|
|
|
|
|
2017-12-08 21:46:09 +00:00
|
|
|
ImGuiLayer fImGuiLayer;
|
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;
|
2017-11-14 20:32:20 +00:00
|
|
|
bool fShowSlidePicker;
|
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 fShowImGuiTestWindow;
|
|
|
|
|
2017-02-13 14:39:57 +00:00
|
|
|
bool fShowZoomWindow;
|
2018-06-26 18:23:20 +00:00
|
|
|
bool fZoomWindowFixed;
|
|
|
|
SkPoint fZoomWindowLocation;
|
2017-02-13 14:39:57 +00:00
|
|
|
sk_sp<SkImage> fLastImage;
|
2018-07-24 22:01:53 +00:00
|
|
|
bool fZoomUI;
|
2017-02-13 14:39:57 +00:00
|
|
|
|
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-11-09 15:27:55 +00:00
|
|
|
SkColorSpaceTransferFn fColorSpaceTransferFn;
|
2017-02-08 15:47:28 +00:00
|
|
|
|
2016-04-08 19:51:45 +00:00
|
|
|
// transform data
|
|
|
|
SkScalar fZoomLevel;
|
2018-04-23 16:55:06 +00:00
|
|
|
SkScalar fRotation;
|
2018-06-26 18:23:20 +00:00
|
|
|
SkVector fOffset;
|
2016-04-08 19:51:45 +00:00
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
TouchGesture 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
|
|
|
|
2018-05-02 19:40:20 +00:00
|
|
|
enum PerspectiveMode {
|
|
|
|
kPerspective_Off,
|
|
|
|
kPerspective_Real,
|
|
|
|
kPerspective_Fake,
|
|
|
|
};
|
|
|
|
PerspectiveMode fPerspectiveMode;
|
2018-04-26 19:55:00 +00:00
|
|
|
SkPoint fPerspectivePoints[4];
|
|
|
|
|
2017-02-24 16:57:23 +00:00
|
|
|
SkTArray<std::function<void(void)>> fDeferredActions;
|
|
|
|
|
2018-02-12 21:37:28 +00:00
|
|
|
SkPaint fPaint;
|
|
|
|
SkPaintFields fPaintOverrides;
|
2018-04-13 18:30:23 +00:00
|
|
|
bool fPixelGeometryOverrides = false;
|
2016-04-06 13:08:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|