Skip to content

Commit

Permalink
Add SDKVersion interface and removed the "upper camel case" function …
Browse files Browse the repository at this point in the history
…name on Web platform. (#397)

(cherry picked from commit 2118050)
  • Loading branch information
zenoslin authored and libpag-pag committed Jul 4, 2022
1 parent 72e6904 commit f1dc741
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 44 deletions.
2 changes: 2 additions & 0 deletions src/platform/web/PAGWasmBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ EMSCRIPTEN_BINDINGS(pag) {
WebSoftwareDecoderFactory::Make(factory).release());
}));

function("_SDKVersion", &PAG::SDKVersion);

register_vector<std::shared_ptr<PAGLayer>>("VectorPAGLayer");
register_vector<std::string>("VectorString");
register_vector<int>("VectorInt");
Expand Down
2 changes: 1 addition & 1 deletion web/demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ window.onload = async () => {
tablecloth!.style.height = `${canvasElementSize}px`;
}

console.log('wasm loaded!', PAG);
console.log(`wasm loaded! SDKVersion ${PAG.SDKVersion()}`, PAG);

document.getElementById('waiting')!.style.display = 'none';
document.getElementById('container')!.style.display = isMobile ? 'block' : '';
Expand Down
3 changes: 3 additions & 0 deletions web/src/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export const binding = (module: PAG) => {
module.registerSoftwareDecoderFactory = function (factory = null) {
module._registerSoftwareDecoderFactory(factory);
};
module.SDKVersion = function () {
return module._SDKVersion();
};
};

