Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | List of all members
Viewer Class Reference

#include <Viewer.h>

Inheritance diagram for Viewer:
sk_app::Application sk_app::Window::Layer

Classes

struct  DisplayFields
 
struct  SkFontFields
 
struct  SkPaintFields
 
struct  SkSurfacePropsFields
 

Public Member Functions

 Viewer (int argc, char **argv, void *platformData)
 
 ~Viewer () override
 
void onIdle () override
 
void onBackendCreated () override
 
void onPaint (SkSurface *) override
 
void onResize (int width, int height) override
 
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
 
bool onMouseWheel (float delta, int x, int y, skui::ModifierKey) override
 
void onUIStateChanged (const SkString &stateName, const SkString &stateValue) override
 
bool onKey (skui::Key key, skui::InputState state, skui::ModifierKey modifiers) override
 
bool onChar (SkUnichar c, skui::ModifierKey modifiers) override
 
bool onPinch (skui::InputState state, float scale, float x, float y) override
 
bool onFling (skui::InputState state) override
 
- Public Member Functions inherited from sk_app::Application
virtual ~Application ()
 
virtual void onIdle ()=0
 

Static Public Member Functions

static GrContextOptions::ShaderErrorHandlerShaderErrorHandler ()
 
- Static Public Member Functions inherited from sk_app::Application
static ApplicationCreate (int argc, char **argv, void *platformData)
 

Detailed Description

Definition at line 43 of file Viewer.h.

Constructor & Destructor Documentation

◆ Viewer()

Viewer::Viewer ( int  argc,
char **  argv,
void *  platformData 
)

Definition at line 498 of file Viewer.cpp.

