Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 ()
 

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 493 of file Viewer.cpp.

494 : fCurrentSlide(-1)
495 , fRefresh(false)
496 , fSaveToSKP(false)
497 , fShowSlideDimensions(false)
498 , fShowImGuiDebugWindow(false)
499 , fShowSlidePicker(false)
500 , fShowImGuiTestWindow(false)
501 , fShowHistogramWindow(false)
502 , fShowZoomWindow(false)
503 , fZoomWindowFixed(false)
504 , fZoomWindowLocation{0.0f, 0.0f}
505 , fLastImage(nullptr)
506 , fZoomUI(false)
507 , fBackendType(sk_app::Window::kNativeGL_BackendType)
508 , fColorMode(ColorMode::kLegacy)
509 , fColorSpacePrimaries(gSrgbPrimaries)
510 // Our UI can only tweak gamma (currently), so start out gamma-only
511 , fColorSpaceTransferFn(SkNamedTransferFn::k2Dot2)
512 , fApplyBackingScale(true)
513 , fZoomLevel(0.0f)
514 , fRotation(0.0f)
515 , fOffset{0.5f, 0.5f}
516 , fGestureDevice(GestureDevice::kNone)
517 , fTiled(false)
518 , fDrawTileBoundaries(false)
519 , fTileScale{0.25f, 0.25f}
520 , fPerspectiveMode(kPerspective_Off)
521{
523#if defined(SK_ENABLE_SVG)
525#endif
527
528 gGaneshPathRendererNames[GpuPathRenderers::kDefault] = "Default Path Renderers";
529 gGaneshPathRendererNames[GpuPathRenderers::kAtlas] = "Atlas (tessellation)";
531 gGaneshPathRendererNames[GpuPathRenderers::kSmall] = "Small paths (cached sdf or alpha masks)";
534
535 SkDebugf("Command line arguments: ");
536 for (int i = 1; i < argc; ++i) {
537 SkDebugf("%s ", argv[i]);
538 }
539 SkDebugf("\n");
540
541 CommandLineFlags::Parse(argc, argv);
542#ifdef SK_BUILD_FOR_ANDROID
543 SetResourcePath("/data/local/tmp/resources");
544#endif
545
547 static SkTaskGroup::Enabler kTaskGroupEnabler(FLAGS_threads);
548
549 fBackendType = get_backend_type(FLAGS_backend[0]);
550 fWindow = Window::CreateNativeWindow(platformData);
551
552 DisplayParams displayParams;
553 displayParams.fMSAASampleCount = FLAGS_msaa;
555 displayParams.fGrContextOptions.fPersistentCache = &fPersistentCache;
559 displayParams.fGrContextOptions.fSuppressPrints = true;
561 if (FLAGS_dmsaa) {
562 displayParams.fSurfaceProps = SkSurfaceProps(
564 displayParams.fSurfaceProps.pixelGeometry());
565 }
566 displayParams.fCreateProtectedNativeBackend = FLAGS_createProtected;
567#if defined(SK_GRAPHITE)
568 displayParams.fGraphiteContextOptions.fPriv.fPathRendererStrategy =
569 get_path_renderer_strategy_type(FLAGS_pathstrategy[0]);
570#endif
571 fWindow->setRequestedDisplayParams(displayParams);
572 fDisplay = fWindow->getRequestedDisplayParams();
573 fRefresh = FLAGS_redraw;
574
575 fImGuiLayer.setScaleFactor(fWindow->scaleFactor());
576 fStatsLayer.setDisplayScale((fZoomUI ? 2.0f : 1.0f) * fWindow->scaleFactor());
577
578 // Configure timers
579 fStatsLayer.setActive(FLAGS_stats);
580 fAnimateTimer = fStatsLayer.addTimer("Animate", SK_ColorMAGENTA, 0xffff66ff);
581 fPaintTimer = fStatsLayer.addTimer("Paint", SK_ColorGREEN);
582 fFlushTimer = fStatsLayer.addTimer("Flush", SK_ColorRED, 0xffff6666);
583
584 // register callbacks
585 fCommands.attach(fWindow);
586 fWindow->pushLayer(this);
587 fWindow->pushLayer(&fStatsLayer);
588 fWindow->pushLayer(&fImGuiLayer);
589
590 // add key-bindings
591 fCommands.addCommand(' ', "GUI", "Toggle Debug GUI", [this]() {
592 this->fShowImGuiDebugWindow = !this->fShowImGuiDebugWindow;
593 fWindow->inval();
594 });
595 // Command to jump directly to the slide picker and give it focus
596 fCommands.addCommand('/', "GUI", "Jump to slide picker", [this]() {
597 this->fShowImGuiDebugWindow = true;
598 this->fShowSlidePicker = true;
599 fWindow->inval();
600 });
601 // Alias that to Backspace, to match SampleApp
602 fCommands.addCommand(skui::Key::kBack, "Backspace", "GUI", "Jump to slide picker", [this]() {
603 this->fShowImGuiDebugWindow = true;
604 this->fShowSlidePicker = true;
605 fWindow->inval();
606 });
607 fCommands.addCommand('g', "GUI", "Toggle GUI Demo", [this]() {
608 this->fShowImGuiTestWindow = !this->fShowImGuiTestWindow;
609 fWindow->inval();
610 });
611 fCommands.addCommand('z', "GUI", "Toggle zoom window", [this]() {
612 this->fShowZoomWindow = !this->fShowZoomWindow;
613 fWindow->inval();
614 });
615 fCommands.addCommand('Z', "GUI", "Toggle zoom window state", [this]() {
616 this->fZoomWindowFixed = !this->fZoomWindowFixed;
617 fWindow->inval();
618 });
619 fCommands.addCommand('v', "Swapchain", "Toggle vsync on/off", [this]() {
621 params.fDisableVsync = !params.fDisableVsync;
623 this->updateTitle();
624 fWindow->inval();
625 });
626 fCommands.addCommand('V', "Swapchain", "Toggle delayed acquire on/off (Metal only)", [this]() {
628 params.fDelayDrawableAcquisition = !params.fDelayDrawableAcquisition;
630 this->updateTitle();
631 fWindow->inval();
632 });
633 fCommands.addCommand('r', "Redraw", "Toggle redraw", [this]() {
634 fRefresh = !fRefresh;
635 fWindow->inval();
636 });
637 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() {
638 fStatsLayer.setActive(!fStatsLayer.getActive());
639 fWindow->inval();
640 });
641 fCommands.addCommand('0', "Overlays", "Reset stats", [this]() {
642 fStatsLayer.resetMeasurements();
643 this->updateTitle();
644 fWindow->inval();
645 });
646 fCommands.addCommand('C', "GUI", "Toggle color histogram", [this]() {
647 this->fShowHistogramWindow = !this->fShowHistogramWindow;
648 fWindow->inval();
649 });
650 fCommands.addCommand('c', "Modes", "Cycle color mode", [this]() {
651 switch (fColorMode) {
652 case ColorMode::kLegacy:
653 this->setColorMode(ColorMode::kColorManaged8888);
654 break;
655 case ColorMode::kColorManaged8888:
656 this->setColorMode(ColorMode::kColorManagedF16);
657 break;
658 case ColorMode::kColorManagedF16:
659 this->setColorMode(ColorMode::kColorManagedF16Norm);
660 break;
661 case ColorMode::kColorManagedF16Norm:
662 this->setColorMode(ColorMode::kLegacy);
663 break;
664 }
665 });
666 fCommands.addCommand('w', "Modes", "Toggle wireframe", [this]() {
668 params.fGrContextOptions.fWireframeMode = !params.fGrContextOptions.fWireframeMode;
670 fWindow->inval();
671 });
672 fCommands.addCommand('w', "Modes", "Toggle reduced shaders", [this]() {
675 !params.fGrContextOptions.fReducedShaderVariations;
677 fWindow->inval();
678 });
679 fCommands.addCommand(skui::Key::kRight, "Right", "Navigation", "Next slide", [this]() {
680 this->setCurrentSlide(fCurrentSlide < fSlides.size() - 1 ? fCurrentSlide + 1 : 0);
681 });
682 fCommands.addCommand(skui::Key::kLeft, "Left", "Navigation", "Previous slide", [this]() {
683 this->setCurrentSlide(fCurrentSlide > 0 ? fCurrentSlide - 1 : fSlides.size() - 1);
684 });
685 fCommands.addCommand(skui::Key::kUp, "Up", "Transform", "Zoom in", [this]() {
686 this->changeZoomLevel(1.f / 32.f);
687 fWindow->inval();
688 });
689 fCommands.addCommand(skui::Key::kDown, "Down", "Transform", "Zoom out", [this]() {
690 this->changeZoomLevel(-1.f / 32.f);
691 fWindow->inval();
692 });
693 fCommands.addCommand('d', "Modes", "Change rendering backend", [this]() {
695 (fBackendType + 1) % sk_app::Window::kBackendTypeCount);
696 // Switching to and from Vulkan is problematic on Linux so disabled for now
697#if defined(SK_BUILD_FOR_UNIX) && defined(SK_VULKAN)
698 if (newBackend == sk_app::Window::kVulkan_BackendType) {
699 newBackend = (sk_app::Window::BackendType)((newBackend + 1) %
701 } else if (fBackendType == sk_app::Window::kVulkan_BackendType) {
702 newBackend = sk_app::Window::kVulkan_BackendType;
703 }
704#endif
705 this->setBackend(newBackend);
706 });
707 fCommands.addCommand('K', "IO", "Save slide to SKP", [this]() {
708 fSaveToSKP = true;
709 fWindow->inval();
710 });
711 fCommands.addCommand('&', "Overlays", "Show slide dimensios", [this]() {
712 fShowSlideDimensions = !fShowSlideDimensions;
713 fWindow->inval();
714 });
715 fCommands.addCommand('G', "Modes", "Geometry", [this]() {
717 uint32_t flags = params.fSurfaceProps.flags();
718 SkPixelGeometry defaultPixelGeometry = fDisplay.fSurfaceProps.pixelGeometry();
719 if (!fDisplayOverrides.fSurfaceProps.fPixelGeometry) {
720 fDisplayOverrides.fSurfaceProps.fPixelGeometry = true;
722 } else {
723 switch (params.fSurfaceProps.pixelGeometry()) {
726 break;
729 break;
732 break;
735 break;
737 params.fSurfaceProps = SkSurfaceProps(flags, defaultPixelGeometry);
738 fDisplayOverrides.fSurfaceProps.fPixelGeometry = false;
739 break;
740 }
741 }
743 this->updateTitle();
744 fWindow->inval();
745 });
746 fCommands.addCommand('H', "Font", "Hinting mode", [this]() {
747 if (!fFontOverrides.fHinting) {
748 fFontOverrides.fHinting = true;
750 } else {
751 switch (fFont.getHinting()) {
754 break;
757 break;
760 break;
763 fFontOverrides.fHinting = false;
764 break;
765 }
766 }
767 this->updateTitle();
768 fWindow->inval();
769 });
770 fCommands.addCommand('D', "Modes", "DFT", [this]() {
772 uint32_t flags = params.fSurfaceProps.flags();
774 params.fSurfaceProps = SkSurfaceProps(flags, params.fSurfaceProps.pixelGeometry());
776 this->updateTitle();
777 fWindow->inval();
778 });
779 fCommands.addCommand('L', "Font", "Subpixel Antialias Mode", [this]() {
780 if (!fFontOverrides.fEdging) {
781 fFontOverrides.fEdging = true;
783 } else {
784 switch (fFont.getEdging()) {
787 break;
790 break;
793 fFontOverrides.fEdging = false;
794 break;
795 }
796 }
797 this->updateTitle();
798 fWindow->inval();
799 });
800 fCommands.addCommand('S', "Font", "Subpixel Position Mode", [this]() {
801 if (!fFontOverrides.fSubpixel) {
802 fFontOverrides.fSubpixel = true;
803 fFont.setSubpixel(false);
804 } else {
805 if (!fFont.isSubpixel()) {
806 fFont.setSubpixel(true);
807 } else {
808 fFontOverrides.fSubpixel = false;
809 }
810 }
811 this->updateTitle();
812 fWindow->inval();
813 });
814 fCommands.addCommand('B', "Font", "Baseline Snapping", [this]() {
815 if (!fFontOverrides.fBaselineSnap) {
816 fFontOverrides.fBaselineSnap = true;
817 fFont.setBaselineSnap(false);
818 } else {
819 if (!fFont.isBaselineSnap()) {
820 fFont.setBaselineSnap(true);
821 } else {
822 fFontOverrides.fBaselineSnap = false;
823 }
824 }
825 this->updateTitle();
826 fWindow->inval();
827 });
828 fCommands.addCommand('p', "Transform", "Toggle Perspective Mode", [this]() {
829 fPerspectiveMode = (kPerspective_Real == fPerspectiveMode) ? kPerspective_Fake
830 : kPerspective_Real;
831 this->updateTitle();
832 fWindow->inval();
833 });
834 fCommands.addCommand('P', "Transform", "Toggle Perspective", [this]() {
835 fPerspectiveMode = (kPerspective_Off == fPerspectiveMode) ? kPerspective_Real
836 : kPerspective_Off;
837 this->updateTitle();
838 fWindow->inval();
839 });
840 fCommands.addCommand('a', "Transform", "Toggle Animation", [this]() {
841 fAnimTimer.togglePauseResume();
842 });
843 fCommands.addCommand('u', "GUI", "Zoom UI", [this]() {
844 fZoomUI = !fZoomUI;
845 fStatsLayer.setDisplayScale((fZoomUI ? 2.0f : 1.0f) * fWindow->scaleFactor());
846 fWindow->inval();
847 });
848 fCommands.addCommand('$', "ViaSerialize", "Toggle ViaSerialize", [this]() {
849 fDrawViaSerialize = !fDrawViaSerialize;
850 this->updateTitle();
851 fWindow->inval();
852 });
853
854 // set up slides
855 this->initSlides();
856 if (FLAGS_list) {
857 this->listNames();
858 }
859
860 fPerspectivePoints[0].set(0, 0);
861 fPerspectivePoints[1].set(1, 0);
862 fPerspectivePoints[2].set(0, 1);
863 fPerspectivePoints[3].set(1, 1);
864 fAnimTimer.run();
865
866 auto gamutImage = ToolUtils::GetResourceAsImage("images/gamut.png");
867 if (gamutImage) {
868 fImGuiGamutPaint.setShader(gamutImage->makeShader(SkSamplingOptions(SkFilterMode::kLinear)));
869 }
870 fImGuiGamutPaint.setColor(SK_ColorWHITE);
871
872 fWindow->attach(backend_type_for_window(fBackendType));
873 this->setCurrentSlide(this->startupSlide());
874}
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:431
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:469
static sk_app::Window::BackendType get_backend_type(const char *str)
Definition Viewer.cpp:382
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)
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)
static void Init()
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)
void resetMeasurements()
void setDisplayScale(float scale)
Definition StatsLayer.h:32
void attach(Window *window)
void addCommand(SkUnichar c, const char *group, const char *description, std::function< void(void)> function)
void setActive(bool active)
Definition Window.h:109
virtual const DisplayParams & getRequestedDisplayParams()
Definition Window.h:155
@ kBackendTypeCount
Definition Window.h:95
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
virtual float scaleFactor() const
Definition Window.h:153
int size() const
Definition SkTArray.h:416
const EmbeddedViewParams * params
FlutterSemanticsFlag flags
void RegisterAllAvailable()
Definition CodecUtils.h:60
void SetCtxOptions(struct GrContextOptions *)
static constexpr skcms_TransferFunction k2Dot2
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition DecodeUtils.h:25
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
PersistentCache * fPersistentCache
ShaderErrorHandler * fShaderErrorHandler
ShaderCacheStrategy fShaderCacheStrategy
void set(float x, float y)
SkSurfacePropsFields fSurfaceProps
Definition Viewer.h:141
SkSurfaceProps fSurfaceProps
GrContextOptions fGrContextOptions

