[Impeller] backfilled golden tests from playground tests in aiks_unittests. (flutter/engine#40770)

[Impeller] backfilled golden tests from playground tests in aiks_unittests.
This commit is contained in:
gaaclarke
2023-03-30 14:38:22 -07:00
committed by GitHub
parent 8c5378eb5e
commit 0407296be4
27 changed files with 412 additions and 72 deletions

View File

@@ -134,7 +134,6 @@
../../../flutter/impeller/fixtures
../../../flutter/impeller/geometry/README.md
../../../flutter/impeller/geometry/geometry_unittests.cc
../../../flutter/impeller/geometry/geometry_unittests.h
../../../flutter/impeller/golden_tests/README.md
../../../flutter/impeller/golden_tests_harvester/.dart_tool
../../../flutter/impeller/golden_tests_harvester/.gitignore

View File

@@ -1311,6 +1311,7 @@ ORIGIN: ../../../flutter/impeller/geometry/color.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/geometry/color.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/geometry/constants.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/geometry/constants.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/geometry/geometry_asserts.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/geometry/geometry_benchmarks.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/geometry/gradient.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/geometry/gradient.h + ../../../flutter/LICENSE
@@ -1344,6 +1345,9 @@ ORIGIN: ../../../flutter/impeller/geometry/vector.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/geometry/vector.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/golden_digest.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/golden_digest.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/golden_playground_test.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/golden_playground_test_mac.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/golden_playground_test_stub.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/golden_tests.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/main.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/golden_tests/metal_screenshot.h + ../../../flutter/LICENSE
@@ -3880,6 +3884,7 @@ FILE: ../../../flutter/impeller/geometry/color.cc
FILE: ../../../flutter/impeller/geometry/color.h
FILE: ../../../flutter/impeller/geometry/constants.cc
FILE: ../../../flutter/impeller/geometry/constants.h
FILE: ../../../flutter/impeller/geometry/geometry_asserts.h
FILE: ../../../flutter/impeller/geometry/geometry_benchmarks.cc
FILE: ../../../flutter/impeller/geometry/gradient.cc
FILE: ../../../flutter/impeller/geometry/gradient.h
@@ -3913,6 +3918,9 @@ FILE: ../../../flutter/impeller/geometry/vector.cc
FILE: ../../../flutter/impeller/geometry/vector.h
FILE: ../../../flutter/impeller/golden_tests/golden_digest.cc
FILE: ../../../flutter/impeller/golden_tests/golden_digest.h
FILE: ../../../flutter/impeller/golden_tests/golden_playground_test.h
FILE: ../../../flutter/impeller/golden_tests/golden_playground_test_mac.cc
FILE: ../../../flutter/impeller/golden_tests/golden_playground_test_stub.cc
FILE: ../../../flutter/impeller/golden_tests/golden_tests.cc
FILE: ../../../flutter/impeller/golden_tests/main.cc
FILE: ../../../flutter/impeller/golden_tests/metal_screenshot.h

View File

@@ -84,6 +84,7 @@ impeller_component("impeller_unittests") {
"display_list:display_list_unittests",
"entity:entity_unittests",
"fixtures",
"geometry:geometry_unittests",
"image:image_unittests",
"playground",
"renderer:renderer_unittests",

View File

@@ -31,17 +31,43 @@ impeller_component("aiks") {
deps = [ "//flutter/fml" ]
}
impeller_component("aiks_unittests") {
impeller_component("aiks_playground") {
testonly = true
sources = [
"aiks_playground.cc",
"aiks_playground.h",
"aiks_unittests.cc",
]
deps = [
":aiks",
"../geometry:geometry_unittests",
"../playground:playground_test",
"//flutter/testing",
]
}
impeller_component("aiks_unittests") {
testonly = true
sources = [ "aiks_unittests.cc" ]
deps = [
":aiks",
":aiks_playground",
"//flutter/impeller/geometry:geometry_asserts",
"//flutter/impeller/golden_tests:golden_playground_test",
"//flutter/impeller/playground:playground_test",
"//flutter/testing:testing_lib",
]
}
impeller_component("aiks_unittests_golden") {
testonly = true
defines = [ "IMPELLER_GOLDEN_TESTS" ]
sources = [ "aiks_unittests.cc" ]
deps = [
":aiks",
":aiks_playground",
"//flutter/impeller/geometry:geometry_asserts",
"//flutter/impeller/golden_tests:golden_playground_test",
"//flutter/impeller/playground:playground_test",
"//flutter/testing:testing_lib",
]
}

View File

@@ -23,9 +23,10 @@
#include "impeller/entity/contents/tiled_texture_contents.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/constants.h"
#include "impeller/geometry/geometry_unittests.h"
#include "impeller/geometry/geometry_asserts.h"
#include "impeller/geometry/matrix.h"
#include "impeller/geometry/path_builder.h"
#include "impeller/golden_tests/golden_playground_test.h"
#include "impeller/playground/widgets.h"
#include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/snapshot.h"
@@ -39,7 +40,11 @@
namespace impeller {
namespace testing {
#ifdef IMPELLER_GOLDEN_TESTS
using AiksTest = GoldenPlaygroundTest;
#else
using AiksTest = AiksPlayground;
#endif
INSTANTIATE_PLAYGROUND_SUITE(AiksTest);
TEST_P(AiksTest, CanvasCTMCanBeUpdated) {
@@ -1286,7 +1291,7 @@ TEST_P(AiksTest, CanRenderTextOutsideBoundaries) {
SkFont sk_font(SkTypeface::MakeFromData(mapping), font_size);
Paint text_paint;
text_paint.color = Color::White().WithAlpha(0.8);
text_paint.color = Color::Blue().WithAlpha(0.8);
struct {
Point position;

View File

@@ -28,7 +28,8 @@ std::optional<Snapshot> Picture::Snapshot(AiksContext& context) {
.transform = Matrix::MakeTranslation(coverage.value().origin)};
}
std::shared_ptr<Image> Picture::ToImage(AiksContext& context, ISize size) {
std::shared_ptr<Image> Picture::ToImage(AiksContext& context,
ISize size) const {
if (size.IsEmpty()) {
return nullptr;
}
@@ -39,7 +40,7 @@ std::shared_ptr<Image> Picture::ToImage(AiksContext& context, ISize size) {
std::shared_ptr<Texture> Picture::RenderToTexture(
AiksContext& context,
ISize size,
std::optional<const Matrix> translate) {
std::optional<const Matrix> translate) const {
FML_DCHECK(!size.IsEmpty());
pass->IterateAllEntities([&translate](auto& entity) -> bool {

View File

@@ -21,13 +21,13 @@ struct Picture {
std::optional<Snapshot> Snapshot(AiksContext& context);
std::shared_ptr<Image> ToImage(AiksContext& context, ISize size);
std::shared_ptr<Image> ToImage(AiksContext& context, ISize size) const;
private:
std::shared_ptr<Texture> RenderToTexture(
AiksContext& context,
ISize size,
std::optional<const Matrix> translate = std::nullopt);
std::optional<const Matrix> translate = std::nullopt) const;
};
} // namespace impeller

View File

@@ -246,7 +246,7 @@ impeller_component("entity_unittests") {
deps = [
":entity",
"../geometry:geometry_unittests",
"../geometry:geometry_asserts",
"../playground:playground_test",
]
}

View File

@@ -7,7 +7,7 @@
#include "gtest/gtest.h"
#include "impeller/entity/contents/filters/inputs/filter_input.h"
#include "impeller/entity/entity.h"
#include "impeller/geometry/geometry_unittests.h"
#include "impeller/geometry/geometry_asserts.h"
namespace impeller {
namespace testing {

View File

@@ -34,7 +34,7 @@
#include "impeller/entity/entity_playground.h"
#include "impeller/entity/geometry.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/geometry_unittests.h"
#include "impeller/geometry/geometry_asserts.h"
#include "impeller/geometry/path_builder.h"
#include "impeller/geometry/sigma.h"
#include "impeller/playground/playground.h"

View File

@@ -45,15 +45,22 @@ impeller_component("geometry") {
deps = [ "//flutter/fml" ]
}
impeller_component("geometry_unittests") {
impeller_component("geometry_asserts") {
testonly = true
sources = [
"geometry_unittests.cc",
"geometry_unittests.h",
]
sources = [ "geometry_asserts.h" ]
deps = [
":geometry",
"//flutter/testing",
"//flutter/testing:testing_lib",
]
}
impeller_component("geometry_unittests") {
testonly = true
sources = [ "geometry_unittests.cc" ]
deps = [
":geometry",
":geometry_asserts",
"//flutter/testing:testing_lib",
]
}

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 "impeller/geometry/geometry_unittests.h"
#include "impeller/geometry/geometry_asserts.h"
#include <limits>
#include <sstream>

View File

@@ -5,9 +5,56 @@
import("//flutter/common/config.gni")
import("//flutter/impeller/tools/impeller.gni")
impeller_component("golden_playground_test") {
testonly = true
sources = [ "golden_playground_test.h" ]
deps = [
":digest",
"//flutter/fml",
"//flutter/impeller/aiks",
"//flutter/impeller/playground",
"//flutter/testing:testing_lib",
]
if (is_mac) {
sources += [ "golden_playground_test_mac.cc" ]
deps += [ ":metal_screenshot" ]
} else {
sources += [ "golden_playground_test_stub.cc" ]
}
}
impeller_component("digest") {
testonly = true
sources = [
"golden_digest.cc",
"golden_digest.h",
"working_directory.cc",
"working_directory.h",
]
deps = [ "//flutter/fml" ]
}
if (is_mac) {
test_fixtures("impeller_golden_tests_fixtures") {
fixtures = []
impeller_component("metal_screenshot") {
testonly = true
sources = [
"metal_screenshot.h",
"metal_screenshot.mm",
"metal_screenshoter.h",
"metal_screenshoter.mm",
]
deps = [
"//flutter/impeller/aiks",
"//flutter/impeller/playground",
"//flutter/impeller/renderer/backend/metal:metal",
]
}
impeller_component("impeller_golden_tests") {
@@ -16,23 +63,16 @@ if (is_mac) {
testonly = true
sources = [
"golden_digest.cc",
"golden_digest.h",
"golden_tests.cc",
"main.cc",
"metal_screenshot.h",
"metal_screenshot.mm",
"metal_screenshoter.h",
"metal_screenshoter.mm",
"working_directory.cc",
"working_directory.h",
]
deps = [
":impeller_golden_tests_fixtures",
":digest",
":metal_screenshot",
"//flutter/impeller/aiks",
"//flutter/impeller/playground",
"//flutter/impeller/renderer/backend/metal:metal",
"//flutter/impeller/aiks:aiks_unittests_golden",
"//flutter/impeller/fixtures",
"//third_party/googletest:gtest",
]
}

View File

@@ -39,8 +39,9 @@ bool GoldenDigest::Write(WorkingDirectory* working_directory) {
for (const auto& entry : entries_) {
if (!is_first) {
fout << "," << std::endl;
is_first = false;
}
is_first = false;
fout << " { "
<< "\"testName\" : \"" << entry.test_name << "\", "
<< "\"filename\" : \"" << entry.filename << "\", "

View File

@@ -0,0 +1,52 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include <memory>
#include "flutter/fml/macros.h"
#include "flutter/impeller/aiks/aiks_context.h"
#include "flutter/impeller/playground/playground.h"
#include "flutter/impeller/renderer/render_target.h"
#include "flutter/testing/testing.h"
namespace impeller {
class GoldenPlaygroundTest
: public ::testing::TestWithParam<PlaygroundBackend> {
public:
using AiksPlaygroundCallback =
std::function<bool(AiksContext& renderer, RenderTarget& render_target)>;
GoldenPlaygroundTest();
void SetUp();
PlaygroundBackend GetBackend() const;
bool OpenPlaygroundHere(const Picture& picture);
bool OpenPlaygroundHere(const AiksPlaygroundCallback& callback);
std::shared_ptr<Texture> CreateTextureForFixture(
const char* fixture_name,
bool enable_mipmapping = false) const;
std::shared_ptr<Context> GetContext() const;
Point GetContentScale() const;
Scalar GetSecondsElapsed() const;
ISize GetWindowSize() const;
private:
struct GoldenPlaygroundTestImpl;
// This is only a shared_ptr so it can work with a forward declared type.
std::shared_ptr<GoldenPlaygroundTestImpl> pimpl_;
FML_DISALLOW_COPY_AND_ASSIGN(GoldenPlaygroundTest);
};
} // namespace impeller

View File

@@ -0,0 +1,139 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// 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/golden_playground_test.h"
#include "flutter/impeller/aiks/picture.h"
#include "flutter/impeller/golden_tests/golden_digest.h"
#include "flutter/impeller/golden_tests/metal_screenshoter.h"
namespace impeller {
namespace {
std::string GetTestName() {
std::string suite_name =
::testing::UnitTest::GetInstance()->current_test_suite()->name();
std::string test_name =
::testing::UnitTest::GetInstance()->current_test_info()->name();
std::stringstream ss;
ss << "impeller_" << suite_name << "_" << test_name;
std::string result = ss.str();
// Make sure there are no slashes in the test name.
std::replace(result.begin(), result.end(), '/', '_');
return result;
}
std::string GetGoldenFilename() {
return GetTestName() + ".png";
}
bool SaveScreenshot(std::unique_ptr<testing::MetalScreenshot> screenshot) {
if (!screenshot || !screenshot->GetBytes()) {
return false;
}
std::string test_name = GetTestName();
std::string filename = GetGoldenFilename();
testing::GoldenDigest::Instance()->AddImage(
test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
return screenshot->WriteToPNG(
testing::WorkingDirectory::Instance()->GetFilenamePath(filename));
}
} // namespace
struct GoldenPlaygroundTest::GoldenPlaygroundTestImpl {
GoldenPlaygroundTestImpl()
: screenshoter_(new testing::MetalScreenshoter()) {}
std::unique_ptr<testing::MetalScreenshoter> screenshoter_;
ISize window_size_ = ISize{1024, 768};
};
GoldenPlaygroundTest::GoldenPlaygroundTest()
: pimpl_(new GoldenPlaygroundTest::GoldenPlaygroundTestImpl()) {}
void GoldenPlaygroundTest::SetUp() {
if (GetBackend() != PlaygroundBackend::kMetal) {
GTEST_SKIP_("GoldenPlaygroundTest doesn't support this backend type.");
return;
}
std::string test_name = GetTestName();
if (test_name == "impeller_Play_AiksTest_CanRenderTiledTexture_Metal" ||
test_name ==
"impeller_Play_AiksTest_CanRenderLinearGradientWithOverlappingStops_"
"Metal" ||
test_name ==
"impeller_Play_AiksTest_CanRenderLinearGradientManyColors_Metal" ||
test_name ==
"impeller_Play_AiksTest_CanRenderLinearGradientWayManyColors_Metal" ||
test_name ==
"impeller_Play_AiksTest_CanRenderLinearGradientManyColorsUnevenStops_"
"Metal" ||
test_name == "impeller_Play_AiksTest_CanRenderRadialGradient_Metal" ||
test_name ==
"impeller_Play_AiksTest_CanRenderRadialGradientManyColors_Metal" ||
test_name == "impeller_Play_AiksTest_CanRenderSweepGradient_Metal" ||
test_name ==
"impeller_Play_AiksTest_CanRenderSweepGradientManyColors_Metal" ||
test_name == "impeller_Play_AiksTest_CanPictureConvertToImage_Metal" ||
test_name == "impeller_Play_AiksTest_TextFrameSubpixelAlignment_Metal" ||
test_name == "impeller_Play_AiksTest_ColorWheel_Metal" ||
test_name == "impeller_Play_AiksTest_SolidStrokesRenderCorrectly_Metal" ||
test_name ==
"impeller_Play_AiksTest_GradientStrokesRenderCorrectly_Metal" ||
test_name ==
"impeller_Play_AiksTest_"
"CoverageOriginShouldBeAccountedForInSubpasses_Metal" ||
test_name == "impeller_Play_AiksTest_SceneColorSource_Metal" ||
test_name == "impeller_Play_AiksTest_CanRenderLinearGradient_Metal") {
GTEST_SKIP_(
"GoldenPlaygroundTest doesn't support interactive playground tests "
"yet.");
}
}
PlaygroundBackend GoldenPlaygroundTest::GetBackend() const {
return GetParam();
}
bool GoldenPlaygroundTest::OpenPlaygroundHere(const Picture& picture) {
auto screenshot =
pimpl_->screenshoter_->MakeScreenshot(picture, pimpl_->window_size_);
return SaveScreenshot(std::move(screenshot));
}
bool GoldenPlaygroundTest::OpenPlaygroundHere(
const AiksPlaygroundCallback& callback) {
return false;
}
std::shared_ptr<Texture> GoldenPlaygroundTest::CreateTextureForFixture(
const char* fixture_name,
bool enable_mipmapping) const {
std::shared_ptr<fml::Mapping> mapping =
flutter::testing::OpenFixtureAsMapping(fixture_name);
auto result = Playground::CreateTextureForMapping(GetContext(), mapping,
enable_mipmapping);
if (result) {
result->SetLabel(fixture_name);
}
return result;
}
std::shared_ptr<Context> GoldenPlaygroundTest::GetContext() const {
return pimpl_->screenshoter_->GetContext().GetContext();
}
Point GoldenPlaygroundTest::GetContentScale() const {
return pimpl_->screenshoter_->GetPlayground().GetContentScale();
}
Scalar GoldenPlaygroundTest::GetSecondsElapsed() const {
return 0.0f;
}
ISize GoldenPlaygroundTest::GetWindowSize() const {
return pimpl_->window_size_;
}
} // namespace impeller

View File

@@ -0,0 +1,50 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// 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/golden_playground_test.h"
namespace impeller {
GoldenPlaygroundTest::GoldenPlaygroundTest() {}
void GoldenPlaygroundTest::SetUp() {
GTEST_SKIP_("GoldenPlaygroundTest doesn't support this backend type.");
}
PlaygroundBackend GoldenPlaygroundTest::GetBackend() const {
return GetParam();
}
bool GoldenPlaygroundTest::OpenPlaygroundHere(const Picture& picture) {
return false;
}
bool GoldenPlaygroundTest::OpenPlaygroundHere(
const AiksPlaygroundCallback& callback) {
return false;
}
std::shared_ptr<Texture> GoldenPlaygroundTest::CreateTextureForFixture(
const char* fixture_name,
bool enable_mipmapping) const {
return nullptr;
}
std::shared_ptr<Context> GoldenPlaygroundTest::GetContext() const {
return nullptr;
}
Point GoldenPlaygroundTest::GetContentScale() const {
return Point();
}
Scalar GoldenPlaygroundTest::GetSecondsElapsed() const {
return Scalar();
}
ISize GoldenPlaygroundTest::GetWindowSize() const {
return ISize();
}
} // namespace impeller

View File

@@ -72,7 +72,7 @@ TEST_F(GoldenTests, ConicalGradient) {
paint.style = Paint::Style::kFill;
canvas.DrawRect(Rect(10, 10, 250, 250), paint);
Picture picture = canvas.EndRecordingAsPicture();
auto screenshot = Screenshoter().MakeScreenshot(std::move(picture));
auto screenshot = Screenshoter().MakeScreenshot(picture);
ASSERT_TRUE(SaveScreenshot(std::move(screenshot)));
}
} // namespace testing

View File

@@ -17,10 +17,16 @@ class MetalScreenshoter {
public:
MetalScreenshoter();
std::unique_ptr<MetalScreenshot> MakeScreenshot(Picture&& picture,
std::unique_ptr<MetalScreenshot> MakeScreenshot(const Picture& picture,
const ISize& size = {300,
300});
AiksContext& GetContext() { return *aiks_context_; }
const AiksContext& GetContext() const { return *aiks_context_; }
const PlaygroundImpl& GetPlayground() const { return *playground_; }
private:
std::unique_ptr<PlaygroundImpl> playground_;
std::unique_ptr<AiksContext> aiks_context_;

View File

@@ -21,9 +21,12 @@ MetalScreenshoter::MetalScreenshoter() {
}
std::unique_ptr<MetalScreenshot> MetalScreenshoter::MakeScreenshot(
Picture&& picture,
const Picture& picture,
const ISize& size) {
std::shared_ptr<Image> image = picture.ToImage(*aiks_context_, size);
Vector2 content_scale = playground_->GetContentScale();
std::shared_ptr<Image> image = picture.ToImage(
*aiks_context_,
ISize(size.width * content_scale.x, size.height * content_scale.y));
std::shared_ptr<Texture> texture = image->GetTexture();
id<MTLTexture> metal_texture =
std::static_pointer_cast<TextureMTL>(texture)->GetMTLTexture();

View File

@@ -78,6 +78,6 @@ impeller_component("playground_test") {
public_deps = [
":playground",
"//flutter/testing",
"//flutter/testing:testing_lib",
]
}

View File

@@ -366,7 +366,7 @@ bool Playground::OpenPlaygroundHere(SinglePassCallback pass_callback) {
}
std::shared_ptr<CompressedImage> Playground::LoadFixtureImageCompressed(
std::shared_ptr<fml::Mapping> mapping) const {
std::shared_ptr<fml::Mapping> mapping) {
auto compressed_image = CompressedImageSkia::Create(std::move(mapping));
if (!compressed_image) {
VALIDATION_LOG << "Could not create compressed image.";
@@ -377,7 +377,7 @@ std::shared_ptr<CompressedImage> Playground::LoadFixtureImageCompressed(
}
std::optional<DecompressedImage> Playground::DecodeImageRGBA(
const std::shared_ptr<CompressedImage>& compressed) const {
const std::shared_ptr<CompressedImage>& compressed) {
if (compressed == nullptr) {
return std::nullopt;
}
@@ -395,9 +395,11 @@ std::optional<DecompressedImage> Playground::DecodeImageRGBA(
return image;
}
std::shared_ptr<Texture> Playground::CreateTextureForFixture(
namespace {
std::shared_ptr<Texture> CreateTextureForDecompressedImage(
const std::shared_ptr<Context>& context,
DecompressedImage& decompressed_image,
bool enable_mipmapping) const {
bool enable_mipmapping) {
auto texture_descriptor = TextureDescriptor{};
texture_descriptor.storage_mode = StorageMode::kHostVisible;
texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
@@ -405,8 +407,8 @@ std::shared_ptr<Texture> Playground::CreateTextureForFixture(
texture_descriptor.mip_count =
enable_mipmapping ? decompressed_image.GetSize().MipCount() : 1u;
auto texture = renderer_->GetContext()->GetResourceAllocator()->CreateTexture(
texture_descriptor);
auto texture =
context->GetResourceAllocator()->CreateTexture(texture_descriptor);
if (!texture) {
VALIDATION_LOG << "Could not allocate texture for fixture.";
return nullptr;
@@ -419,21 +421,26 @@ std::shared_ptr<Texture> Playground::CreateTextureForFixture(
}
return texture;
}
} // namespace
std::shared_ptr<Texture> Playground::CreateTextureForFixture(
std::shared_ptr<Texture> Playground::CreateTextureForMapping(
const std::shared_ptr<Context>& context,
std::shared_ptr<fml::Mapping> mapping,
bool enable_mipmapping) const {
auto image = DecodeImageRGBA(LoadFixtureImageCompressed(std::move(mapping)));
bool enable_mipmapping) {
auto image = Playground::DecodeImageRGBA(
Playground::LoadFixtureImageCompressed(std::move(mapping)));
if (!image.has_value()) {
return nullptr;
}
return CreateTextureForFixture(image.value(), enable_mipmapping);
return CreateTextureForDecompressedImage(context, image.value(),
enable_mipmapping);
}
std::shared_ptr<Texture> Playground::CreateTextureForFixture(
const char* fixture_name,
bool enable_mipmapping) const {
auto texture = CreateTextureForFixture(OpenAssetAsMapping(fixture_name),
auto texture = CreateTextureForMapping(renderer_->GetContext(),
OpenAssetAsMapping(fixture_name),
enable_mipmapping);
if (texture == nullptr) {
return nullptr;

View File

@@ -62,19 +62,16 @@ class Playground {
bool OpenPlaygroundHere(SinglePassCallback pass_callback);
std::shared_ptr<CompressedImage> LoadFixtureImageCompressed(
std::shared_ptr<fml::Mapping> mapping) const;
static std::shared_ptr<CompressedImage> LoadFixtureImageCompressed(
std::shared_ptr<fml::Mapping> mapping);
std::optional<DecompressedImage> DecodeImageRGBA(
const std::shared_ptr<CompressedImage>& compressed) const;
static std::optional<DecompressedImage> DecodeImageRGBA(
const std::shared_ptr<CompressedImage>& compressed);
std::shared_ptr<Texture> CreateTextureForFixture(
DecompressedImage& decompressed_image,
bool enable_mipmapping = false) const;
std::shared_ptr<Texture> CreateTextureForFixture(
static std::shared_ptr<Texture> CreateTextureForMapping(
const std::shared_ptr<Context>& context,
std::shared_ptr<fml::Mapping> mapping,
bool enable_mipmapping = false) const;
bool enable_mipmapping = false);
std::shared_ptr<Texture> CreateTextureForFixture(
const char* fixture_name,

View File

@@ -118,7 +118,7 @@ impeller_component("importer_unittests") {
deps = [
":importer_lib",
"../../fixtures",
"../../geometry:geometry_unittests",
"../../geometry:geometry_asserts",
"//flutter/testing:testing_lib",
]
}

View File

@@ -3,7 +3,7 @@
// found in the LICENSE file.
#include "flutter/testing/testing.h"
#include "impeller/geometry/geometry_unittests.h"
#include "impeller/geometry/geometry_asserts.h"
#include "impeller/geometry/matrix.h"
#include "impeller/scene/importer/conversions.h"
#include "impeller/scene/importer/importer.h"

View File

@@ -17,12 +17,18 @@ source_set("testing_lib") {
sources = [
"assertions.h",
"debugger_detection.cc",
"debugger_detection.h",
"display_list_testing.cc",
"display_list_testing.h",
"mock_canvas.cc",
"mock_canvas.h",
"post_task_sync.cc",
"post_task_sync.h",
"test_args.cc",
"test_args.h",
"test_timeout_listener.cc",
"test_timeout_listener.h",
"testing.cc",
"testing.h",
"thread_test.cc",
@@ -41,15 +47,7 @@ source_set("testing_lib") {
source_set("testing") {
testonly = true
sources = [
"debugger_detection.cc",
"debugger_detection.h",
"run_all_unittests.cc",
"test_args.cc",
"test_args.h",
"test_timeout_listener.cc",
"test_timeout_listener.h",
]
sources = [ "run_all_unittests.cc" ]
public_deps = [ ":testing_lib" ]
public_configs = [ ":dynamic_symbols" ]