Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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"
21
22namespace impeller {
23
24class PlaygroundImpl;
25
27 kMetal,
30 kVulkan,
31};
32
34
36 public:
37 using SinglePassCallback = std::function<bool(RenderPass& pass)>;
38
39 explicit Playground(PlaygroundSwitches switches);
40
41 virtual ~Playground();
42
43 static bool ShouldOpenNewPlaygrounds();
44
46 const PlaygroundSwitches& switches);
47
48 void SetupWindow();
49
50 void TeardownWindow();
51
52 bool IsPlaygroundEnabled() const;
53
55
56 ISize GetWindowSize() const;
57
58 IRect GetWindowBounds() const;
59
60 Point GetContentScale() const;
61
62 /// @brief Get the amount of time elapsed from the start of the playground's
63 /// execution.
65
66 std::shared_ptr<Context> GetContext() const;
67
68 std::shared_ptr<Context> MakeContext() const;
69
70 using RenderCallback = std::function<bool(RenderTarget& render_target)>;
71
72 bool OpenPlaygroundHere(const RenderCallback& render_callback);
73
74 bool OpenPlaygroundHere(SinglePassCallback pass_callback);
75
76 static std::shared_ptr<CompressedImage> LoadFixtureImageCompressed(
77 std::shared_ptr<fml::Mapping> mapping);
78
79 static std::optional<DecompressedImage> DecodeImageRGBA(
80 const std::shared_ptr<CompressedImage>& compressed);
81
82 static std::shared_ptr<Texture> CreateTextureForMapping(
83 const std::shared_ptr<Context>& context,
84 std::shared_ptr<fml::Mapping> mapping,
85 bool enable_mipmapping = false);
86
87 std::shared_ptr<Texture> CreateTextureForFixture(
88 const char* fixture_name,
89 bool enable_mipmapping = false) const;
90
91 std::shared_ptr<Texture> CreateTextureCubeForFixture(
92 std::array<const char*, 6> fixture_names) const;
93
94 static bool SupportsBackend(PlaygroundBackend backend);
95
96 virtual std::unique_ptr<fml::Mapping> OpenAssetAsMapping(
97 std::string asset_name) const = 0;
98
99 virtual std::string GetWindowTitle() const = 0;
100
101 [[nodiscard]] fml::Status SetCapabilities(
102 const std::shared_ptr<Capabilities>& capabilities);
103
104 /// Returns true if `OpenPlaygroundHere` will actually render anything.
105 bool WillRenderSomething() const;
106
107 using GLProcAddressResolver = std::function<void*(const char* proc_name)>;
109
111 std::function<void*(void* instance, const char* proc_name)>;
113
114 /// @brief Mark the GPU as unavilable.
115 ///
116 /// Only supported on the Metal backend.
117 void SetGPUDisabled(bool disabled) const;
118
120
121 protected:
123
124 virtual bool ShouldKeepRendering() const;
125
126 void SetWindowSize(ISize size);
127
128 private:
129 fml::TimeDelta start_time_;
130 std::unique_ptr<PlaygroundImpl> impl_;
131 std::shared_ptr<Context> context_;
132 Point cursor_position_;
133 ISize window_size_ = ISize{1024, 768};
134 std::shared_ptr<HostBuffer> host_buffer_;
135
136 void SetCursorPosition(Point pos);
137
138 Playground(const Playground&) = delete;
139
140 Playground& operator=(const Playground&) = delete;
141};
142
143} // namespace impeller
144
145#endif // FLUTTER_IMPELLER_PLAYGROUND_PLAYGROUND_H_
bool OpenPlaygroundHere(const RenderCallback &render_callback)
std::shared_ptr< Context > MakeContext() const
Definition playground.cc:98
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:37
void SetupContext(PlaygroundBackend backend, const PlaygroundSwitches &switches)
GLProcAddressResolver CreateGLProcAddressResolver() const
bool WillRenderSomething() const
Returns true if OpenPlaygroundHere will actually render anything.
RuntimeStageBackend GetRuntimeStageBackend() const
virtual std::string GetWindowTitle() const =0
std::function< bool(RenderTarget &render_target)> RenderCallback
Definition playground.h:70
void SetGPUDisabled(bool disabled) const
Mark the GPU as unavilable.
const PlaygroundSwitches switches_
Definition playground.h:122
std::shared_ptr< Context > GetContext() const
Definition playground.cc:94
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)
IRect GetWindowBounds() const
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:111
std::function< void *(const char *proc_name)> GLProcAddressResolver
Definition playground.h:107
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
std::string PlaygroundBackendToString(PlaygroundBackend backend)
Definition playground.cc:47
float Scalar
Definition scalar.h:19
PlaygroundBackend
Definition playground.h:26