@@ -53,8 +53,8 @@ export function supportsDirectArrayBuffers() {
5353 return _supportsDirectArrayBuffers ;
5454}
5555
56- export function createArrayBufferOrNativeArray ( length : number , useInts = false ) {
57- if ( ! supportsDirectArrayBuffers ( ) ) {
56+ export function createArrayBufferOrNativeArray ( length : number , useInts = false , canReturnBuffer = true ) {
57+ if ( ! supportsDirectArrayBuffers ( ) || ! canReturnBuffer ) {
5858 return createNativeArray ( length , useInts ) ;
5959 } else {
6060 return createArrayBuffer ( length , useInts ) ;
@@ -75,8 +75,8 @@ export function createArrayBuffer(length: number, useInts = false): TypedArray {
7575 //@ts -ignore
7676 return useInts ? new Int8Array ( length ) : new Float32Array ( length ) ;
7777}
78- export function pointsFromBuffer ( typedArray : TypedArray , useInts = false ) {
79- if ( ! supportsDirectArrayBuffers ( ) ) {
78+ export function pointsFromBuffer ( typedArray : TypedArray , useInts = false , canReturnBuffer = true ) {
79+ if ( ! supportsDirectArrayBuffers ( ) || ! canReturnBuffer ) {
8080 if ( useInts ) {
8181 const buffer = typedArray . buffer ;
8282 return ( ( buffer as any ) . nativeObject as java . nio . ByteBuffer ) . array ( ) ;
@@ -90,14 +90,23 @@ export function pointsFromBuffer(typedArray: TypedArray, useInts = false) {
9090 return typedArray ;
9191}
9292
93- export function arrayToNativeArray ( array : number [ ] | TypedArray , useInts = false ) {
94- if ( ! Array . isArray ( array ) ) {
93+ export function arrayToNativeArray ( array : number [ ] | TypedArray , useInts = false , canReturnBuffer = true ) {
94+ const isBufferView = ArrayBuffer . isView ( array ) ;
95+ if ( ! Array . isArray ( array ) && ! isBufferView ) {
9596 return array ;
9697 }
98+ // for now we cant do it the old way
99+ if ( ! isBufferView && supportsDirectArrayBuffers ( ) ) {
100+ const nArray = createNativeArray ( array . length , useInts ) ;
101+ for ( let index = 0 ; index < array . length ; index ++ ) {
102+ nArray [ index ] = array [ index ] ;
103+ }
104+ return nArray ;
105+ }
97106 const length = array . length ;
98107 const typedArray = ArrayBuffer . isView ( array ) ? ( array as any as TypedArray ) : createArrayBuffer ( length , useInts ) ;
99108
100- return pointsFromBuffer ( typedArray , useInts ) ;
109+ return pointsFromBuffer ( typedArray , useInts , canReturnBuffer ) ;
101110}
102111
103112// export const nativeArrayToArray = profile('nativeArrayToArray', function(array) {
@@ -192,7 +201,7 @@ class ProxyClass<T> {
192201 if ( element && element . getNative ) {
193202 args [ index ] = element . getNative ( ) ;
194203 } else if ( Array . isArray ( element ) ) {
195- args [ index ] = arrayToNativeArray ( element ) ;
204+ args [ index ] = arrayToNativeArray ( element , false , false ) ;
196205 }
197206 }
198207 const result = target . handleCustomMethods ( target , native , methodName , args ) ;
@@ -239,7 +248,6 @@ class Canvas extends ProxyClass<android.graphics.Canvas> {
239248 } else if ( methodName === 'drawColor' ) {
240249 args [ 0 ] = createColorParam ( args [ 0 ] ) ;
241250 } else if ( methodName === 'drawLines' ) {
242- args [ 0 ] = arrayToNativeArray ( args [ 0 ] ) ;
243251 const last = args [ args . length - 1 ] ;
244252 if ( last instanceof android . graphics . Matrix ) {
245253 last . mapPoints ( args [ 0 ] ) ;
0 commit comments