summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2024-01-22 12:08:01 +0100
committerGitHub <noreply@github.com>2024-01-22 12:08:01 +0100
commit8f767627938ef10802864419061e58a8a75db567 (patch)
tree81f61ba0f8c14fb820a72500840eb0c619d54362 /runtime
parentb4990d1aa233db662cf22d7f872d45b3a947e0f6 (diff)
feat(web): ImageBitmap (#21898)
Diffstat (limited to 'runtime')
-rw-r--r--runtime/Cargo.toml2
-rw-r--r--runtime/js/98_global_scope_shared.js62
-rw-r--r--runtime/lib.rs1
-rw-r--r--runtime/snapshot.rs1
-rw-r--r--runtime/web_worker.rs1
-rw-r--r--runtime/worker.rs1
6 files changed, 66 insertions, 2 deletions
diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml
index 18bad2d07..0b07839b2 100644
--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -42,6 +42,7 @@ path = "examples/extension_with_ops/main.rs"
deno_ast.workspace = true
deno_broadcast_channel.workspace = true
deno_cache.workspace = true
+deno_canvas.workspace = true
deno_console.workspace = true
deno_core.workspace = true
deno_cron.workspace = true
@@ -73,6 +74,7 @@ winapi.workspace = true
deno_ast.workspace = true
deno_broadcast_channel.workspace = true
deno_cache.workspace = true
+deno_canvas.workspace = true
deno_console.workspace = true
deno_core.workspace = true
deno_cron.workspace = true
diff --git a/runtime/js/98_global_scope_shared.js b/runtime/js/98_global_scope_shared.js
index 04a6e4bd3..8ef269539 100644
--- a/runtime/js/98_global_scope_shared.js
+++ b/runtime/js/98_global_scope_shared.js
@@ -31,11 +31,67 @@ import * as messagePort from "ext:deno_web/13_message_port.js";
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import * as abortSignal from "ext:deno_web/03_abort_signal.js";
-import * as imageData from "ext:deno_web/16_image_data.js";
import { webgpu, webGPUNonEnumerable } from "ext:deno_webgpu/00_init.js";
import * as webgpuSurface from "ext:deno_webgpu/02_surface.js";
import { unstableIds } from "ext:runtime/90_deno_ns.js";
+const { op_lazy_load_esm } = core.ensureFastOps(true);
+let image;
+
+function ImageNonEnumerable(getter) {
+ let valueIsSet = false;
+ let value;
+
+ return {
+ get() {
+ loadImage();
+
+ if (valueIsSet) {
+ return value;
+ } else {
+ return getter();
+ }
+ },
+ set(v) {
+ loadImage();
+
+ valueIsSet = true;
+ value = v;
+ },
+ enumerable: false,
+ configurable: true,
+ };
+}
+function ImageWritable(getter) {
+ let valueIsSet = false;
+ let value;
+
+ return {
+ get() {
+ loadImage();
+
+ if (valueIsSet) {
+ return value;
+ } else {
+ return getter();
+ }
+ },
+ set(v) {
+ loadImage();
+
+ valueIsSet = true;
+ value = v;
+ },
+ enumerable: true,
+ configurable: true,
+ };
+}
+function loadImage() {
+ if (!image) {
+ image = op_lazy_load_esm("ext:deno_canvas/01_image.js");
+ }
+}
+
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope
const windowOrWorkerGlobalScope = {
AbortController: util.nonEnumerable(abortSignal.AbortController),
@@ -60,7 +116,8 @@ const windowOrWorkerGlobalScope = {
FileReader: util.nonEnumerable(fileReader.FileReader),
FormData: util.nonEnumerable(formData.FormData),
Headers: util.nonEnumerable(headers.Headers),
- ImageData: util.nonEnumerable(imageData.ImageData),
+ ImageData: ImageNonEnumerable(() => image.ImageData),
+ ImageBitmap: ImageNonEnumerable(() => image.ImageBitmap),
MessageEvent: util.nonEnumerable(event.MessageEvent),
Performance: util.nonEnumerable(performance.Performance),
PerformanceEntry: util.nonEnumerable(performance.PerformanceEntry),
@@ -110,6 +167,7 @@ const windowOrWorkerGlobalScope = {
),
atob: util.writable(base64.atob),
btoa: util.writable(base64.btoa),
+ createImageBitmap: ImageWritable(() => image.createImageBitmap),
clearInterval: util.writable(timers.clearInterval),
clearTimeout: util.writable(timers.clearTimeout),
caches: {
diff --git a/runtime/lib.rs b/runtime/lib.rs
index dbdce7850..5aa4e21a1 100644
--- a/runtime/lib.rs
+++ b/runtime/lib.rs
@@ -2,6 +2,7 @@
pub use deno_broadcast_channel;
pub use deno_cache;
+pub use deno_canvas;
pub use deno_console;
pub use deno_core;
pub use deno_cron;
diff --git a/runtime/snapshot.rs b/runtime/snapshot.rs
index a50f0773a..794de14d9 100644
--- a/runtime/snapshot.rs
+++ b/runtime/snapshot.rs
@@ -212,6 +212,7 @@ pub fn create_runtime_snapshot(
Default::default(),
),
deno_webgpu::deno_webgpu::init_ops_and_esm(),
+ deno_canvas::deno_canvas::init_ops_and_esm(),
deno_fetch::deno_fetch::init_ops_and_esm::<Permissions>(Default::default()),
deno_cache::deno_cache::init_ops_and_esm::<SqliteBackedCache>(None),
deno_websocket::deno_websocket::init_ops_and_esm::<Permissions>(
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs
index de32e3994..2b6eb19c9 100644
--- a/runtime/web_worker.rs
+++ b/runtime/web_worker.rs
@@ -411,6 +411,7 @@ impl WebWorker {
Some(main_module.clone()),
),
deno_webgpu::deno_webgpu::init_ops_and_esm(),
+ deno_canvas::deno_canvas::init_ops_and_esm(),
deno_fetch::deno_fetch::init_ops_and_esm::<PermissionsContainer>(
deno_fetch::Options {
user_agent: options.bootstrap.user_agent.clone(),
diff --git a/runtime/worker.rs b/runtime/worker.rs
index 2cb1ab491..5dc5db71d 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -346,6 +346,7 @@ impl MainWorker {
options.bootstrap.location.clone(),
),
deno_webgpu::deno_webgpu::init_ops_and_esm(),
+ deno_canvas::deno_canvas::init_ops_and_esm(),
deno_fetch::deno_fetch::init_ops_and_esm::<PermissionsContainer>(
deno_fetch::Options {
user_agent: options.bootstrap.user_agent.clone(),