[Impeller] Run DisplayList render tests. (flutter/engine#46422)

Revisiting this project as it may help with [attribute] X [rendering op] matrix testing of Impeller. It's not an exhaustive combinatorial test of all combinations of rendering attributes, but it attempts each op with each attribute both default and non-default.

For Impeller it only tests that the rendering produced output (i.e wasn't a NOP due to missing implementation), that the output changed if the given attribute was supposed to change the output, and that it rendered within the computed bounds that the rest of the engine will be assuming.

These changes will not result in any automatic CI testing of Impeller as is since they are only run on the Metal backend which is not enabled by default. Running `out/host_[variant]/display_list_rendertests --enable-metal` manually on a Mac host, though, will run the tests through Impeller and there will be a lot of error output. Also, there is one known crash as reported in https://github.com/flutter/flutter/issues/135766
This commit is contained in:
Jim Graham
2023-10-09 12:10:05 -07:00
committed by GitHub
parent 92590c5464
commit c97916810d
14 changed files with 1310 additions and 874 deletions

View File

@@ -1417,8 +1417,8 @@ ORIGIN: ../../../flutter/impeller/golden_tests/golden_tests.cc + ../../../flutte
ORIGIN: ../../../flutter/impeller/golden_tests/main.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/metal_screenshot.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/metal_screenshot.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/metal_screenshoter.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/metal_screenshoter.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/metal_screenshotter.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/metal_screenshotter.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/working_directory.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/working_directory.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests_harvester/bin/golden_tests_harvester.dart + ../../../flutter/LICENSE
@@ -4176,8 +4176,8 @@ FILE: ../../../flutter/impeller/golden_tests/golden_tests.cc
FILE: ../../../flutter/impeller/golden_tests/main.cc
FILE: ../../../flutter/impeller/golden_tests/metal_screenshot.h
FILE: ../../../flutter/impeller/golden_tests/metal_screenshot.mm
FILE: ../../../flutter/impeller/golden_tests/metal_screenshoter.h
FILE: ../../../flutter/impeller/golden_tests/metal_screenshoter.mm
FILE: ../../../flutter/impeller/golden_tests/metal_screenshotter.h
FILE: ../../../flutter/impeller/golden_tests/metal_screenshotter.mm
FILE: ../../../flutter/impeller/golden_tests/working_directory.cc
FILE: ../../../flutter/impeller/golden_tests/working_directory.h
FILE: ../../../flutter/impeller/golden_tests_harvester/bin/golden_tests_harvester.dart

View File

@@ -69,6 +69,10 @@ source_set("display_list_surface_provider") {
"//flutter/testing:testing_lib",
]
if (is_mac) {
deps += [ "//flutter/impeller/golden_tests:metal_screenshot" ]
}
public_configs = [ ":surface_provider_config" ]
if (is_android) {
@@ -99,6 +103,9 @@ source_set("display_list_surface_provider") {
"dl_test_surface_metal.cc",
"dl_test_surface_metal.h",
]
deps += [ "//flutter/testing:metal" ]
deps += [
"//flutter/impeller/display_list",
"//flutter/testing:metal",
]
}
}

View File

@@ -3,6 +3,9 @@
// found in the LICENSE file.
#include "flutter/display_list/testing/dl_test_surface_metal.h"
#include "flutter/impeller/display_list/dl_dispatcher.h"
#include "flutter/impeller/display_list/dl_image_impeller.h"
#include "flutter/impeller/typographer/backends/skia/typographer_context_skia.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkSurface.h"
@@ -54,5 +57,71 @@ std::shared_ptr<DlSurfaceInstance> DlMetalSurfaceProvider::MakeOffscreenSurface(
return std::make_shared<DlMetalSurfaceInstance>(std::move(surface));
}
class DlMetalPixelData : public DlPixelData {
using MetalScreenshot = impeller::testing::MetalScreenshot;
public:
explicit DlMetalPixelData(std::unique_ptr<MetalScreenshot> screenshot)
: screenshot_(std::move(screenshot)),
addr_(reinterpret_cast<const uint32_t*>(screenshot_->GetBytes())),
ints_per_row_(screenshot_->GetBytesPerRow() / 4) {
FML_DCHECK(screenshot_->GetBytesPerRow() == ints_per_row_ * 4);
}
~DlMetalPixelData() override = default;
const uint32_t* addr32(int x, int y) const override {
return addr_ + (y * ints_per_row_) + x;
}
size_t width() const override { return screenshot_->GetWidth(); }
size_t height() const override { return screenshot_->GetHeight(); }
void write(const std::string& path) const override {
screenshot_->WriteToPNG(path);
}
private:
std::unique_ptr<MetalScreenshot> screenshot_;
const uint32_t* addr_;
const uint32_t ints_per_row_;
};
sk_sp<DlPixelData> DlMetalSurfaceProvider::ImpellerSnapshot(
const sk_sp<DisplayList>& list,
int width,
int height) const {
InitScreenShotter();
impeller::DlDispatcher dispatcher;
dispatcher.drawColor(flutter::DlColor::kTransparent(),
flutter::DlBlendMode::kSrc);
list->Dispatch(dispatcher);
auto picture = dispatcher.EndRecordingAsPicture();
return sk_make_sp<DlMetalPixelData>(snapshotter_->MakeScreenshot(
*aiks_context_, picture, {width, height}, false));
}
sk_sp<DlImage> DlMetalSurfaceProvider::MakeImpellerImage(
const sk_sp<DisplayList>& list,
int width,
int height) const {
InitScreenShotter();
impeller::DlDispatcher dispatcher;
dispatcher.drawColor(flutter::DlColor::kTransparent(),
flutter::DlBlendMode::kSrc);
list->Dispatch(dispatcher);
auto picture = dispatcher.EndRecordingAsPicture();
std::shared_ptr<impeller::Image> image =
picture.ToImage(*aiks_context_, {width, height});
std::shared_ptr<impeller::Texture> texture = image->GetTexture();
return impeller::DlImageImpeller::Make(texture);
}
void DlMetalSurfaceProvider::InitScreenShotter() const {
if (!snapshotter_) {
snapshotter_.reset(new MetalScreenshotter());
auto typographer = impeller::TypographerContextSkia::Make();
aiks_context_.reset(new impeller::AiksContext(
snapshotter_->GetPlayground().GetContext(), typographer));
}
}
} // namespace testing
} // namespace flutter