◆ ~Viewer()

Viewer::~Viewer ( )
override

Definition at line 1107 of file Viewer.cpp.

1107 {
1108 for(auto& slide : fSlides) {
1109 slide->gpuTeardown();
1110 }
1111
1112 fWindow->detach();
1113 delete fWindow;
1114}
void detach()
Definition Window.cpp:25

Member Function Documentation

◆ onBackendCreated()

void Viewer::onBackendCreated ( )
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 1847 of file Viewer.cpp.

1847 {
1848 this->setupCurrentSlide();
1849 fWindow->show();
1850}
virtual void show()=0

◆ onChar()

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

Reimplemented from sk_app::Window::Layer.

Definition at line 3331 of file Viewer.cpp.

3331 {
3332 if (fSlides[fCurrentSlide]->onChar(c)) {
3333 fWindow->inval();
3334 return true;
3335 } else {
3336 return fCommands.onChar(c, modifiers);
3337 }
3338}
bool onChar(SkUnichar c, skui::ModifierKey modifiers) override
Definition Viewer.cpp:3331
bool onChar(SkUnichar, skui::ModifierKey modifiers)

◆ onFling()

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

Reimplemented from sk_app::Window::Layer.

Definition at line 1988 of file Viewer.cpp.

1988 {
1990 this->setCurrentSlide(fCurrentSlide > 0 ? fCurrentSlide - 1 : fSlides.size() - 1);
1991 return true;
1992 } else if (skui::InputState::kLeft == state) {
1993 this->setCurrentSlide(fCurrentSlide < fSlides.size() - 1 ? fCurrentSlide + 1 : 0);
1994 return true;
1995 }
1996 return false;
1997}
AtkStateType state

