Skip to content

Commit

Permalink
[DisplayList] Migrate DlVertices onto Impeller/DisplayList geometry c…
Browse files Browse the repository at this point in the history
…lasses
  • Loading branch information
flar committed Dec 17, 2024
1 parent 5b8e9f5 commit 6956f80
Show file tree
Hide file tree
Showing 16 changed files with 481 additions and 455 deletions.
4 changes: 2 additions & 2 deletions display_list/benchmarking/dl_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,8 @@ std::shared_ptr<DlVertices> GetTestVertices(SkPoint center,
}

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

std::string VertexModeToString(DlVertexMode mode) {
Expand Down
2 changes: 1 addition & 1 deletion display_list/benchmarking/dl_complexity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ TEST(DisplayListComplexity, DrawArc) {
TEST(DisplayListComplexity, DrawVertices) {
auto points = GetTestPoints();
auto vertices = DlVertices::Make(DlVertexMode::kTriangles, points.size(),
points.data(), nullptr, nullptr);
ToDlPoints(points.data()), nullptr, nullptr);
DisplayListBuilder builder;
builder.DrawVertices(vertices, DlBlendMode::kSrc, DlPaint());
auto display_list = builder.Build();
Expand Down
13 changes: 6 additions & 7 deletions display_list/display_list_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5066,14 +5066,13 @@ TEST_F(DisplayListTest, ClipPathRRectNonCulling) {

TEST_F(DisplayListTest, RecordLargeVertices) {
constexpr size_t vertex_count = 2000000;
auto points = std::vector<SkPoint>();
auto points = std::vector<DlPoint>();
points.reserve(vertex_count);
auto colors = std::vector<DlColor>();
colors.reserve(vertex_count);
for (size_t i = 0; i < vertex_count; i++) {
colors.emplace_back(DlColor(-i));
points.emplace_back(((i & 1) == 0) ? SkPoint::Make(-i, i)
: SkPoint::Make(i, i));
points.emplace_back(((i & 1) == 0) ? DlPoint(-i, i) : DlPoint(i, i));
}
ASSERT_EQ(points.size(), vertex_count);
ASSERT_EQ(colors.size(), vertex_count);
Expand Down Expand Up @@ -5552,7 +5551,7 @@ TEST_F(DisplayListTest, BoundedRenderOpsDoNotReportUnbounded) {
test_draw_points(PointMode::kPolygon);

test_bounded("DrawVerticesTriangles", [](DlCanvas& builder) {
SkPoint points[6] = {
DlPoint points[6] = {
{draw_rect.left(), draw_rect.top()},
{draw_rect.right(), draw_rect.top()},
{draw_rect.right(), draw_rect.bottom()},
Expand All @@ -5567,7 +5566,7 @@ TEST_F(DisplayListTest, BoundedRenderOpsDoNotReportUnbounded) {
});

test_bounded("DrawVerticesTriangleStrip", [](DlCanvas& builder) {
SkPoint points[6] = {
DlPoint points[6] = {
{draw_rect.left(), draw_rect.top()},
{draw_rect.right(), draw_rect.top()},
{draw_rect.right(), draw_rect.bottom()},
Expand All @@ -5582,8 +5581,8 @@ TEST_F(DisplayListTest, BoundedRenderOpsDoNotReportUnbounded) {
});

test_bounded("DrawVerticesTriangleFan", [](DlCanvas& builder) {
SkPoint points[6] = {
draw_rect.center(),
DlPoint points[6] = {
ToDlPoint(draw_rect.center()),
{draw_rect.left(), draw_rect.top()},
{draw_rect.right(), draw_rect.top()},
{draw_rect.right(), draw_rect.bottom()},
Expand Down
60 changes: 30 additions & 30 deletions display_list/dl_vertices.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ static void DlVerticesDeleter(void* p) {
static size_t bytes_needed(int vertex_count, Flags flags, int index_count) {
int needed = sizeof(DlVertices);
// We always have vertices
needed += vertex_count * sizeof(SkPoint);
needed += vertex_count * sizeof(DlPoint);
if (flags.has_texture_coordinates) {
needed += vertex_count * sizeof(SkPoint);
needed += vertex_count * sizeof(DlPoint);
}
if (flags.has_colors) {
needed += vertex_count * sizeof(DlColor);
Expand All @@ -39,8 +39,8 @@ static size_t bytes_needed(int vertex_count, Flags flags, int index_count) {
std::shared_ptr<DlVertices> DlVertices::Make(
DlVertexMode mode,
int vertex_count,
const SkPoint vertices[],
const SkPoint texture_coordinates[],
const DlPoint vertices[],
const DlPoint texture_coordinates[],
const DlColor colors[],
int index_count,
const uint16_t indices[],
Expand Down Expand Up @@ -89,22 +89,22 @@ size_t DlVertices::size() const {
index_count_);
}

static SkRect compute_bounds(const SkPoint* points, int count) {
static DlRect compute_bounds(const DlPoint* points, int count) {
AccumulationRect accumulator;
for (int i = 0; i < count; i++) {
accumulator.accumulate(points[i]);
}
return accumulator.bounds();
return accumulator.GetBounds();
}

DlVertices::DlVertices(DlVertexMode mode,
int unchecked_vertex_count,
const SkPoint* vertices,
const SkPoint* texture_coordinates,
const DlPoint* vertices,
const DlPoint* texture_coordinates,
const DlColor* colors,
int unchecked_index_count,
const uint16_t* indices,
const SkRect* bounds)
const DlRect* bounds)
: mode_(mode),
vertex_count_(std::max(unchecked_vertex_count, 0)),
index_count_(indices ? std::max(unchecked_index_count, 0) : 0) {
Expand Down Expand Up @@ -137,8 +137,8 @@ DlVertices::DlVertices(DlVertexMode mode,
DlVertices::DlVertices(const DlVertices* other)
: DlVertices(other->mode_,
other->vertex_count_,
other->vertices(),
other->texture_coordinates(),
other->vertex_data(),
other->texture_coordinate_data(),
other->colors(),
other->index_count_,
other->indices(),
Expand Down Expand Up @@ -166,16 +166,16 @@ DlVertices::DlVertices(DlVertexMode mode,
}
};

vertices_offset_ = advance(sizeof(SkPoint), vertex_count_);
vertices_offset_ = advance(sizeof(DlPoint), vertex_count_);
texture_coordinates_offset_ = advance(
sizeof(SkPoint), flags.has_texture_coordinates ? vertex_count_ : 0);
sizeof(DlPoint), flags.has_texture_coordinates ? vertex_count_ : 0);
colors_offset_ =
advance(sizeof(DlColor), flags.has_colors ? vertex_count_ : 0);
indices_offset_ = advance(sizeof(uint16_t), index_count_);
FML_DCHECK(offset == bytes_needed(vertex_count_, flags, index_count_));
FML_DCHECK((vertex_count_ != 0) == (vertices() != nullptr));
FML_DCHECK((vertex_count_ != 0) == (vertex_data() != nullptr));
FML_DCHECK((vertex_count_ != 0 && flags.has_texture_coordinates) ==
(texture_coordinates() != nullptr));
(texture_coordinate_data() != nullptr));
FML_DCHECK((vertex_count_ != 0 && flags.has_colors) == (colors() != nullptr));
FML_DCHECK((index_count_ != 0) == (indices() != nullptr));
}
Expand All @@ -192,14 +192,15 @@ bool DlVertices::operator==(DlVertices const& other) const {
}
return true;
};
return //
mode_ == other.mode_ && //
vertex_count_ == other.vertex_count_ && //
lists_equal(vertices(), other.vertices(), vertex_count_) && //
lists_equal(texture_coordinates(), other.texture_coordinates(), //
vertex_count_) && //
lists_equal(colors(), other.colors(), vertex_count_) && //
index_count_ == other.index_count_ && //
return //
mode_ == other.mode_ && //
vertex_count_ == other.vertex_count_ && //
lists_equal(vertex_data(), other.vertex_data(), vertex_count_) && //
lists_equal(texture_coordinate_data(), //
other.texture_coordinate_data(), //
vertex_count_) && //
lists_equal(colors(), other.colors(), vertex_count_) && //
index_count_ == other.index_count_ && //
lists_equal(indices(), other.indices(), index_count_);
}

Expand All @@ -220,13 +221,13 @@ DlVertices::Builder::Builder(DlVertexMode mode,
}

static void store_points(char* dst, int offset, const float* src, int count) {
SkPoint* points = reinterpret_cast<SkPoint*>(dst + offset);
DlPoint* points = reinterpret_cast<DlPoint*>(dst + offset);
for (int i = 0; i < count; i++) {
points[i] = SkPoint::Make(src[i * 2], src[i * 2 + 1]);
points[i] = DlPoint(src[i * 2], src[i * 2 + 1]);
}
}

void DlVertices::Builder::store_vertices(const SkPoint vertices[]) {
void DlVertices::Builder::store_vertices(const DlPoint vertices[]) {
FML_DCHECK(is_valid());
FML_DCHECK(needs_vertices_);
char* pod = reinterpret_cast<char*>(vertices_.get());
Expand All @@ -244,7 +245,7 @@ void DlVertices::Builder::store_vertices(const float vertices[]) {
needs_vertices_ = false;
}

void DlVertices::Builder::store_texture_coordinates(const SkPoint coords[]) {
void DlVertices::Builder::store_texture_coordinates(const DlPoint coords[]) {
FML_DCHECK(is_valid());
FML_DCHECK(needs_texture_coords_);
char* pod = reinterpret_cast<char*>(vertices_.get());
Expand Down Expand Up @@ -293,8 +294,7 @@ void DlVertices::Builder::store_indices(const uint16_t indices[]) {
}

void DlVertices::Builder::store_bounds(DlRect bounds) {
vertices_->bounds_ = SkRect::MakeLTRB(bounds.GetLeft(), bounds.GetTop(),
bounds.GetRight(), bounds.GetBottom());
vertices_->bounds_ = bounds;
needs_bounds_ = false;
}

Expand All @@ -313,7 +313,7 @@ std::shared_ptr<DlVertices> DlVertices::Builder::build() {

if (needs_bounds_) {
vertices_->bounds_ =
compute_bounds(vertices_->vertices(), vertices_->vertex_count_);
compute_bounds(vertices_->vertex_data(), vertices_->vertex_count_);
}

return std::move(vertices_);
Expand Down
29 changes: 13 additions & 16 deletions display_list/dl_vertices.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include "flutter/display_list/dl_color.h"

#include "third_party/skia/include/core/SkRect.h"

namespace flutter {

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -117,7 +115,7 @@ class DlVertices {
/// @brief Copies the indicated list of points as vertices.
///
/// fails if vertices have already been supplied.
void store_vertices(const SkPoint points[]);
void store_vertices(const DlPoint vertices[]);

/// @brief Copies the indicated list of float pairs as vertices.
///
Expand All @@ -128,7 +126,7 @@ class DlVertices {
///
/// fails if texture coordinates have already been supplied or if they
/// were not promised by the flags.has_texture_coordinates.
void store_texture_coordinates(const SkPoint points[]);
void store_texture_coordinates(const DlPoint points[]);

/// @brief Copies the indicated list of float pairs as texture coordinates.
///
Expand Down Expand Up @@ -183,8 +181,8 @@ class DlVertices {
/// non-null and the index_count is positive (>0).
static std::shared_ptr<DlVertices> Make(DlVertexMode mode,
int vertex_count,
const SkPoint vertices[],
const SkPoint texture_coordinates[],
const DlPoint vertices[],
const DlPoint texture_coordinates[],
const DlColor colors[],
int index_count = 0,
const uint16_t indices[] = nullptr,
Expand All @@ -194,8 +192,7 @@ class DlVertices {
size_t size() const;

/// Returns the bounds of the vertices.
SkRect bounds() const { return bounds_; }
DlRect GetBounds() const { return ToDlRect(bounds_); }
DlRect GetBounds() const { return bounds_; }

/// Returns the vertex mode that defines how the vertices (or the indices)
/// are turned into triangles.
Expand All @@ -206,14 +203,14 @@ class DlVertices {
int vertex_count() const { return vertex_count_; }

/// Returns a pointer to the vertex information. Should be non-null.
const SkPoint* vertices() const {
return static_cast<const SkPoint*>(pod(vertices_offset_));
const DlPoint* vertex_data() const {
return static_cast<const DlPoint*>(pod(vertices_offset_));
}

/// Returns a pointer to the vertex texture coordinate
/// or null if none were provided.
const SkPoint* texture_coordinates() const {
return static_cast<const SkPoint*>(pod(texture_coordinates_offset_));
const DlPoint* texture_coordinate_data() const {
return static_cast<const DlPoint*>(pod(texture_coordinates_offset_));
}

/// Returns a pointer to the vertex colors
Expand Down Expand Up @@ -243,12 +240,12 @@ class DlVertices {
// the class body and all of its arrays, such as in Builder.
DlVertices(DlVertexMode mode,
int vertex_count,
const SkPoint vertices[],
const SkPoint texture_coordinates[],
const DlPoint vertices[],
const DlPoint texture_coordinates[],
const DlColor colors[],
int index_count,
const uint16_t indices[],
const SkRect* bounds = nullptr);
const DlRect* bounds = nullptr);

// This constructor is specifically used by the DlVertices::Builder to
// establish the object before the copying of data is requested.
Expand All @@ -273,7 +270,7 @@ class DlVertices {
int index_count_;
size_t indices_offset_;

SkRect bounds_;
DlRect bounds_;

const void* pod(int offset) const {
if (offset <= 0) {
Expand Down
Loading

0 comments on commit 6956f80

Please sign in to comment.