Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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
18#include "third_party/abseil-cpp/absl/status/statusor.h"
19#include "third_party/imgui/imgui.h"
20
21#if FML_OS_MACOSX
23#endif
24
25namespace impeller {
26
28 : public ::testing::TestWithParam<PlaygroundBackend> {
29 public:
31 std::function<std::optional<Picture>(AiksContext& renderer)>;
32
33 using AiksDlPlaygroundCallback = std::function<sk_sp<flutter::DisplayList>()>;
34
36
38
39 void SetUp();
40
41 void TearDown();
42
44
46 std::shared_ptr<TypographerContext> typographer_context);
47
48 bool OpenPlaygroundHere(Picture picture);
49
51
53
54 bool OpenPlaygroundHere(const sk_sp<flutter::DisplayList>& list);
55
56 /// Renders `callback` into an offscreen render pass and saves the result as
57 /// a golden image. The render target is single-sampled, uses the context's
58 /// default color format, and has no depth or stencil attachment, so a
59 /// pipeline built from `PipelineBuilder<>::MakeDefaultPipelineDescriptor`
60 /// must be reduced to match by calling `SetSampleCount(kCount1)`,
61 /// `ClearStencilAttachments()`, and `ClearDepthAttachment()` on it. Calling
62 /// only `SetStencilAttachmentDescriptors(nullopt)` leaves the stencil pixel
63 /// format set and trips Metal's render pipeline validation.
65
66 std::unique_ptr<testing::Screenshot> MakeScreenshot(
67 const sk_sp<flutter::DisplayList>& list);
68
69 static bool SaveScreenshot(std::unique_ptr<testing::Screenshot> screenshot,
70 const std::string& postfix = "");
71
72 std::shared_ptr<Texture> CreateTextureForFixture(
73 const char* fixture_name,
74 bool enable_mipmapping = false) const;
75
76 sk_sp<flutter::DlImage> CreateDlImageForFixture(
77 const char* fixture_name,
78 bool enable_mipmapping = false) const;
79
80 absl::StatusOr<RuntimeStage::Map> OpenAssetAsRuntimeStage(
81 const char* asset_name) const;
82
83 std::shared_ptr<Context> GetContext() const;
84
85 std::shared_ptr<Context> MakeContext() const;
86
87 Point GetContentScale() const;
88
90
91 ISize GetWindowSize() const;
92
93 IRect GetWindowBounds() const;
94
95 [[nodiscard]] fml::Status SetCapabilities(
96 const std::shared_ptr<Capabilities>& capabilities);
97
99
100 /// @brief Sets a particular test to either write a golden or not.
101 ///
102 /// For purposes of the GoldenPlayground test harness, we don't maintain
103 /// a flag for this status, all tests are assumed to be golden tests and
104 /// passing false here means we should just skip this test entirely
105 /// (enforced in the implementation with a GTEST_SKIP).
106 void SetEnableWriteGolden(bool write_golden);
107
108 bool IsPlaygroundEnabled() const { return false; }
109
110 /// @brief Initializes the provided |PipelineDescriptor| with appropriate
111 /// default values to match the conditions under which a pipeline
112 /// will be rendered.
114
115 protected:
116 void SetWindowSize(ISize size);
117
118 /// @brief Returns true if the rendering path supports MSAA rendering.
119 ///
120 /// In the case of goldens, all tests are rendered to a non-MSAA backend.
121 bool RenderingSupportsMSAA() const { return false; }
122
123 /// @brief Returns the default sample count of the rendering path.
124 ///
125 /// In the case of goldens, all tests are rendered to a non-MSAA backend.
127
128 // See |Playground::EnsureContextIsUnique|
129 // GoldenPlaygroundTest uses context replacement on the fly to support this.
131
132 // See |Playground::EnsureContextSupportsWideGamut|
133 // GoldenPlaygroundTest uses testname matching in |Setup| to manage this.
134 // In particular, it will automatically GTEST_SKIP if the platform doesn't
135 // support wide gamuts.
136 [[nodiscard]] bool EnsureContextSupportsWideGamut() { return true; }
137
138 private:
139#if FML_OS_MACOSX
140 // This must be placed first so that the autorelease pool is not destroyed
141 // until the GoldenPlaygroundTestImpl has been destructed.
142 fml::ScopedNSAutoreleasePool autorelease_pool_;
143#endif
144
145 std::shared_ptr<TypographerContext> typographer_context_;
146
147 struct GoldenPlaygroundTestImpl;
148 // This is only a shared_ptr so it can work with a forward declared type.
149 std::shared_ptr<GoldenPlaygroundTestImpl> pimpl_;
150
152
153 GoldenPlaygroundTest& operator=(const GoldenPlaygroundTest&) = delete;
154};
155
156} // namespace impeller
157
158#endif // FLUTTER_IMPELLER_GOLDEN_TESTS_GOLDEN_PLAYGROUND_TEST_H_
bool OpenPlaygroundHere(AiksPlaygroundCallback callback)
RuntimeStageBackend GetRuntimeStageBackend() const
std::function< std::optional< Picture >(AiksContext &renderer)> AiksPlaygroundCallback
sk_sp< flutter::DlImage > CreateDlImageForFixture(const char *fixture_name, bool enable_mipmapping=false) const
fml::Status SetCapabilities(const std::shared_ptr< Capabilities > &capabilities)
void SetTypographerContext(std::shared_ptr< TypographerContext > typographer_context)
std::shared_ptr< Context > MakeContext() const
void SetEnableWriteGolden(bool write_golden)
Sets a particular test to either write a golden or not.
bool RenderingSupportsMSAA() const
Returns true if the rendering path supports MSAA rendering.
static bool SaveScreenshot(std::unique_ptr< testing::Screenshot > screenshot, const std::string &postfix="")
bool InitializePipelineDescriptorForRendering(PipelineDescriptor &desc) const
Initializes the provided |PipelineDescriptor| with appropriate default values to match the conditions...
std::unique_ptr< testing::Screenshot > MakeScreenshot(const sk_sp< flutter::DisplayList > &list)
bool OpenPlaygroundHere(Picture picture)
std::function< sk_sp< flutter::DisplayList >()> AiksDlPlaygroundCallback
SampleCount GetDefaultSampleCount() const
Returns the default sample count of the rendering path.
absl::StatusOr< RuntimeStage::Map > OpenAssetAsRuntimeStage(const char *asset_name) const
std::shared_ptr< Context > GetContext() const
std::shared_ptr< Texture > CreateTextureForFixture(const char *fixture_name, bool enable_mipmapping=false) const
std::function< bool(RenderPass &pass)> SinglePassCallback
Definition playground.h:44
FlutterDesktopBinaryReply callback
float Scalar
Definition scalar.h:19
PlaygroundBackend
Definition playground.h:32