499 : fCurrentSlide(-1)
500 , fRefresh(false)
501 , fSaveToSKP(false)
502 , fShowSlideDimensions(false)
503 , fShowImGuiDebugWindow(false)
504 , fShowSlidePicker(false)
505 , fShowImGuiTestWindow(false)
506 , fShowHistogramWindow(false)
507 , fShowZoomWindow(false)
508 , fZoomWindowFixed(false)
509 , fZoomWindowLocation{0.0f, 0.0f}
510 , fLastImage(nullptr)
511 , fZoomUI(false)
512 , fBackendType(sk_app::Window::kNativeGL_BackendType)
513 , fColorMode(ColorMode::kLegacy)
514 , fColorSpacePrimaries(gSrgbPrimaries)
515 // Our UI can only tweak gamma (currently), so start out gamma-only
516 , fColorSpaceTransferFn(SkNamedTransferFn::k2Dot2)
517 , fApplyBackingScale(true)
518 , fZoomLevel(0.0f)
519 , fRotation(0.0f)
520 , fOffset{0.5f, 0.5f}
521 , fGestureDevice(GestureDevice::kNone)
522 , fTiled(false)
523 , fDrawTileBoundaries(false)
524 , fTileScale{0.25f, 0.25f}
525 , fPerspectiveMode(kPerspective_Off)
526{
528#if defined(SK_ENABLE_SVG)
530#endif
532
533 gGaneshPathRendererNames[GpuPathRenderers::kDefault] = "Default Path Renderers";
534 gGaneshPathRendererNames[GpuPathRenderers::kAtlas] = "Atlas (tessellation)";
536 gGaneshPathRendererNames[GpuPathRenderers::kSmall] = "Small paths (cached sdf or alpha masks)";
539
540 SkDebugf("Command line arguments: ");
541 for (int i = 1; i < argc; ++i) {
542 SkDebugf("%s ", argv[i]);
543 }
544 SkDebugf("\n");
545
547#ifdef SK_BUILD_FOR_ANDROID
548 SetResourcePath("/data/local/tmp/resources");
549#endif
550
552 static SkTaskGroup::Enabler kTaskGroupEnabler(FLAGS_threads);
553
554 fBackendType = get_backend_type(FLAGS_backend[0]);
555 fWindow = Window::CreateNativeWindow(platformData);
556
557 DisplayParams displayParams;
558 displayParams.fMSAASampleCount = FLAGS_msaa;
560 displayParams.fGrContextOptions.fPersistentCache = &fPersistentCache;
564 displayParams.fGrContextOptions.fSuppressPrints = true;
566 if (FLAGS_dmsaa) {
567 displayParams.fSurfaceProps = SkSurfaceProps(
569 displayParams.fSurfaceProps.pixelGeometry());
570 }
571 displayParams.fCreateProtectedNativeBackend = FLAGS_createProtected;
572#if defined(SK_GRAPHITE)
573 displayParams.fGraphiteContextOptions.fPriv.fPathRendererStrategy =
574 get_path_renderer_strategy_type(FLAGS_pathstrategy[0]);
575#if defined(SK_DAWN)
576 displayParams.fDisableTintSymbolRenaming = FLAGS_disable_tint_symbol_renaming;
577#endif
578#endif
579 fWindow->setRequestedDisplayParams(displayParams);
580 fDisplay = fWindow->getRequestedDisplayParams();
581 fRefresh = FLAGS_redraw;
582
583 fImGuiLayer.setScaleFactor(fWindow->scaleFactor());
584 fStatsLayer.setDisplayScale((fZoomUI ? 2.0f : 1.0f) * fWindow->scaleFactor());
585
586 // Configure timers
587 fStatsLayer.setActive(FLAGS_stats);
588 fAnimateTimer = fStatsLayer.addTimer("Animate", SK_ColorMAGENTA, 0xffff66ff);
589 fPaintTimer = fStatsLayer.addTimer("Paint", SK_ColorGREEN);
590 fFlushTimer = fStatsLayer.addTimer("Flush", SK_ColorRED, 0xffff6666);
591
592 // register callbacks
593 fCommands.attach(fWindow);
594 fWindow->pushLayer(this);
595 fWindow->pushLayer(&fStatsLayer);
596 fWindow->pushLayer(&fImGuiLayer);
597
598 // add key-bindings
599 fCommands.addCommand(' ', "GUI", "Toggle Debug GUI", [this]() {
600 this->fShowImGuiDebugWindow = !this->fShowImGuiDebugWindow;
601 fWindow->inval();
602 });
603 // Command to jump directly to the slide picker and give it focus
604 fCommands.addCommand('/', "GUI", "Jump to slide picker", [this]() {
605 this->fShowImGuiDebugWindow = true;
606 this->fShowSlidePicker = true;
607 fWindow->inval();
608 });
609 // Alias that to Backspace, to match SampleApp
610 fCommands.addCommand(skui::Key::kBack, "Backspace", "GUI", "Jump to slide picker", [this]() {
611 this->fShowImGuiDebugWindow = true;
612 this->fShowSlidePicker = true;
613 fWindow->inval();
614 });
615 fCommands.addCommand('g', "GUI", "Toggle GUI Demo", [this]() {
616 this->fShowImGuiTestWindow = !this->fShowImGuiTestWindow;
617 fWindow->inval();
618 });
619 fCommands.addCommand('z', "GUI", "Toggle zoom window", [this]() {
620 this->fShowZoomWindow = !this->fShowZoomWindow;
621 fWindow->inval();
622 });
623 fCommands.addCommand('Z', "GUI", "Toggle zoom window state", [this]() {
624 this->fZoomWindowFixed = !this->fZoomWindowFixed;
625 fWindow->inval();
626 });
627 fCommands.addCommand('v', "Swapchain", "Toggle vsync on/off", [this]() {
629 params.fDisableVsync = !params.fDisableVsync;
631 this->updateTitle();
632 fWindow->inval();
633 });
634 fCommands.addCommand('V', "Swapchain", "Toggle delayed acquire on/off (Metal only)", [this]() {
636 params.fDelayDrawableAcquisition = !params.fDelayDrawableAcquisition;
638 this->updateTitle();
639 fWindow->inval();
640 });
641 fCommands.addCommand('r', "Redraw", "Toggle redraw", [this]() {
642 fRefresh = !fRefresh;
643 fWindow->inval();
644 });
645 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() {
646 fStatsLayer.setActive(!fStatsLayer.getActive());
647 fWindow->inval();
648 });
649 fCommands.addCommand('0', "Overlays", "Reset stats", [this]() {
650 fStatsLayer.resetMeasurements();
651 this->updateTitle();
652 fWindow->inval();
653 });
654 fCommands.addCommand('C', "GUI", "Toggle color histogram", [this]() {
655 this->fShowHistogramWindow = !this->fShowHistogramWindow;
656 fWindow->inval();
657 });
658 fCommands.addCommand('c', "Modes", "Cycle color mode", [this]() {
659 switch (fColorMode) {
660 case ColorMode::kLegacy:
661 this->setColorMode(ColorMode::kColorManaged8888);
662 break;
663 case ColorMode::kColorManaged8888:
664 this->setColorMode(ColorMode::kColorManagedF16);
665 break;
666 case ColorMode::kColorManagedF16:
667 this->setColorMode(ColorMode::kColorManagedF16Norm);
668 break;
669 case ColorMode::kColorManagedF16Norm:
670 this->setColorMode(ColorMode::kLegacy);
671 break;
672 }
673 });
674 fCommands.addCommand('w', "Modes", "Toggle wireframe", [this]() {
676 params.fGrContextOptions.fWireframeMode = !params.fGrContextOptions.fWireframeMode;
678 fWindow->inval();
679 });
680 fCommands.addCommand('w', "Modes", "Toggle reduced shaders", [this]() {
682 params.fGrContextOptions.fReducedShaderVariations =
683 !params.fGrContextOptions.fReducedShaderVariations;
685 fWindow->inval();
686 });
687 fCommands.addCommand(skui::Key::kRight, "Right", "Navigation", "Next slide", [this]() {
688 this->setCurrentSlide(fCurrentSlide < fSlides.size() - 1 ? fCurrentSlide + 1 : 0);
689 });
690 fCommands.addCommand(skui::Key::kLeft, "Left", "Navigation", "Previous slide", [this]() {
691 this->setCurrentSlide(fCurrentSlide > 0 ? fCurrentSlide - 1 : fSlides.size() - 1);
692 });
693 fCommands.addCommand(skui::Key::kUp, "Up", "Transform", "Zoom in", [this]() {
694 this->changeZoomLevel(1.f / 32.f);
695 fWindow->inval();
696 });
697 fCommands.addCommand(skui::Key::kDown, "Down", "Transform", "Zoom out", [this]() {
698 this->changeZoomLevel(-1.f / 32.f);
699 fWindow->inval();
700 });
701 fCommands.addCommand('d', "Modes", "Change rendering backend", [this]() {
703 (fBackendType + 1) % sk_app::Window::kBackendTypeCount);
704 // Switching to and from Vulkan is problematic on Linux so disabled for now
705#if defined(SK_BUILD_FOR_UNIX) && defined(SK_VULKAN)
706 if (newBackend == sk_app::Window::kVulkan_BackendType) {
707 newBackend = (sk_app::Window::BackendType)((newBackend + 1) %
709 } else if (fBackendType == sk_app::Window::kVulkan_BackendType) {
710 newBackend = sk_app::Window::kVulkan_BackendType;
711 }
712#endif
713 this->setBackend(newBackend);
714 });
715 fCommands.addCommand('K', "IO", "Save slide to SKP", [this]() {
716 fSaveToSKP = true;
717 fWindow->inval();
718 });
719 fCommands.addCommand('&', "Overlays", "Show slide dimensios", [this]() {
720 fShowSlideDimensions = !fShowSlideDimensions;
721 fWindow->inval();
722 });
723 fCommands.addCommand('G', "Modes", "Geometry", [this]() {
725 uint32_t flags = params.fSurfaceProps.flags();
726 SkPixelGeometry defaultPixelGeometry = fDisplay.fSurfaceProps.pixelGeometry();
727 if (!fDisplayOverrides.fSurfaceProps.fPixelGeometry) {
728 fDisplayOverrides.fSurfaceProps.fPixelGeometry = true;
730 } else {
731 switch (params.fSurfaceProps.pixelGeometry()) {
734 break;
737 break;
740 break;
743 break;
745 params.fSurfaceProps = SkSurfaceProps(flags, defaultPixelGeometry);
746 fDisplayOverrides.fSurfaceProps.fPixelGeometry = false;
747 break;
748 }
749 }
751 this->updateTitle();
752 fWindow->inval();
753 });
754 fCommands.addCommand('H', "Font", "Hinting mode", [this]() {
755 if (!fFontOverrides.fHinting) {
756 fFontOverrides.fHinting = true;
758 } else {
759 switch (fFont.getHinting()) {
762 break;
765 break;
768 break;
771 fFontOverrides.fHinting = false;
772 break;
773 }
774 }
775 this->updateTitle();
776 fWindow->inval();
777 });
778 fCommands.addCommand('D', "Modes", "DFT", [this]() {
780 uint32_t flags = params.fSurfaceProps.flags();
782 params.fSurfaceProps = SkSurfaceProps(flags, params.fSurfaceProps.pixelGeometry());
784 this->updateTitle();
785 fWindow->inval();
786 });
787 fCommands.addCommand('L', "Font", "Subpixel Antialias Mode", [this]() {
788 if (!fFontOverrides.fEdging) {
789 fFontOverrides.fEdging = true;
791 } else {
792 switch (fFont.getEdging()) {
795 break;
798 break;
801 fFontOverrides.fEdging = false;
802 break;
803 }
804 }
805 this->updateTitle();
806 fWindow->inval();
807 });
808 fCommands.addCommand('S', "Font", "Subpixel Position Mode", [this]() {
809 if (!fFontOverrides.fSubpixel) {
810 fFontOverrides.fSubpixel = true;
811 fFont.setSubpixel(false);
812 } else {
813 if (!fFont.isSubpixel()) {
814 fFont.setSubpixel(true);
815 } else {
816 fFontOverrides.fSubpixel = false;
817 }
818 }
819 this->updateTitle();
820 fWindow->inval();
821 });
822 fCommands.addCommand('B', "Font", "Baseline Snapping", [this]() {
823 if (!fFontOverrides.fBaselineSnap) {
824 fFontOverrides.fBaselineSnap = true;
825 fFont.setBaselineSnap(false);
826 } else {
827 if (!fFont.isBaselineSnap()) {
828 fFont.setBaselineSnap(true);
829 } else {
830 fFontOverrides.fBaselineSnap = false;
831 }
832 }
833 this->updateTitle();
834 fWindow->inval();
835 });
836 fCommands.addCommand('p', "Transform", "Toggle Perspective Mode", [this]() {
837 fPerspectiveMode = (kPerspective_Real == fPerspectiveMode) ? kPerspective_Fake
838 : kPerspective_Real;
839 this->updateTitle();
840 fWindow->inval();
841 });
842 fCommands.addCommand('P', "Transform", "Toggle Perspective", [this]() {
843 fPerspectiveMode = (kPerspective_Off == fPerspectiveMode) ? kPerspective_Real
844 : kPerspective_Off;
845 this->updateTitle();
846 fWindow->inval();
847 });
848 fCommands.addCommand('a', "Transform", "Toggle Animation", [this]() {
849 fAnimTimer.togglePauseResume();
850 });
851 fCommands.addCommand('u', "GUI", "Zoom UI", [this]() {
852 fZoomUI = !fZoomUI;
853 fStatsLayer.setDisplayScale((fZoomUI ? 2.0f : 1.0f) * fWindow->scaleFactor());
854 fWindow->inval();
855 });
856 fCommands.addCommand('=', "Transform", "Apply Backing Scale", [this]() {
857 fApplyBackingScale = !fApplyBackingScale;
858 fWindow->inval();
859 });
860 fCommands.addCommand('$', "ViaSerialize", "Toggle ViaSerialize", [this]() {
861 fDrawViaSerialize = !fDrawViaSerialize;
862 this->updateTitle();
863 fWindow->inval();
864 });
865
866 // set up slides
867 this->initSlides();
868 if (FLAGS_list) {
869 this->listNames();
870 }
871
872 fPerspectivePoints[0].set(0, 0);
873 fPerspectivePoints[1].set(1, 0);
874 fPerspectivePoints[2].set(0, 1);
875 fPerspectivePoints[3].set(1, 1);
876 fAnimTimer.run();
877
878 auto gamutImage = ToolUtils::GetResourceAsImage("images/gamut.png");
879 if (gamutImage) {
880 fImGuiGamutPaint.setShader(gamutImage->makeShader(SkSamplingOptions(SkFilterMode::kLinear)));
881 }
882 fImGuiGamutPaint.setColor(SK_ColorWHITE);
883
884 fWindow->attach(backend_type_for_window(fBackendType));
885 this->setCurrentSlide(this->startupSlide());
886}
void initializeEventTracingForTools(const char *traceFlag)
void SetResourcePath(const char *resource)
Definition: Resources.cpp:27
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
@ kNormal
glyph outlines modified to improve constrast
@ kNone
glyph outlines unchanged
@ kSlight
minimal modification to improve constrast
@ kFull
modifies glyph outlines for maximum constrast
SkPixelGeometry
@ kUnknown_SkPixelGeometry
@ kRGB_V_SkPixelGeometry
@ kBGR_H_SkPixelGeometry
@ kRGB_H_SkPixelGeometry
@ kBGR_V_SkPixelGeometry
static SkColorSpacePrimaries gSrgbPrimaries
Definition: Viewer.cpp:436
static std::map< GpuPathRenderers, std::string > gGaneshPathRendererNames
Definition: Viewer.cpp:173
static CapturingShaderErrorHandler gShaderErrorHandler
Definition: Viewer.cpp:165
static Window::BackendType backend_type_for_window(Window::BackendType backendType)
Definition: Viewer.cpp:474
static sk_app::Window::BackendType get_backend_type(const char *str)
Definition: Viewer.cpp:387
void togglePauseResume()
Definition: AnimTimer.h:68
void run()
Definition: AnimTimer.h:45
static void Parse(int argc, const char *const *argv)
void setScaleFactor(float scaleFactor)
Definition: ImGuiLayer.cpp:79
bool isBaselineSnap() const
Definition: SkFont.h:133
void setSubpixel(bool subpixel)
Definition: SkFont.cpp:109
Edging getEdging() const
Definition: SkFont.h:180
void setBaselineSnap(bool baselineSnap)
Definition: SkFont.cpp:118
void setEdging(Edging edging)
Definition: SkFont.cpp:121
SkFontHinting getHinting() const
Definition: SkFont.h:194
bool isSubpixel() const
Definition: SkFont.h:113
void setHinting(SkFontHinting hintingLevel)
Definition: SkFont.cpp:125
@ kAntiAlias
may have transparent pixels on glyph edges
@ kAlias
no transparent pixels on glyph edges
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
static OpenTypeSVGDecoderFactory SetOpenTypeSVGDecoderFactory(OpenTypeSVGDecoderFactory)
Definition: SkGraphics.cpp:96
static void Init()
Definition: SkGraphics.cpp:22
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setShader(sk_sp< SkShader > shader)
static std::unique_ptr< SkOpenTypeSVGDecoder > Make(const uint8_t *svg, size_t svgLength)
@ kUseDeviceIndependentFonts_Flag
uint32_t flags() const
SkPixelGeometry pixelGeometry() const
Timer addTimer(const char *label, SkColor color, SkColor labelColor=0)
Definition: StatsLayer.cpp:49
void resetMeasurements()
Definition: StatsLayer.cpp:38
void setDisplayScale(float scale)
Definition: StatsLayer.h:32
void attach(Window *window)
Definition: CommandSet.cpp:41
void addCommand(SkUnichar c, const char *group, const char *description, std::function< void(void)> function)
Definition: CommandSet.cpp:79
void setActive(bool active)
Definition: Window.h:109
@ kBackendTypeCount
Definition: Window.h:95
virtual const DisplayParams & getRequestedDisplayParams()
Definition: Window.h:155
void pushLayer(Layer *layer)
Definition: Window.h:132
virtual void setRequestedDisplayParams(const DisplayParams &, bool allowReattach=true)
Definition: Window.cpp:137
virtual bool attach(BackendType)=0
void inval()
Definition: Window.cpp:195
virtual float scaleFactor() const
Definition: Window.h:153
int size() const
Definition: SkTArray.h:421
const EmbeddedViewParams * params
FlutterSemanticsFlag flags
char ** argv
Definition: library.h:9
void RegisterAllAvailable()
Definition: CodecUtils.h:60
void SetCtxOptions(struct GrContextOptions *)
static constexpr skcms_TransferFunction k2Dot2
Definition: SkColorSpace.h:48
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
@ kBack
(CLR)
PersistentCache * fPersistentCache
ShaderErrorHandler * fShaderErrorHandler
ShaderCacheStrategy fShaderCacheStrategy
void set(float x, float y)
Definition: SkPoint_impl.h:200
SkSurfacePropsFields fSurfaceProps
Definition: Viewer.h:141
SkSurfaceProps fSurfaceProps
Definition: DisplayParams.h:68
GrContextOptions fGrContextOptions
Definition: DisplayParams.h:61