export let PAGModule: PAG;
5 changes: 4 additions & 1 deletion web/src/core/web-mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export class WebMask {
public fillPath(path: Path2D, fillType: ctor) {
const context = this.canvas.getContext('2d') as CanvasRenderingContext2D;
context.setTransform(1, 0, 0, 1, 0, 0);
if (fillType === PAGModule.TGFXPathFillType.InverseWinding || fillType === PAGModule.TGFXPathFillType.InverseEvenOdd) {
if (
fillType === PAGModule.TGFXPathFillType.InverseWinding ||
fillType === PAGModule.TGFXPathFillType.InverseEvenOdd
) {
context.clip(path, fillType === PAGModule.TGFXPathFillType.InverseEvenOdd ? 'evenodd' : 'nonzero');
context.fillRect(0, 0, this.canvas.width, this.canvas.height);
} else {
Expand Down
10 changes: 0 additions & 10 deletions web/src/pag-composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ import type { Marker } from './types';
@destroyVerify
@wasmAwaitRewind
export class PAGComposition extends PAGLayer {
/**
* [Deprecated]
* Make a empty PAGComposition with specified size.
*/
public static Make(width: number, height: number): PAGComposition {
console.warn(
'Please use PAGComposition.make to create PAGComposition object! This interface will be removed in the next version!',
);
return PAGComposition.make(width, height);
}
/**
* Make a empty PAGComposition with specified size.
*/
Expand Down
10 changes: 0 additions & 10 deletions web/src/pag-image-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ import type { PAGVideoRange } from './types';
@destroyVerify
@wasmAwaitRewind
export class PAGImageLayer extends PAGLayer {
/**
* [Deprecated]
* Make a empty PAGImageLayer with specified size.
*/
public static Make(width: number, height: number, duration: number): PAGImageLayer {
console.warn(
'Please use PAGImageLayer.make to create PAGImageLayer object! This interface will be removed in the next version!',
);
return PAGImageLayer.make(width, height, duration);
}
/**
* Make a empty PAGImageLayer with specified size.
*/
Expand Down
10 changes: 5 additions & 5 deletions web/src/pag-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PAGModule } from './binding';
import { PAGFile } from './pag-file';
import { PAGSurface } from './pag-surface';
import { wasmAwaitRewind, wasmAsyncMethod, destroyVerify } from './utils/decorators';
import { layer2typeLayer, proxyVector } from './utils/type-utils';
import { getWasmIns, layer2typeLayer, proxyVector } from './utils/type-utils';
import { Matrix } from './core/matrix';

import type { PAGLayer } from './pag-layer';
Expand Down Expand Up @@ -133,8 +133,8 @@ export class PAGPlayer {
/**
* Set the PAGSurface object for PAGPlayer to render onto.
*/
public setSurface(pagSurface: PAGSurface): void {
this.wasmIns._setSurface(pagSurface.wasmIns);
public setSurface(pagSurface: PAGSurface | null): void {
this.wasmIns._setSurface(getWasmIns(pagSurface));
}
/**
*
Expand All @@ -153,8 +153,8 @@ export class PAGPlayer {
* Sets a new PAGComposition for PAGPlayer to render as content.
*/

public setComposition(pagComposition: PAGComposition) {
this.wasmIns._setComposition(pagComposition.wasmIns);
public setComposition(pagComposition: PAGComposition | null) {
this.wasmIns._setComposition(getWasmIns(pagComposition));
}
/**
* Returns the PAGSurface object for PAGPlayer to render onto.
Expand Down
10 changes: 0 additions & 10 deletions web/src/pag-solid-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ import type { Color } from './types';
@destroyVerify
@wasmAwaitRewind
export class PAGSolidLayer extends PAGLayer {
/**
* [Deprecated]
* Make a empty PAGSolidLayer with specified size.
*/
public static Make(duration: number, width: number, height: number, solidColor: Color, opacity: number) {
console.warn(
'Please use PAGSolidLayer.make to create PAGSolidLayer object! This interface will be removed in the next version!',
);
return PAGSolidLayer.make(duration, width, height, solidColor, opacity);
}
/**
* Make a empty PAGSolidLayer with specified size.
*/
Expand Down
6 changes: 3 additions & 3 deletions web/src/pag-text-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import type { Color, TextDocument } from './types';
@destroyVerify
@wasmAwaitRewind
export class PAGTextLayer extends PAGLayer {
public static Make(
public static make(
duration: number,
text: string,
fontSize: number,
fontFamily: string,
fontStyle: string,
): PAGTextLayer;
public static Make(duration: number, textDocumentHandle: TextDocument): PAGTextLayer;
public static Make(
public static make(duration: number, textDocumentHandle: TextDocument): PAGTextLayer;
public static make(
duration: number,
text: string | TextDocument,
fontSize = 0,
Expand Down
3 changes: 1 addition & 2 deletions web/src/pag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { binding } from './binding';
import * as types from './types';
import createPAG from './wasm/libpag';
import { WebAssemblyQueue } from './utils/queue';
import { version } from '../package.json';

export interface moduleOption {
/**
Expand All @@ -30,4 +29,4 @@ const PAGInit = (moduleOption: moduleOption = {}): Promise<types.PAG> =>
throw new Error('PAGInit fail! Please check .wasm file path valid.');
});

export { PAGInit, types, version };
export { PAGInit, types };
1 change: 1 addition & 0 deletions web/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export interface PAG extends EmscriptenModule {
Matrix: typeof ClassMatrix;
traceImage: (info: { width: number; height: number }, pixels: Uint8Array, tag: string) => void;
registerSoftwareDecoderFactory: (factory: SoftwareDecoderFactory | null) => void;
SDKVersion: () => string;
[key: string]: any;
}

Expand Down
11 changes: 9 additions & 2 deletions web/src/utils/type-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const layer2typeLayer = (wasmIns: any): PAGSolidLayer | PAGTextLayer | PA
}
};

export const getLayerTypeName = (layerType:LayerType)=> {
export const getLayerTypeName = (layerType: LayerType) => {
switch (layerType) {
case LayerType.Solid:
return 'Solid';
Expand All @@ -77,4 +77,11 @@ export const getLayerTypeName = (layerType:LayerType)=> {
default:
return 'Unknown';
}
}
};

export const getWasmIns = (value: any) => {
if (value?.wasmIns) {
return value.wasmIns;
}
return value;
};

0 comments on commit f1dc741

Please sign in to comment.