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