◆ ~Viewer()

Viewer::~Viewer ( )
override

Definition at line 1119 of file Viewer.cpp.

1119 {
1120 for(auto& slide : fSlides) {
1121 slide->gpuTeardown();
1122 }
1123
1124 fWindow->detach();
1125 delete fWindow;
1126}
void detach()
Definition: Window.cpp:25

Member Function Documentation

◆ onBackendCreated()

void Viewer::onBackendCreated ( )
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 1871 of file Viewer.cpp.

1871 {
1872 this->setupCurrentSlide();
1873 fWindow->show();
1874}
virtual void show()=0

◆ onChar()

bool Viewer::onChar ( SkUnichar  c,
skui::ModifierKey  modifiers 
)
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 3359 of file Viewer.cpp.

3359 {
3360 if (fSlides[fCurrentSlide]->onChar(c)) {
3361 fWindow->inval();
3362 return true;
3363 } else {
3364 return fCommands.onChar(c, modifiers);
3365 }
3366}
bool onChar(SkUnichar c, skui::ModifierKey modifiers) override
Definition: Viewer.cpp:3359
bool onChar(SkUnichar, skui::ModifierKey modifiers)
Definition: CommandSet.cpp:58

◆ onFling()

bool Viewer::onFling ( skui::InputState  state)
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 2016 of file Viewer.cpp.

