Skip to content

Commit

Permalink
chore: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Oct 17, 2023
1 parent 991972a commit c2cf251
Show file tree
Hide file tree
Showing 58 changed files with 1,398 additions and 1,620 deletions.
4 changes: 2 additions & 2 deletions packages/canvas-polyfill/async/file/file.android.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare var com;

import { File } from '@nativescript/core';
export class FileManager {
public static writeFile(bytes: any, path: string, callback: (...args) => void) {
const listener = new com.github.triniwiz.async.Async2.FileManager.Callback({
Expand Down Expand Up @@ -29,7 +29,7 @@ export class FileManager {
if (this._readFile === undefined) {
this._readFile = !!global?.CanvasModule?.readFile;
}
if (global?.CanvasModule?.readFile) {
if (this._readFile) {
global?.CanvasModule?.readFile(path, (error, buffer: ArrayBuffer) => {
if (error) {
callback(new Error(error), null);
Expand Down
6 changes: 3 additions & 3 deletions packages/canvas/Canvas/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Canvas extends CanvasBase {

constructor() {
super();
const activity = Application.android.foregroundActivity || Application.android.startActivity;
const activity = Application.android.foregroundActivity || Application.android.startActivity || Utils.android.getApplicationContext();
this._canvas = new org.nativescript.canvas.NSCCanvas(activity);
(global as any).__canvasLoaded = true;
}
Expand Down Expand Up @@ -304,7 +304,7 @@ export class Canvas extends CanvasBase {
this._layoutNative();
const opts = Object.assign({ version: 'v1' }, Object.assign(defaultOpts, this._handleContextOptions(type, options)));

this._canvas.initContext(type, opts.alpha, opts.antialias, opts.depth, opts.failIfMajorPerformanceCaveat, opts.powerPreference, opts.premultipliedAlpha, opts.preserveDrawingBuffer, opts.stencil, opts.desynchronized, opts.xrCompatible);
this._canvas.initContext(type, true, false, opts.depth, opts.failIfMajorPerformanceCaveat, opts.powerPreference, opts.premultipliedAlpha, opts.preserveDrawingBuffer, opts.stencil, opts.desynchronized, opts.xrCompatible);
this._webglContext = new (WebGLRenderingContext as any)(this._canvas, opts);
(this._webglContext as any)._canvas = this;
this._webglContext._type = 'webgl';
Expand All @@ -320,7 +320,7 @@ export class Canvas extends CanvasBase {
this._layoutNative();
const opts = Object.assign({ version: 'v2' }, Object.assign(defaultOpts, this._handleContextOptions(type, options)));

this._canvas.initContext(type, opts.alpha, opts.antialias, opts.depth, opts.failIfMajorPerformanceCaveat, opts.powerPreference, opts.premultipliedAlpha, opts.preserveDrawingBuffer, opts.stencil, opts.desynchronized, opts.xrCompatible);
this._canvas.initContext(type, opts.alpha, false, opts.depth, opts.failIfMajorPerformanceCaveat, opts.powerPreference, opts.premultipliedAlpha, opts.preserveDrawingBuffer, opts.stencil, opts.desynchronized, opts.xrCompatible);

this._webgl2Context = new (WebGL2RenderingContext as any)(this._canvas, opts);
(this._webgl2Context as any)._canvas = this;
Expand Down
8 changes: 5 additions & 3 deletions packages/canvas/Canvas/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class Canvas extends CanvasBase {
}
this.native.__startRaf();
};

}

[ignorePixelScalingProperty.setNative](value: boolean) {
Expand Down Expand Up @@ -271,7 +272,7 @@ export class Canvas extends CanvasBase {
this._layoutNative();
const opts = Object.assign({ version: 'v1' }, Object.assign(defaultOpts, this._handleContextOptions(type, options)));

this._canvas.initContext(type, opts.alpha, opts.antialias, opts.depth, opts.failIfMajorPerformanceCaveat, opts.powerPreference, opts.premultipliedAlpha, opts.preserveDrawingBuffer, opts.stencil, opts.desynchronized, opts.xrCompatible);
this._canvas.initContext(type, opts.alpha, false, opts.depth, opts.failIfMajorPerformanceCaveat, opts.powerPreference, opts.premultipliedAlpha, opts.preserveDrawingBuffer, opts.stencil, opts.desynchronized, opts.xrCompatible);

this._webglContext = new (WebGLRenderingContext as any)(this._canvas, opts);
(this._webglContext as any)._canvas = this;
Expand All @@ -284,11 +285,12 @@ export class Canvas extends CanvasBase {
return null;
}


if (!this._webgl2Context) {
this._layoutNative();
const opts = Object.assign({ version: 'v2' }, Object.assign(defaultOpts, this._handleContextOptions(type, options)));

this._canvas.initContext(type, opts.alpha, opts.antialias, opts.depth, opts.failIfMajorPerformanceCaveat, opts.powerPreference, opts.premultipliedAlpha, opts.preserveDrawingBuffer, opts.stencil, opts.desynchronized, opts.xrCompatible);
this._canvas.initContext(type, opts.alpha, false, opts.depth, opts.failIfMajorPerformanceCaveat, opts.powerPreference, opts.premultipliedAlpha, opts.preserveDrawingBuffer, opts.stencil, opts.desynchronized, opts.xrCompatible);

this._webgl2Context = new (WebGL2RenderingContext as any)(this._canvas, opts);
(this._webgl2Context as any)._canvas = this;
Expand Down
14 changes: 8 additions & 6 deletions packages/canvas/ImageBitmap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@ export class ImageBitmap {
}
}

global.CanvasModule.createImageBitmap(realSource, sx, sy, sWidth, sHeight, options, (error, value) => {
if (value) {
resolve(ImageBitmap.fromNative(value));
} else {
reject(new Error(error));
}
setTimeout(() => {
global.CanvasModule.createImageBitmap(realSource, sx, sy, sWidth, sHeight, options, (error, value) => {
if (value) {
resolve(ImageBitmap.fromNative(value));
} else {
reject(new Error(error));
}
});
});
});
}
Expand Down
6 changes: 3 additions & 3 deletions packages/canvas/WebGL/WebGLRenderingContext/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ import { Helpers } from '../../helpers';
let ctor;

export class WebGLRenderingContext extends WebGLRenderingContextBase {
public static isDebug = false;
public static isDebug = true;
public static filter: 'both' | 'error' | 'args' = 'both';
_context;

static {
Helpers.initialize();
ctor = global.CanvasModule.createWebGLContext;
}

constructor(context, contextOptions?) {
Expand Down Expand Up @@ -79,7 +78,8 @@ export class WebGLRenderingContext extends WebGLRenderingContextBase {
//direction = 1;
}

this._context = ctor(contextOptions, ctx, Screen.mainScreen.scale, -16777216, Screen.mainScreen.scale * 160, direction);

this._context = global.CanvasModule.createWebGLContext(contextOptions, ctx, Screen.mainScreen.scale, -16777216, Screen.mainScreen.scale * 160, direction);
} else {
this._context = context;
}
Expand Down
Loading

0 comments on commit c2cf251

Please sign in to comment.