[Impeller] finish experimental canvas changes. (flutter/engine#54569)
Make sure the old dispatcher cannot be used if the new dispatcher is enabled. Migrate tests using old canvas to new canvas, mostly to make deleting the old one easier...
This commit is contained in:
@@ -87,6 +87,11 @@ sk_sp<DlPixelData> DlMetalSurfaceProvider::ImpellerSnapshot(
|
||||
const sk_sp<DisplayList>& list,
|
||||
int width,
|
||||
int height) const {
|
||||
#if EXPERIMENTAL_CANVAS
|
||||
auto texture = DisplayListToTexture(list, {width, height}, *aiks_context_);
|
||||
return sk_make_sp<DlMetalPixelData>(
|
||||
snapshotter_->MakeScreenshot(*aiks_context_, texture));
|
||||
#else
|
||||
InitScreenShotter();
|
||||
impeller::DlDispatcher dispatcher;
|
||||
dispatcher.drawColor(flutter::DlColor::kTransparent(),
|
||||
@@ -95,6 +100,8 @@ sk_sp<DlPixelData> DlMetalSurfaceProvider::ImpellerSnapshot(
|
||||
auto picture = dispatcher.EndRecordingAsPicture();
|
||||
return sk_make_sp<DlMetalPixelData>(snapshotter_->MakeScreenshot(
|
||||
*aiks_context_, picture, {width, height}, false));
|
||||
|
||||
#endif // EXPERIMENTAL_CANVAS
|
||||
}
|
||||
|
||||
sk_sp<DlImage> DlMetalSurfaceProvider::MakeImpellerImage(
|
||||
@@ -102,6 +109,10 @@ sk_sp<DlImage> DlMetalSurfaceProvider::MakeImpellerImage(
|
||||
int width,
|
||||
int height) const {
|
||||
InitScreenShotter();
|
||||
#if EXPERIMENTAL_CANVAS
|
||||
return impeller::DlImageImpeller::Make(
|
||||
DisplayListToTexture(list, {width, height}, *aiks_context_));
|
||||
#else
|
||||
impeller::DlDispatcher dispatcher;
|
||||
dispatcher.drawColor(flutter::DlColor::kTransparent(),
|
||||
flutter::DlBlendMode::kSrc);
|
||||
@@ -111,6 +122,8 @@ sk_sp<DlImage> DlMetalSurfaceProvider::MakeImpellerImage(
|
||||
picture.ToImage(*aiks_context_, {width, height});
|
||||
std::shared_ptr<impeller::Texture> texture = image->GetTexture();
|
||||
return impeller::DlImageImpeller::Make(texture);
|
||||
|
||||
#endif // EXPERIMENTAL_CANVAS
|
||||
}
|
||||
|
||||
void DlMetalSurfaceProvider::InitScreenShotter() const {
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/testing/testing.h"
|
||||
#include "impeller/aiks/canvas.h"
|
||||
#include "impeller/aiks/image_filter.h"
|
||||
#include "impeller/aiks/aiks_context.h"
|
||||
#include "impeller/aiks/aiks_unittests.h"
|
||||
#include "impeller/aiks/experimental_canvas.h"
|
||||
#include "impeller/geometry/path_builder.h"
|
||||
|
||||
// TODO(zanderso): https://github.com/flutter/flutter/issues/127701
|
||||
@@ -13,252 +14,285 @@
|
||||
namespace impeller {
|
||||
namespace testing {
|
||||
|
||||
using AiksCanvasTest = ::testing::Test;
|
||||
std::unique_ptr<ExperimentalCanvas> CreateTestCanvas(
|
||||
ContentContext& context,
|
||||
std::optional<Rect> cull_rect = std::nullopt) {
|
||||
RenderTarget render_target = context.GetRenderTargetCache()->CreateOffscreen(
|
||||
*context.GetContext(), {1, 1}, 1);
|
||||
|
||||
TEST(AiksCanvasTest, EmptyCullRect) {
|
||||
Canvas canvas;
|
||||
|
||||
ASSERT_FALSE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
if (cull_rect.has_value()) {
|
||||
return std::make_unique<ExperimentalCanvas>(context, render_target, false,
|
||||
cull_rect.value());
|
||||
}
|
||||
return std::make_unique<ExperimentalCanvas>(context, render_target, false);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, InitialCullRect) {
|
||||
TEST_P(AiksTest, EmptyCullRect) {
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context);
|
||||
|
||||
ASSERT_FALSE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
}
|
||||
|
||||
TEST_P(AiksTest, InitialCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), initial_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), initial_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, TranslatedCullRect) {
|
||||
TEST_P(AiksTest, TranslatedCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
Rect translated_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.Translate(Vector3(5, 5, 0));
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->Translate(Vector3(5, 5, 0));
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), translated_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), translated_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, ScaledCullRect) {
|
||||
TEST_P(AiksTest, ScaledCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
Rect scaled_cull = Rect::MakeXYWH(10, 10, 20, 20);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.Scale(Vector2(0.5, 0.5));
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->Scale(Vector2(0.5, 0.5));
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), scaled_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), scaled_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RectClipIntersectAgainstEmptyCullRect) {
|
||||
TEST_P(AiksTest, RectClipIntersectAgainstEmptyCullRect) {
|
||||
Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
|
||||
Canvas canvas;
|
||||
canvas.ClipRect(rect_clip, Entity::ClipOperation::kIntersect);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context);
|
||||
canvas->ClipRect(rect_clip, Entity::ClipOperation::kIntersect);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), rect_clip);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), rect_clip);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RectClipDiffAgainstEmptyCullRect) {
|
||||
TEST_P(AiksTest, RectClipDiffAgainstEmptyCullRect) {
|
||||
Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
|
||||
Canvas canvas;
|
||||
canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context);
|
||||
canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_FALSE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_FALSE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RectClipIntersectAgainstCullRect) {
|
||||
TEST_P(AiksTest, RectClipIntersectAgainstCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
Rect result_cull = Rect::MakeXYWH(5, 5, 5, 5);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRect(rect_clip, Entity::ClipOperation::kIntersect);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRect(rect_clip, Entity::ClipOperation::kIntersect);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RectClipDiffAgainstNonCoveredCullRect) {
|
||||
TEST_P(AiksTest, RectClipDiffAgainstNonCoveredCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
Rect result_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RectClipDiffAboveCullRect) {
|
||||
TEST_P(AiksTest, RectClipDiffAboveCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(0, 0, 20, 4);
|
||||
Rect result_cull = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RectClipDiffBelowCullRect) {
|
||||
TEST_P(AiksTest, RectClipDiffBelowCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(0, 16, 20, 4);
|
||||
Rect result_cull = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RectClipDiffLeftOfCullRect) {
|
||||
TEST_P(AiksTest, RectClipDiffLeftOfCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(0, 0, 4, 20);
|
||||
Rect result_cull = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RectClipDiffRightOfCullRect) {
|
||||
TEST_P(AiksTest, RectClipDiffRightOfCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(16, 0, 4, 20);
|
||||
Rect result_cull = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RectClipDiffAgainstVCoveredCullRect) {
|
||||
TEST_P(AiksTest, RectClipDiffAgainstVCoveredCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(5, 0, 10, 10);
|
||||
Rect result_cull = Rect::MakeXYWH(0, 0, 5, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RectClipDiffAgainstHCoveredCullRect) {
|
||||
TEST_P(AiksTest, RectClipDiffAgainstHCoveredCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(0, 5, 10, 10);
|
||||
Rect result_cull = Rect::MakeXYWH(0, 0, 10, 5);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRect(rect_clip, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RRectClipIntersectAgainstEmptyCullRect) {
|
||||
TEST_P(AiksTest, RRectClipIntersectAgainstEmptyCullRect) {
|
||||
Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
|
||||
Canvas canvas;
|
||||
canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kIntersect);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context);
|
||||
canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kIntersect);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), rect_clip);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), rect_clip);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RRectClipDiffAgainstEmptyCullRect) {
|
||||
TEST_P(AiksTest, RRectClipDiffAgainstEmptyCullRect) {
|
||||
Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
|
||||
Canvas canvas;
|
||||
canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context);
|
||||
canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_FALSE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_FALSE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RRectClipIntersectAgainstCullRect) {
|
||||
TEST_P(AiksTest, RRectClipIntersectAgainstCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
Rect result_cull = Rect::MakeXYWH(5, 5, 5, 5);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kIntersect);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kIntersect);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RRectClipDiffAgainstNonCoveredCullRect) {
|
||||
TEST_P(AiksTest, RRectClipDiffAgainstNonCoveredCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
Rect result_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RRectClipDiffAgainstVPartiallyCoveredCullRect) {
|
||||
TEST_P(AiksTest, RRectClipDiffAgainstVPartiallyCoveredCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(5, 0, 10, 10);
|
||||
Rect result_cull = Rect::MakeXYWH(0, 0, 6, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RRectClipDiffAgainstVFullyCoveredCullRect) {
|
||||
TEST_P(AiksTest, RRectClipDiffAgainstVFullyCoveredCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(5, -2, 10, 14);
|
||||
Rect result_cull = Rect::MakeXYWH(0, 0, 5, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RRectClipDiffAgainstHPartiallyCoveredCullRect) {
|
||||
TEST_P(AiksTest, RRectClipDiffAgainstHPartiallyCoveredCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(0, 5, 10, 10);
|
||||
Rect result_cull = Rect::MakeXYWH(0, 0, 10, 6);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, RRectClipDiffAgainstHFullyCoveredCullRect) {
|
||||
TEST_P(AiksTest, RRectClipDiffAgainstHFullyCoveredCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
Rect rect_clip = Rect::MakeXYWH(-2, 5, 14, 10);
|
||||
Rect result_cull = Rect::MakeXYWH(0, 0, 10, 5);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipRRect(rect_clip, {1, 1}, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, PathClipIntersectAgainstEmptyCullRect) {
|
||||
TEST_P(AiksTest, PathClipIntersectAgainstEmptyCullRect) {
|
||||
PathBuilder builder;
|
||||
builder.AddRect(Rect::MakeXYWH(5, 5, 1, 1));
|
||||
builder.AddRect(Rect::MakeXYWH(5, 14, 1, 1));
|
||||
@@ -267,14 +301,15 @@ TEST(AiksCanvasTest, PathClipIntersectAgainstEmptyCullRect) {
|
||||
Path path = builder.TakePath();
|
||||
Rect rect_clip = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
|
||||
Canvas canvas;
|
||||
canvas.ClipPath(path, Entity::ClipOperation::kIntersect);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context);
|
||||
canvas->ClipPath(path, Entity::ClipOperation::kIntersect);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), rect_clip);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), rect_clip);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, PathClipDiffAgainstEmptyCullRect) {
|
||||
TEST_P(AiksTest, PathClipDiffAgainstEmptyCullRect) {
|
||||
PathBuilder builder;
|
||||
builder.AddRect(Rect::MakeXYWH(5, 5, 1, 1));
|
||||
builder.AddRect(Rect::MakeXYWH(5, 14, 1, 1));
|
||||
@@ -282,13 +317,14 @@ TEST(AiksCanvasTest, PathClipDiffAgainstEmptyCullRect) {
|
||||
builder.AddRect(Rect::MakeXYWH(14, 14, 1, 1));
|
||||
Path path = builder.TakePath();
|
||||
|
||||
Canvas canvas;
|
||||
canvas.ClipPath(path, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context);
|
||||
canvas->ClipPath(path, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_FALSE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_FALSE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, PathClipIntersectAgainstCullRect) {
|
||||
TEST_P(AiksTest, PathClipIntersectAgainstCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
PathBuilder builder;
|
||||
builder.AddRect(Rect::MakeXYWH(5, 5, 1, 1));
|
||||
@@ -298,14 +334,15 @@ TEST(AiksCanvasTest, PathClipIntersectAgainstCullRect) {
|
||||
Path path = builder.TakePath();
|
||||
Rect result_cull = Rect::MakeXYWH(5, 5, 5, 5);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipPath(path, Entity::ClipOperation::kIntersect);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipPath(path, Entity::ClipOperation::kIntersect);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, PathClipDiffAgainstNonCoveredCullRect) {
|
||||
TEST_P(AiksTest, PathClipDiffAgainstNonCoveredCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
PathBuilder builder;
|
||||
builder.AddRect(Rect::MakeXYWH(5, 5, 1, 1));
|
||||
@@ -315,14 +352,15 @@ TEST(AiksCanvasTest, PathClipDiffAgainstNonCoveredCullRect) {
|
||||
Path path = builder.TakePath();
|
||||
Rect result_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipPath(path, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipPath(path, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, PathClipDiffAgainstFullyCoveredCullRect) {
|
||||
TEST_P(AiksTest, PathClipDiffAgainstFullyCoveredCullRect) {
|
||||
Rect initial_cull = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
PathBuilder builder;
|
||||
builder.AddRect(Rect::MakeXYWH(0, 0, 100, 100));
|
||||
@@ -330,28 +368,12 @@ TEST(AiksCanvasTest, PathClipDiffAgainstFullyCoveredCullRect) {
|
||||
// Diff clip of Paths is ignored due to complexity
|
||||
Rect result_cull = Rect::MakeXYWH(5, 5, 10, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
canvas.ClipPath(path, Entity::ClipOperation::kDifference);
|
||||
ContentContext context(GetContext(), nullptr);
|
||||
auto canvas = CreateTestCanvas(context, initial_cull);
|
||||
canvas->ClipPath(path, Entity::ClipOperation::kDifference);
|
||||
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas.GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
TEST(AiksCanvasTest, DisableLocalBoundsRectForFilteredSaveLayers) {
|
||||
Rect initial_cull = Rect::MakeXYWH(0, 0, 10, 10);
|
||||
|
||||
Canvas canvas(initial_cull);
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
|
||||
canvas.Save();
|
||||
canvas.SaveLayer(
|
||||
Paint{.image_filter = ImageFilter::MakeBlur(
|
||||
Sigma(10), Sigma(10), FilterContents::BlurStyle::kNormal,
|
||||
Entity::TileMode::kDecal)});
|
||||
ASSERT_FALSE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
|
||||
canvas.Restore();
|
||||
ASSERT_TRUE(canvas.GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_TRUE(canvas->GetCurrentLocalCullingBounds().has_value());
|
||||
ASSERT_EQ(canvas->GetCurrentLocalCullingBounds().value(), result_cull);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
@@ -847,5 +847,48 @@ TEST_P(AiksTest, CanDrawScaledPointsLargeScaleSmallRadius) {
|
||||
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
|
||||
}
|
||||
|
||||
TEST_P(AiksTest, TransparentShadowProducesCorrectColor) {
|
||||
DisplayListBuilder builder;
|
||||
builder.Save();
|
||||
builder.Scale(1.618, 1.618);
|
||||
SkPath path = SkPath{}.addRect(SkRect::MakeXYWH(0, 0, 200, 100));
|
||||
|
||||
builder.DrawShadow(path, flutter::DlColor::kTransparent(), 15, false, 1);
|
||||
builder.Restore();
|
||||
|
||||
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
|
||||
}
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/130613
|
||||
TEST_P(AiksTest, DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists) {
|
||||
flutter::DisplayListBuilder sub_builder(true);
|
||||
sub_builder.DrawRect(SkRect::MakeXYWH(0, 0, 50, 50),
|
||||
flutter::DlPaint(flutter::DlColor::kRed()));
|
||||
auto display_list = sub_builder.Build();
|
||||
|
||||
AiksContext context(GetContext(), nullptr);
|
||||
RenderTarget render_target =
|
||||
context.GetContentContext().GetRenderTargetCache()->CreateOffscreen(
|
||||
*context.GetContext(), {2400, 1800}, 1);
|
||||
|
||||
DisplayListBuilder builder;
|
||||
|
||||
builder.Scale(2.0, 2.0);
|
||||
builder.Translate(-93.0, 0.0);
|
||||
|
||||
// clang-format off
|
||||
builder.TransformFullPerspective(
|
||||
0.8, -0.2, -0.1, -0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
1.4, 1.3, 1.0, 0.0,
|
||||
63.2, 65.3, 48.6, 1.1
|
||||
);
|
||||
// clang-format on
|
||||
builder.Translate(35.0, 75.0);
|
||||
builder.DrawDisplayList(display_list, 1.0f);
|
||||
|
||||
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
@@ -1220,6 +1220,7 @@ Picture DlDispatcherBase::EndRecordingAsPicture() {
|
||||
|
||||
/// Subclasses
|
||||
|
||||
#if !EXPERIMENTAL_CANVAS
|
||||
DlDispatcher::DlDispatcher() = default;
|
||||
|
||||
DlDispatcher::DlDispatcher(IRect cull_rect) : canvas_(cull_rect) {}
|
||||
@@ -1229,6 +1230,7 @@ DlDispatcher::DlDispatcher(Rect cull_rect) : canvas_(cull_rect) {}
|
||||
Canvas& DlDispatcher::GetCanvas() {
|
||||
return canvas_;
|
||||
}
|
||||
#endif // !EXPERIMENTAL_CANVAS
|
||||
|
||||
static bool RequiresReadbackForBlends(
|
||||
const ContentContext& renderer,
|
||||
@@ -1415,4 +1417,51 @@ void TextFrameDispatcher::setStrokeJoin(flutter::DlStrokeJoin join) {
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> DisplayListToTexture(
|
||||
const 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
|
||||
);
|
||||
}
|
||||
|
||||
SkIRect sk_cull_rect = SkIRect::MakeWH(size.width, size.height);
|
||||
impeller::TextFrameDispatcher collector(context.GetContentContext(),
|
||||
impeller::Matrix());
|
||||
display_list->Dispatch(collector, sk_cull_rect);
|
||||
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, sk_cull_rect);
|
||||
impeller_dispatcher.FinishRecording();
|
||||
|
||||
context.GetContentContext().GetTransientsBuffer().Reset();
|
||||
context.GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames();
|
||||
|
||||
return target.GetRenderTargetTexture();
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -261,6 +261,7 @@ class DlDispatcherBase : public flutter::DlOpReceiver {
|
||||
const Paint& paint);
|
||||
};
|
||||
|
||||
#if !EXPERIMENTAL_CANVAS
|
||||
class DlDispatcher : public DlDispatcherBase {
|
||||
public:
|
||||
DlDispatcher();
|
||||
@@ -297,6 +298,7 @@ class DlDispatcher : public DlDispatcherBase {
|
||||
|
||||
Canvas& GetCanvas() override;
|
||||
};
|
||||
#endif // !EXPERIMENTAL_CANVAS
|
||||
|
||||
class ExperimentalDlDispatcher : public DlDispatcherBase {
|
||||
public:
|
||||
@@ -403,6 +405,12 @@ class TextFrameDispatcher : public flutter::IgnoreAttributeDispatchHelper,
|
||||
Paint paint_;
|
||||
};
|
||||
|
||||
/// Render the provided display list to a texture with the given size.
|
||||
std::shared_ptr<Texture> DisplayListToTexture(
|
||||
const sk_sp<flutter::DisplayList>& display_list,
|
||||
ISize size,
|
||||
AiksContext& context);
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
#endif // FLUTTER_IMPELLER_DISPLAY_LIST_DL_DISPATCHER_H_
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "flutter/display_list/effects/dl_mask_filter.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "impeller/aiks/aiks_context.h"
|
||||
#include "impeller/display_list/dl_dispatcher.h"
|
||||
#include "impeller/display_list/dl_image_impeller.h"
|
||||
#include "impeller/display_list/dl_playground.h"
|
||||
@@ -910,69 +911,6 @@ TEST_P(DisplayListTest, CanDrawShadow) {
|
||||
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
|
||||
}
|
||||
|
||||
TEST_P(DisplayListTest,
|
||||
DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists) {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/130613
|
||||
flutter::DisplayListBuilder sub_builder(true);
|
||||
sub_builder.DrawRect(SkRect::MakeXYWH(0, 0, 50, 50),
|
||||
flutter::DlPaint(flutter::DlColor::kRed()));
|
||||
auto display_list = sub_builder.Build();
|
||||
|
||||
DlDispatcher dispatcher(Rect::MakeLTRB(0, 0, 2400, 1800));
|
||||
dispatcher.scale(2.0, 2.0);
|
||||
dispatcher.translate(-93.0, 0.0);
|
||||
// clang-format off
|
||||
dispatcher.transformFullPerspective(
|
||||
0.8, -0.2, -0.1, -0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
1.4, 1.3, 1.0, 0.0,
|
||||
63.2, 65.3, 48.6, 1.1
|
||||
);
|
||||
// clang-format on
|
||||
dispatcher.translate(35.0, 75.0);
|
||||
dispatcher.drawDisplayList(display_list, 1.0f);
|
||||
auto picture = dispatcher.EndRecordingAsPicture();
|
||||
|
||||
bool found = false;
|
||||
picture.pass->IterateAllEntities([&found](Entity& entity) {
|
||||
if (std::static_pointer_cast<SolidColorContents>(entity.GetContents())
|
||||
->GetColor() == Color::Red()) {
|
||||
found = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
EXPECT_TRUE(found);
|
||||
}
|
||||
|
||||
TEST_P(DisplayListTest, TransparentShadowProducesCorrectColor) {
|
||||
DlDispatcher dispatcher;
|
||||
dispatcher.save();
|
||||
dispatcher.scale(1.618, 1.618);
|
||||
SkPath path = SkPath{}.addRect(SkRect::MakeXYWH(0, 0, 200, 100));
|
||||
flutter::DlOpReceiver::CacheablePath cache(path);
|
||||
dispatcher.drawShadow(cache, flutter::DlColor::kTransparent(), 15, false, 1);
|
||||
dispatcher.restore();
|
||||
auto picture = dispatcher.EndRecordingAsPicture();
|
||||
|
||||
std::shared_ptr<SolidRRectBlurContents> rrect_blur;
|
||||
picture.pass->IterateAllEntities([&rrect_blur](Entity& entity) {
|
||||
if (ScalarNearlyEqual(entity.GetTransform().GetScale().x, 1.618f)) {
|
||||
rrect_blur = std::static_pointer_cast<SolidRRectBlurContents>(
|
||||
entity.GetContents());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
ASSERT_NE(rrect_blur, nullptr);
|
||||
ASSERT_EQ(rrect_blur->GetColor().red, 0);
|
||||
ASSERT_EQ(rrect_blur->GetColor().green, 0);
|
||||
ASSERT_EQ(rrect_blur->GetColor().blue, 0);
|
||||
ASSERT_EQ(rrect_blur->GetColor().alpha, 0);
|
||||
}
|
||||
|
||||
TEST_P(DisplayListTest, CanDrawZeroWidthLine) {
|
||||
flutter::DisplayListBuilder builder;
|
||||
std::vector<flutter::DlStrokeCap> caps = {
|
||||
@@ -1558,50 +1496,6 @@ static std::optional<Rect> GetCoverageOfFirstEntity(const Picture& picture) {
|
||||
return coverage;
|
||||
}
|
||||
|
||||
TEST(DisplayListTest, RRectBoundsComputation) {
|
||||
SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeLTRB(0, 0, 100, 100), 4, 4);
|
||||
SkPath path = SkPath().addRRect(rrect);
|
||||
|
||||
flutter::DlPaint paint;
|
||||
flutter::DisplayListBuilder builder;
|
||||
|
||||
builder.DrawPath(path, paint);
|
||||
auto display_list = builder.Build();
|
||||
|
||||
DlDispatcher dispatcher;
|
||||
display_list->Dispatch(dispatcher);
|
||||
auto picture = dispatcher.EndRecordingAsPicture();
|
||||
|
||||
std::optional<Rect> coverage =
|
||||
GetCoverageOfFirstEntity<SolidColorContents>(picture);
|
||||
|
||||
// Validate that the RRect coverage is _exactly_ the same as the input rect.
|
||||
ASSERT_TRUE(coverage.has_value());
|
||||
ASSERT_EQ(coverage.value_or(Rect::MakeMaximum()),
|
||||
Rect::MakeLTRB(0, 0, 100, 100));
|
||||
}
|
||||
|
||||
TEST(DisplayListTest, CircleBoundsComputation) {
|
||||
SkPath path = SkPath().addCircle(0, 0, 5);
|
||||
|
||||
flutter::DlPaint paint;
|
||||
flutter::DisplayListBuilder builder;
|
||||
|
||||
builder.DrawPath(path, paint);
|
||||
auto display_list = builder.Build();
|
||||
|
||||
DlDispatcher dispatcher;
|
||||
display_list->Dispatch(dispatcher);
|
||||
auto picture = dispatcher.EndRecordingAsPicture();
|
||||
|
||||
std::optional<Rect> coverage =
|
||||
GetCoverageOfFirstEntity<SolidColorContents>(picture);
|
||||
|
||||
ASSERT_TRUE(coverage.has_value());
|
||||
ASSERT_EQ(coverage.value_or(Rect::MakeMaximum()),
|
||||
Rect::MakeLTRB(-5, -5, 5, 5));
|
||||
}
|
||||
|
||||
#ifdef IMPELLER_ENABLE_3D
|
||||
TEST_P(DisplayListTest, SceneColorSource) {
|
||||
// Load up the scene.
|
||||
|
||||
@@ -58,55 +58,6 @@ const std::unique_ptr<PlaygroundImpl>& GetSharedVulkanPlayground(
|
||||
}
|
||||
}
|
||||
|
||||
#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
|
||||
);
|
||||
}
|
||||
|
||||
SkIRect sk_cull_rect = SkIRect::MakeWH(size.width, size.height);
|
||||
impeller::TextFrameDispatcher collector(context.GetContentContext(),
|
||||
impeller::Matrix());
|
||||
display_list->Dispatch(collector, sk_cull_rect);
|
||||
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, sk_cull_rect);
|
||||
impeller_dispatcher.FinishRecording();
|
||||
|
||||
context.GetContentContext().GetTransientsBuffer().Reset();
|
||||
context.GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames();
|
||||
|
||||
return target.GetRenderTargetTexture();
|
||||
}
|
||||
#endif // EXPERIMENTAL_CANVAS
|
||||
|
||||
} // namespace
|
||||
|
||||
#define IMP_AIKSTEST(name) \
|
||||
@@ -399,6 +350,10 @@ std::unique_ptr<testing::Screenshot> GoldenPlaygroundTest::MakeScreenshot(
|
||||
const sk_sp<flutter::DisplayList>& list) {
|
||||
AiksContext renderer(GetContext(), typographer_context_);
|
||||
|
||||
#if EXPERIMENTAL_CANVAS
|
||||
return pimpl_->screenshotter->MakeScreenshot(
|
||||
renderer, DisplayListToTexture(list, pimpl_->window_size, renderer));
|
||||
#else
|
||||
DlDispatcher dispatcher;
|
||||
list->Dispatch(dispatcher);
|
||||
Picture picture = dispatcher.EndRecordingAsPicture();
|
||||
@@ -408,6 +363,7 @@ std::unique_ptr<testing::Screenshot> GoldenPlaygroundTest::MakeScreenshot(
|
||||
pimpl_->window_size);
|
||||
|
||||
return screenshot;
|
||||
#endif // EXPERIMENTAL_CANVAS
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -925,13 +925,22 @@ ScreenshotLayerTreeAsImageImpeller(
|
||||
RenderFrameForScreenshot(compositor_context, &builder, tree, nullptr,
|
||||
aiks_context);
|
||||
|
||||
std::shared_ptr<impeller::Texture> texture;
|
||||
#if EXPERIMENTAL_CANVAS
|
||||
texture = impeller::DisplayListToTexture(
|
||||
builder.Build(),
|
||||
impeller::ISize(tree->frame_size().fWidth, tree->frame_size().fHeight),
|
||||
*aiks_context);
|
||||
#else
|
||||
impeller::DlDispatcher dispatcher;
|
||||
builder.Build()->Dispatch(dispatcher);
|
||||
const auto& picture = dispatcher.EndRecordingAsPicture();
|
||||
const auto& image = picture.ToImage(
|
||||
*aiks_context,
|
||||
impeller::ISize(tree->frame_size().fWidth, tree->frame_size().fHeight));
|
||||
const auto& texture = image->GetTexture();
|
||||
texture = image->GetTexture();
|
||||
#endif // EXPERIMENTAL_CANVAS
|
||||
|
||||
impeller::DeviceBufferDescriptor buffer_desc;
|
||||
buffer_desc.storage_mode = impeller::StorageMode::kHostVisible;
|
||||
buffer_desc.size =
|
||||
|
||||
@@ -98,7 +98,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGLImpeller::AcquireFrame(
|
||||
impeller::ISize{size.width(), size.height()} // fbo_size
|
||||
);
|
||||
|
||||
const impeller::RenderTarget& render_target =
|
||||
impeller::RenderTarget render_target =
|
||||
surface->GetTargetRenderPassDescriptor();
|
||||
|
||||
SurfaceFrame::EncodeCallback encode_calback =
|
||||
@@ -117,13 +117,35 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGLImpeller::AcquireFrame(
|
||||
|
||||
auto cull_rect = render_target.GetRenderTargetSize();
|
||||
impeller::Rect dl_cull_rect = impeller::Rect::MakeSize(cull_rect);
|
||||
const bool reset_host_buffer = surface_frame.submit_info().frame_boundary;
|
||||
|
||||
#if EXPERIMENTAL_CANVAS
|
||||
auto skia_cull_rect = SkIRect::MakeWH(cull_rect.width, cull_rect.height);
|
||||
impeller::TextFrameDispatcher collector(aiks_context->GetContentContext(),
|
||||
impeller::Matrix());
|
||||
display_list->Dispatch(collector, skia_cull_rect);
|
||||
|
||||
impeller::ExperimentalDlDispatcher impeller_dispatcher(
|
||||
aiks_context->GetContentContext(), render_target,
|
||||
display_list->root_has_backdrop_filter(),
|
||||
display_list->max_root_blend_mode(),
|
||||
impeller::IRect::MakeSize(cull_rect));
|
||||
display_list->Dispatch(impeller_dispatcher, skia_cull_rect);
|
||||
impeller_dispatcher.FinishRecording();
|
||||
aiks_context->GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames();
|
||||
if (reset_host_buffer) {
|
||||
aiks_context->GetContentContext().GetTransientsBuffer().Reset();
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
impeller::DlDispatcher impeller_dispatcher(dl_cull_rect);
|
||||
display_list->Dispatch(impeller_dispatcher,
|
||||
SkIRect::MakeWH(cull_rect.width, cull_rect.height));
|
||||
auto picture = impeller_dispatcher.EndRecordingAsPicture();
|
||||
const bool reset_host_buffer = surface_frame.submit_info().frame_boundary;
|
||||
|
||||
return aiks_context->Render(picture, render_target, reset_host_buffer);
|
||||
|
||||
#endif // EXPERIMENTAL_CANVAS
|
||||
};
|
||||
|
||||
return std::make_unique<SurfaceFrame>(
|
||||
|
||||
@@ -129,7 +129,7 @@ bool EmbedderExternalView::Render(const EmbedderRenderTarget& render_target,
|
||||
slice_->render_into(&dl_builder);
|
||||
auto display_list = dl_builder.Build();
|
||||
|
||||
#if ENABLE_EXPERIMENTAL_CANVAS
|
||||
#if EXPERIMENTAL_CANVAS
|
||||
auto cull_rect =
|
||||
impeller::IRect::MakeSize(impeller_target->GetRenderTargetSize());
|
||||
SkIRect sk_cull_rect =
|
||||
|
||||
@@ -532,6 +532,9 @@ impeller_Play_AiksTest_CoordinateConversionsAreCorrect_Vulkan.png
|
||||
impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_Metal.png
|
||||
impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_OpenGLES.png
|
||||
impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_Vulkan.png
|
||||
impeller_Play_AiksTest_DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists_Metal.png
|
||||
impeller_Play_AiksTest_DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists_OpenGLES.png
|
||||
impeller_Play_AiksTest_DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists_Vulkan.png
|
||||
impeller_Play_AiksTest_DrawAdvancedBlendPartlyOffscreen_Metal.png
|
||||
impeller_Play_AiksTest_DrawAdvancedBlendPartlyOffscreen_OpenGLES.png
|
||||
impeller_Play_AiksTest_DrawAdvancedBlendPartlyOffscreen_Vulkan.png
|
||||
@@ -846,6 +849,9 @@ impeller_Play_AiksTest_TranslucentSaveLayerWithColorMatrixColorFilterDrawsCorrec
|
||||
impeller_Play_AiksTest_TranslucentSaveLayerWithColorMatrixImageFilterDrawsCorrectly_Metal.png
|
||||
impeller_Play_AiksTest_TranslucentSaveLayerWithColorMatrixImageFilterDrawsCorrectly_OpenGLES.png
|
||||
impeller_Play_AiksTest_TranslucentSaveLayerWithColorMatrixImageFilterDrawsCorrectly_Vulkan.png
|
||||
impeller_Play_AiksTest_TransparentShadowProducesCorrectColor_Metal.png
|
||||
impeller_Play_AiksTest_TransparentShadowProducesCorrectColor_OpenGLES.png
|
||||
impeller_Play_AiksTest_TransparentShadowProducesCorrectColor_Vulkan.png
|
||||
impeller_Play_AiksTest_VerifyNonOptimizedGradient_Metal.png
|
||||
impeller_Play_AiksTest_VerifyNonOptimizedGradient_OpenGLES.png
|
||||
impeller_Play_AiksTest_VerifyNonOptimizedGradient_Vulkan.png
|
||||
|
||||
Reference in New Issue
Block a user