2016 {
2018 this->setCurrentSlide(fCurrentSlide > 0 ? fCurrentSlide - 1 : fSlides.size() - 1);
2019 return true;
2020 } else if (skui::InputState::kLeft == state) {
2021 this->setCurrentSlide(fCurrentSlide < fSlides.size() - 1 ? fCurrentSlide + 1 : 0);
2022 return true;
2023 }
2024 return false;
2025}
AtkStateType state

◆ onIdle()

void Viewer::onIdle ( )
overridevirtual

Implements sk_app::Application.

Definition at line 3153 of file Viewer.cpp.

3153 {
3154 TArray<std::function<void()>> actionsToRun;
3155 actionsToRun.swap(fDeferredActions);
3156
3157 for (const auto& fn : actionsToRun) {
3158 fn();
3159 }
3160
3161 fStatsLayer.beginTiming(fAnimateTimer);
3162 fAnimTimer.updateTime();
3163 bool animateWantsInval = fSlides[fCurrentSlide]->animate(fAnimTimer.nanos());
3164 fStatsLayer.endTiming(fAnimateTimer);
3165
3166 ImGuiIO& io = ImGui::GetIO();
3167 // ImGui always has at least one "active" window, which is the default "Debug" window. It may
3168 // not be visible, though. So we need to redraw if there is at least one visible window, or
3169 // more than one active window. Newly created windows are active but not visible for one frame
3170 // while they determine their layout and sizing.
3171 if (animateWantsInval || fStatsLayer.getActive() || fRefresh ||
3172 io.MetricsActiveWindows > 1 || io.MetricsRenderWindows > 0) {
3173 fWindow->inval();
3174 }
3175}
double nanos() const
Definition: AnimTimer.h:34
void updateTime()
Definition: AnimTimer.h:83
void beginTiming(Timer)
Definition: StatsLayer.cpp:59
void endTiming(Timer)
Definition: StatsLayer.cpp:65
Dart_NativeFunction function
Definition: fuchsia.cc:51

