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