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
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/private/SkTDArray.h"
|
|
|
|
#include "tools/sk_app/DisplayParams.h"
|
2019-08-29 14:39:22 +00:00
|
|
|
#include "tools/skui/InputState.h"
|
|
|
|
#include "tools/skui/Key.h"
|
|
|
|
#include "tools/skui/ModifierKey.h"
|
2016-04-06 19:08:51 +00:00
|
|
|
|
2020-11-25 17:50:19 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2020-07-10 17:55:21 +00:00
|
|
|
class GrDirectContext;
|
2016-04-06 13:08:59 +00:00
|
|
|
class SkCanvas;
|
2016-06-16 21:10:34 +00:00
|
|
|
class SkSurface;
|
2018-04-13 18:30:23 +00:00
|
|
|
class SkSurfaceProps;
|
2020-03-30 19:57:14 +00:00
|
|
|
class SkString;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2021-09-30 20:27:30 +00:00
|
|
|
namespace skgpu {
|
|
|
|
class Context;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2019-08-01 20:21:49 +00:00
|
|
|
virtual ~Window();
|
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
|
|
|
|
2020-11-10 18:10:29 +00:00
|
|
|
// Interface to the system clipboard. Only implemented on UNIX.
|
|
|
|
virtual const char* getClipboardText() { return nullptr; }
|
|
|
|
virtual void setClipboardText(const char*) {}
|
|
|
|
|
|
|
|
// Schedules an invalidation event for window if one is not currently pending.
|
2016-05-23 17:52:34 +00:00
|
|
|
// 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 {
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
2016-04-06 13:08:59 +00:00
|
|
|
kNativeGL_BackendType,
|
2020-03-19 19:54:28 +00:00
|
|
|
#endif
|
2017-08-17 18:37:06 +00:00
|
|
|
#if SK_ANGLE && defined(SK_BUILD_FOR_WIN)
|
|
|
|
kANGLE_BackendType,
|
|
|
|
#endif
|
2019-08-02 19:04:52 +00:00
|
|
|
#ifdef SK_DAWN
|
|
|
|
kDawn_BackendType,
|
|
|
|
#endif
|
2016-06-17 16:29:14 +00:00
|
|
|
#ifdef SK_VULKAN
|
2016-05-20 13:01:06 +00:00
|
|
|
kVulkan_BackendType,
|
2019-02-08 20:36:14 +00:00
|
|
|
#endif
|
2019-09-03 13:42:57 +00:00
|
|
|
#ifdef SK_METAL
|
2019-02-08 20:36:14 +00:00
|
|
|
kMetal_BackendType,
|
2021-09-30 20:27:30 +00:00
|
|
|
#ifdef SK_GRAPHITE_ENABLED
|
|
|
|
kGraphiteMetal_BackendType,
|
|
|
|
#endif
|
2020-05-13 20:54:09 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SK_DIRECT3D
|
|
|
|
kDirect3D_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-04-06 19:08:51 +00:00
|
|
|
|
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) {}
|
2019-08-29 14:39:22 +00:00
|
|
|
virtual bool onChar(SkUnichar c, skui::ModifierKey) { return false; }
|
|
|
|
virtual bool onKey(skui::Key, skui::InputState, skui::ModifierKey) { return false; }
|
|
|
|
virtual bool onMouse(int x, int y, skui::InputState, skui::ModifierKey) { return false; }
|
|
|
|
virtual bool onMouseWheel(float delta, skui::ModifierKey) { return false; }
|
|
|
|
virtual bool onTouch(intptr_t owner, skui::InputState, float x, float y) { return false; }
|
2019-09-09 20:53:39 +00:00
|
|
|
// Platform-detected gesture events
|
|
|
|
virtual bool onFling(skui::InputState state) { return false; }
|
|
|
|
virtual bool onPinch(skui::InputState state, float scale, float x, float y) { return false; }
|
2017-12-08 21:45:43 +00:00
|
|
|
virtual void onUIStateChanged(const SkString& stateName, const SkString& stateValue) {}
|
2017-12-08 21:46:09 +00:00
|
|
|
virtual void onPrePaint() {}
|
2019-03-04 16:00:10 +00:00
|
|
|
virtual void onPaint(SkSurface*) {}
|
2018-08-09 19:06:19 +00:00
|
|
|
virtual void onResize(int width, int height) {}
|
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);
|
2018-08-08 15:23:41 +00:00
|
|
|
fLayers.push_back(layer);
|
2016-05-27 15:52:52 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 20:22:53 +00:00
|
|
|
void onBackendCreated();
|
2019-08-29 14:39:22 +00:00
|
|
|
bool onChar(SkUnichar c, skui::ModifierKey modifiers);
|
|
|
|
bool onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers);
|
|
|
|
bool onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers);
|
|
|
|
bool onMouseWheel(float delta, skui::ModifierKey modifiers);
|
|
|
|
bool onTouch(intptr_t owner, skui::InputState state, float x, float y); // multi-owner = multi-touch
|
2019-09-09 20:53:39 +00:00
|
|
|
// Platform-detected gesture events
|
|
|
|
bool onFling(skui::InputState state);
|
|
|
|
bool onPinch(skui::InputState state, float scale, float x, float y);
|
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);
|
2020-11-16 16:06:58 +00:00
|
|
|
void onActivate(bool isActive);
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2019-02-06 16:23:34 +00:00
|
|
|
int width() const;
|
|
|
|
int height() const;
|
2021-01-28 19:30:59 +00:00
|
|
|
virtual float scaleFactor() const { return 1.0f; }
|
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.
|
2020-07-10 17:55:21 +00:00
|
|
|
GrDirectContext* directContext() const;
|
2021-09-30 20:27:30 +00:00
|
|
|
skgpu::Context* graphiteContext() const;
|
2017-02-28 00:00:53 +00:00
|
|
|
|
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;
|
2020-11-16 16:06:58 +00:00
|
|
|
bool fIsActive = true;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2019-08-01 20:21:49 +00:00
|
|
|
std::unique_ptr<WindowContext> fWindowContext;
|
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
|