Flutter Engine
 
Loading...
Searching...
No Matches
playground.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_IMPELLER_PLAYGROUND_PLAYGROUND_H_
6#define FLUTTER_IMPELLER_PLAYGROUND_PLAYGROUND_H_
7
8#include <chrono>
9#include <memory>
10
11#include "flutter/fml/status.h"
22
23namespace impeller {
24
25class PlaygroundImpl;
26
28 kMetal,
30 kVulkan,
31};
32
45
47
49 public:
50 using SinglePassCallback = std::function<bool(RenderPass& pass)>;
51
52 explicit Playground(PlaygroundSwitches switches);
53
54 virtual ~Playground();
55
56 static bool ShouldOpenNewPlaygrounds();
57
59 const PlaygroundSwitches& switches);
60
61 void SetupWindow();
62
63 void TeardownWindow();
64
65 bool IsPlaygroundEnabled() const;
66
68
69 ISize GetWindowSize() const;
70
71 Point GetContentScale() const;
72
73 /// @brief Get the amount of time elapsed from the start of the playground's
74 /// execution.
76
77 std::shared_ptr<Context> GetContext() const;
78
79 std::shared_ptr<Context> MakeContext() const;
80
81 using RenderCallback = std::function<bool(RenderTarget& render_target)>;
82
83 bool OpenPlaygroundHere(const RenderCallback& render_callback);
84
85 bool OpenPlaygroundHere(SinglePassCallback pass_callback);
86
87 static std::shared_ptr<CompressedImage> LoadFixtureImageCompressed(
88 std::shared_ptr<fml::Mapping> mapping);
89
90 static std::optional<DecompressedImage> DecodeImageRGBA(
91 const std::shared_ptr<CompressedImage>& compressed);
92
93 static std::shared_ptr<Texture> CreateTextureForMapping(
94 const std::shared_ptr<Context>& context,
95 std::shared_ptr<fml::Mapping> mapping,
96 bool enable_mipmapping = false);
97
98 std::shared_ptr<Texture> CreateTextureForFixture(
99 const char* fixture_name,
100 bool enable_mipmapping = false) const;
101
102 std::shared_ptr<Texture> CreateTextureCubeForFixture(
103 std::array<const char*, 6> fixture_names) const;
104
105 static bool SupportsBackend(PlaygroundBackend backend);
106
107 virtual std::unique_ptr<fml::Mapping> OpenAssetAsMapping(
108 std::string asset_name) const = 0;
109
110 virtual std::string GetWindowTitle() const = 0;
111
112 [[nodiscard]] fml::Status SetCapabilities(
113 const std::shared_ptr<Capabilities>& capabilities);
114
115 /// Returns true if `OpenPlaygroundHere` will actually render anything.
116 bool WillRenderSomething() const;
117
118 using GLProcAddressResolver = std::function<void*(const char* proc_name)>;
120
122 std::function<void*(void* instance, const char* proc_name)>;
124
125 /// @brief Mark the GPU as unavilable.
126 ///
127 /// Only supported on the Metal backend.
128 void SetGPUDisabled(bool disabled) const;
129
130 protected:
132
133 virtual bool ShouldKeepRendering() const;
134
135 void SetWindowSize(ISize size);
136
137 private:
138 fml::TimeDelta start_time_;
139 std::unique_ptr<PlaygroundImpl> impl_;
140 std::shared_ptr<Context> context_;
141 Point cursor_position_;
142 ISize window_size_ = ISize{1024, 768};
143 std::shared_ptr<HostBuffer> host_buffer_;
144
145 void SetCursorPosition(Point pos);
146
147 Playground(const Playground&) = delete;
148
149 Playground& operator=(const Playground&) = delete;
150};
151
152} // namespace impeller
153
154#endif // FLUTTER_IMPELLER_PLAYGROUND_PLAYGROUND_H_
bool OpenPlaygroundHere(const RenderCallback &render_callback)
std::shared_ptr< Context > MakeContext() const
Definition playground.cc:95
bool IsPlaygroundEnabled() const
virtual bool ShouldKeepRendering() const
static bool ShouldOpenNewPlaygrounds()
Point GetCursorPosition() const
void SetWindowSize(ISize size)
static std::shared_ptr< CompressedImage > LoadFixtureImageCompressed(std::shared_ptr< fml::Mapping > mapping)
ISize GetWindowSize() const
std::function< bool(RenderPass &pass)> SinglePassCallback
Definition playground.h:50
void SetupContext(PlaygroundBackend backend, const PlaygroundSwitches &switches)
GLProcAddressResolver CreateGLProcAddressResolver() const
bool WillRenderSomething() const
Returns true if OpenPlaygroundHere will actually render anything.
virtual std::string GetWindowTitle() const =0
std::function< bool(RenderTarget &render_target)> RenderCallback
Definition playground.h:81
void SetGPUDisabled(bool disabled) const
Mark the GPU as unavilable.
const PlaygroundSwitches switches_
Definition playground.h:131
std::shared_ptr< Context > GetContext() const
Definition playground.cc:91
static bool SupportsBackend(PlaygroundBackend backend)
static std::shared_ptr< Texture > CreateTextureForMapping(const std::shared_ptr< Context > &context, std::shared_ptr< fml::Mapping > mapping, bool enable_mipmapping=false)
virtual std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const =0
Point GetContentScale() const
std::shared_ptr< Texture > CreateTextureForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Scalar GetSecondsElapsed() const
Get the amount of time elapsed from the start of the playground's execution.
std::function< void *(void *instance, const char *proc_name)> VKProcAddressResolver
Definition playground.h:122
std::function< void *(const char *proc_name)> GLProcAddressResolver
Definition playground.h:118
static std::optional< DecompressedImage > DecodeImageRGBA(const std::shared_ptr< CompressedImage > &compressed)
std::shared_ptr< Texture > CreateTextureCubeForFixture(std::array< const char *, 6 > fixture_names) const
fml::Status SetCapabilities(const std::shared_ptr< Capabilities > &capabilities)
VKProcAddressResolver CreateVKProcAddressResolver() const
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition render_pass.h:30
VkInstance instance
Definition main.cc:64
#define FML_UNREACHABLE()
Definition logging.h:128
std::string PlaygroundBackendToString(PlaygroundBackend backend)
Definition playground.cc:46
float Scalar
Definition scalar.h:19
constexpr RuntimeStageBackend PlaygroundBackendToRuntimeStageBackend(PlaygroundBackend backend)
Definition playground.h:33
PlaygroundBackend
Definition playground.h:27