Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android RenderScript Allocation copy from NIO Direct ByteBuffer

On Android platform (API-19) I would like to copy a direct byte buffer into a render script allocation. Is it possible to improve the following code, for example by using NDK?

final ByteBuffer buffer = ...src;

final byte[] bytes;
if (buffer.hasArray()) {
    bytes = buffer.array();
} else {
    bytes = new byte[buffer.capacity()];
    buffer.get(bytes);
    buffer.rewind();
}
allocation.copyFromUnchecked(bytes);
like image 872
Antoni Jakubiak Avatar asked Apr 26 '26 17:04

Antoni Jakubiak


1 Answers

Unfortunately, no. The APIs are not constructed where you can provide the backing data store for the Allocation or even retrieve an NIO based buffer that the Allocation created. The closest thing you could use would be to have a Bitmap based Allocation which was created with USAGE_SHARED so it could be sync'd as differences rather than a full copy.

like image 154
Larry Schiefer Avatar answered Apr 30 '26 22:04

Larry Schiefer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!