Skip to content

Commit

Permalink
Add dl vertices object (flutter#32329)
Browse files Browse the repository at this point in the history
  • Loading branch information
flar authored Mar 31, 2022
1 parent be7fffa commit e4f9ee1
Show file tree
Hide file tree
Showing 30 changed files with 1,794 additions and 117 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ deps = {
'src': 'https://github.com/flutter/buildroot.git' + '@' + '9b3955d9ad8621dbf961044dc28d8b12804abb58',

'src/flutter/impeller':
Var('github_git') + '/flutter/impeller' + '@' + '1e4f9e421c7d77d64d2bbe472d23eec3939f7ebb',
Var('github_git') + '/flutter/impeller' + '@' + '2adc41bb87acffab0bca6bcdb9bc8da330068cc9',

# Fuchsia compatibility
#
Expand Down
7 changes: 7 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ FILE: ../../../flutter/display_list/display_list_tile_mode.h
FILE: ../../../flutter/display_list/display_list_unittests.cc
FILE: ../../../flutter/display_list/display_list_utils.cc
FILE: ../../../flutter/display_list/display_list_utils.h
FILE: ../../../flutter/display_list/display_list_vertices.cc
FILE: ../../../flutter/display_list/display_list_vertices.h
FILE: ../../../flutter/display_list/display_list_vertices_unittests.cc
FILE: ../../../flutter/display_list/types.h
FILE: ../../../flutter/flow/compositor_context.cc
FILE: ../../../flutter/flow/compositor_context.h
Expand Down Expand Up @@ -458,10 +461,14 @@ FILE: ../../../flutter/impeller/entity/contents/filters/blend_filter_contents.cc
FILE: ../../../flutter/impeller/entity/contents/filters/blend_filter_contents.h
FILE: ../../../flutter/impeller/entity/contents/filters/filter_contents.cc
FILE: ../../../flutter/impeller/entity/contents/filters/filter_contents.h
FILE: ../../../flutter/impeller/entity/contents/filters/filter_input.cc
FILE: ../../../flutter/impeller/entity/contents/filters/filter_input.h
FILE: ../../../flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc
FILE: ../../../flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.h
FILE: ../../../flutter/impeller/entity/contents/linear_gradient_contents.cc
FILE: ../../../flutter/impeller/entity/contents/linear_gradient_contents.h
FILE: ../../../flutter/impeller/entity/contents/snapshot.cc
FILE: ../../../flutter/impeller/entity/contents/snapshot.h
FILE: ../../../flutter/impeller/entity/contents/solid_color_contents.cc
FILE: ../../../flutter/impeller/entity/contents/solid_color_contents.h
FILE: ../../../flutter/impeller/entity/contents/solid_stroke_contents.cc
Expand Down
3 changes: 3 additions & 0 deletions display_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ source_set("display_list") {
"display_list_tile_mode.h",
"display_list_utils.cc",
"display_list_utils.h",
"display_list_vertices.cc",
"display_list_vertices.h",
"types.h",
]

Expand All @@ -70,6 +72,7 @@ source_set("unittests") {
"display_list_test_utils.cc",
"display_list_test_utils.h",
"display_list_unittests.cc",
"display_list_vertices_unittests.cc",
]

deps = [
Expand Down
1 change: 1 addition & 0 deletions display_list/display_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ namespace flutter {
V(DrawLines) \
V(DrawPolygon) \
V(DrawVertices) \
V(DrawSkVertices) \
\
V(DrawImage) \
V(DrawImageWithAttr) \
Expand Down
4 changes: 2 additions & 2 deletions display_list/display_list_attributes_testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void TestEquals(T& source1, T& source2) {
ASSERT_EQ(source1, source2);
ASSERT_EQ(source2, source1);
ASSERT_TRUE(Equals(&source1, &source2));
ASSERT_TRUE(Equals(source1.shared(), source2.shared()));
ASSERT_TRUE(Equals(&source2, &source1));
}

template <class T>
Expand All @@ -33,7 +33,7 @@ static void TestNotEquals(T& source1, T& source2, std::string label) {
ASSERT_NE(source1, source2) << label;
ASSERT_NE(source2, source1) << label;
ASSERT_TRUE(NotEquals(&source1, &source2));
ASSERT_TRUE(NotEquals(source1.shared(), source2.shared()));
ASSERT_TRUE(NotEquals(&source2, &source1));
}

} // namespace testing
Expand Down
32 changes: 16 additions & 16 deletions display_list/display_list_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,11 @@ void BM_DrawPath(benchmark::State& state,
// and the final vertex being the center point of the disc.
//
// Each vertex colour will alternate through Red, Green, Blue and Cyan.
sk_sp<SkVertices> GetTestVertices(SkPoint center,
float radius,
size_t vertex_count,
SkVertices::VertexMode mode,
size_t& final_vertex_count) {
std::shared_ptr<DlVertices> GetTestVertices(SkPoint center,
float radius,
size_t vertex_count,
DlVertexMode mode,
size_t& final_vertex_count) {
size_t outer_vertex_count = vertex_count / 2;
std::vector<SkPoint> outer_points =
GetPolygonPoints(outer_vertex_count, center, radius);
Expand All @@ -701,7 +701,7 @@ sk_sp<SkVertices> GetTestVertices(SkPoint center,
std::vector<SkColor> colors;

switch (mode) {
case SkVertices::VertexMode::kTriangleFan_VertexMode:
case DlVertexMode::kTriangleFan:
// Calling the points on the outer circle O_0, O_1, O_2, ..., and
// the center point C, this should create a triangle fan with vertices
// C, O_0, O_1, O_2, O_3, ...
Expand All @@ -718,7 +718,7 @@ sk_sp<SkVertices> GetTestVertices(SkPoint center,
}
}
break;
case SkVertices::VertexMode::kTriangles_VertexMode:
case DlVertexMode::kTriangles:
// Calling the points on the outer circle O_0, O_1, O_2, ..., and
// the center point C, this should create a series of triangles with
// vertices O_0, O_1, C, O_1, O_2, C, O_2, O_3, C, ...
Expand All @@ -731,7 +731,7 @@ sk_sp<SkVertices> GetTestVertices(SkPoint center,
colors.push_back(SK_ColorBLUE);
}
break;
case SkVertices::VertexMode::kTriangleStrip_VertexMode:
case DlVertexMode::kTriangleStrip:
// Calling the points on the outer circle O_0, O_1, O_2, ..., and
// the center point C, this should create a strip with vertices
// O_0, O_1, C, O_2, O_3, C, O_4, O_5, C, ...
Expand All @@ -749,17 +749,17 @@ sk_sp<SkVertices> GetTestVertices(SkPoint center,
}

final_vertex_count = vertices.size();
return SkVertices::MakeCopy(mode, vertices.size(), vertices.data(), nullptr,
colors.data());
return DlVertices::Make(mode, vertices.size(), vertices.data(), nullptr,
colors.data());
}

std::string VertexModeToString(SkVertices::VertexMode mode) {
std::string VertexModeToString(DlVertexMode mode) {
switch (mode) {
case SkVertices::VertexMode::kTriangleStrip_VertexMode:
case DlVertexMode::kTriangleStrip:
return "TriangleStrip";
case SkVertices::VertexMode::kTriangleFan_VertexMode:
case DlVertexMode::kTriangleFan:
return "TriangleFan";
case SkVertices::VertexMode::kTriangles_VertexMode:
case DlVertexMode::kTriangles:
return "Triangles";
}
return "Unknown";
Expand All @@ -776,7 +776,7 @@ std::string VertexModeToString(SkVertices::VertexMode mode) {
void BM_DrawVertices(benchmark::State& state,
BackendType backend_type,
unsigned attributes,
SkVertices::VertexMode mode) {
DlVertexMode mode) {
auto canvas_provider = CreateCanvasProvider(backend_type);
DisplayListBuilder builder;
builder.setAttributesFromPaint(GetPaintForRun(attributes),
Expand All @@ -799,7 +799,7 @@ void BM_DrawVertices(benchmark::State& state,

state.counters["DrawCallCount"] = center_points.size();
for (SkPoint p : center_points) {
sk_sp<SkVertices> vertices =
std::shared_ptr<DlVertices> vertices =
GetTestVertices(p, radius, 50, mode, vertex_count);
total_vertex_count += vertex_count;
builder.drawVertices(vertices, DlBlendMode::kSrc);
Expand Down
9 changes: 5 additions & 4 deletions display_list/display_list_benchmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define FLUTTER_FLOW_DISPLAY_LIST_BENCHMARKS_H_

#include "flutter/display_list/display_list_benchmarks_canvas_provider.h"
#include "flutter/display_list/display_list_vertices.h"

#include "third_party/benchmark/include/benchmark/benchmark.h"
#include "third_party/skia/include/core/SkCanvas.h"
Expand Down Expand Up @@ -76,7 +77,7 @@ void BM_DrawPoints(benchmark::State& state,
void BM_DrawVertices(benchmark::State& state,
BackendType backend_type,
unsigned attributes,
SkVertices::VertexMode mode);
DlVertexMode mode);
void BM_DrawImage(benchmark::State& state,
BackendType backend_type,
unsigned attributes,
Expand Down Expand Up @@ -238,7 +239,7 @@ void BM_SaveLayer(benchmark::State& state,
TriangleStrip/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkVertices::VertexMode::kTriangleStrip_VertexMode) \
DlVertexMode::kTriangleStrip) \
->RangeMultiplier(2) \
->Range(16, 2048) \
->UseRealTime() \
Expand All @@ -249,7 +250,7 @@ void BM_SaveLayer(benchmark::State& state,
TriangleFan/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkVertices::VertexMode::kTriangleFan_VertexMode) \
DlVertexMode::kTriangleFan) \
->RangeMultiplier(2) \
->Range(16, 2048) \
->UseRealTime() \
Expand All @@ -260,7 +261,7 @@ void BM_SaveLayer(benchmark::State& state,
Triangles/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkVertices::VertexMode::kTriangles_VertexMode) \
DlVertexMode::kTriangles) \
->RangeMultiplier(2) \
->Range(16, 2048) \
->UseRealTime() \
Expand Down
14 changes: 12 additions & 2 deletions display_list/display_list_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,19 @@ void DisplayListBuilder::drawPoints(SkCanvas::PointMode mode,
// See: https://fiddle.skia.org/c/228459001d2de8db117ce25ef5cedb0c
UpdateLayerOpacityCompatibility(false);
}
void DisplayListBuilder::drawVertices(const sk_sp<SkVertices> vertices,
void DisplayListBuilder::drawSkVertices(const sk_sp<SkVertices> vertices,
SkBlendMode mode) {
Push<DrawSkVerticesOp>(0, 1, std::move(vertices), mode);
// DrawVertices applies its colors to the paint so we have no way
// of controlling opacity using the current paint attributes.
// Although, examination of the |mode| might find some predictable
// cases.
UpdateLayerOpacityCompatibility(false);
}
void DisplayListBuilder::drawVertices(const DlVertices* vertices,
DlBlendMode mode) {
Push<DrawVerticesOp>(0, 1, std::move(vertices), mode);
void* pod = Push<DrawVerticesOp>(vertices->size(), 1, mode);
new (pod) DlVertices(vertices);
// DrawVertices applies its colors to the paint so we have no way
// of controlling opacity using the current paint attributes.
// Although, examination of the |mode| might find some predictable
Expand Down
9 changes: 7 additions & 2 deletions display_list/display_list_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,13 @@ class DisplayListBuilder final : public virtual Dispatcher,
void drawPoints(SkCanvas::PointMode mode,
uint32_t count,
const SkPoint pts[]) override;
void drawVertices(const sk_sp<SkVertices> vertices,
DlBlendMode mode) override;
void drawSkVertices(const sk_sp<SkVertices> vertices,
SkBlendMode mode) override;
void drawVertices(const DlVertices* vertices, DlBlendMode mode) override;
void drawVertices(const std::shared_ptr<const DlVertices> vertices,
DlBlendMode mode) {
drawVertices(vertices.get(), mode);
}
void drawImage(const sk_sp<DlImage> image,
const SkPoint point,
const SkSamplingOptions& sampling,
Expand Down
9 changes: 7 additions & 2 deletions display_list/display_list_canvas_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,14 @@ void DisplayListCanvasDispatcher::drawPoints(SkCanvas::PointMode mode,
const SkPoint pts[]) {
canvas_->drawPoints(mode, count, pts, paint());
}
void DisplayListCanvasDispatcher::drawVertices(const sk_sp<SkVertices> vertices,
void DisplayListCanvasDispatcher::drawSkVertices(
const sk_sp<SkVertices> vertices,
SkBlendMode mode) {
canvas_->drawVertices(vertices, mode, paint());
}
void DisplayListCanvasDispatcher::drawVertices(const DlVertices* vertices,
DlBlendMode mode) {
canvas_->drawVertices(vertices, ToSk(mode), paint());
canvas_->drawVertices(vertices->skia_object(), ToSk(mode), paint());
}
void DisplayListCanvasDispatcher::drawImage(const sk_sp<DlImage> image,
const SkPoint point,
Expand Down
5 changes: 3 additions & 2 deletions display_list/display_list_canvas_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class DisplayListCanvasDispatcher : public virtual Dispatcher,
void drawPoints(SkCanvas::PointMode mode,
uint32_t count,
const SkPoint pts[]) override;
void drawVertices(const sk_sp<SkVertices> vertices,
DlBlendMode mode) override;
void drawSkVertices(const sk_sp<SkVertices> vertices,
SkBlendMode mode) override;
void drawVertices(const DlVertices* vertices, DlBlendMode mode) override;
void drawImage(const sk_sp<DlImage> image,
const SkPoint point,
const SkSamplingOptions& sampling,
Expand Down
2 changes: 1 addition & 1 deletion display_list/display_list_canvas_recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void DisplayListCanvasRecorder::onDrawVerticesObject(const SkVertices* vertices,
SkBlendMode mode,
const SkPaint& paint) {
builder_->setAttributesFromPaint(paint, kDrawVerticesFlags);
builder_->drawVertices(sk_ref_sp(vertices), ToDl(mode));
builder_->drawSkVertices(sk_ref_sp(vertices), mode);
}

void DisplayListCanvasRecorder::onDrawImage2(const SkImage* image,
Expand Down
16 changes: 7 additions & 9 deletions display_list/display_list_canvas_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2487,20 +2487,20 @@ TEST_F(DisplayListCanvas, DrawVerticesWithColors) {
SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN,
SK_ColorCYAN, SK_ColorYELLOW, SK_ColorMAGENTA,
};
const sk_sp<SkVertices> vertices = SkVertices::MakeCopy(
SkVertices::kTriangles_VertexMode, 6, pts, nullptr, colors);
const std::shared_ptr<DlVertices> vertices =
DlVertices::Make(DlVertexMode::kTriangles, 6, pts, nullptr, colors);

CanvasCompareTester::RenderAll( //
TestParameters(
[=](SkCanvas* canvas, const SkPaint& paint) { //
canvas->drawVertices(vertices.get(), SkBlendMode::kSrcOver, paint);
canvas->drawVertices(vertices->skia_object(), SkBlendMode::kSrcOver,
paint);
},
[=](DisplayListBuilder& builder) { //
builder.drawVertices(vertices, DlBlendMode::kSrcOver);
},
kDrawVerticesFlags)
.set_draw_vertices());
EXPECT_TRUE(vertices->unique());
}

TEST_F(DisplayListCanvas, DrawVerticesWithImage) {
Expand Down Expand Up @@ -2531,8 +2531,8 @@ TEST_F(DisplayListCanvas, DrawVerticesWithImage) {
SkPoint::Make(0, 0),
SkPoint::Make(RenderWidth, 0),
};
const sk_sp<SkVertices> vertices = SkVertices::MakeCopy(
SkVertices::kTriangles_VertexMode, 6, pts, tex, nullptr);
const std::shared_ptr<DlVertices> vertices =
DlVertices::Make(DlVertexMode::kTriangles, 6, pts, tex, nullptr);

CanvasCompareTester::RenderAll( //
TestParameters(
Expand All @@ -2542,7 +2542,7 @@ TEST_F(DisplayListCanvas, DrawVerticesWithImage) {
v_paint.setShader(
CanvasCompareTester::testImageColorSource.skia_object());
}
canvas->drawVertices(vertices.get(), SkBlendMode::kSrcOver,
canvas->drawVertices(vertices->skia_object(), SkBlendMode::kSrcOver,
v_paint);
},
[=](DisplayListBuilder& builder) { //
Expand All @@ -2554,8 +2554,6 @@ TEST_F(DisplayListCanvas, DrawVerticesWithImage) {
},
kDrawVerticesFlags)
.set_draw_vertices());

EXPECT_TRUE(vertices->unique());
}

TEST_F(DisplayListCanvas, DrawImageNearest) {
Expand Down
23 changes: 21 additions & 2 deletions display_list/display_list_complexity_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ void DisplayListGLComplexityCalculator::GLHelper::drawPoints(
AccumulateComplexity(complexity);
}

void DisplayListGLComplexityCalculator::GLHelper::drawVertices(
void DisplayListGLComplexityCalculator::GLHelper::drawSkVertices(
const sk_sp<SkVertices> vertices,
DlBlendMode mode) {
SkBlendMode mode) {
// There is currently no way for us to get the VertexMode from the SkVertices
// object, but for future reference:
//
Expand All @@ -504,6 +504,25 @@ void DisplayListGLComplexityCalculator::GLHelper::drawVertices(
AccumulateComplexity(complexity);
}

void DisplayListGLComplexityCalculator::GLHelper::drawVertices(
const DlVertices* vertices,
DlBlendMode mode) {
// There is currently no way for us to get the VertexMode from the SkVertices
// object, but for future reference:
//
// TriangleStrip is roughly 25% more expensive than TriangleFan.
// TriangleFan is roughly 5% more expensive than Triangles.

// For the baseline, it's hard to identify the trend. It might be O(n^1/2)
// For now, treat it as linear as an approximation.
//
// m = 1/1600
// c = 1
unsigned int complexity = (vertices->vertex_count() + 1600) * 250 / 2;

AccumulateComplexity(complexity);
}

void DisplayListGLComplexityCalculator::GLHelper::drawImage(
const sk_sp<DlImage> image,
const SkPoint point,
Expand Down
4 changes: 2 additions & 2 deletions display_list/display_list_complexity_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class DisplayListGLComplexityCalculator
void drawPoints(SkCanvas::PointMode mode,
uint32_t count,
const SkPoint points[]) override;
void drawVertices(const sk_sp<SkVertices> vertices,
DlBlendMode mode) override;
void drawSkVertices(const sk_sp<SkVertices>, SkBlendMode mode) override;
void drawVertices(const DlVertices* vertices, DlBlendMode mode) override;
void drawImage(const sk_sp<DlImage> image,
const SkPoint point,
const SkSamplingOptions& sampling,
Expand Down
Loading

0 comments on commit e4f9ee1

Please sign in to comment.