Flutter Engine
The Flutter Engine
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"
12#include "flutter/fml/time/time_delta.h"
22
23namespace impeller {
24
25class PlaygroundImpl;
26
28 kMetal,
29 kOpenGLES,
30 kVulkan,
31};
32
35 switch (backend) {
42 }
44}
45
47
49 public:
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 bool OpenPlaygroundHere(const Renderer::RenderCallback& render_callback);
82
83 bool OpenPlaygroundHere(SinglePassCallback pass_callback);
84
85 static std::shared_ptr<CompressedImage> LoadFixtureImageCompressed(
86 std::shared_ptr<fml::Mapping> mapping);
87
88 static std::optional<DecompressedImage> DecodeImageRGBA(
89 const std::shared_ptr<CompressedImage>& compressed);
90
91 static std::shared_ptr<Texture> CreateTextureForMapping(
92 const std::shared_ptr<Context>& context,
93 std::shared_ptr<fml::Mapping> mapping,
94 bool enable_mipmapping = false);
95
96 std::shared_ptr<Texture> CreateTextureForFixture(
97 const char* fixture_name,
98 bool enable_mipmapping = false) const;
99
100 std::shared_ptr<Texture> CreateTextureCubeForFixture(
101 std::array<const char*, 6> fixture_names) const;
102
104
105 virtual std::unique_ptr<fml::Mapping> OpenAssetAsMapping(
106 std::string asset_name) const = 0;
107
108 virtual std::string GetWindowTitle() const = 0;
109
110 [[nodiscard]] fml::Status SetCapabilities(
111 const std::shared_ptr<Capabilities>& capabilities);
112
113 /// TODO(https://github.com/flutter/flutter/issues/139950): Remove this.
114 /// Returns true if `OpenPlaygroundHere` will actually render anything.
115 bool WillRenderSomething() const;
116
117 protected:
119
120 virtual bool ShouldKeepRendering() const;
121
123
124 private:
125 fml::TimeDelta start_time_;
126 std::unique_ptr<PlaygroundImpl> impl_;
127 std::shared_ptr<Context> context_;
128 std::unique_ptr<Renderer> renderer_;
129 Point cursor_position_;
130 ISize window_size_ = ISize{1024, 768};
131
132 void SetCursorPosition(Point pos);
133
134 Playground(const Playground&) = delete;
135
136 Playground& operator=(const Playground&) = delete;
137};
138
139} // namespace impeller
140
141#endif // FLUTTER_IMPELLER_PLAYGROUND_PLAYGROUND_H_
const char * backend
SkPoint pos
Playground(PlaygroundSwitches switches)
Definition: playground.cc:83
std::shared_ptr< Context > MakeContext() const
Definition: playground.cc:94
bool IsPlaygroundEnabled() const
Definition: playground.cc:152
virtual bool ShouldKeepRendering() const
Definition: playground.cc:521
static bool ShouldOpenNewPlaygrounds()
Definition: playground.cc:167
Point GetCursorPosition() const
Definition: playground.cc:184
void SetWindowSize(ISize size)
Definition: playground.cc:517
static std::shared_ptr< CompressedImage > LoadFixtureImageCompressed(std::shared_ptr< fml::Mapping > mapping)
Definition: playground.cc:369
ISize GetWindowSize() const
Definition: playground.cc:188
std::function< bool(RenderPass &pass)> SinglePassCallback
Definition: playground.h:50
void SetupContext(PlaygroundBackend backend, const PlaygroundSwitches &switches)
Definition: playground.cc:124
bool WillRenderSomething() const
Definition: playground.cc:530
virtual std::string GetWindowTitle() const =0
const PlaygroundSwitches switches_
Definition: playground.h:118
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:90
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
Definition: playground.cc:204
static bool SupportsBackend(PlaygroundBackend backend)
Definition: playground.cc:100
static std::shared_ptr< Texture > CreateTextureForMapping(const std::shared_ptr< Context > &context, std::shared_ptr< fml::Mapping > mapping, bool enable_mipmapping=false)
Definition: playground.cc:441
virtual std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const =0
Point GetContentScale() const
Definition: playground.cc:192
std::shared_ptr< Texture > CreateTextureForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Definition: playground.cc:454
Scalar GetSecondsElapsed() const
Get the amount of time elapsed from the start of the playground's execution.
Definition: playground.cc:196
static std::optional< DecompressedImage > DecodeImageRGBA(const std::shared_ptr< CompressedImage > &compressed)
Definition: playground.cc:380
std::shared_ptr< Texture > CreateTextureCubeForFixture(std::array< const char *, 6 > fixture_names) const
Definition: playground.cc:467
fml::Status SetCapabilities(const std::shared_ptr< Capabilities > &capabilities)
Definition: playground.cc:525
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
std::function< bool(RenderTarget &render_target)> RenderCallback
Definition: renderer.h:23
#define FML_UNREACHABLE()
Definition: logging.h:109
Dart_NativeFunction function
Definition: fuchsia.cc:51
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
std::string PlaygroundBackendToString(PlaygroundBackend backend)
Definition: playground.cc:45
float Scalar
Definition: scalar.h:18
constexpr RuntimeStageBackend PlaygroundBackendToRuntimeStageBackend(PlaygroundBackend backend)
Definition: playground.h:33
PlaygroundBackend
Definition: playground.h:27