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
3 changes: 1 addition & 2 deletions packages/canvas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export { Canvas, createSVGMatrix, TouchEvent, PointerEvent } from './Canvas';
import { TextEncoder } from './TextEncoder';
import { TextDecoder } from './TextDecoder';
import { ImageBitmap } from './ImageBitmap';
import {ImageAsset} from './ImageAsset';
import { ImageAsset } from './ImageAsset';

import { CanvasPattern, CanvasGradient, Path2D, ImageData, DOMMatrix } from './Canvas2D';

Expand Down Expand Up @@ -105,7 +105,6 @@ Object.defineProperty(global, 'ImageAsset', {
writable: true,
});


export { ImageBitmap } from './ImageBitmap';
export { CanvasRenderingContext2D } from './Canvas2D/CanvasRenderingContext2D';
export { WebGLRenderingContext } from './WebGL/WebGLRenderingContext';
Expand Down
Binary file modified packages/canvas/platforms/android/canvas-release.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>CanvasNative.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>CanvasNative.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -197,36 +197,6 @@ typedef struct WebGLState WebGLState;

typedef struct WebGLSync WebGLSync;

#if defined(TARGET_OS_ANDROID)
typedef struct AChoreographer {
uint8_t _unused[0];
} AChoreographer;
#endif

#if defined(TARGET_OS_ANDROID)
/**
* Prototype of the function that is called when a new frame is being rendered.
* It's passed the time that the frame is being rendered as nanoseconds in the
* CLOCK_MONOTONIC time base, as well as the data pointer provided by the
* application that registered a callback. All callbacks that run as part of
* rendering a frame will observe the same frame time, so it should be used
* whenever events need to be synchronized (e.g. animations).
*/
typedef void (*AChoreographer_frameCallback)(long frameTimeNanos, void *data);
#endif

#if defined(TARGET_OS_ANDROID)
/**
* Prototype of the function that is called when a new frame is being rendered.
* It's passed the time that the frame is being rendered as nanoseconds in the
* CLOCK_MONOTONIC time base, as well as the data pointer provided by the
* application that registered a callback. All callbacks that run as part of
* rendering a frame will observe the same frame time, so it should be used
* whenever events need to be synchronized (e.g. animations).
*/
typedef void (*AChoreographer_frameCallback64)(int64_t frameTimeNanos, void *data);
#endif

void canvas_native_image_filter_destroy(struct ImageFilter *value);

void canvas_native_helper_destroy(struct FileHelper *value);
Expand Down Expand Up @@ -2592,55 +2562,6 @@ void canvas_native_matrix_destroy(struct Matrix *value);

void canvas_native_path_destroy(struct Path *value);

#if defined(TARGET_OS_ANDROID)
/**
* Get the AChoreographer instance for the current thread. This must be called
* on an ALooper thread.
*/
extern struct AChoreographer *AChoreographer_getInstance(void);
#endif

#if defined(TARGET_OS_ANDROID)
/**
* Deprecated: Use AChoreographer_postFrameCallback64 instead.
*/
extern void AChoreographer_postFrameCallback(struct AChoreographer *choreographer,
AChoreographer_frameCallback callback,
void *data);
#endif

#if defined(TARGET_OS_ANDROID)
/**
* Deprecated: Use AChoreographer_postFrameCallbackDelayed64 instead.
*/
extern void AChoreographer_postFrameCallbackDelayed(struct AChoreographer *choreographer,
AChoreographer_frameCallback callback,
void *data,
long delayMillis);
#endif

#if defined(TARGET_OS_ANDROID)
/**
* Power a callback to be run on the next frame. The data pointer provided will
* be passed to the callback function when it's called.
*/
extern void AChoreographer_postFrameCallback64(struct AChoreographer *chroreographer,
AChoreographer_frameCallback64 callback,
void *data);
#endif

#if defined(TARGET_OS_ANDROID)
/**
* Post a callback to be run on the frame following the specified delay. The
* data pointer provided will be passed to the callback function when it's
* called.
*/
extern void AChoreographer_postFrameCallbackDelayed64(struct AChoreographer *choreographer,
AChoreographer_frameCallback64 callback,
void *data,
uint32_t delayMillis);
#endif

const uint8_t *canvas_native_u8_buffer_get_bytes(const struct U8Buffer *buffer);

uint8_t *canvas_native_u8_buffer_get_bytes_mut(struct U8Buffer *buffer);
Expand Down
Binary file not shown.
Loading

0 comments on commit c2cf251

Please sign in to comment.