mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Use the SkVertices::Builder API (#3549)
This commit is contained in:
parent
8f4457fed9
commit
4c05830aaf
@ -11,26 +11,16 @@ namespace blink {
|
||||
|
||||
namespace {
|
||||
|
||||
std::unique_ptr<SkPoint[]> DecodePoints(
|
||||
const tonic::Float32List& coords) {
|
||||
std::unique_ptr<SkPoint[]> result;
|
||||
if (coords.data()) {
|
||||
result.reset(new SkPoint[coords.num_elements() / 2]);
|
||||
for (int i = 0; i < coords.num_elements(); i += 2)
|
||||
result[i / 2] = SkPoint::Make(coords[i], coords[i + 1]);
|
||||
}
|
||||
return result;
|
||||
void DecodePoints(const tonic::Float32List& coords,
|
||||
SkPoint* points) {
|
||||
for (int i = 0; i < coords.num_elements(); i += 2)
|
||||
points[i / 2] = SkPoint::Make(coords[i], coords[i + 1]);
|
||||
}
|
||||
|
||||
template <typename T> std::unique_ptr<T[]> DecodeInts(
|
||||
const tonic::Int32List& ints) {
|
||||
std::unique_ptr<T[]> result;
|
||||
if (ints.data()) {
|
||||
result.reset(new T[ints.num_elements()]);
|
||||
for (int i = 0; i < ints.num_elements(); i++)
|
||||
result[i] = ints[i];
|
||||
}
|
||||
return result;
|
||||
template <typename T> void DecodeInts(const tonic::Int32List& ints,
|
||||
T* out) {
|
||||
for (int i = 0; i < ints.num_elements(); i++)
|
||||
out[i] = ints[i];
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -64,20 +54,26 @@ void Vertices::init(SkCanvas::VertexMode vertex_mode,
|
||||
const tonic::Float32List& texture_coordinates,
|
||||
const tonic::Int32List& colors,
|
||||
const tonic::Int32List& indices) {
|
||||
std::unique_ptr<const SkPoint[]> sk_positions(DecodePoints(positions));
|
||||
std::unique_ptr<const SkPoint[]> sk_texs(DecodePoints(texture_coordinates));
|
||||
uint32_t builderFlags = 0;
|
||||
if (texture_coordinates.data())
|
||||
builderFlags |= SkVertices::kHasTexCoords_BuilderFlag;
|
||||
if (colors.data())
|
||||
builderFlags |= SkVertices::kHasColors_BuilderFlag;
|
||||
|
||||
std::unique_ptr<const SkColor[]> sk_colors(DecodeInts<SkColor>(colors));
|
||||
std::unique_ptr<const uint16_t[]> sk_indices(DecodeInts<uint16_t>(indices));
|
||||
SkVertices::Builder builder(vertex_mode,
|
||||
positions.num_elements() / 2,
|
||||
indices.num_elements(),
|
||||
builderFlags);
|
||||
if (positions.data())
|
||||
DecodePoints(positions, builder.positions());
|
||||
if (texture_coordinates.data())
|
||||
DecodePoints(texture_coordinates, builder.texCoords());
|
||||
if (colors.data())
|
||||
DecodeInts<SkColor>(colors, builder.colors());
|
||||
if (indices.data())
|
||||
DecodeInts<uint16_t>(indices, builder.indices());
|
||||
|
||||
// TODO(fmalita): refactor to use SkVertices::Builder and avoid a copy.
|
||||
vertices_ = SkVertices::MakeCopy(vertex_mode,
|
||||
positions.num_elements() / 2,
|
||||
sk_positions.get(),
|
||||
sk_texs.get(),
|
||||
sk_colors.get(),
|
||||
indices.num_elements(),
|
||||
sk_indices.get());
|
||||
vertices_ = builder.detach();
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user