◆ onIdle()

void Viewer::onIdle ( )
overridevirtual

Implements sk_app::Application.

Definition at line 3125 of file Viewer.cpp.

3125 {
3126 TArray<std::function<void()>> actionsToRun;
3127 actionsToRun.swap(fDeferredActions);
3128
3129 for (const auto& fn : actionsToRun) {
3130 fn();
3131 }
3132
3133 fStatsLayer.beginTiming(fAnimateTimer);
3134 fAnimTimer.updateTime();
3135 bool animateWantsInval = fSlides[fCurrentSlide]->animate(fAnimTimer.nanos());
3136 fStatsLayer.endTiming(fAnimateTimer);
3137
3138 ImGuiIO& io = ImGui::GetIO();
3139 // ImGui always has at least one "active" window, which is the default "Debug" window. It may
3140 // not be visible, though. So we need to redraw if there is at least one visible window, or
3141 // more than one active window. Newly created windows are active but not visible for one frame
3142 // while they determine their layout and sizing.
3143 if (animateWantsInval || fStatsLayer.getActive() || fRefresh ||
3144 io.MetricsActiveWindows > 1 || io.MetricsRenderWindows > 0) {
3145 fWindow->inval();
3146 }
3147}
double nanos() const
Definition AnimTimer.h:34
void updateTime()
Definition AnimTimer.h:83
void beginTiming(Timer)
void endTiming(Timer)
void swap(TArray &that)
Definition SkTArray.h:353

