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"
15 #include "flutter/testing/testing.h"
17 #include "third_party/imgui/imgui.h"
18 
19 #if FML_OS_MACOSX
20 #include "flutter/fml/platform/darwin/scoped_nsautorelease_pool.h"
21 #endif
22 
23 namespace impeller {
24 
26  : public ::testing::TestWithParam<PlaygroundBackend> {
27  public:
29  std::function<std::optional<Picture>(AiksContext& renderer)>;
30 
31  using AiksDlPlaygroundCallback = std::function<sk_sp<flutter::DisplayList>()>;
32 
34 
35  ~GoldenPlaygroundTest() override;
36 
37  void SetUp();
38 
39  void TearDown();
40 
42 
44  std::shared_ptr<TypographerContext> typographer_context);
45 
46  bool OpenPlaygroundHere(Picture picture);
47 
49 
50  bool OpenPlaygroundHere(const AiksDlPlaygroundCallback& callback);
51 
52  bool OpenPlaygroundHere(const sk_sp<flutter::DisplayList>& list);
53 
54  static bool ImGuiBegin(const char* name,
55  bool* p_open,
56  ImGuiWindowFlags flags);
57 
58  std::shared_ptr<Texture> CreateTextureForFixture(
59  const char* fixture_name,
60  bool enable_mipmapping = false) const;
61 
62  sk_sp<flutter::DlImage> CreateDlImageForFixture(
63  const char* fixture_name,
64  bool enable_mipmapping = false) const;
65 
66  RuntimeStage::Map OpenAssetAsRuntimeStage(const char* asset_name) const;
67 
68  std::shared_ptr<Context> GetContext() const;
69 
70  std::shared_ptr<Context> MakeContext() const;
71 
72  Point GetContentScale() const;
73 
74  Scalar GetSecondsElapsed() const;
75 
76  ISize GetWindowSize() const;
77 
78  [[nodiscard]] fml::Status SetCapabilities(
79  const std::shared_ptr<Capabilities>& capabilities);
80 
81  /// TODO(https://github.com/flutter/flutter/issues/139950): Remove this.
82  /// Returns true if `OpenPlaygroundHere` will actually render anything.
83  bool WillRenderSomething() const { return true; }
84 
85  protected:
86  void SetWindowSize(ISize size);
87 
88  private:
89 #if FML_OS_MACOSX
90  // This must be placed first so that the autorelease pool is not destroyed
91  // until the GoldenPlaygroundTestImpl has been destructed.
92  fml::ScopedNSAutoreleasePool autorelease_pool_;
93 #endif
94 
95  std::shared_ptr<TypographerContext> typographer_context_;
96 
97  struct GoldenPlaygroundTestImpl;
98  // This is only a shared_ptr so it can work with a forward declared type.
99  std::shared_ptr<GoldenPlaygroundTestImpl> pimpl_;
100 
102 
103  GoldenPlaygroundTest& operator=(const GoldenPlaygroundTest&) = delete;
104 };
105 
106 } // namespace impeller
107 
108 #endif // FLUTTER_IMPELLER_GOLDEN_TESTS_GOLDEN_PLAYGROUND_TEST_H_
impeller::GoldenPlaygroundTest::WillRenderSomething
bool WillRenderSomething() const
Definition: golden_playground_test.h:83
impeller::GoldenPlaygroundTest::ImGuiBegin
static bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
Definition: golden_playground_test_mac.cc:259
impeller::GoldenPlaygroundTest::GetContentScale
Point GetContentScale() const
Definition: golden_playground_test_mac.cc:319
impeller::GoldenPlaygroundTest::AiksPlaygroundCallback
std::function< std::optional< Picture >(AiksContext &renderer)> AiksPlaygroundCallback
Definition: golden_playground_test.h:29
impeller::GoldenPlaygroundTest::SetCapabilities
fml::Status SetCapabilities(const std::shared_ptr< Capabilities > &capabilities)
Definition: golden_playground_test_mac.cc:335
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::AiksContext
Definition: aiks_context.h:19
impeller::GoldenPlaygroundTest::MakeContext
std::shared_ptr< Context > MakeContext() const
Definition: golden_playground_test_mac.cc:300
aiks_context.h
playground.h
impeller::PlaygroundBackend
PlaygroundBackend
Definition: playground.h:27
impeller::GoldenPlaygroundTest::OpenPlaygroundHere
bool OpenPlaygroundHere(Picture picture)
Definition: golden_playground_test_mac.cc:205
typographer_context.h
impeller::GoldenPlaygroundTest::GetContext
std::shared_ptr< Context > GetContext() const
Definition: golden_playground_test_mac.cc:296
impeller::GoldenPlaygroundTest::~GoldenPlaygroundTest
~GoldenPlaygroundTest() override
impeller::GoldenPlaygroundTest::SetTypographerContext
void SetTypographerContext(std::shared_ptr< TypographerContext > typographer_context)
Definition: golden_playground_test_mac.cc:125
impeller::Picture
Definition: picture.h:17
impeller::TSize
Definition: size.h:19
impeller::GoldenPlaygroundTest::GoldenPlaygroundTest
GoldenPlaygroundTest()
Definition: golden_playground_test_mac.cc:119
impeller::GoldenPlaygroundTest::GetBackend
PlaygroundBackend GetBackend() const
Definition: golden_playground_test_mac.cc:201
impeller::GoldenPlaygroundTest::SetWindowSize
void SetWindowSize(ISize size)
Definition: golden_playground_test_stub.cc:83
impeller::GoldenPlaygroundTest::SetUp
void SetUp()
Definition: golden_playground_test_mac.cc:144
impeller::GoldenPlaygroundTest
Definition: golden_playground_test.h:25
impeller::GoldenPlaygroundTest::CreateTextureForFixture
std::shared_ptr< Texture > CreateTextureForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Definition: golden_playground_test_mac.cc:265
impeller::GoldenPlaygroundTest::CreateDlImageForFixture
sk_sp< flutter::DlImage > CreateDlImageForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Definition: golden_playground_test_mac.cc:278
impeller::GoldenPlaygroundTest::AiksDlPlaygroundCallback
std::function< sk_sp< flutter::DisplayList >()> AiksDlPlaygroundCallback
Definition: golden_playground_test.h:31
impeller::GoldenPlaygroundTest::GetSecondsElapsed
Scalar GetSecondsElapsed() const
Definition: golden_playground_test_mac.cc:323
impeller::GoldenPlaygroundTest::TearDown
void TearDown()
Definition: golden_playground_test_mac.cc:130
impeller::TPoint< Scalar >
render_target.h
impeller
Definition: aiks_blend_unittests.cc:18
impeller::GoldenPlaygroundTest::GetWindowSize
ISize GetWindowSize() const
Definition: golden_playground_test_mac.cc:327
impeller::GoldenPlaygroundTest::OpenAssetAsRuntimeStage
RuntimeStage::Map OpenAssetAsRuntimeStage(const char *asset_name) const
Definition: golden_playground_test_mac.cc:286
impeller::RuntimeStage::Map
std::map< RuntimeStageBackend, std::shared_ptr< RuntimeStage > > Map
Definition: runtime_stage.h:24