◆ onKey()

bool Viewer::onKey ( skui::Key  key,
skui::InputState  state,
skui::ModifierKey  modifiers 
)
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 3355 of file Viewer.cpp.

3355 {
3356 return fCommands.onKey(key, state, modifiers);
3357}
bool onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers)
Definition: CommandSet.cpp:45

◆ onMouse()

bool Viewer::onMouse ( int  x,
int  y,
skui::InputState  state,
skui::ModifierKey  modifiers 
)
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 1967 of file Viewer.cpp.

1967 {
1968 if (GestureDevice::kTouch == fGestureDevice) {
1969 return false;
1970 }
1971
1972 const auto slidePt = this->mapEvent(x, y);
1973 if (fSlides[fCurrentSlide]->onMouse(slidePt.x(), slidePt.y(), state, modifiers)) {
1974 fWindow->inval();
1975 return true;
1976 }
1977
1978 switch (state) {
1979 case skui::InputState::kUp: {
1980 fGesture.touchEnd(nullptr);
1981 break;
1982 }
1984 fGesture.touchBegin(nullptr, x, y);
1985 break;
1986 }
1988 fGesture.touchMoved(nullptr, x, y);
1989 break;
1990 }
1991 default: {
1992 SkASSERT(false); // shouldn't see kRight or kLeft here
1993 break;
1994 }
1995 }
1996 fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kMouse : GestureDevice::kNone;
1997
1998 if (state != skui::InputState::kMove || fGesture.isBeingTouched()) {
1999 fWindow->inval();
2000 }
2001 return true;
2002}
#define SkASSERT(cond)
Definition: SkAssert.h:116
void touchEnd(void *owner)
bool isBeingTouched()
Definition: TouchGesture.h:30
void touchBegin(void *owner, float x, float y)
void touchMoved(void *owner, float x, float y)
bool onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers) override
Definition: Viewer.cpp:1967
double y
double x

