@@ -53,8 +53,8 @@ export function supportsDirectArrayBuffers() {
53
53
return _supportsDirectArrayBuffers ;
54
54
}
55
55
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 ) {
58
58
return createNativeArray ( length , useInts ) ;
59
59
} else {
60
60
return createArrayBuffer ( length , useInts ) ;
@@ -75,8 +75,8 @@ export function createArrayBuffer(length: number, useInts = false): TypedArray {
75
75
//@ts -ignore
76
76
return useInts ? new Int8Array ( length ) : new Float32Array ( length ) ;
77
77
}
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 ) {
80
80
if ( useInts ) {
81
81
const buffer = typedArray . buffer ;
82
82
return ( ( buffer as any ) . nativeObject as java . nio . ByteBuffer ) . array ( ) ;
@@ -90,14 +90,23 @@ export function pointsFromBuffer(typedArray: TypedArray, useInts = false) {
90
90
return typedArray ;
91
91
}
92
92
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 ) {
95
96
return array ;
96
97
}
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
+ }
97
106
const length = array . length ;
98
107
const typedArray = ArrayBuffer . isView ( array ) ? ( array as any as TypedArray ) : createArrayBuffer ( length , useInts ) ;
99
108
100
- return pointsFromBuffer ( typedArray , useInts ) ;
109
+ return pointsFromBuffer ( typedArray , useInts , canReturnBuffer ) ;
101
110
}
102
111
103
112
// export const nativeArrayToArray = profile('nativeArrayToArray', function(array) {
@@ -192,7 +201,7 @@ class ProxyClass<T> {
192
201
if ( element && element . getNative ) {
193
202
args [ index ] = element . getNative ( ) ;
194
203
} else if ( Array . isArray ( element ) ) {
195
- args [ index ] = arrayToNativeArray ( element ) ;
204
+ args [ index ] = arrayToNativeArray ( element , false , false ) ;
196
205
}
197
206
}
198
207
const result = target . handleCustomMethods ( target , native , methodName , args ) ;
@@ -239,7 +248,6 @@ class Canvas extends ProxyClass<android.graphics.Canvas> {
239
248
} else if ( methodName === 'drawColor' ) {
240
249
args [ 0 ] = createColorParam ( args [ 0 ] ) ;
241
250
} else if ( methodName === 'drawLines' ) {
242
- args [ 0 ] = arrayToNativeArray ( args [ 0 ] ) ;
243
251
const last = args [ args . length - 1 ] ;
244
252
if ( last instanceof android . graphics . Matrix ) {
245
253
last . mapPoints ( args [ 0 ] ) ;
0 commit comments