◆ onKey()

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

Reimplemented from sk_app::Window::Layer.

Definition at line 3327 of file Viewer.cpp.

3327 {
3328 return fCommands.onKey(key, state, modifiers);
3329}
bool onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers)

◆ onMouse()

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

Reimplemented from sk_app::Window::Layer.

Definition at line 1939 of file Viewer.cpp.

1939 {
1940 if (GestureDevice::kTouch == fGestureDevice) {
1941 return false;
1942 }
1943
1944 const auto slidePt = this->mapEvent(x, y);
1945 if (fSlides[fCurrentSlide]->onMouse(slidePt.x(), slidePt.y(), state, modifiers)) {
1946 fWindow->inval();
1947 return true;
1948 }
1949
1950 switch (state) {
1951 case skui::InputState::kUp: {
1952 fGesture.touchEnd(nullptr);
1953 break;
1954 }
1956 fGesture.touchBegin(nullptr, x, y);
1957 break;
1958 }
1960 fGesture.touchMoved(nullptr, x, y);
1961 break;
1962 }
1963 default: {
1964 SkASSERT(false); // shouldn't see kRight or kLeft here
1965 break;
1966 }
1967 }
1968 fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kMouse : GestureDevice::kNone;
1969
1970 if (state != skui::InputState::kMove || fGesture.isBeingTouched()) {
1971 fWindow->inval();
1972 }
1973 return true;
1974}
#define SkASSERT(cond)
Definition SkAssert.h:116
void touchEnd(void *owner)
bool isBeingTouched()
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:1939
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 1976 of file Viewer.cpp.