◆ onMouseWheel()

bool Viewer::onMouseWheel ( float  delta,
int  x,
int  y,
skui::ModifierKey   
)
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 2004 of file Viewer.cpp.

2004 {
2005 // Rather than updating the fixed zoom level, treat a mouse wheel event as a gesture, which
2006 // applies a pre- and post-translation to the transform, resulting in a zoom effect centered at
2007 // the mouse cursor position.
2008 SkScalar scale = exp(delta * 0.001);
2009 fGesture.startZoom();
2010 fGesture.updateZoom(scale, x, y, x, y);
2011 fGesture.endZoom();
2012 fWindow->inval();
2013 return true;
2014}
void updateZoom(float scale, float startX, float startY, float lastX, float lastY)
float SkScalar
Definition: extension.cpp:12
const Scalar scale

◆ onPaint()

void Viewer::onPaint ( SkSurface surface)
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 1876 of file Viewer.cpp.

1876 {
1877 this->drawSlide(surface);
1878
1879 fCommands.drawHelp(surface->getCanvas());
1880
1881 this->drawImGui();
1882
1883 fLastImage.reset();
1884
1885 if (auto direct = fWindow->directContext()) {
1886 // Clean out cache items that haven't been used in more than 10 seconds.
1887 direct->performDeferredCleanup(std::chrono::seconds(10));
1888 }
1889}
void drawHelp(SkCanvas *canvas)
Definition: CommandSet.cpp:97
GrDirectContext * directContext() const
Definition: Window.cpp:158
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
VkSurfaceKHR surface
Definition: main.cc:49

