未验证 提交 ed1f3fd9 编写于 作者: J Jason Simmons 提交者: GitHub

Change Vertices.indices to use a Uint16 list to more accurately reflect Skia's API (#8657)

Also throw if SkVertices::Builder reports an invalid configuration.

Fixes https://github.com/flutter/flutter/issues/31270
上级 4f2fd84c
......@@ -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',
......
Signature: cb9e296575fc050579bacb3a1c06c9b5
Signature: b4f8888f322c420b204e79450f0692ae
UNUSED LICENSES:
......@@ -18086,6 +18086,7 @@ FILE: ../../../third_party/tonic/scopes/dart_isolate_scope.cc
FILE: ../../../third_party/tonic/scopes/dart_isolate_scope.h
FILE: ../../../third_party/tonic/typed_data/dart_byte_data.h
FILE: ../../../third_party/tonic/typed_data/int32_list.h
FILE: ../../../third_party/tonic/typed_data/uint16_list.h
FILE: ../../../third_party/tonic/typed_data/uint8_list.h
----------------------------------------------------------------------------------------------------
Copyright 2016 The Fuchsia Authors. All rights reserved.
......@@ -18223,6 +18224,7 @@ FILE: ../../../third_party/tonic/typed_data/float32_list.h
FILE: ../../../third_party/tonic/typed_data/float64_list.cc
FILE: ../../../third_party/tonic/typed_data/float64_list.h
FILE: ../../../third_party/tonic/typed_data/int32_list.cc
FILE: ../../../third_party/tonic/typed_data/uint16_list.cc
FILE: ../../../third_party/tonic/typed_data/uint8_list.cc
----------------------------------------------------------------------------------------------------
Copyright 2015 The Fuchsia Authors. All rights reserved.
......@@ -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_; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册