Skip to content

Support Dart_TypedDataAcquireData of Unmodifiable TypedData classes #42785

@zanderso

Description

@zanderso

It is useful for embedders to be able to expose read-only memory regions to Dart code as external type data. This will let Flutter avoid expensive copies on the Dart thread of large amounts of image data, for example see here:

https://github.com/flutter/engine/blob/18fee597ab6ec957e6311ba2bc74d4732ad55bd7/lib/ui/painting/image_encoding.cc#L48

for Image.toByteData:

https://github.com/flutter/engine/blob/18fee597ab6ec957e6311ba2bc74d4732ad55bd7/lib/ui/painting.dart#L1610

(The caller of that API could then do a copy to a writable buffer if they need one.)

The best match for this in the Dart SDK appears to be the unmodifiable typed data view classes like UnmodifiableByteDataView. Unfortunately, when these buffers come back into the embedder for various reasons, a call to Dart_TypedDataAcquireData() will fail by returning an error because the Unmodifiable typed data classes don't pass the tests here:

if (!IsExternalTypedDataClassId(class_id) &&
.

This issue is a feature request to integrate the Unmodifiable typed data classes more seamlessly with the VM so that they're a good match for the read-only buffers we can expose from Flutter as an optimization. If there's another approach that would solve the problem, then I'm interested in that, too.

/cc @a-siva @rmacnak-google @dnfield

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.customer-flutterlibrary-typed-datatype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions