fabric-texture
Version:
This JavaScript library enables fast and efficient image distortion transformations using Canvas 2D.
50 lines (49 loc) • 1.89 kB
TypeScript
import type { Texture } from '../texture.class';
/**
* 在 Web Worker 中使用 WebGL 创建并渲染贴图
*
* 使用 Web Worker 和 WebGL 在后台线程中执行贴图渲染,提供最佳性能:
* 1. 利用 GPU 加速进行图像处理
* 2. 在后台线程执行避免阻塞主线程
* 3. 通过 OffscreenCanvas 实现高效渲染
* 4. 使用 ImageBitmap 优化内存传输
*
* 工作流程:
* 1. 提取贴图数据:准备可传输的贴图信息
* 2. 创建 Worker:初始化 WebGL 环境
* 3. 执行渲染:使用 GPU 加速处理图像
* 4. 传输结果:通过 ImageBitmap 返回渲染结果
*
* @param texture - 贴图对象,包含变形网格和渲染选项
* @param imageData - 源图像数据
* @param destination - 目标渲染画布,如果为 null 则自动创建
* @param options - 渲染配置选项
* @property {number} x - 渲染位置 X 坐标
* @property {number} y - 渲染位置 Y 坐标
* @property {number} width - 渲染宽度
* @property {number} height - 渲染高度
* @property {number} [sourceScale=1] - 源图像缩放比例
* @property {number} [destinationScale=1] - 目标画布缩放比例
*
* @returns {Promise<HTMLCanvasElement>} 渲染完成的画布对象
*
* @throws {Error}
* - 当 WebGL 不受支持时
* - 当 Worker 或 OffscreenCanvas 不受支持时
* - 当 GPU 资源不足时
*
* @performance
* - 使用 WebGL 实现 GPU 加速
* - Worker 执行避免主线程阻塞
* - OffscreenCanvas 优化渲染性能
* - ImageBitmap 优化内存使用
*/
declare const createTextureWithWorker: (texture: Texture, imageData: ImageData, destination: HTMLCanvasElement | null, options: {
x: number;
y: number;
width: number;
height: number;
sourceScale?: number;
destinationScale?: number;
}) => Promise<HTMLCanvasElement>;
export default createTextureWithWorker;