6
6
#include < filesystem>
7
7
#include < memory>
8
8
9
+ #include " display_list/display_list.h"
9
10
#include " flutter/impeller/golden_tests/golden_playground_test.h"
10
11
11
12
#include " flutter/impeller/aiks/picture.h"
14
15
#include " flutter/impeller/golden_tests/vulkan_screenshotter.h"
15
16
#include " flutter/third_party/abseil-cpp/absl/base/no_destructor.h"
16
17
#include " fml/closure.h"
18
+ #include " impeller/aiks/aiks_context.h"
17
19
#include " impeller/display_list/dl_dispatcher.h"
18
20
#include " impeller/display_list/dl_image_impeller.h"
19
21
#include " impeller/typographer/backends/skia/typographer_context_skia.h"
22
24
#define GLFW_INCLUDE_NONE
23
25
#include " third_party/glfw/include/GLFW/glfw3.h"
24
26
27
+ #define EXPERIMENTAL_CANVAS false
28
+
25
29
namespace impeller {
26
30
27
31
namespace {
@@ -55,6 +59,56 @@ const std::unique_ptr<PlaygroundImpl>& GetSharedVulkanPlayground(
55
59
return *vulkan_playground;
56
60
}
57
61
}
62
+
63
+ #if EXPERIMENTAL_CANVAS
64
+ std::shared_ptr<Texture> DisplayListToTexture (
65
+ sk_sp<flutter::DisplayList>& display_list,
66
+ ISize size,
67
+ AiksContext& context) {
68
+ // Do not use the render target cache as the lifecycle of this texture
69
+ // will outlive a particular frame.
70
+ impeller::RenderTargetAllocator render_target_allocator =
71
+ impeller::RenderTargetAllocator (
72
+ context.GetContext ()->GetResourceAllocator ());
73
+ impeller::RenderTarget target;
74
+ if (context.GetContext ()->GetCapabilities ()->SupportsOffscreenMSAA ()) {
75
+ target = render_target_allocator.CreateOffscreenMSAA (
76
+ *context.GetContext (), // context
77
+ size, // size
78
+ /* mip_count=*/ 1 ,
79
+ " Picture Snapshot MSAA" , // label
80
+ impeller::RenderTarget::
81
+ kDefaultColorAttachmentConfigMSAA // color_attachment_config
82
+ );
83
+ } else {
84
+ target = render_target_allocator.CreateOffscreen (
85
+ *context.GetContext (), // context
86
+ size, // size
87
+ /* mip_count=*/ 1 ,
88
+ " Picture Snapshot" , // label
89
+ impeller::RenderTarget::
90
+ kDefaultColorAttachmentConfig // color_attachment_config
91
+ );
92
+ }
93
+
94
+ impeller::TextFrameDispatcher collector (context.GetContentContext (),
95
+ impeller::Matrix ());
96
+ display_list->Dispatch (
97
+ collector, SkIRect::MakeSize (SkISize::Make (size.width , size.height )));
98
+ impeller::ExperimentalDlDispatcher impeller_dispatcher (
99
+ context.GetContentContext (), target,
100
+ display_list->root_has_backdrop_filter (),
101
+ display_list->max_root_blend_mode (), impeller::IRect::MakeSize (size));
102
+ display_list->Dispatch (impeller_dispatcher, SkIRect::MakeSize (SkISize::Make (
103
+ size.width , size.height )));
104
+ impeller_dispatcher.FinishRecording ();
105
+
106
+ context.GetContentContext ().GetLazyGlyphAtlas ()->ResetTextFrames ();
107
+
108
+ return target.GetRenderTargetTexture ();
109
+ }
110
+ #endif // EXPERIMENTAL_CANVAS
111
+
58
112
} // namespace
59
113
60
114
#define IMP_AIKSTEST (name ) \
@@ -214,8 +268,16 @@ bool GoldenPlaygroundTest::OpenPlaygroundHere(
214
268
const AiksDlPlaygroundCallback& callback) {
215
269
AiksContext renderer (GetContext (), typographer_context_);
216
270
217
- std::optional<Picture> picture;
218
271
std::unique_ptr<testing::Screenshot> screenshot;
272
+ #if EXPERIMENTAL_CANVAS
273
+ for (int i = 0 ; i < 2 ; ++i) {
274
+ auto display_list = callback ();
275
+ auto texture =
276
+ DisplayListToTexture (display_list, pimpl_->window_size , renderer);
277
+ screenshot = pimpl_->screenshotter ->MakeScreenshot (renderer, texture);
278
+ }
279
+ #else
280
+ std::optional<Picture> picture;
219
281
for (int i = 0 ; i < 2 ; ++i) {
220
282
auto display_list = callback ();
221
283
DlDispatcher dispatcher;
@@ -225,7 +287,7 @@ bool GoldenPlaygroundTest::OpenPlaygroundHere(
225
287
screenshot = pimpl_->screenshotter ->MakeScreenshot (renderer, picture,
226
288
pimpl_->window_size );
227
289
}
228
-
290
+ # endif // EXPERIMENTAL_CANVAS
229
291
return SaveScreenshot (std::move (screenshot));
230
292
}
231
293
@@ -250,10 +312,7 @@ bool GoldenPlaygroundTest::OpenPlaygroundHere(
250
312
251
313
bool GoldenPlaygroundTest::OpenPlaygroundHere (
252
314
const sk_sp<flutter::DisplayList>& list) {
253
- DlDispatcher dispatcher;
254
- list->Dispatch (dispatcher);
255
- Picture picture = dispatcher.EndRecordingAsPicture ();
256
- return OpenPlaygroundHere (std::move (picture));
315
+ return OpenPlaygroundHere ([&list]() { return list; });
257
316
}
258
317
259
318
bool GoldenPlaygroundTest::ImGuiBegin (const char * name,
0 commit comments