1976 {
1977 // Rather than updating the fixed zoom level, treat a mouse wheel event as a gesture, which
1978 // applies a pre- and post-translation to the transform, resulting in a zoom effect centered at
1979 // the mouse cursor position.
1980 SkScalar scale = exp(delta * 0.001);
1981 fGesture.startZoom();
1982 fGesture.updateZoom(scale, x, y, x, y);
1983 fGesture.endZoom();
1984 fWindow->inval();
1985 return true;
1986}
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 1852 of file Viewer.cpp.

1852 {
1853 this->drawSlide(surface);
1854
1855 fCommands.drawHelp(surface->getCanvas());
1856
1857 this->drawImGui();
1858
1859 fLastImage.reset();
1860
1861 if (auto direct = fWindow->directContext()) {
1862 // Clean out cache items that haven't been used in more than 10 seconds.
1863 direct->performDeferredCleanup(std::chrono::seconds(10));
1864 }
1865}
void drawHelp(SkCanvas *canvas)
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 1999 of file Viewer.cpp.

1999 {
2000 switch (state) {
2002 fGesture.startZoom();
2003 return true;
2005 fGesture.updateZoom(scale, x, y, x, y);
2006 return true;
2008 fGesture.endZoom();
2009 return true;
2010 default:
2011 SkASSERT(false);
2012 break;
2013 }
2014
2015 return false;
2016}

