@solidtv/renderer 1.1.0 → 1.1.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.
- package/dist/src/core/CoreTextureManager.js +82 -24
- package/dist/src/core/CoreTextureManager.js.map +1 -1
- package/dist/src/core/TextureError.d.ts +2 -1
- package/dist/src/core/TextureError.js +2 -0
- package/dist/src/core/TextureError.js.map +1 -1
- package/dist/src/core/lib/ImageWorker.d.ts +1 -1
- package/dist/src/core/lib/ImageWorker.js +46 -26
- package/dist/src/core/lib/ImageWorker.js.map +1 -1
- package/dist/src/core/textures/ColorTexture.js +3 -1
- package/dist/src/core/textures/ColorTexture.js.map +1 -1
- package/dist/src/core/textures/ImageTexture.js +24 -16
- package/dist/src/core/textures/ImageTexture.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/CoreTextureManager.ts +101 -22
- package/src/core/TextureError.ts +2 -0
- package/src/core/lib/ImageWorker.ts +50 -27
- package/src/core/textures/ColorTexture.ts +3 -1
- package/src/core/textures/ImageTexture.ts +29 -20
|
@@ -147,11 +147,22 @@ export class ImageTexture extends Texture {
|
|
|
147
147
|
data: HTMLImageElement | null;
|
|
148
148
|
premultiplyAlpha: boolean;
|
|
149
149
|
}>((resolve, reject) => {
|
|
150
|
+
let objectUrl: string | null = null;
|
|
151
|
+
|
|
152
|
+
const cleanup = () => {
|
|
153
|
+
if (objectUrl !== null) {
|
|
154
|
+
URL.revokeObjectURL(objectUrl);
|
|
155
|
+
objectUrl = null;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
150
159
|
img.onload = () => {
|
|
160
|
+
cleanup();
|
|
151
161
|
resolve({ data: img, premultiplyAlpha: hasAlpha });
|
|
152
162
|
};
|
|
153
163
|
|
|
154
164
|
img.onerror = (err) => {
|
|
165
|
+
cleanup();
|
|
155
166
|
const errorMessage =
|
|
156
167
|
err instanceof Error
|
|
157
168
|
? err.message
|
|
@@ -162,7 +173,8 @@ export class ImageTexture extends Texture {
|
|
|
162
173
|
};
|
|
163
174
|
|
|
164
175
|
if (src instanceof Blob) {
|
|
165
|
-
|
|
176
|
+
objectUrl = URL.createObjectURL(src);
|
|
177
|
+
img.src = objectUrl;
|
|
166
178
|
} else {
|
|
167
179
|
img.src = src;
|
|
168
180
|
}
|
|
@@ -218,10 +230,11 @@ export class ImageTexture extends Texture {
|
|
|
218
230
|
|
|
219
231
|
async loadImage(src: string) {
|
|
220
232
|
const { premultiplyAlpha, sx, sy, sw, sh } = this.props;
|
|
233
|
+
const isBase64 = isBase64Image(src);
|
|
221
234
|
|
|
222
235
|
if (this.txManager.hasCreateImageBitmap === true) {
|
|
223
236
|
if (
|
|
224
|
-
|
|
237
|
+
isBase64 === false &&
|
|
225
238
|
this.txManager.hasWorker === true &&
|
|
226
239
|
this.txManager.imageWorkerManager !== null
|
|
227
240
|
) {
|
|
@@ -235,15 +248,9 @@ export class ImageTexture extends Texture {
|
|
|
235
248
|
);
|
|
236
249
|
}
|
|
237
250
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
blob = dataURIToBlob(src);
|
|
242
|
-
} else {
|
|
243
|
-
blob = await fetchJson(src, 'blob').then(
|
|
244
|
-
(response) => response as Blob,
|
|
245
|
-
);
|
|
246
|
-
}
|
|
251
|
+
const blob = isBase64
|
|
252
|
+
? dataURIToBlob(src)
|
|
253
|
+
: ((await fetchJson(src, 'blob')) as Blob);
|
|
247
254
|
|
|
248
255
|
return this.createImageBitmap(blob, premultiplyAlpha, sx, sy, sw, sh);
|
|
249
256
|
}
|
|
@@ -357,16 +364,18 @@ export class ImageTexture extends Texture {
|
|
|
357
364
|
return false;
|
|
358
365
|
}
|
|
359
366
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
367
|
+
// Inline default values so the key is stable whether or not the caller
|
|
368
|
+
// has run them through resolveDefaults first. Must mirror the defaults
|
|
369
|
+
// in resolveDefaults below.
|
|
370
|
+
const premultiplyAlpha = props.premultiplyAlpha ?? true;
|
|
371
|
+
const maxRetryCount = props.maxRetryCount ?? 5;
|
|
372
|
+
|
|
373
|
+
let cacheKey = `ImageTexture,${key},${premultiplyAlpha},${maxRetryCount}`;
|
|
363
374
|
|
|
364
|
-
if (props.sh
|
|
365
|
-
cacheKey += '
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
cacheKey += props.sw || '';
|
|
369
|
-
cacheKey += props.sh || '';
|
|
375
|
+
if (props.sh != null && props.sw != null) {
|
|
376
|
+
cacheKey += `,${props.sx ?? ''},${props.sy ?? ''},${props.sw || ''},${
|
|
377
|
+
props.sh || ''
|
|
378
|
+
}`;
|
|
370
379
|
}
|
|
371
380
|
|
|
372
381
|
return cacheKey;
|