Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 65 additions & 6 deletions impeller/golden_tests/golden_playground_test_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <filesystem>
#include <memory>

#include "display_list/display_list.h"
#include "flutter/impeller/golden_tests/golden_playground_test.h"

#include "flutter/impeller/aiks/picture.h"
Expand All @@ -14,6 +15,7 @@
#include "flutter/impeller/golden_tests/vulkan_screenshotter.h"
#include "flutter/third_party/abseil-cpp/absl/base/no_destructor.h"
#include "fml/closure.h"
#include "impeller/aiks/aiks_context.h"
#include "impeller/display_list/dl_dispatcher.h"
#include "impeller/display_list/dl_image_impeller.h"
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
Expand All @@ -22,6 +24,8 @@
#define GLFW_INCLUDE_NONE
#include "third_party/glfw/include/GLFW/glfw3.h"

#define EXPERIMENTAL_CANVAS false

namespace impeller {

namespace {
Expand Down Expand Up @@ -55,6 +59,56 @@ const std::unique_ptr<PlaygroundImpl>& GetSharedVulkanPlayground(
return *vulkan_playground;
}
}

#if EXPERIMENTAL_CANVAS
std::shared_ptr<Texture> DisplayListToTexture(
sk_sp<flutter::DisplayList>& display_list,
ISize size,
AiksContext& context) {
// Do not use the render target cache as the lifecycle of this texture
// will outlive a particular frame.
impeller::RenderTargetAllocator render_target_allocator =
impeller::RenderTargetAllocator(
context.GetContext()->GetResourceAllocator());
impeller::RenderTarget target;
if (context.GetContext()->GetCapabilities()->SupportsOffscreenMSAA()) {
target = render_target_allocator.CreateOffscreenMSAA(
*context.GetContext(), // context
size, // size
/*mip_count=*/1,
"Picture Snapshot MSAA", // label
impeller::RenderTarget::
kDefaultColorAttachmentConfigMSAA // color_attachment_config
);
} else {
target = render_target_allocator.CreateOffscreen(
*context.GetContext(), // context
size, // size
/*mip_count=*/1,
"Picture Snapshot", // label
impeller::RenderTarget::
kDefaultColorAttachmentConfig // color_attachment_config
);
}

impeller::TextFrameDispatcher collector(context.GetContentContext(),
impeller::Matrix());
display_list->Dispatch(
collector, SkIRect::MakeSize(SkISize::Make(size.width, size.height)));
impeller::ExperimentalDlDispatcher impeller_dispatcher(
context.GetContentContext(), target,
display_list->root_has_backdrop_filter(),
display_list->max_root_blend_mode(), impeller::IRect::MakeSize(size));
display_list->Dispatch(impeller_dispatcher, SkIRect::MakeSize(SkISize::Make(
size.width, size.height)));
impeller_dispatcher.FinishRecording();

context.GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames();

return target.GetRenderTargetTexture();
}
#endif // EXPERIMENTAL_CANVAS

} // namespace

#define IMP_AIKSTEST(name) \
Expand Down Expand Up @@ -214,8 +268,16 @@ bool GoldenPlaygroundTest::OpenPlaygroundHere(
const AiksDlPlaygroundCallback& callback) {
AiksContext renderer(GetContext(), typographer_context_);

std::optional<Picture> picture;
std::unique_ptr<testing::Screenshot> screenshot;
#if EXPERIMENTAL_CANVAS
for (int i = 0; i < 2; ++i) {
auto display_list = callback();
auto texture =
DisplayListToTexture(display_list, pimpl_->window_size, renderer);
screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, texture);
}
#else
std::optional<Picture> picture;
for (int i = 0; i < 2; ++i) {
auto display_list = callback();
DlDispatcher dispatcher;
Expand All @@ -225,7 +287,7 @@ bool GoldenPlaygroundTest::OpenPlaygroundHere(
screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, picture,
pimpl_->window_size);
}

#endif // EXPERIMENTAL_CANVAS
return SaveScreenshot(std::move(screenshot));
}

Expand All @@ -250,10 +312,7 @@ bool GoldenPlaygroundTest::OpenPlaygroundHere(

bool GoldenPlaygroundTest::OpenPlaygroundHere(
const sk_sp<flutter::DisplayList>& list) {
DlDispatcher dispatcher;
list->Dispatch(dispatcher);
Picture picture = dispatcher.EndRecordingAsPicture();
return OpenPlaygroundHere(std::move(picture));
return OpenPlaygroundHere([&list]() { return list; });
}

bool GoldenPlaygroundTest::ImGuiBegin(const char* name,
Expand Down
4 changes: 4 additions & 0 deletions impeller/golden_tests/metal_screenshotter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class MetalScreenshotter : public Screenshotter {
const ISize& size = {300, 300},
bool scale_content = true) override;

std::unique_ptr<Screenshot> MakeScreenshot(
AiksContext& aiks_context,
const std::shared_ptr<Texture> texture) override;

PlaygroundImpl& GetPlayground() override { return *playground_; }

private:
Expand Down
6 changes: 6 additions & 0 deletions impeller/golden_tests/metal_screenshotter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
aiks_context,
ISize(size.width * content_scale.x, size.height * content_scale.y));
std::shared_ptr<Texture> texture = image->GetTexture();
return MakeScreenshot(aiks_context, texture);
}

std::unique_ptr<Screenshot> MetalScreenshotter::MakeScreenshot(
AiksContext& aiks_context,
const std::shared_ptr<Texture> texture) {
id<MTLTexture> metal_texture =
std::static_pointer_cast<TextureMTL>(texture)->GetMTLTexture();

Expand Down
4 changes: 4 additions & 0 deletions impeller/golden_tests/screenshotter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class Screenshotter {
const ISize& size = {300, 300},
bool scale_content = true) = 0;

virtual std::unique_ptr<Screenshot> MakeScreenshot(
AiksContext& aiks_context,
const std::shared_ptr<Texture> texture) = 0;

virtual PlaygroundImpl& GetPlayground() = 0;
};

Expand Down
4 changes: 4 additions & 0 deletions impeller/golden_tests/vulkan_screenshotter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class VulkanScreenshotter : public Screenshotter {
const ISize& size = {300, 300},
bool scale_content = true) override;

std::unique_ptr<Screenshot> MakeScreenshot(
AiksContext& aiks_context,
const std::shared_ptr<Texture> texture) override;

PlaygroundImpl& GetPlayground() override { return *playground_; }

private:
Expand Down
6 changes: 6 additions & 0 deletions impeller/golden_tests/vulkan_screenshotter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,11 @@ CGImagePtr flipped_image(CGBitmapContextCreateImage(flipped_context.get()),
return ReadTexture(aiks_context.GetContext(), texture);
}

std::unique_ptr<Screenshot> VulkanScreenshotter::MakeScreenshot(
AiksContext& aiks_context,
const std::shared_ptr<Texture> texture) {
return ReadTexture(aiks_context.GetContext(), texture);
}

} // namespace testing
} // namespace impeller