Don't use OffscreenCanvas on Safari
PiperOrigin-RevId: 522689566
This commit is contained in:
committed by
Copybara-Service
parent
8cedb82df1
commit
938b501d15
@@ -40,6 +40,7 @@ mediapipe_ts_library(
|
||||
"//mediapipe/tasks/web/core:task_runner",
|
||||
"//mediapipe/web/graph_runner:graph_runner_image_lib_ts",
|
||||
"//mediapipe/web/graph_runner:graph_runner_ts",
|
||||
"//mediapipe/web/graph_runner:platform_utils",
|
||||
"//mediapipe/web/graph_runner:register_model_resources_graph_service_ts",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -20,6 +20,7 @@ import {WasmFileset} from '../../../../tasks/web/core/wasm_fileset';
|
||||
import {ImageProcessingOptions} from '../../../../tasks/web/vision/core/image_processing_options';
|
||||
import {GraphRunner, ImageSource, WasmMediaPipeConstructor} from '../../../../web/graph_runner/graph_runner';
|
||||
import {SupportImage, WasmImage} from '../../../../web/graph_runner/graph_runner_image_lib';
|
||||
import {isWebKit} from '../../../../web/graph_runner/platform_utils';
|
||||
import {SupportModelResourcesGraphService} from '../../../../web/graph_runner/register_model_resources_graph_service';
|
||||
|
||||
import {VisionTaskOptions} from './vision_task_options';
|
||||
@@ -39,11 +40,13 @@ export class VisionGraphRunner extends GraphRunnerVisionType {}
|
||||
* GraphRunner should create its own canvas.
|
||||
*/
|
||||
function createCanvas(): HTMLCanvasElement|OffscreenCanvas|undefined {
|
||||
// Returns an HTML canvas or `undefined` if OffscreenCanvas is available
|
||||
const supportsWebGL2ForOffscreenCanvas =
|
||||
typeof OffscreenCanvas !== 'undefined' && !isWebKit();
|
||||
|
||||
// Returns an HTML canvas or `undefined` if OffscreenCanvas is fully supported
|
||||
// (since the graph runner can initialize its own OffscreenCanvas).
|
||||
return typeof OffscreenCanvas === 'undefined' ?
|
||||
document.createElement('canvas') :
|
||||
undefined;
|
||||
return supportsWebGL2ForOffscreenCanvas ? undefined :
|
||||
document.createElement('canvas');
|
||||
}
|
||||
|
||||
/** Base class for all MediaPipe Vision Tasks. */
|
||||
|
||||
Reference in New Issue
Block a user