◆ onPinch()

bool Viewer::onPinch ( skui::InputState  state,
float  scale,
float  x,
float  y 
)
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 2027 of file Viewer.cpp.

2027 {
2028 switch (state) {
2030 fGesture.startZoom();
2031 return true;
2033 fGesture.updateZoom(scale, x, y, x, y);
2034 return true;
2036 fGesture.endZoom();
2037 return true;
2038 default:
2039 SkASSERT(false);
2040 break;
2041 }
2042
2043 return false;
2044}

◆ onResize()

void Viewer::onResize ( int  width,
int  height 
)
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 1891 of file Viewer.cpp.

1891 {
1892 if (fCurrentSlide >= 0) {
1893 // Resizing can reset the context on some backends so just tear it all down.
1894 // We'll rebuild these resources on the next draw.
1895 fSlides[fCurrentSlide]->gpuTeardown();
1896
1897 SkScalar scaleFactor = 1.0;
1898 if (fApplyBackingScale) {
1899 scaleFactor = fWindow->scaleFactor();
1900 }
1901 fSlides[fCurrentSlide]->resize(width / scaleFactor, height / scaleFactor);
1902 }
1903}
void resize(size_t count)
Definition: SkTArray.h:423
int32_t height
int32_t width

◆ onTouch()

bool Viewer::onTouch ( intptr_t  owner,
skui::InputState  state,
float  x,
float  y 
)
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 1914 of file Viewer.cpp.

1914 {
1915 if (GestureDevice::kMouse == fGestureDevice) {
1916 return false;
1917 }
1918
1919 const auto slidePt = this->mapEvent(x, y);
1920 if (fSlides[fCurrentSlide]->onMouse(slidePt.x(), slidePt.y(), state, skui::ModifierKey::kNone)) {
1921 fWindow->inval();
1922 return true;
1923 }
1924
1925 void* castedOwner = reinterpret_cast<void*>(owner);
1926 switch (state) {
1927 case skui::InputState::kUp: {
1928 fGesture.touchEnd(castedOwner);
1929#if defined(SK_BUILD_FOR_IOS)
1930 // TODO: move IOS swipe detection higher up into the platform code
1931 SkPoint dir;
1932 if (fGesture.isFling(&dir)) {
1933 // swiping left or right
1934 if (SkTAbs(dir.fX) > SkTAbs(dir.fY)) {
1935 if (dir.fX < 0) {
1936 this->setCurrentSlide(fCurrentSlide < fSlides.size() - 1 ?
1937 fCurrentSlide + 1 : 0);
1938 } else {
1939 this->setCurrentSlide(fCurrentSlide > 0 ?
1940 fCurrentSlide - 1 : fSlides.size() - 1);
1941 }
1942 }
1943 fGesture.reset();
1944 }
1945#endif
1946 break;
1947 }
1949 fGesture.touchBegin(castedOwner, x, y);
1950 break;
1951 }
1953 fGesture.touchMoved(castedOwner, x, y);
1954 break;
1955 }
1956 default: {
1957 // kLeft and kRight are only for swipes
1958 SkASSERT(false);
1959 break;
1960 }
1961 }
1962 fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kTouch : GestureDevice::kNone;
1963 fWindow->inval();
1964 return true;
1965}
static T SkTAbs(T value)
Definition: SkTemplates.h:43
bool isFling(SkPoint *dir)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145

