diff --git a/lib/ui/painting/fragment_program.cc b/lib/ui/painting/fragment_program.cc index 12a1824d0b8f7..9156302789ea8 100644 --- a/lib/ui/painting/fragment_program.cc +++ b/lib/ui/painting/fragment_program.cc @@ -55,7 +55,7 @@ void FragmentProgram::init(std::string sksl, bool debugPrintSksl) { fml::RefPtr FragmentProgram::shader( Dart_Handle shader, - const tonic::Float32List& uniforms, + tonic::Float32List& uniforms, Dart_Handle samplers) { auto sampler_shaders = tonic::DartConverter>::FromDart(samplers); @@ -69,6 +69,7 @@ fml::RefPtr FragmentProgram::shader( for (size_t i = 0; i < uniform_count; i++) { uniform_floats[i] = uniforms[i]; } + uniforms.Release(); std::vector> sk_samplers(sampler_shaders.size()); for (size_t i = 0; i < sampler_shaders.size(); i++) { ImageShader* image_shader = sampler_shaders[i]; diff --git a/lib/ui/painting/fragment_program.h b/lib/ui/painting/fragment_program.h index 06cf429b32e42..a1b518a3b8168 100644 --- a/lib/ui/painting/fragment_program.h +++ b/lib/ui/painting/fragment_program.h @@ -31,7 +31,7 @@ class FragmentProgram : public RefCountedDartWrappable { void init(std::string sksl, bool debugPrintSksl); fml::RefPtr shader(Dart_Handle shader, - const tonic::Float32List& uniforms, + tonic::Float32List& uniforms, Dart_Handle samplers); static void RegisterNatives(tonic::DartLibraryNatives* natives); diff --git a/lib/ui/painting/path.cc b/lib/ui/painting/path.cc index 223f3058b5506..be9762dd7e44a 100644 --- a/lib/ui/painting/path.cc +++ b/lib/ui/painting/path.cc @@ -253,16 +253,17 @@ void CanvasPath::addPathWithMatrix(CanvasPath* path, double dy, tonic::Float64List& matrix4) { if (!path) { + matrix4.Release(); Dart_ThrowException( ToDart("Path.addPathWithMatrix called with non-genuine Path.")); return; } SkMatrix matrix = ToSkMatrix(matrix4); + matrix4.Release(); matrix.setTranslateX(matrix.getTranslateX() + dx); matrix.setTranslateY(matrix.getTranslateY() + dy); mutable_path().addPath(path->path(), matrix, SkPath::kAppend_AddPathMode); - matrix4.Release(); resetVolatility(); } @@ -281,16 +282,17 @@ void CanvasPath::extendWithPathAndMatrix(CanvasPath* path, double dy, tonic::Float64List& matrix4) { if (!path) { + matrix4.Release(); Dart_ThrowException( ToDart("Path.addPathWithMatrix called with non-genuine Path.")); return; } SkMatrix matrix = ToSkMatrix(matrix4); + matrix4.Release(); matrix.setTranslateX(matrix.getTranslateX() + dx); matrix.setTranslateY(matrix.getTranslateY() + dy); mutable_path().addPath(path->path(), matrix, SkPath::kExtend_AddPathMode); - matrix4.Release(); resetVolatility(); } @@ -317,10 +319,11 @@ void CanvasPath::shift(Dart_Handle path_handle, double dx, double dy) { void CanvasPath::transform(Dart_Handle path_handle, tonic::Float64List& matrix4) { + auto sk_matrix = ToSkMatrix(matrix4); + matrix4.Release(); fml::RefPtr path = CanvasPath::Create(path_handle); auto& other_mutable_path = path->mutable_path(); - mutable_path().transform(ToSkMatrix(matrix4), &other_mutable_path); - matrix4.Release(); + mutable_path().transform(sk_matrix, &other_mutable_path); } tonic::Float32List CanvasPath::getBounds() { diff --git a/lib/ui/painting/vertices.cc b/lib/ui/painting/vertices.cc index 8617aee51f554..9b73939a70b2d 100644 --- a/lib/ui/painting/vertices.cc +++ b/lib/ui/painting/vertices.cc @@ -45,10 +45,10 @@ void Vertices::RegisterNatives(tonic::DartLibraryNatives* natives) { bool Vertices::init(Dart_Handle vertices_handle, SkVertices::VertexMode vertex_mode, - const tonic::Float32List& positions, - const tonic::Float32List& texture_coordinates, - const tonic::Int32List& colors, - const tonic::Uint16List& indices) { + tonic::Float32List& positions, + tonic::Float32List& texture_coordinates, + tonic::Int32List& colors, + tonic::Uint16List& indices) { UIDartState::ThrowIfUIOperationsProhibited(); uint32_t builderFlags = 0; if (texture_coordinates.data()) { @@ -76,6 +76,7 @@ bool Vertices::init(Dart_Handle vertices_handle, FML_DCHECK(positions.num_elements() == texture_coordinates.num_elements()); DecodePoints(texture_coordinates, builder.texCoords()); } + if (colors.data()) { // SkVertices::Builder assumes equal numbers of elements FML_DCHECK(positions.num_elements() / 2 == colors.num_elements()); @@ -87,6 +88,11 @@ bool Vertices::init(Dart_Handle vertices_handle, builder.indices()); } + positions.Release(); + texture_coordinates.Release(); + colors.Release(); + indices.Release(); + auto vertices = fml::MakeRefCounted(); vertices->vertices_ = builder.detach(); vertices->AssociateWithDartWrapper(vertices_handle); diff --git a/lib/ui/painting/vertices.h b/lib/ui/painting/vertices.h index 1b4c8601df806..0a6555be9ae84 100644 --- a/lib/ui/painting/vertices.h +++ b/lib/ui/painting/vertices.h @@ -26,10 +26,10 @@ class Vertices : public RefCountedDartWrappable { static bool init(Dart_Handle vertices_handle, SkVertices::VertexMode vertex_mode, - const tonic::Float32List& positions, - const tonic::Float32List& texture_coordinates, - const tonic::Int32List& colors, - const tonic::Uint16List& indices); + tonic::Float32List& positions, + tonic::Float32List& texture_coordinates, + tonic::Int32List& colors, + tonic::Uint16List& indices); const sk_sp& vertices() const { return vertices_; }