◆ onResize()

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

Reimplemented from sk_app::Window::Layer.

Definition at line 1867 of file Viewer.cpp.

1867 {
1868 if (fCurrentSlide >= 0) {
1869 SkScalar scaleFactor = 1.0;
1870 if (fApplyBackingScale) {
1871 scaleFactor = fWindow->scaleFactor();
1872 }
1873 fSlides[fCurrentSlide]->resize(width / scaleFactor, height / scaleFactor);
1874 }
1875}
void resize(size_t count)
Definition SkTArray.h:418
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 1886 of file Viewer.cpp.

1886 {
1887 if (GestureDevice::kMouse == fGestureDevice) {
1888 return false;
1889 }
1890
1891 const auto slidePt = this->mapEvent(x, y);
1892 if (fSlides[fCurrentSlide]->onMouse(slidePt.x(), slidePt.y(), state, skui::ModifierKey::kNone)) {
1893 fWindow->inval();
1894 return true;
1895 }
1896
1897 void* castedOwner = reinterpret_cast<void*>(owner);
1898 switch (state) {
1899 case skui::InputState::kUp: {
1900 fGesture.touchEnd(castedOwner);
1901#if defined(SK_BUILD_FOR_IOS)
1902 // TODO: move IOS swipe detection higher up into the platform code
1903 SkPoint dir;
1904 if (fGesture.isFling(&dir)) {
1905 // swiping left or right
1906 if (SkTAbs(dir.fX) > SkTAbs(dir.fY)) {
1907 if (dir.fX < 0) {
1908 this->setCurrentSlide(fCurrentSlide < fSlides.size() - 1 ?
1909 fCurrentSlide + 1 : 0);
1910 } else {
1911 this->setCurrentSlide(fCurrentSlide > 0 ?
1912 fCurrentSlide - 1 : fSlides.size() - 1);
1913 }
1914 }
1915 fGesture.reset();
1916 }
1917#endif
1918 break;
1919 }
1921 fGesture.touchBegin(castedOwner, x, y);
1922 break;
1923 }
1925 fGesture.touchMoved(castedOwner, x, y);
1926 break;
1927 }
1928 default: {
1929 // kLeft and kRight are only for swipes
1930 SkASSERT(false);
1931 break;
1932 }
1933 }
1934 fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kTouch : GestureDevice::kNone;
1935 fWindow->inval();
1936 return true;
1937}
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 3260 of file Viewer.cpp.

