From ed1f3fd99ffc7d871b87dd2c9e34361454aaf3c6 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 22 Apr 2019 16:13:22 -0700 Subject: [PATCH] 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 --- DEPS | 2 +- ci/licenses_golden/licenses_third_party | 4 +++- lib/ui/painting.dart | 16 +++++++++------- lib/ui/painting/vertices.cc | 17 +++++++++++++---- lib/ui/painting/vertices.h | 5 +++-- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/DEPS b/DEPS index e0e5203204e6f..3d1704ecfb81e 100644 --- a/DEPS +++ b/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', diff --git a/ci/licenses_golden/licenses_third_party b/ci/licenses_golden/licenses_third_party index ebbcabfd2c6ea..8741970773fec 100644 --- a/ci/licenses_golden/licenses_third_party +++ b/ci/licenses_golden/licenses_third_party @@ -1,4 +1,4 @@ -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. diff --git a/lib/ui/painting.dart b/lib/ui/painting.dart index 6703dfd01083e..a4f82c4638be9 100644 --- a/lib/ui/painting.dart +++ b/lib/ui/painting.dart @@ -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. diff --git a/lib/ui/painting/vertices.cc b/lib/ui/painting/vertices.cc index 0cfae48236fef..d9ae98c2fc57b 100644 --- a/lib/ui/painting/vertices.cc +++ b/lib/ui/painting/vertices.cc @@ -4,6 +4,8 @@ #include "flutter/lib/ui/painting/vertices.h" +#include + #include "third_party/tonic/dart_binding_macros.h" #include "third_party/tonic/dart_library_natives.h" @@ -47,11 +49,11 @@ fml::RefPtr Vertices::Create() { return fml::MakeRefCounted(); } -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(colors, builder.colors()); } - if (indices.data()) - DecodeInts(indices, builder.indices()); + if (indices.data()) { + std::copy(indices.data(), indices.data() + indices.num_elements(), + builder.indices()); + } vertices_ = builder.detach(); + + return true; } } // namespace flutter diff --git a/lib/ui/painting/vertices.h b/lib/ui/painting/vertices.h index 8d9d3861fcaf5..71e3db34f4549 100644 --- a/lib/ui/painting/vertices.h +++ b/lib/ui/painting/vertices.h @@ -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 { static fml::RefPtr 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& vertices() const { return vertices_; }