Skip to content

Commit

Permalink
chore(canvas): android performance tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Apr 20, 2021
1 parent 254f22f commit 934b5a3
Show file tree
Hide file tree
Showing 58 changed files with 3,666 additions and 32,445 deletions.
203 changes: 152 additions & 51 deletions packages/canvas/WebGL/WebGLRenderingContext/index.android.ts

Large diffs are not rendered by default.

231 changes: 217 additions & 14 deletions packages/canvas/WebGL2/WebGL2RenderingContext/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class WebGL2RenderingContext extends WebGL2RenderingContextBase {
super(context);
}

// native: org.nativescript.canvas.TNSWebGL2RenderingContext;
native: org.nativescript.canvas.TNSWebGL2RenderingContext;
/* Transform feedback */

static toPrimitive(value): any {
Expand Down Expand Up @@ -735,19 +735,104 @@ export class WebGL2RenderingContext extends WebGL2RenderingContextBase {
source
);
} else if (source && source.buffer) {
if (source instanceof Uint8Array) {
this.native.texImage3D(
target,
level,
internalformat,
width,
height,
depth,
border,
format,
type,
this.toNativeArray(source as any, 'byte')
);
if (source && source.buffer) {
if (source instanceof Uint8Array || source instanceof Uint8ClampedArray) {
this.native.texImage3DByte(
target,
level,
internalformat,
width,
height,
depth,
border,
format,
type,
Array.from(source)
);
} else if (source instanceof Uint16Array || source instanceof Int16Array) {
this.native.texImage3DShort(
target,
level,
internalformat,
width,
height,
depth,
border,
format,
type,
Array.from(source)
);
} else if (source instanceof Uint32Array || source instanceof Int32Array) {
this.native.texImage3DInt(
target,
level,
internalformat,
width,
height,
depth,
border,
format,
type,
Array.from(source)
);
} else if (source instanceof Float32Array) {
this.native.texImage3DFloat(
target,
level,
internalformat,
width,
height,
depth,
border,
format,
type,
Array.from(source)
);
} else if (source instanceof Float64Array) {
this.native.texImage3DDouble(
target,
level,
internalformat,
width,
height,
depth,
border,
format,
type,
Array.from(source)
);
}
} else if (source instanceof ArrayBuffer) {
// @ts-ignore
if(source.nativeObject){
// @ts-ignore
this.native.texImage3D(
target,
level,
internalformat,
width,
height,
depth,
border,
format,
type,
// @ts-ignore
source.nativeObject
);
}else {
this.native.texImage3DByte(
target,
level,
internalformat,
width,
height,
depth,
border,
format,
type,
Array.from(new Uint8Array(source))
);
}
}
} else if (source instanceof android.graphics.Bitmap) {
this.native.texImage3D(
Expand Down Expand Up @@ -998,6 +1083,124 @@ export class WebGL2RenderingContext extends WebGL2RenderingContextBase {
);
}
}


if (srcData && srcData.buffer) {
if (srcData instanceof Uint8Array || srcData instanceof Uint8ClampedArray) {
this.native.texSubImage3DByte(
target,
level,
xoffset,
yoffset,
zoffset,
width,
height,
depth,
format,
type,
Array.from(srcData),
srcOffset
);
} else if (srcData instanceof Uint16Array || srcData instanceof Int16Array) {
this.native.texSubImage3DShort(
target,
level,
xoffset,
yoffset,
zoffset,
width,
height,
depth,
format,
type,
Array.from(srcData),
srcOffset
);
} else if (srcData instanceof Uint32Array || srcData instanceof Int32Array) {
this.native.texSubImage3DInt(
target,
level,
xoffset,
yoffset,
zoffset,
width,
height,
depth,
format,
type,
Array.from(srcData),
srcOffset
);
} else if (srcData instanceof Float32Array) {
this.native.texSubImage3DFloat(
target,
level,
xoffset,
yoffset,
zoffset,
width,
height,
depth,
format,
type,
Array.from(srcData),
srcOffset
);
} else if (srcData instanceof Float64Array) {
this.native.texSubImage3DDouble(
target,
level,
xoffset,
yoffset,
zoffset,
width,
height,
depth,
format,
type,
Array.from(srcData),
srcOffset
);
}
} else if (srcData instanceof ArrayBuffer) {
// @ts-ignore
if(source.nativeObject){

this.native.texSubImage3DByte(
target,
level,
xoffset,
yoffset,
zoffset,
width,
height,
depth,
format,
type,
// @ts-ignore
source.nativeObject,
srcOffset
);
}else {
this.native.texSubImage3DDouble(
target,
level,
xoffset,
yoffset,
zoffset,
width,
height,
depth,
format,
type,
Array.from(new Uint8Array(srcData)),
srcOffset
);
}
}



} else if (srcData instanceof android.graphics.Bitmap) {
this.native.texSubImage3D(
target,
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nativescript/canvas",
"version": "0.9.19",
"version": "0.9.20",
"description": "DOM Canvas API for NativeScript",
"main": "index",
"typings": "index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas/platforms/android/include.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ allprojects {
}

dependencies {
implementation 'org.nativescript:canvas:0.9.17'
implementation 'org.nativescript:canvas:0.9.18'
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ signing {

group = "org.nativescript"
archivesBaseName = "canvas"
version = "0.9.17"
version = "0.9.18"

uploadArchives {
repositories {
Expand Down
Loading

0 comments on commit 934b5a3

Please sign in to comment.