3260 {
3261 // For those who will add more features to handle the state change in this function:
3262 // After the change, please call updateUIState no notify the frontend (e.g., Android app).
3263 // For example, after slide change, updateUIState is called inside setupCurrentSlide;
3264 // after backend change, updateUIState is called in this function.
3265 if (stateName.equals(kSlideStateName)) {
3266 for (int i = 0; i < fSlides.size(); ++i) {
3267 if (fSlides[i]->getName().equals(stateValue)) {
3268 this->setCurrentSlide(i);
3269 return;
3270 }
3271 }
3272
3273 SkDebugf("Slide not found: %s", stateValue.c_str());
3274 } else if (stateName.equals(kBackendStateName)) {
3275 for (int i = 0; i < sk_app::Window::kBackendTypeCount; i++) {
3276 auto backendType = static_cast<sk_app::Window::BackendType>(i);
3277 if (stateValue.equals(get_backend_string(backendType))) {
3278 if (fBackendType != i) {
3279 fBackendType = backendType;
3280 for(auto& slide : fSlides) {
3281 slide->gpuTeardown();
3282 }
3283 fWindow->detach();
3284 fWindow->attach(backend_type_for_window(fBackendType));
3285 }
3286 break;
3287 }
3288 }
3289 } else if (stateName.equals(kMSAAStateName)) {
3291 int sampleCount = atoi(stateValue.c_str());
3292 if (sampleCount != params.fMSAASampleCount) {
3293 params.fMSAASampleCount = sampleCount;
3295 fWindow->inval();
3296 this->updateTitle();
3297 this->updateUIState();
3298 }
3299 } else if (stateName.equals(kPathRendererStateName)) {
3301 for (const auto& pair : gGaneshPathRendererNames) {
3302 if (pair.second == stateValue.c_str()) {
3303 if (params.fGrContextOptions.fGpuPathRenderers != pair.first) {
3304 params.fGrContextOptions.fGpuPathRenderers = pair.first;
3306 fWindow->inval();
3307 this->updateTitle();
3308 this->updateUIState();
3309 }
3310 break;
3311 }
3312 }
3313 } else if (stateName.equals(kSoftkeyStateName)) {
3314 if (!stateValue.equals(kSoftkeyHint)) {
3315 fCommands.onSoftkey(stateValue);
3316 this->updateUIState(); // This is still needed to reset the value to kSoftkeyHint
3317 }
3318 } else if (stateName.equals(kRefreshStateName)) {
3319 // This state is actually NOT in the UI state.
3320 // We use this to allow Android to quickly set bool fRefresh.
3321 fRefresh = stateValue.equals(kON);
3322 } else {
3323 SkDebugf("Unknown stateName: %s", stateName.c_str());
3324 }
3325}
static bool equals(T *a, T *b)
static const char kSoftkeyHint[]
Definition Viewer.cpp:489
static const char kON[]
Definition Viewer.cpp:490
const char * get_backend_string(sk_app::Window::BackendType type)
Definition Viewer.cpp:350
static const char kMSAAStateName[]
Definition Viewer.cpp:486
static const char kPathRendererStateName[]
Definition Viewer.cpp:487
static const char kRefreshStateName[]
Definition Viewer.cpp:491
static const char kBackendStateName[]
Definition Viewer.cpp:485
static const char kSlideStateName[]
Definition Viewer.cpp:484
static const char kSoftkeyStateName[]
Definition Viewer.cpp:488
bool equals(const SkString &) const
Definition SkString.cpp:324
const char * c_str() const
Definition SkString.h:133
bool onSoftkey(const SkString &softkey)

◆ 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: