| Flutter Impeller |

golden_playground_test.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_GOLDEN_TESTS_GOLDEN_PLAYGROUND_TEST_H_
6 #define FLUTTER_IMPELLER_GOLDEN_TESTS_GOLDEN_PLAYGROUND_TEST_H_
7
8 #include <memory>
9
10 #include "flutter/display_list/display_list.h"
11 #include "flutter/display_list/image/dl_image.h"
12 #include "flutter/impeller/display_list/aiks_context.h"
13 #include "flutter/impeller/golden_tests/screenshot.h"
14 #include "flutter/impeller/playground/playground.h"
15 #include "flutter/impeller/renderer/render_target.h"
16 #include "flutter/testing/testing.h"
17 #include "impeller/typographer/typographer_context.h"
18 #include "third_party/imgui/imgui.h"
19
20 #if FML_OS_MACOSX
21 #include "flutter/fml/platform/darwin/scoped_nsautorelease_pool.h"
22 #endif
23
24 namespace impeller {
25
26 class GoldenPlaygroundTest
27 : public ::testing::TestWithParam<PlaygroundBackend> {
28 public:
29 using AiksPlaygroundCallback =
30 std::function<std::optional<Picture>(AiksContext& renderer)>;
31
32 using AiksDlPlaygroundCallback = std::function<sk_sp<flutter::DisplayList>()>;
33
34 GoldenPlaygroundTest();
35
36 ~GoldenPlaygroundTest() override;
37
38 void SetUp();
39
40 void TearDown();
41
42 PlaygroundBackend GetBackend() const;
43
44 void SetTypographerContext(
45 std::shared_ptr<TypographerContext> typographer_context);
46
47 bool OpenPlaygroundHere(Picture picture);
48
49 bool OpenPlaygroundHere(AiksPlaygroundCallback callback);
50
51 bool OpenPlaygroundHere(const AiksDlPlaygroundCallback& callback);
52
53 bool OpenPlaygroundHere(const sk_sp<flutter::DisplayList>& list);
54
55 std::unique_ptr<testing::Screenshot> MakeScreenshot(
56 const sk_sp<flutter::DisplayList>& list);
57
58 static bool SaveScreenshot(std::unique_ptr<testing::Screenshot> screenshot,
59 const std::string& postfix = "");
60
61 static bool ImGuiBegin(const char* name,
62 bool* p_open,
63 ImGuiWindowFlags flags);
64
65 std::shared_ptr<Texture> CreateTextureForFixture(
66 const char* fixture_name,
67 bool enable_mipmapping = false) const;
68
69 sk_sp<flutter::DlImage> CreateDlImageForFixture(
70 const char* fixture_name,
71 bool enable_mipmapping = false) const;
72
73 RuntimeStage::Map OpenAssetAsRuntimeStage(const char* asset_name) const;
74
75 std::shared_ptr<Context> GetContext() const;
76
77 std::shared_ptr<Context> MakeContext() const;
78
79 Point GetContentScale() const;
80
81 Scalar GetSecondsElapsed() const;
82
83 ISize GetWindowSize() const;
84
85 [[nodiscard]] fml::Status SetCapabilities(
86 const std::shared_ptr<Capabilities>& capabilities);
87
88 /// Returns true if `OpenPlaygroundHere` will actually render anything.
89 bool WillRenderSomething() const { return true; }
90
91 protected:
92 void SetWindowSize(ISize size);
93
94 private:
95 #if FML_OS_MACOSX
96 // This must be placed first so that the autorelease pool is not destroyed
97 // until the GoldenPlaygroundTestImpl has been destructed.
98 fml::ScopedNSAutoreleasePool autorelease_pool_;
99 #endif
100
101 std::shared_ptr<TypographerContext> typographer_context_;
102
103 struct GoldenPlaygroundTestImpl;
104 // This is only a shared_ptr so it can work with a forward declared type.
105 std::shared_ptr<GoldenPlaygroundTestImpl> pimpl_;
106
107 GoldenPlaygroundTest(const GoldenPlaygroundTest&) = delete;
108
109 GoldenPlaygroundTest& operator=(const GoldenPlaygroundTest&) = delete;
110 };
111
112 } // namespace impeller
113
114 #endif // FLUTTER_IMPELLER_GOLDEN_TESTS_GOLDEN_PLAYGROUND_TEST_H_
aiks_context.h
impeller::AiksContext
Definition: aiks_context.h:20
impeller::GoldenPlaygroundTest
Definition: golden_playground_test.h:27
impeller::GoldenPlaygroundTest::OpenPlaygroundHere
bool OpenPlaygroundHere(AiksPlaygroundCallback callback)
impeller::GoldenPlaygroundTest::GetBackend
PlaygroundBackend GetBackend() const
Definition: golden_playground_test_mac.cc:221
impeller::GoldenPlaygroundTest::GetWindowSize
ISize GetWindowSize() const
Definition: golden_playground_test_mac.cc:321
impeller::GoldenPlaygroundTest::AiksPlaygroundCallback
std::function< std::optional< Picture >(AiksContext &renderer)> AiksPlaygroundCallback
Definition: golden_playground_test.h:30
impeller::GoldenPlaygroundTest::CreateDlImageForFixture
sk_sp< flutter::DlImage > CreateDlImageForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Definition: golden_playground_test_mac.cc:269
impeller::GoldenPlaygroundTest::GetContentScale
Point GetContentScale() const
Definition: golden_playground_test_mac.cc:313
impeller::GoldenPlaygroundTest::SetCapabilities
fml::Status SetCapabilities(const std::shared_ptr< Capabilities > &capabilities)
Definition: golden_playground_test_mac.cc:329
impeller::GoldenPlaygroundTest::SetTypographerContext
void SetTypographerContext(std::shared_ptr< TypographerContext > typographer_context)
Definition: golden_playground_test_mac.cc:128
impeller::GoldenPlaygroundTest::MakeContext
std::shared_ptr< Context > MakeContext() const
Definition: golden_playground_test_mac.cc:294
impeller::GoldenPlaygroundTest::SaveScreenshot
static bool SaveScreenshot(std::unique_ptr< testing::Screenshot > screenshot, const std::string &postfix="")
Definition: golden_playground_test_mac.cc:96
impeller::GoldenPlaygroundTest::TearDown
void TearDown()
Definition: golden_playground_test_mac.cc:133
impeller::GoldenPlaygroundTest::MakeScreenshot
std::unique_ptr< testing::Screenshot > MakeScreenshot(const sk_sp< flutter::DisplayList > &list)
Definition: golden_playground_test_mac.cc:334
impeller::GoldenPlaygroundTest::GetSecondsElapsed
Scalar GetSecondsElapsed() const
Definition: golden_playground_test_mac.cc:317
impeller::GoldenPlaygroundTest::OpenAssetAsRuntimeStage
RuntimeStage::Map OpenAssetAsRuntimeStage(const char *asset_name) const
Definition: golden_playground_test_mac.cc:277
impeller::GoldenPlaygroundTest::OpenPlaygroundHere
bool OpenPlaygroundHere(Picture picture)
impeller::GoldenPlaygroundTest::ImGuiBegin
static bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
Definition: golden_playground_test_mac.cc:250
impeller::GoldenPlaygroundTest::AiksDlPlaygroundCallback
std::function< sk_sp< flutter::DisplayList >()> AiksDlPlaygroundCallback
Definition: golden_playground_test.h:32
impeller::GoldenPlaygroundTest::SetUp
void SetUp()
Definition: golden_playground_test_mac.cc:152
impeller::GoldenPlaygroundTest::~GoldenPlaygroundTest
~GoldenPlaygroundTest() override
impeller::GoldenPlaygroundTest::GetContext
std::shared_ptr< Context > GetContext() const
Definition: golden_playground_test_mac.cc:287
impeller::GoldenPlaygroundTest::SetWindowSize
void SetWindowSize(ISize size)
Definition: golden_playground_test_stub.cc:71
impeller::GoldenPlaygroundTest::WillRenderSomething
bool WillRenderSomething() const
Returns true if OpenPlaygroundHere will actually render anything.
Definition: golden_playground_test.h:89
impeller::GoldenPlaygroundTest::GoldenPlaygroundTest
GoldenPlaygroundTest()
Definition: golden_playground_test_mac.cc:122
impeller::GoldenPlaygroundTest::CreateTextureForFixture
std::shared_ptr< Texture > CreateTextureForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Definition: golden_playground_test_mac.cc:256
impeller::RuntimeStage::Map
std::map< RuntimeStageBackend, std::shared_ptr< RuntimeStage > > Map
Definition: runtime_stage.h:24
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::PlaygroundBackend
PlaygroundBackend
Definition: playground.h:27
playground.h
render_target.h
screenshot.h
impeller::TPoint< Scalar >
impeller::TSize
Definition: size.h:25
typographer_context.h