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
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkExecutor.h"
|
|
|
|
#include "include/core/SkFont.h"
|
2020-06-18 18:18:27 +00:00
|
|
|
#include "include/gpu/GrContextOptions.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkScan.h"
|
|
|
|
#include "src/sksl/SkSLString.h"
|
|
|
|
#include "src/sksl/ir/SkSLProgram.h"
|
|
|
|
#include "tools/gpu/MemoryCache.h"
|
|
|
|
#include "tools/sk_app/Application.h"
|
|
|
|
#include "tools/sk_app/CommandSet.h"
|
|
|
|
#include "tools/sk_app/Window.h"
|
2019-07-11 20:32:53 +00:00
|
|
|
#include "tools/viewer/AnimTimer.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/viewer/ImGuiLayer.h"
|
|
|
|
#include "tools/viewer/Slide.h"
|
|
|
|
#include "tools/viewer/StatsLayer.h"
|
|
|
|
#include "tools/viewer/TouchGesture.h"
|
2016-04-06 13:08:59 +00:00
|
|
|
|
|
|
|
class SkCanvas;
|
2019-04-12 15:47:19 +00:00
|
|
|
class SkData;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
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;
|
2019-03-04 16:00:10 +00:00
|
|
|
void onPaint(SkSurface*) override;
|
2018-08-09 19:06:19 +00:00
|
|
|
void onResize(int width, int height) override;
|
2019-08-29 14:39:22 +00:00
|
|
|
bool onTouch(intptr_t owner, skui::InputState state, float x, float y) override;
|
|
|
|
bool onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers) override;
|
2017-12-08 21:45:43 +00:00
|
|
|
void onUIStateChanged(const SkString& stateName, const SkString& stateValue) override;
|
2019-08-29 14:39:22 +00:00
|
|
|
bool onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers) override;
|
|
|
|
bool onChar(SkUnichar c, skui::ModifierKey modifiers) override;
|
2019-09-09 20:53:39 +00:00
|
|
|
bool onPinch(skui::InputState state, float scale, float x, float y) override;
|
|
|
|
bool onFling(skui::InputState state) override;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2020-06-18 18:18:27 +00:00
|
|
|
static GrContextOptions::ShaderErrorHandler* ShaderErrorHandler();
|
|
|
|
|
2019-01-04 15:11:46 +00:00
|
|
|
struct SkFontFields {
|
2018-02-12 21:37:28 +00:00
|
|
|
bool fTypeface = false;
|
2019-03-21 17:35:44 +00:00
|
|
|
bool fSize = false;
|
|
|
|
SkScalar fSizeRange[2] = { 0, 20 };
|
|
|
|
bool fScaleX = false;
|
|
|
|
bool fSkewX = false;
|
2019-01-04 15:11:46 +00:00
|
|
|
bool fHinting = false;
|
2019-01-10 18:55:35 +00:00
|
|
|
bool fEdging = false;
|
|
|
|
bool fSubpixel = false;
|
2019-01-23 15:34:59 +00:00
|
|
|
bool fForceAutoHinting = false;
|
|
|
|
bool fEmbeddedBitmaps = false;
|
|
|
|
bool fLinearMetrics = false;
|
|
|
|
bool fEmbolden = false;
|
2019-08-26 20:59:09 +00:00
|
|
|
bool fBaselineSnap = false;
|
2019-01-04 15:11:46 +00:00
|
|
|
};
|
|
|
|
struct SkPaintFields {
|
2018-02-12 21:37:28 +00:00
|
|
|
bool fPathEffect = false;
|
|
|
|
bool fShader = false;
|
|
|
|
bool fMaskFilter = false;
|
|
|
|
bool fColorFilter = false;
|
|
|
|
bool fDrawLooper = false;
|
|
|
|
bool fImageFilter = false;
|
|
|
|
|
|
|
|
bool fColor = false;
|
|
|
|
bool fWidth = false;
|
|
|
|
bool fMiterLimit = false;
|
|
|
|
bool fBlendMode = false;
|
|
|
|
|
2019-01-23 15:34:59 +00:00
|
|
|
bool fAntiAlias = false;
|
|
|
|
bool fDither = false;
|
2018-02-12 21:37:28 +00:00
|
|
|
enum class AntiAliasState {
|
|
|
|
Alias,
|
|
|
|
Normal,
|
|
|
|
AnalyticAAEnabled,
|
|
|
|
AnalyticAAForced,
|
2019-01-23 15:34:59 +00:00
|
|
|
} fAntiAliasState = AntiAliasState::Alias;
|
2018-04-17 15:16:32 +00:00
|
|
|
const bool fOriginalSkUseAnalyticAA = gSkUseAnalyticAA;
|
|
|
|
const bool fOriginalSkForceAnalyticAA = gSkForceAnalyticAA;
|
2018-02-12 21:37:28 +00:00
|
|
|
|
|
|
|
bool fCapType = false;
|
|
|
|
bool fJoinType = false;
|
|
|
|
bool fStyle = false;
|
|
|
|
};
|
2020-09-24 18:49:00 +00:00
|
|
|
struct SkSurfacePropsFields {
|
|
|
|
bool fFlags = false;
|
|
|
|
bool fPixelGeometry = false;
|
|
|
|
};
|
|
|
|
struct DisplayFields {
|
|
|
|
bool fColorType = false;
|
|
|
|
bool fColorSpace = false;
|
|
|
|
bool fMSAASampleCount = false;
|
|
|
|
bool fGrContextOptions = false;
|
|
|
|
SkSurfacePropsFields fSurfaceProps;
|
|
|
|
bool fDisableVsync = false;
|
|
|
|
};
|
2016-04-06 13:08:59 +00:00
|
|
|
private:
|
2017-03-06 16:47:26 +00:00
|
|
|
enum class ColorMode {
|
2019-09-18 15:22:44 +00:00
|
|
|
kLegacy, // 8888, no color management
|
|
|
|
kColorManaged8888, // 8888 with color management
|
|
|
|
kColorManagedF16, // F16 with color management
|
|
|
|
kColorManagedF16Norm, // Normalized F16 with color management
|
2017-03-06 16:47:26 +00:00
|
|
|
};
|
|
|
|
|
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();
|
|
|
|
|
2019-03-04 16:00:10 +00:00
|
|
|
void drawSlide(SkSurface* surface);
|
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
|
|
|
|
2019-03-20 16:55:08 +00:00
|
|
|
AnimTimer 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;
|
2019-03-14 15:39:02 +00:00
|
|
|
bool fShowSlideDimensions;
|
2017-12-01 16:23:53 +00:00
|
|
|
|
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;
|
2019-01-04 22:03:00 +00:00
|
|
|
skcms_TransferFunction fColorSpaceTransferFn;
|
2017-02-08 15:47:28 +00:00
|
|
|
|
2016-04-08 19:51:45 +00:00
|
|
|
// transform data
|
2021-02-01 20:38:58 +00:00
|
|
|
bool fApplyBackingScale;
|
2016-04-08 19:51:45 +00:00
|
|
|
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-11-26 19:50:05 +00:00
|
|
|
bool fTiled;
|
|
|
|
bool fDrawTileBoundaries;
|
|
|
|
SkSize fTileScale;
|
2020-03-12 17:56:34 +00:00
|
|
|
bool fDrawViaSerialize = false;
|
2018-11-26 19:50:05 +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;
|
|
|
|
|
2020-09-24 18:49:00 +00:00
|
|
|
// fPaint contains override values, fPaintOverrides controls if overrides are applied.
|
2018-02-12 21:37:28 +00:00
|
|
|
SkPaint fPaint;
|
|
|
|
SkPaintFields fPaintOverrides;
|
2020-09-24 18:49:00 +00:00
|
|
|
|
|
|
|
// fFont contains override values, fFontOverrides controls if overrides are applied.
|
2019-01-04 15:11:46 +00:00
|
|
|
SkFont fFont;
|
|
|
|
SkFontFields fFontOverrides;
|
2020-09-24 18:49:00 +00:00
|
|
|
|
|
|
|
// fDisplay contains default values (fWindow.fRequestedDisplayParams contains the overrides),
|
|
|
|
// fDisplayOverrides controls if overrides are applied.
|
|
|
|
sk_app::DisplayParams fDisplay;
|
|
|
|
DisplayFields fDisplayOverrides;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2020-06-16 19:11:34 +00:00
|
|
|
struct CachedShader {
|
2019-04-12 15:47:19 +00:00
|
|
|
bool fHovered = false;
|
|
|
|
|
|
|
|
sk_sp<const SkData> fKey;
|
|
|
|
SkString fKeyString;
|
|
|
|
|
2019-04-25 13:44:43 +00:00
|
|
|
SkFourByteTag fShaderType;
|
|
|
|
SkSL::String fShader[kGrShaderTypeCount];
|
|
|
|
SkSL::Program::Inputs fInputs[kGrShaderTypeCount];
|
2019-04-12 15:47:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
sk_gpu_test::MemoryCache fPersistentCache;
|
2020-06-16 19:11:34 +00:00
|
|
|
SkTArray<CachedShader> fCachedShaders;
|
2019-04-12 15:47:19 +00:00
|
|
|
};
|
2016-04-06 13:08:59 +00:00
|
|
|
|
|
|
|
#endif
|