-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathFilterBackend.ts
32 lines (28 loc) · 1.09 KB
/
FilterBackend.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { config } from '../config';
import { Canvas2dFilterBackend } from './2d_backend.class';
import { WebGLFilterBackend } from './webgl_backend.class';
import { webGLProbe } from './WebGLProbe';
export type FilterBackend = WebGLFilterBackend | Canvas2dFilterBackend;
let filterBackend: FilterBackend;
/**
* Verifies if it is possible to initialize webgl or fallback on a canvas2d filtering backend
*/
export function initFilterBackend(): FilterBackend {
webGLProbe.queryWebGL();
if (config.enableGLFiltering && webGLProbe.isSupported(config.textureSize)) {
return new WebGLFilterBackend({ tileSize: config.textureSize });
} else {
return new Canvas2dFilterBackend();
}
}
/**
* Get the current fabricJS filter backend or initialize one if not avaialble yet
* @param [strict] pass `true` to create the backend if it wasn't created yet (default behavior),
* pass `false` to get the backend ref without mutating it
*/
export function getFilterBackend(strict = true): FilterBackend {
if (!filterBackend && strict) {
filterBackend = initFilterBackend();
}
return filterBackend;
}