@predy-js/render-interface 0.3.1 → 0.3.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
1
  import type { ImageBitmapCallback, ImageBitmapConstructor } from './ImageBitmapInternal';
2
- import type { TypedArray } from '../type';
2
+ import type { TypedArray, vec2 } from '../type';
3
3
  import type { GPUCapability } from '../GPUCapability';
4
4
  import type { PredyResizeTemplate, SDFImageOptions, SDFImage } from '@predy-js/specification';
5
5
  import type { ImageBitmapInternal } from './ImageBitmapInternal';
6
+
6
7
  export interface PredyRequestOptions {
7
8
  url: string,
8
9
  //用于测试缓存,生产中不要使用
@@ -15,10 +16,13 @@ export interface PredyRequestOptions {
15
16
  //使用系统网络库(仅用于试验)
16
17
  useSystemNetwork?: boolean,
17
18
  }
19
+
18
20
  export enum PredyResourceCacheStatus {
19
21
  noCache = 0, // 没有缓存,走网络请求
20
22
  cached = 1, // 命中缓存,如果请求同一个url,在关闭APP之前,一定会命中缓存,关闭APP后,清理时间由系统决定
21
23
  preloaded = 2, // 命中预推
24
+ hitCDN = 3, // 从正常CDN加载
25
+ missCDN = 4, // CDN异常加载(回源)
22
26
  }
23
27
 
24
28
  export interface PredyRequestResponse {
@@ -29,44 +33,84 @@ export interface PredyRequestResponse {
29
33
 
30
34
  export type PredyRequestCallback = (err: string | undefined, res: PredyRequestResponse) => void;
31
35
 
36
+ export const DataCompressMethodZlib = 1;
37
+
38
+ type DataCompressMethod = typeof DataCompressMethodZlib;
39
+
40
+ export enum PredyTextEncoding {
41
+ utf8 = 0,
42
+ ascii = 1,
43
+ }
44
+
32
45
  export interface PredyNativeInternal {
33
46
  webpDisabled?: boolean,
34
47
 
35
- createImageBitmap (data: TypedArray | string, //图片文件的数据
48
+ createImageBitmap(data: TypedArray | string, //图片文件的数据
36
49
  options: ImageBitmapConstructor, callback: ImageBitmapCallback): void,
37
50
 
38
- getDefaultGPUCapability (): GPUCapability,
51
+ getDefaultGPUCapability(): GPUCapability,
39
52
 
40
- requestWithCache (options: PredyRequestOptions, callback: PredyRequestCallback): void,
53
+ requestWithCache(options: PredyRequestOptions, callback: PredyRequestCallback): void,
41
54
 
42
55
  /**
43
- * decode utf8 text from data
44
- * @param data
45
- */
46
- decodeText(data: Uint8Array): string,
56
+ * decode text from data
57
+ * @param data
58
+ * @param encoding 默认utf8
59
+ */
60
+ decodeText(data: Uint8Array, encoding?: PredyTextEncoding): string,
61
+
47
62
  /**
48
- * 将图片绘制到画布上,同时替换文案,绘制的顺序如下
49
- * 创建template.size尺寸的画布, 接下来的绘制均应用 template.offset
50
- * 将images绘制到画布上,images的尺寸由image.frame决定
51
- * 将数据模板content绘制到画布上,使用variables替换文案
52
- * @param template
53
- */
54
- renderImageTemplate (template: PredyResizeTemplate): ImageBitmapInternal,
63
+ * 将图片绘制到画布上,同时替换文案,绘制的顺序如下
64
+ * 创建template.size尺寸的画布, 接下来的绘制均应用 template.offset
65
+ * 将images绘制到画布上,images的尺寸由image.frame决定
66
+ * 将数据模板content绘制到画布上,使用variables替换文案
67
+ * @param template
68
+ */
69
+ renderImageTemplate(template: PredyResizeTemplate): ImageBitmapInternal,
55
70
 
56
71
  /**
57
- * 异步绘制图片的模板
58
- * @param options
59
- * @param callback 如果传入callback就是异步绘制,否则会直接返回结果
60
- */
61
- generateSDFImage (options: SDFImageOptions, callback?: renderSDFImageCallback): SDFImage | undefined,
72
+ * 异步绘制图片的模板
73
+ * @param options
74
+ * @param callback 如果传入callback就是异步绘制,否则会直接返回结果
75
+ */
76
+ generateSDFImage(options: SDFImageOptions, callback?: renderSDFImageCallback): SDFImage | undefined,
77
+
78
+ /**
79
+ * 下载并且执行脚本文件,此方法会缓存https的脚本内容
80
+ * 对于http的请求(开发环境),每次都重新请求
81
+ * @param url
82
+ * @param callback
83
+ */
84
+ evaluateScriptURL(url: string, callback: (err: Error, result: any) => void): void,
85
+
86
+ /**
87
+ * 将float32Array转换为half float,写入Uint16Array中,
88
+ * 如果提供了range参数,代表float16会被重新map到range中,以此提高精度范围
89
+ * 提供range参数后,算法求出source的最大最小值,然后将float16重新映射到range中
90
+ * 如果source和target的长度不匹配,返回false
91
+ */
92
+ float32ToFloat16(source: Float32Array, target: Uint16Array, range?: vec2): boolean,
93
+
94
+ /**
95
+ * 将half float转换为float32,通过Float32Array返回,
96
+ * 如果提供了range参数,代表float16会被重新map到range中,以此提高精度范围
97
+ * 如果没有提供,float16会被直接转化为float32
98
+ * 如果source和target的长度不匹配,返回false
99
+ */
100
+ float16ToFloat32(source: Uint16Array, target: Float32Array, range?: vec2): boolean,
101
+
102
+ /**
103
+ * 解压数据
104
+ * @param data
105
+ * @param method
106
+ */
107
+ inflateData(data: Uint8Array, method: DataCompressMethod): Uint8Array | undefined,
62
108
 
63
109
  /**
64
- * 下载并且执行脚本文件,此方法会缓存https的脚本内容
65
- * 对于http的请求(开发环境),每次都重新请求
66
- * @param url
67
- * @param callback
110
+ * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
111
+ * 调用此函数后,当前的JSContext会被恢复
68
112
  */
69
- evaluateScriptURL (url: string, callback: (err: Error, result: any) => void): void,
113
+ restoreJSContext(): boolean,
70
114
  }
71
115
 
72
116
  type renderSDFImageCallback = (img: SDFImage) => void;
@@ -11,6 +11,7 @@ import type { GPUCapability } from '../GPUCapability';
11
11
  import type { TextureInternal, TextureInternalConstructOptions } from './TextureInternal';
12
12
  import type { AndGLContext } from './AndGLContext';
13
13
  import type { MetalInternal } from './MetalInternal';
14
+ import type { vec2 } from '../type';
14
15
 
15
16
  /**
16
17
  * renderer 内部创建的对象,用来统计信息,排查资源泄漏的问题
@@ -109,6 +110,10 @@ export abstract class RendererInternal implements ResourceInternal {
109
110
  */
110
111
  abstract getErrors (): string[];
111
112
 
112
- abstract resize (width: number, height: number): void;
113
+ /**
114
+ * resize predy view,并且相关的fbo和render pass都需要设为相应的尺寸
115
+ * @param size 如果不提供size,则使用当前predy view parent的尺寸
116
+ */
117
+ abstract resize (size?: vec2): void;
113
118
  }
114
119
 
@@ -55,10 +55,14 @@ export abstract class TextureInternal implements ResourceInternal {
55
55
  abstract update2DImageData (data: ImageData, mipmapLevel?: number): void;
56
56
 
57
57
  /**
58
- * 上传压缩纹理数据
58
+ * 上传2D压缩纹理数据
59
59
  */
60
+ abstract update2DCompressedData (data: Uint8Array, mipmapLevel?: number): void;
60
61
 
61
- abstract update2DCompressedImage (data: ImageData, mipmapLevel?: number): void;
62
+ /**
63
+ * 上传Cube压缩纹理数据
64
+ */
65
+ abstract update2DCompressedCubeData (data: Uint8Array[], mipmapLevel?: number): void;
62
66
 
63
67
  /**
64
68
  * imageBitmap的尺寸也必须和Texture相同