| Flutter Impeller |

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 #pragma once
6
7 #include <chrono>
8 #include <memory>
9
10 #include "flutter/fml/closure.h"
11 #include "flutter/fml/macros.h"
12 #include "flutter/fml/time/time_delta.h"
13 #include "impeller/core/texture.h"
14 #include "impeller/geometry/point.h"
15 #include "impeller/image/compressed_image.h"
16 #include "impeller/image/decompressed_image.h"
17 #include "impeller/playground/switches.h"
18 #include "impeller/renderer/renderer.h"
19 #include "impeller/runtime_stage/runtime_stage.h"
20
21 namespace impeller {
22
23 class PlaygroundImpl;
24
25 enum class PlaygroundBackend {
26 kMetal,
27 kOpenGLES,
28 kVulkan,
29 };
30
31 std::string PlaygroundBackendToString(PlaygroundBackend backend);
32
33 class Playground {
34 public:
35 using SinglePassCallback = std::function<bool(RenderPass& pass)>;
36
37 explicit Playground(PlaygroundSwitches switches);
38
39 virtual ~Playground();
40
41 static bool ShouldOpenNewPlaygrounds();
42
43 void SetupContext(PlaygroundBackend backend);
44
45 void SetupWindow();
46
47 void TeardownWindow();
48
49 Point GetCursorPosition() const;
50
51 ISize GetWindowSize() const;
52
53 Point GetContentScale() const;
54
55 /// @brief Get the amount of time elapsed from the start of the playground's
56 /// execution.
57 Scalar GetSecondsElapsed() const;
58
59 std::shared_ptr<Context> GetContext() const;
60
61 bool OpenPlaygroundHere(const Renderer::RenderCallback& render_callback);
62
63 bool OpenPlaygroundHere(SinglePassCallback pass_callback);
64
65 static std::shared_ptr<CompressedImage> LoadFixtureImageCompressed(
66 std::shared_ptr<fml::Mapping> mapping);
67
68 static std::optional<DecompressedImage> DecodeImageRGBA(
69 const std::shared_ptr<CompressedImage>& compressed);
70
71 static std::shared_ptr<Texture> CreateTextureForMapping(
72 const std::shared_ptr<Context>& context,
73 std::shared_ptr<fml::Mapping> mapping,
74 bool enable_mipmapping = false);
75
76 std::shared_ptr<Texture> CreateTextureForFixture(
77 const char* fixture_name,
78 bool enable_mipmapping = false) const;
79
80 std::shared_ptr<Texture> CreateTextureCubeForFixture(
81 std::array<const char*, 6> fixture_names) const;
82
83 static bool SupportsBackend(PlaygroundBackend backend);
84
85 virtual std::unique_ptr<fml::Mapping> OpenAssetAsMapping(
86 std::string asset_name) const = 0;
87
88 virtual std::string GetWindowTitle() const = 0;
89
90 protected:
91 const PlaygroundSwitches switches_;
92
93 virtual bool ShouldKeepRendering() const;
94
95 private:
96 struct GLFWInitializer;
97
98 fml::TimeDelta start_time_;
99 std::unique_ptr<GLFWInitializer> glfw_initializer_;
100 std::unique_ptr<PlaygroundImpl> impl_;
101 std::shared_ptr<Context> context_;
102 std::unique_ptr<Renderer> renderer_;
103 Point cursor_position_;
104 ISize window_size_ = ISize{1024, 768};
105
106 void SetCursorPosition(Point pos);
107
108 void SetWindowSize(ISize size);
109
110 FML_DISALLOW_COPY_AND_ASSIGN(Playground);
111 };
112
113 } // namespace impeller
impeller::Playground::ShouldOpenNewPlaygrounds
static bool ShouldOpenNewPlaygrounds()
Definition: playground.cc:152
impeller::Playground::CreateTextureCubeForFixture
std::shared_ptr< Texture > CreateTextureCubeForFixture(std::array< const char *, 6 > fixture_names) const
Definition: playground.cc:487
impeller::PlaygroundBackend::kVulkan
@ kVulkan
point.h
impeller::Scalar
float Scalar
Definition: scalar.h:15
impeller::Playground::ShouldKeepRendering
virtual bool ShouldKeepRendering() const
Definition: playground.cc:531
impeller::Renderer::RenderCallback
std::function< bool(RenderTarget &render_target)> RenderCallback
Definition: renderer.h:25
impeller::Playground::DecodeImageRGBA
static std::optional< DecompressedImage > DecodeImageRGBA(const std::shared_ptr< CompressedImage > &compressed)
Definition: playground.cc:365
impeller::Playground::GetSecondsElapsed
Scalar GetSecondsElapsed() const
Get the amount of time elapsed from the start of the playground's execution.
Definition: playground.cc:181
impeller::Playground::GetWindowSize
ISize GetWindowSize() const
Definition: playground.cc:173
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::PlaygroundBackendToString
std::string PlaygroundBackendToString(PlaygroundBackend backend)
Definition: playground.cc:39
impeller::PlaygroundBackend
PlaygroundBackend
Definition: playground.h:25
impeller::TSize< int64_t >
runtime_stage.h
impeller::Playground
Definition: playground.h:33
impeller::Playground::SetupWindow
void SetupWindow()
Definition: playground.cc:126
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:91
impeller::Playground::GLFWInitializer
Definition: playground.cc:51
impeller::Playground::SinglePassCallback
std::function< bool(RenderPass &pass)> SinglePassCallback
Definition: playground.h:35
switches.h
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:27
decompressed_image.h
impeller::Playground::~Playground
virtual ~Playground()
impeller::PlaygroundBackend::kOpenGLES
@ kOpenGLES
impeller::Playground::CreateTextureForMapping
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:461
impeller::Playground::GetContentScale
Point GetContentScale() const
Definition: playground.cc:177
impeller::PlaygroundSwitches
Definition: switches.h:15
impeller::Playground::LoadFixtureImageCompressed
static std::shared_ptr< CompressedImage > LoadFixtureImageCompressed(std::shared_ptr< fml::Mapping > mapping)
Definition: playground.cc:354
impeller::Playground::GetWindowTitle
virtual std::string GetWindowTitle() const =0
impeller::TPoint< Scalar >
impeller::Playground::OpenAssetAsMapping
virtual std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const =0
impeller::Playground::GetCursorPosition
Point GetCursorPosition() const
Definition: playground.cc:169
texture.h
impeller::Playground::SetupContext
void SetupContext(PlaygroundBackend backend)
Definition: playground.cc:114
impeller::Playground::SupportsBackend
static bool SupportsBackend(PlaygroundBackend backend)
Definition: playground.cc:90
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
Definition: playground.cc:189
impeller::Playground::TeardownWindow
void TeardownWindow()
Definition: playground.cc:141
impeller::Playground::Playground
Playground(PlaygroundSwitches switches)
Definition: playground.cc:80
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:86
renderer.h
impeller
Definition: aiks_context.cc:10
compressed_image.h
impeller::Playground::CreateTextureForFixture
std::shared_ptr< Texture > CreateTextureForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Definition: playground.cc:474