Flutter Engine
The 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/closure.h"
12#include "flutter/fml/macros.h"
13#include "flutter/fml/status.h"
14#include "flutter/fml/time/time_delta.h"
24
25namespace impeller {
26
27class PlaygroundImpl;
28
30 kMetal,
32 kVulkan,
33};
34
47
49
51 public:
52 using SinglePassCallback = std::function<bool(RenderPass& pass)>;
53
54 explicit Playground(PlaygroundSwitches switches);
55
56 virtual ~Playground();
57
58 static bool ShouldOpenNewPlaygrounds();
59
61 const PlaygroundSwitches& switches);
62
63 void SetupWindow();
64
65 void TeardownWindow();
66
67 bool IsPlaygroundEnabled() const;
68
70
71 ISize GetWindowSize() const;
72
73 Point GetContentScale() const;
74
75 /// @brief Get the amount of time elapsed from the start of the playground's
76 /// execution.
78
79 std::shared_ptr<Context> GetContext() const;
80
81 std::shared_ptr<Context> MakeContext() const;
82
83 bool OpenPlaygroundHere(const Renderer::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 /// TODO(https://github.com/flutter/flutter/issues/139950): Remove this.
116 /// Returns true if `OpenPlaygroundHere` will actually render anything.
117 bool WillRenderSomething() const;
118
119 protected:
121
122 virtual bool ShouldKeepRendering() const;
123
124 void SetWindowSize(ISize size);
125
126 private:
127 fml::TimeDelta start_time_;
128 std::unique_ptr<PlaygroundImpl> impl_;
129 std::shared_ptr<Context> context_;
130 std::unique_ptr<Renderer> renderer_;
131 Point cursor_position_;
132 ISize window_size_ = ISize{1024, 768};
133
134 void SetCursorPosition(Point pos);
135
136 Playground(const Playground&) = delete;
137
138 Playground& operator=(const Playground&) = delete;
139};
140
141} // namespace impeller
142
143#endif // FLUTTER_IMPELLER_PLAYGROUND_PLAYGROUND_H_
const char * backend
SkPoint pos
std::shared_ptr< Context > MakeContext() const
Definition playground.cc:93
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:52
void SetupContext(PlaygroundBackend backend, const PlaygroundSwitches &switches)
bool WillRenderSomething() const
virtual std::string GetWindowTitle() const =0
const PlaygroundSwitches switches_
Definition playground.h:120
std::shared_ptr< Context > GetContext() const
Definition playground.cc:89
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
static bool SupportsBackend(PlaygroundBackend backend)
Definition playground.cc:99
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.
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)
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
std::string PlaygroundBackendToString(PlaygroundBackend backend)
Definition playground.cc:44
float Scalar
Definition scalar.h:18
constexpr RuntimeStageBackend PlaygroundBackendToRuntimeStageBackend(PlaygroundBackend backend)
Definition playground.h:35
PlaygroundBackend
Definition playground.h:29