42bb6acf56
The content rect was always identical to the window rect, so most of the related code did nothing. The translation limit code is always useful (to avoid dragging the slide way off-screen with the mouse), so always include it. The auto-scaling to fit the screen is also still useful, but just base it on the window rect. The zoom code has four state variables, only used two of them, and one was a trivially derived computation. Fold most of that work into computeMatrix. (The translation was always zero -- we never changed the zoom center.) Include fDefaultMatrix in the matrix from computeMatrix, rather than needing to apply it specially to the canvas. Don't apply the inverse default matrix to touch or mouse points. The absolute positions of those touch points is not important, but because that matrix includes scale (and sometimes very large or very small scale), it just had the effect of greatly amplifying or damping the drag speed. Without it, the slide always pans at the speed of the touch/mouse drag -- which seems more desirable. The use of the inverse default matrix was a clever trick, but it caused the translation (applied to the global mtx) to be scaled, so the slide was always pinned incorrectly. Instead, supply the unmodified window rect and the default matrix, so the trans limit code can do the obvious correct thing: xform the slide bounds completely, then limit the translation that will be applied after that. Slides are now correctly pinned to screen edge regardless of how much zoom is present in the default matrix. Note: There are still several bugs related to all of this code, but given the web of xform state, it's hard to unravel. The touch gesture still doesn't know about viewer's zoom, so that's ignored when doing the pinning. Beyond that, it doesn't even know about window resize - it only configures the translation limit when setting up a slide. I had a fix for all of this (doing the translation limiting in computeMatrix), but then the touch gesture doesn't know about it, and can accumulate drag motion that needs to be un-dragged to get back on-screen, even though the slide is never really translated that far. SkTouchGesture is in include. No one uses it except viewer: TBR=bsalomon@google.com Bug: skia: Change-Id: I460cc07c3de6d36e63826f57d359faf1facf5ab3 Reviewed-on: https://skia-review.googlesource.com/18524 Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Yuqian Li <liyuqian@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
106 lines
3.2 KiB
C++
106 lines
3.2 KiB
C++
/*
|
|
* Copyright 2016 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#ifndef Viewer_DEFINED
|
|
#define Viewer_DEFINED
|
|
|
|
#include "sk_app/Application.h"
|
|
#include "sk_app/CommandSet.h"
|
|
#include "sk_app/Window.h"
|
|
#include "gm.h"
|
|
#include "SkAnimTimer.h"
|
|
#include "SkTouchGesture.h"
|
|
#include "Slide.h"
|
|
|
|
class SkCanvas;
|
|
|
|
class Viewer : public sk_app::Application {
|
|
public:
|
|
Viewer(int argc, char** argv, void* platformData);
|
|
~Viewer() override;
|
|
|
|
void onBackendCreated();
|
|
void onPaint(SkCanvas* canvas);
|
|
void onIdle() override;
|
|
bool onTouch(intptr_t owner, sk_app::Window::InputState state, float x, float y);
|
|
bool onMouse(float x, float y, sk_app::Window::InputState state, uint32_t modifiers);
|
|
void onUIStateChanged(const SkString& stateName, const SkString& stateValue);
|
|
bool onKey(sk_app::Window::Key key, sk_app::Window::InputState state, uint32_t modifiers);
|
|
bool onChar(SkUnichar c, uint32_t modifiers);
|
|
|
|
private:
|
|
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
|
|
};
|
|
|
|
void initSlides();
|
|
void updateTitle();
|
|
void setBackend(sk_app::Window::BackendType);
|
|
void setColorMode(ColorMode);
|
|
void setStartupSlide();
|
|
void setupCurrentSlide(int previousSlide);
|
|
void listNames();
|
|
|
|
void updateUIState();
|
|
|
|
void drawSlide(SkCanvas* canvs);
|
|
void drawStats(SkCanvas* canvas);
|
|
void drawImGui(SkCanvas* canvas);
|
|
|
|
void changeZoomLevel(float delta);
|
|
SkMatrix computeMatrix();
|
|
|
|
sk_app::Window* fWindow;
|
|
|
|
static const int kMeasurementCount = 64; // should be power of 2 for fast mod
|
|
double fPaintTimes[kMeasurementCount];
|
|
double fFlushTimes[kMeasurementCount];
|
|
double fAnimateTimes[kMeasurementCount];
|
|
int fCurrentMeasurement;
|
|
|
|
SkAnimTimer fAnimTimer;
|
|
SkTArray<sk_sp<Slide>> fSlides;
|
|
int fCurrentSlide;
|
|
|
|
bool fDisplayStats;
|
|
bool fRefresh; // whether to continuously refresh for measuring render time
|
|
|
|
SkPaint fImGuiFontPaint;
|
|
SkPaint fImGuiGamutPaint;
|
|
bool fShowImGuiDebugWindow;
|
|
bool fShowImGuiTestWindow;
|
|
|
|
bool fShowZoomWindow;
|
|
sk_sp<SkImage> fLastImage;
|
|
|
|
sk_app::Window::BackendType fBackendType;
|
|
|
|
// Color properties for slide rendering
|
|
ColorMode fColorMode;
|
|
SkColorSpacePrimaries fColorSpacePrimaries;
|
|
|
|
// transform data
|
|
SkScalar fZoomLevel;
|
|
|
|
sk_app::CommandSet fCommands;
|
|
|
|
SkTouchGesture fGesture;
|
|
|
|
// identity unless the window initially scales the content to fit the screen.
|
|
SkMatrix fDefaultMatrix;
|
|
|
|
SkTArray<std::function<void(void)>> fDeferredActions;
|
|
|
|
Json::Value fAllSlideNames; // cache all slide names for fast updateUIState
|
|
};
|
|
|
|
|
|
#endif
|