Change Vertices.indices to use a Uint16 list to more accurately reflect Skia's API (flutter/engine#8657)
Also throw if SkVertices::Builder reports an invalid configuration. Fixes https://github.com/flutter/flutter/issues/31270
This commit is contained in:
2
DEPS
2
DEPS
@@ -130,7 +130,7 @@ deps = {
|
||||
# and not have to specific specific hashes.
|
||||
|
||||
'src/third_party/tonic':
|
||||
Var('fuchsia_git') + '/tonic' + '@' + '02f9d8dd18dd259e3c5efe1fbe713819a730b6e0',
|
||||
Var('fuchsia_git') + '/tonic' + '@' + '2919ef4751621fabecb721c153ea9a3b72af995d',
|
||||
|
||||
'src/third_party/benchmark':
|
||||
Var('fuchsia_git') + '/third_party/benchmark' + '@' + '21f1eb3fe269ea43eba862bf6b699cde46587ade',
|
||||
|
||||
@@ -2913,12 +2913,13 @@ class Vertices extends NativeFieldWrapperClass2 {
|
||||
final Int32List encodedColors = colors != null
|
||||
? _encodeColorList(colors)
|
||||
: null;
|
||||
final Int32List encodedIndices = indices != null
|
||||
? new Int32List.fromList(indices)
|
||||
final Uint16List encodedIndices = indices != null
|
||||
? new Uint16List.fromList(indices)
|
||||
: null;
|
||||
|
||||
_constructor();
|
||||
_init(mode.index, encodedPositions, encodedTextureCoordinates, encodedColors, encodedIndices);
|
||||
if (!_init(mode.index, encodedPositions, encodedTextureCoordinates, encodedColors, encodedIndices))
|
||||
throw new ArgumentError('Invalid configuration for vertices.');
|
||||
}
|
||||
|
||||
Vertices.raw(
|
||||
@@ -2926,7 +2927,7 @@ class Vertices extends NativeFieldWrapperClass2 {
|
||||
Float32List positions, {
|
||||
Float32List textureCoordinates,
|
||||
Int32List colors,
|
||||
Int32List indices,
|
||||
Uint16List indices,
|
||||
}) : assert(mode != null),
|
||||
assert(positions != null) {
|
||||
if (textureCoordinates != null && textureCoordinates.length != positions.length)
|
||||
@@ -2937,16 +2938,17 @@ class Vertices extends NativeFieldWrapperClass2 {
|
||||
throw new ArgumentError('"indices" values must be valid indices in the positions list.');
|
||||
|
||||
_constructor();
|
||||
_init(mode.index, positions, textureCoordinates, colors, indices);
|
||||
if (!_init(mode.index, positions, textureCoordinates, colors, indices))
|
||||
throw new ArgumentError('Invalid configuration for vertices.');
|
||||
}
|
||||
|
||||
void _constructor() native 'Vertices_constructor';
|
||||
|
||||
void _init(int mode,
|
||||
bool _init(int mode,
|
||||
Float32List positions,
|
||||
Float32List textureCoordinates,
|
||||
Int32List colors,
|
||||
Int32List indices) native 'Vertices_init';
|
||||
Uint16List indices) native 'Vertices_init';
|
||||
}
|
||||
|
||||
/// Defines how a list of points is interpreted when drawing a set of points.
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "flutter/lib/ui/painting/vertices.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "third_party/tonic/dart_binding_macros.h"
|
||||
#include "third_party/tonic/dart_library_natives.h"
|
||||
|
||||
@@ -47,11 +49,11 @@ fml::RefPtr<Vertices> Vertices::Create() {
|
||||
return fml::MakeRefCounted<Vertices>();
|
||||
}
|
||||
|
||||
void Vertices::init(SkVertices::VertexMode vertex_mode,
|
||||
bool Vertices::init(SkVertices::VertexMode vertex_mode,
|
||||
const tonic::Float32List& positions,
|
||||
const tonic::Float32List& texture_coordinates,
|
||||
const tonic::Int32List& colors,
|
||||
const tonic::Int32List& indices) {
|
||||
const tonic::Uint16List& indices) {
|
||||
uint32_t builderFlags = 0;
|
||||
if (texture_coordinates.data())
|
||||
builderFlags |= SkVertices::kHasTexCoords_BuilderFlag;
|
||||
@@ -61,6 +63,9 @@ void Vertices::init(SkVertices::VertexMode vertex_mode,
|
||||
SkVertices::Builder builder(vertex_mode, positions.num_elements() / 2,
|
||||
indices.num_elements(), builderFlags);
|
||||
|
||||
if (!builder.isValid())
|
||||
return false;
|
||||
|
||||
// positions are required for SkVertices::Builder
|
||||
FML_DCHECK(positions.data());
|
||||
if (positions.data())
|
||||
@@ -77,10 +82,14 @@ void Vertices::init(SkVertices::VertexMode vertex_mode,
|
||||
DecodeInts<SkColor>(colors, builder.colors());
|
||||
}
|
||||
|
||||
if (indices.data())
|
||||
DecodeInts<uint16_t>(indices, builder.indices());
|
||||
if (indices.data()) {
|
||||
std::copy(indices.data(), indices.data() + indices.num_elements(),
|
||||
builder.indices());
|
||||
}
|
||||
|
||||
vertices_ = builder.detach();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "third_party/skia/include/core/SkVertices.h"
|
||||
#include "third_party/tonic/typed_data/float32_list.h"
|
||||
#include "third_party/tonic/typed_data/int32_list.h"
|
||||
#include "third_party/tonic/typed_data/uint16_list.h"
|
||||
|
||||
namespace tonic {
|
||||
class DartLibraryNatives;
|
||||
@@ -27,11 +28,11 @@ class Vertices : public RefCountedDartWrappable<Vertices> {
|
||||
|
||||
static fml::RefPtr<Vertices> Create();
|
||||
|
||||
void init(SkVertices::VertexMode vertex_mode,
|
||||
bool init(SkVertices::VertexMode vertex_mode,
|
||||
const tonic::Float32List& positions,
|
||||
const tonic::Float32List& texture_coordinates,
|
||||
const tonic::Int32List& colors,
|
||||
const tonic::Int32List& indices);
|
||||
const tonic::Uint16List& indices);
|
||||
|
||||
const sk_sp<SkVertices>& vertices() const { return vertices_; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user