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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef Window_DEFINED
|
|
|
|
#define Window_DEFINED
|
|
|
|
|
2016-05-06 20:28:57 +00:00
|
|
|
#include "DisplayParams.h"
|
2016-04-21 14:59:44 +00:00
|
|
|
#include "SkRect.h"
|
2016-05-17 19:44:20 +00:00
|
|
|
#include "SkTouchGesture.h"
|
|
|
|
#include "SkTypes.h"
|
2016-04-06 19:08:51 +00:00
|
|
|
|
2017-02-28 00:00:53 +00:00
|
|
|
class GrContext;
|
2016-04-06 13:08:59 +00:00
|
|
|
class SkCanvas;
|
2016-06-16 21:10:34 +00:00
|
|
|
class SkSurface;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-05-04 20:49:13 +00:00
|
|
|
namespace sk_app {
|
|
|
|
|
2016-05-05 19:32:03 +00:00
|
|
|
class WindowContext;
|
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
class Window {
|
|
|
|
public:
|
|
|
|
static Window* CreateNativeWindow(void* platformData);
|
|
|
|
|
2016-10-18 19:33:53 +00:00
|
|
|
virtual ~Window() { this->detach(); }
|
2016-04-06 13:08:59 +00:00
|
|
|
|
|
|
|
virtual void setTitle(const char*) = 0;
|
|
|
|
virtual void show() = 0;
|
2017-11-21 18:18:02 +00:00
|
|
|
|
|
|
|
// JSON-formatted UI state for Android. Do nothing by default
|
|
|
|
virtual void setUIState(const char*) {}
|
2016-05-23 17:52:34 +00:00
|
|
|
|
|
|
|
// Shedules an invalidation event for window if one is not currently pending.
|
|
|
|
// Make sure that either onPaint or markInvalReceived is called when the client window consumes
|
|
|
|
// the the inval event. They unset fIsContentInvalided which allow future onInval.
|
|
|
|
void inval();
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-04-21 14:59:44 +00:00
|
|
|
virtual bool scaleContentToFit() const { return false; }
|
|
|
|
|
2016-05-20 13:01:06 +00:00
|
|
|
enum BackendType {
|
2016-04-06 13:08:59 +00:00
|
|
|
kNativeGL_BackendType,
|
2017-08-17 18:37:06 +00:00
|
|
|
#if SK_ANGLE && defined(SK_BUILD_FOR_WIN)
|
|
|
|
kANGLE_BackendType,
|
|
|
|
#endif
|
2016-06-17 16:29:14 +00:00
|
|
|
#ifdef SK_VULKAN
|
2016-05-20 13:01:06 +00:00
|
|
|
kVulkan_BackendType,
|
2016-06-17 16:29:14 +00:00
|
|
|
#endif
|
2016-06-07 21:22:37 +00:00
|
|
|
kRaster_BackendType,
|
2016-05-20 13:01:06 +00:00
|
|
|
|
2016-06-07 21:22:37 +00:00
|
|
|
kLast_BackendType = kRaster_BackendType
|
2016-05-20 13:01:06 +00:00
|
|
|
};
|
|
|
|
enum {
|
|
|
|
kBackendTypeCount = kLast_BackendType + 1
|
2016-04-06 13:08:59 +00:00
|
|
|
};
|
|
|
|
|
2017-02-24 23:04:47 +00:00
|
|
|
virtual bool attach(BackendType) = 0;
|
2016-04-06 13:08:59 +00:00
|
|
|
void detach();
|
|
|
|
|
|
|
|
// input handling
|
2016-05-10 13:50:49 +00:00
|
|
|
enum class Key {
|
|
|
|
kNONE, //corresponds to android's UNKNOWN
|
|
|
|
|
|
|
|
kLeftSoftKey,
|
|
|
|
kRightSoftKey,
|
|
|
|
|
|
|
|
kHome, //!< the home key - added to match android
|
|
|
|
kBack, //!< (CLR)
|
|
|
|
kSend, //!< the green (talk) key
|
|
|
|
kEnd, //!< the red key
|
|
|
|
|
|
|
|
k0,
|
|
|
|
k1,
|
|
|
|
k2,
|
|
|
|
k3,
|
|
|
|
k4,
|
|
|
|
k5,
|
|
|
|
k6,
|
|
|
|
k7,
|
|
|
|
k8,
|
|
|
|
k9,
|
|
|
|
kStar, //!< the * key
|
|
|
|
kHash, //!< the # key
|
|
|
|
|
|
|
|
kUp,
|
|
|
|
kDown,
|
|
|
|
kLeft,
|
|
|
|
kRight,
|
|
|
|
|
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
|
|
|
// Keys needed by ImGui
|
|
|
|
kTab,
|
|
|
|
kPageUp,
|
|
|
|
kPageDown,
|
|
|
|
kDelete,
|
|
|
|
kEscape,
|
|
|
|
kShift,
|
|
|
|
kCtrl,
|
|
|
|
kOption, // AKA Alt
|
|
|
|
kA,
|
|
|
|
kC,
|
|
|
|
kV,
|
|
|
|
kX,
|
|
|
|
kY,
|
|
|
|
kZ,
|
|
|
|
|
2016-05-10 13:50:49 +00:00
|
|
|
kOK, //!< the center key
|
|
|
|
|
|
|
|
kVolUp, //!< volume up - match android
|
|
|
|
kVolDown, //!< volume down - same
|
|
|
|
kPower, //!< power button - same
|
|
|
|
kCamera, //!< camera - same
|
|
|
|
|
|
|
|
kLast = kCamera
|
2016-04-06 19:08:51 +00:00
|
|
|
};
|
2016-05-10 13:50:49 +00:00
|
|
|
static const int kKeyCount = static_cast<int>(Key::kLast) + 1;
|
2016-04-06 19:08:51 +00:00
|
|
|
|
|
|
|
enum ModifierKeys {
|
|
|
|
kShift_ModifierKey = 1 << 0,
|
|
|
|
kControl_ModifierKey = 1 << 1,
|
|
|
|
kOption_ModifierKey = 1 << 2, // same as ALT
|
|
|
|
kCommand_ModifierKey = 1 << 3,
|
|
|
|
kFirstPress_ModifierKey = 1 << 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum InputState {
|
|
|
|
kDown_InputState,
|
|
|
|
kUp_InputState,
|
|
|
|
kMove_InputState // only valid for mouse
|
|
|
|
};
|
|
|
|
|
2017-12-08 21:45:43 +00:00
|
|
|
class Layer {
|
|
|
|
public:
|
2017-12-19 16:15:16 +00:00
|
|
|
Layer() : fActive(true) {}
|
2017-12-08 21:45:43 +00:00
|
|
|
virtual ~Layer() = default;
|
|
|
|
|
2017-12-19 16:15:16 +00:00
|
|
|
bool getActive() { return fActive; }
|
|
|
|
void setActive(bool active) { fActive = active; }
|
|
|
|
|
2017-12-08 21:45:43 +00:00
|
|
|
// return value of 'true' means 'I have handled this event'
|
|
|
|
virtual void onBackendCreated() {}
|
2017-12-08 21:46:09 +00:00
|
|
|
virtual void onAttach(Window* window) {}
|
2017-12-08 21:45:43 +00:00
|
|
|
virtual bool onChar(SkUnichar c, uint32_t modifiers) { return false; }
|
|
|
|
virtual bool onKey(Key key, InputState state, uint32_t modifiers) { return false; }
|
|
|
|
virtual bool onMouse(int x, int y, InputState state, uint32_t modifiers) { return false; }
|
|
|
|
virtual bool onMouseWheel(float delta, uint32_t modifiers) { return false; }
|
|
|
|
virtual bool onTouch(intptr_t owner, InputState state, float x, float y) { return false; }
|
|
|
|
virtual void onUIStateChanged(const SkString& stateName, const SkString& stateValue) {}
|
2017-12-08 21:46:09 +00:00
|
|
|
virtual void onPrePaint() {}
|
2017-12-08 21:45:43 +00:00
|
|
|
virtual void onPaint(SkCanvas*) {}
|
2017-12-19 16:15:16 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class Window;
|
|
|
|
bool fActive;
|
2017-12-08 21:45:43 +00:00
|
|
|
};
|
2016-05-17 19:44:20 +00:00
|
|
|
|
2017-12-08 21:45:43 +00:00
|
|
|
void pushLayer(Layer* layer) {
|
2017-12-08 21:46:09 +00:00
|
|
|
layer->onAttach(this);
|
2017-12-08 21:45:43 +00:00
|
|
|
fLayers.push(layer);
|
2016-05-27 15:52:52 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 20:22:53 +00:00
|
|
|
void onBackendCreated();
|
2016-04-06 19:08:51 +00:00
|
|
|
bool onChar(SkUnichar c, uint32_t modifiers);
|
|
|
|
bool onKey(Key key, InputState state, uint32_t modifiers);
|
|
|
|
bool onMouse(int x, int y, InputState state, uint32_t modifiers);
|
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 onMouseWheel(float delta, uint32_t modifiers);
|
2016-06-06 15:48:47 +00:00
|
|
|
bool onTouch(intptr_t owner, InputState state, float x, float y); // multi-owner = multi-touch
|
2016-05-27 15:52:52 +00:00
|
|
|
void onUIStateChanged(const SkString& stateName, const SkString& stateValue);
|
2016-04-06 13:08:59 +00:00
|
|
|
void onPaint();
|
2016-07-27 15:50:12 +00:00
|
|
|
void onResize(int width, int height);
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2017-02-24 20:22:53 +00:00
|
|
|
int width();
|
|
|
|
int height();
|
2016-04-08 19:51:45 +00:00
|
|
|
|
2017-02-24 23:04:47 +00:00
|
|
|
virtual const DisplayParams& getRequestedDisplayParams() { return fRequestedDisplayParams; }
|
2017-06-23 17:32:29 +00:00
|
|
|
virtual void setRequestedDisplayParams(const DisplayParams&, bool allowReattach = true);
|
2017-02-24 23:04:47 +00:00
|
|
|
|
|
|
|
// Actual parameters in effect, obtained from the native window.
|
|
|
|
int sampleCount() const;
|
|
|
|
int stencilBits() const;
|
2016-05-06 20:28:57 +00:00
|
|
|
|
2017-02-28 00:00:53 +00:00
|
|
|
// Returns null if there is not a GPU backend or if the backend is not yet created.
|
|
|
|
const GrContext* getGrContext() const;
|
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
protected:
|
|
|
|
Window();
|
|
|
|
|
2017-12-08 21:45:43 +00:00
|
|
|
SkTDArray<Layer*> fLayers;
|
2017-02-24 23:04:47 +00:00
|
|
|
DisplayParams fRequestedDisplayParams;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-05-17 19:44:20 +00:00
|
|
|
WindowContext* fWindowContext = nullptr;
|
2016-05-23 17:52:34 +00:00
|
|
|
|
|
|
|
virtual void onInval() = 0;
|
|
|
|
|
|
|
|
// Uncheck fIsContentInvalided to allow future inval/onInval.
|
|
|
|
void markInvalProcessed();
|
|
|
|
|
|
|
|
bool fIsContentInvalidated = false; // use this to avoid duplicate invalidate events
|
2017-12-19 16:15:16 +00:00
|
|
|
|
|
|
|
void visitLayers(std::function<void(Layer*)> visitor);
|
|
|
|
bool signalLayers(std::function<bool(Layer*)> visitor);
|
2016-04-06 13:08:59 +00:00
|
|
|
};
|
|
|
|
|
2016-05-04 20:49:13 +00:00
|
|
|
} // namespace sk_app
|
2016-04-06 13:08:59 +00:00
|
|
|
#endif
|