View File

@@ -6,12 +6,15 @@
#define FLUTTER_DISPLAY_LIST_TESTING_DL_TEST_SURFACE_METAL_H_
#include "flutter/display_list/testing/dl_test_surface_provider.h"
#include "flutter/fml/platform/darwin/scoped_nsautorelease_pool.h"
#include "flutter/impeller/golden_tests/metal_screenshotter.h"
#include "flutter/testing/test_metal_surface.h"
namespace flutter {
namespace testing {
using MetalScreenshotter = impeller::testing::MetalScreenshotter;
class DlMetalSurfaceProvider : public DlSurfaceProvider {
public:
explicit DlMetalSurfaceProvider() : DlSurfaceProvider() {}
@@ -30,10 +33,25 @@ class DlMetalSurfaceProvider : public DlSurfaceProvider {
bool supports(PixelFormat format) const override {
return format == kN32PremulPixelFormat;
}
bool supports_impeller() const override { return true; }
sk_sp<DlPixelData> ImpellerSnapshot(const sk_sp<DisplayList>& list,
int width,
int height) const override;
virtual sk_sp<DlImage> MakeImpellerImage(const sk_sp<DisplayList>& list,
int width,
int height) const override;
private:
// This must be placed before any other members that may use the
// autorelease pool.
fml::ScopedNSAutoreleasePool autorelease_pool_;
std::unique_ptr<TestMetalContext> metal_context_;
std::shared_ptr<DlSurfaceInstance> metal_surface_;
mutable std::unique_ptr<MetalScreenshotter> snapshotter_;
mutable std::unique_ptr<impeller::AiksContext> aiks_context_;
void InitScreenShotter() const;
};
} // namespace testing

View File

@@ -23,6 +23,17 @@
namespace flutter {
namespace testing {
std::string DlSurfaceProvider::BackendName(BackendType type) {
switch (type) {
case kMetalBackend:
return "Metal";
case kOpenGlBackend:
return "OpenGL";
case kSoftwareBackend:
return "Software";
}
}
std::unique_ptr<DlSurfaceProvider> DlSurfaceProvider::Create(
BackendType backend_type) {
switch (backend_type) {

View File

@@ -7,6 +7,8 @@
#include <utility>
#include "flutter/display_list/display_list.h"
#include "flutter/display_list/image/dl_image.h"
#include "flutter/fml/mapping.h"
#include "flutter/testing/testing.h"
@@ -15,6 +17,16 @@
namespace flutter {
namespace testing {
class DlPixelData : public SkRefCnt {
public:
virtual ~DlPixelData() = default;
virtual const uint32_t* addr32(int x, int y) const = 0;
virtual size_t width() const = 0;
virtual size_t height() const = 0;
virtual void write(const std::string& path) const = 0;
};
class DlSurfaceInstance {
public:
virtual ~DlSurfaceInstance() = default;
@@ -53,12 +65,14 @@ class DlSurfaceProvider {
FML_DCHECK(false);
}
static std::string BackendName(BackendType type);
static std::unique_ptr<DlSurfaceProvider> Create(BackendType backend_type);
virtual ~DlSurfaceProvider() = default;
virtual const std::string backend_name() const = 0;
virtual BackendType backend_type() const = 0;
virtual bool supports(PixelFormat format) const = 0;
virtual bool supports_impeller() const { return false; }
virtual bool InitializeSurface(
size_t width,
size_t height,
@@ -70,6 +84,16 @@ class DlSurfaceProvider {
PixelFormat format = kN32PremulPixelFormat) const = 0;
virtual bool Snapshot(std::string& filename) const;
virtual sk_sp<DlPixelData> ImpellerSnapshot(const sk_sp<DisplayList>& list,
int width,
int height) const {
return nullptr;
}
virtual sk_sp<DlImage> MakeImpellerImage(const sk_sp<DisplayList>& list,
int width,
int height) const {
return nullptr;
}
protected:
DlSurfaceProvider() = default;

View File

@@ -47,12 +47,13 @@ if (is_mac) {
sources = [
"metal_screenshot.h",
"metal_screenshot.mm",
"metal_screenshoter.h",
"metal_screenshoter.mm",
"metal_screenshotter.h",
"metal_screenshotter.mm",
]
deps = [
"//flutter/impeller/aiks",
"//flutter/impeller/display_list",
"//flutter/impeller/playground",
"//flutter/impeller/renderer/backend/metal:metal",
]

View File

@@ -10,7 +10,7 @@
#include "flutter/impeller/aiks/picture.h"
#include "flutter/impeller/golden_tests/golden_digest.h"
#include "flutter/impeller/golden_tests/metal_screenshoter.h"
#include "flutter/impeller/golden_tests/metal_screenshotter.h"
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
#include "impeller/typographer/typographer_context.h"
@@ -85,8 +85,9 @@ bool SaveScreenshot(std::unique_ptr<testing::MetalScreenshot> screenshot) {
} // namespace
struct GoldenPlaygroundTest::GoldenPlaygroundTestImpl {
GoldenPlaygroundTestImpl() : screenshoter(new testing::MetalScreenshoter()) {}
std::unique_ptr<testing::MetalScreenshoter> screenshoter;
GoldenPlaygroundTestImpl()
: screenshotter(new testing::MetalScreenshotter()) {}
std::unique_ptr<testing::MetalScreenshotter> screenshotter;
ISize window_size = ISize{1024, 768};
};
@@ -140,8 +141,8 @@ PlaygroundBackend GoldenPlaygroundTest::GetBackend() const {
bool GoldenPlaygroundTest::OpenPlaygroundHere(Picture picture) {
AiksContext renderer(GetContext(), typographer_context_);
auto screenshot = pimpl_->screenshoter->MakeScreenshot(renderer, picture,
pimpl_->window_size);
auto screenshot = pimpl_->screenshotter->MakeScreenshot(renderer, picture,
pimpl_->window_size);
return SaveScreenshot(std::move(screenshot));
}
@@ -178,11 +179,11 @@ std::shared_ptr<RuntimeStage> GoldenPlaygroundTest::OpenAssetAsRuntimeStage(
}
std::shared_ptr<Context> GoldenPlaygroundTest::GetContext() const {
return pimpl_->screenshoter->GetPlayground().GetContext();
return pimpl_->screenshotter->GetPlayground().GetContext();
}
Point GoldenPlaygroundTest::GetContentScale() const {
return pimpl_->screenshoter->GetPlayground().GetContentScale();
return pimpl_->screenshotter->GetPlayground().GetContentScale();
}
Scalar GoldenPlaygroundTest::GetSecondsElapsed() const {

View File

@@ -13,7 +13,7 @@
#include "impeller/geometry/path_builder.h"
#include "impeller/golden_tests/golden_digest.h"
#include "impeller/golden_tests/metal_screenshot.h"
#include "impeller/golden_tests/metal_screenshoter.h"
#include "impeller/golden_tests/metal_screenshotter.h"
#include "impeller/golden_tests/working_directory.h"
namespace impeller {
@@ -50,14 +50,14 @@ bool SaveScreenshot(std::unique_ptr<MetalScreenshot> screenshot) {
class GoldenTests : public ::testing::Test {
public:
GoldenTests() : screenshoter_(new MetalScreenshoter()) {}
GoldenTests() : screenshotter_(new MetalScreenshotter()) {}
MetalScreenshoter& Screenshoter() { return *screenshoter_; }
MetalScreenshotter& Screenshotter() { return *screenshotter_; }
void SetUp() override {
testing::GoldenDigest::Instance()->AddDimension(
"gpu_string",
Screenshoter().GetPlayground().GetContext()->DescribeGpuModel());
Screenshotter().GetPlayground().GetContext()->DescribeGpuModel());
}
private:
@@ -65,7 +65,7 @@ class GoldenTests : public ::testing::Test {
// autorelease pool.
fml::ScopedNSAutoreleasePool autorelease_pool_;
std::unique_ptr<MetalScreenshoter> screenshoter_;
std::unique_ptr<MetalScreenshotter> screenshotter_;
};
TEST_F(GoldenTests, ConicalGradient) {
@@ -82,8 +82,8 @@ TEST_F(GoldenTests, ConicalGradient) {
Picture picture = canvas.EndRecordingAsPicture();
auto aiks_context =
AiksContext(Screenshoter().GetPlayground().GetContext(), nullptr);
auto screenshot = Screenshoter().MakeScreenshot(aiks_context, picture);
AiksContext(Screenshotter().GetPlayground().GetContext(), nullptr);
auto screenshot = Screenshotter().MakeScreenshot(aiks_context, picture);
ASSERT_TRUE(SaveScreenshot(std::move(screenshot)));
}
} // namespace testing

View File

@@ -13,9 +13,7 @@
namespace impeller {
namespace testing {
class MetalScreenshoter;
/// A screenshot that was produced from `MetalScreenshoter`.
/// A screenshot that was produced from `MetalScreenshotter`.
class MetalScreenshot {
public:
~MetalScreenshot();
@@ -26,10 +24,12 @@ class MetalScreenshot {
size_t GetWidth() const;
size_t GetBytesPerRow() const;
bool WriteToPNG(const std::string& path) const;
private:
friend class MetalScreenshoter;
friend class MetalScreenshotter;
explicit MetalScreenshot(CGImageRef cgImage);
FML_DISALLOW_COPY_AND_ASSIGN(MetalScreenshot);
CGImageRef cg_image_;

View File

@@ -29,6 +29,10 @@ size_t MetalScreenshot::GetWidth() const {
return CGImageGetWidth(cg_image_);
}
size_t MetalScreenshot::GetBytesPerRow() const {
return CGImageGetBytesPerRow(cg_image_);
}
bool MetalScreenshot::WriteToPNG(const std::string& path) const {
bool result = false;
NSURL* output_url =

View File

@@ -12,15 +12,17 @@
namespace impeller {
namespace testing {
/// Converts `Picture`s to `MetalScreenshot`s with the playground backend.
class MetalScreenshoter {
/// Converts `Picture`s and `DisplayList`s to `MetalScreenshot`s with the
/// playground backend.
class MetalScreenshotter {
public:
MetalScreenshoter();
MetalScreenshotter();
std::unique_ptr<MetalScreenshot> MakeScreenshot(AiksContext& aiks_context,
const Picture& picture,
const ISize& size = {300,
300});
300},
bool scale_content = true);
const PlaygroundImpl& GetPlayground() const { return *playground_; }

View File

@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/impeller/golden_tests/metal_screenshoter.h"
#include "flutter/impeller/golden_tests/metal_screenshotter.h"
#include <CoreImage/CoreImage.h>
#include "impeller/renderer/backend/metal/context_mtl.h"
@@ -13,17 +13,19 @@
namespace impeller {
namespace testing {
MetalScreenshoter::MetalScreenshoter() {
MetalScreenshotter::MetalScreenshotter() {
FML_CHECK(::glfwInit() == GLFW_TRUE);
playground_ =
PlaygroundImpl::Create(PlaygroundBackend::kMetal, PlaygroundSwitches{});
}
std::unique_ptr<MetalScreenshot> MetalScreenshoter::MakeScreenshot(
std::unique_ptr<MetalScreenshot> MetalScreenshotter::MakeScreenshot(
AiksContext& aiks_context,
const Picture& picture,
const ISize& size) {
Vector2 content_scale = playground_->GetContentScale();
const ISize& size,
bool scale_content) {
Vector2 content_scale =
scale_content ? playground_->GetContentScale() : Vector2{1, 1};
std::shared_ptr<Image> image = picture.ToImage(
aiks_context,
ISize(size.width * content_scale.x, size.height * content_scale.y));