◆ onUIStateChanged()

void Viewer::onUIStateChanged ( const SkString stateName,
const SkString stateValue 
)
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 3288 of file Viewer.cpp.

3288 {
3289 // For those who will add more features to handle the state change in this function:
3290 // After the change, please call updateUIState no notify the frontend (e.g., Android app).
3291 // For example, after slide change, updateUIState is called inside setupCurrentSlide;
3292 // after backend change, updateUIState is called in this function.
3293 if (stateName.equals(kSlideStateName)) {
3294 for (int i = 0; i < fSlides.size(); ++i) {
3295 if (fSlides[i]->getName().equals(stateValue)) {
3296 this->setCurrentSlide(i);
3297 return;
3298 }
3299 }
3300
3301 SkDebugf("Slide not found: %s", stateValue.c_str());
3302 } else if (stateName.equals(kBackendStateName)) {
3303 for (int i = 0; i < sk_app::Window::kBackendTypeCount; i++) {
3304 auto backendType = static_cast<sk_app::Window::BackendType>(i);
3305 if (stateValue.equals(get_backend_string(backendType))) {
3306 if (fBackendType != i) {
3307 fBackendType = backendType;
3308 for(auto& slide : fSlides) {
3309 slide->gpuTeardown();
3310 }
3311 fWindow->detach();
3312 fWindow->attach(backend_type_for_window(fBackendType));
3313 }
3314 break;
3315 }
3316 }
3317 } else if (stateName.equals(kMSAAStateName)) {
3319 int sampleCount = atoi(stateValue.c_str());
3320 if (sampleCount != params.fMSAASampleCount) {
3321 params.fMSAASampleCount = sampleCount;
3323 fWindow->inval();
3324 this->updateTitle();
3325 this->updateUIState();
3326 }
3327 } else if (stateName.equals(kPathRendererStateName)) {
3329 for (const auto& pair : gGaneshPathRendererNames) {
3330 if (pair.second == stateValue.c_str()) {
3331 if (params.fGrContextOptions.fGpuPathRenderers != pair.first) {
3332 params.fGrContextOptions.fGpuPathRenderers = pair.first;
3334 fWindow->inval();
3335 this->updateTitle();
3336 this->updateUIState();
3337 }
3338 break;
3339 }
3340 }
3341 } else if (stateName.equals(kSoftkeyStateName)) {
3342 if (!stateValue.equals(kSoftkeyHint)) {
3343 fCommands.onSoftkey(stateValue);
3344 this->updateUIState(); // This is still needed to reset the value to kSoftkeyHint
3345 }
3346 } else if (stateName.equals(kRefreshStateName)) {
3347 // This state is actually NOT in the UI state.
3348 // We use this to allow Android to quickly set bool fRefresh.
3349 fRefresh = stateValue.equals(kON);
3350 } else {
3351 SkDebugf("Unknown stateName: %s", stateName.c_str());
3352 }
3353}
bool equals(SkDrawable *a, SkDrawable *b)
static const char kSoftkeyHint[]
Definition: Viewer.cpp:494
static const char kON[]
Definition: Viewer.cpp:495
const char * get_backend_string(sk_app::Window::BackendType type)
Definition: Viewer.cpp:355
static const char kMSAAStateName[]
Definition: Viewer.cpp:491
static const char kPathRendererStateName[]
Definition: Viewer.cpp:492
static const char kRefreshStateName[]
Definition: Viewer.cpp:496
static const char kBackendStateName[]
Definition: Viewer.cpp:490
static const char kSlideStateName[]
Definition: Viewer.cpp:489
static const char kSoftkeyStateName[]
Definition: Viewer.cpp:493
bool equals(const SkString &) const
Definition: SkString.cpp:324
const char * c_str() const
Definition: SkString.h:133
bool onSoftkey(const SkString &softkey)
Definition: CommandSet.cpp:69

◆ ShaderErrorHandler()

GrContextOptions::ShaderErrorHandler * Viewer::ShaderErrorHandler ( )
static

Definition at line 167 of file Viewer.cpp.

167{ return &gShaderErrorHandler; }

The documentation for this class was generated from the following files: