mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
feat(jupyter): make GPUTexture and GPUBuffer displayable (#28117)
This commit is contained in:
parent
1f169f4b09
commit
17a51c401a
13 changed files with 528 additions and 9 deletions
|
@ -299,6 +299,19 @@ async function format(obj) {
|
|||
"text/html": obj.outerHTML,
|
||||
};
|
||||
}
|
||||
if (obj instanceof GPUTexture) {
|
||||
return { "image/png": core.ops.op_jupyter_create_png_from_texture(obj) };
|
||||
}
|
||||
if (obj instanceof GPUBuffer) {
|
||||
return {
|
||||
"text/plain": Deno[Deno.internal].inspectArgs([
|
||||
"%o",
|
||||
core.ops.op_jupyter_get_buffer(obj),
|
||||
], {
|
||||
colors: !Deno.noColor,
|
||||
}),
|
||||
};
|
||||
}
|
||||
return {
|
||||
"text/plain": Deno[Deno.internal].inspectArgs(["%o", obj], {
|
||||
colors: !Deno.noColor,
|
||||
|
@ -387,8 +400,14 @@ function image(obj) {
|
|||
return makeDisplayable({ "image/png": core.ops.op_base64_encode(obj) });
|
||||
}
|
||||
|
||||
if (obj instanceof GPUTexture) {
|
||||
return makeDisplayable({
|
||||
"image/png": core.ops.op_jupyter_create_png_from_texture(obj),
|
||||
});
|
||||
}
|
||||
|
||||
throw new TypeError(
|
||||
"Object is not a valid image or a path to an image. `Deno.jupyter.image` supports displaying JPG or PNG images.",
|
||||
"Object is not a valid image or a path to an image. `Deno.jupyter.image` supports displaying JPG or PNG images, or GPUTextures.",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -452,6 +471,12 @@ function enableJupyter() {
|
|||
evalue: err.message,
|
||||
traceback: stack.split("\n"),
|
||||
});
|
||||
} else if (err instanceof GPUError) {
|
||||
await broadcast("error", {
|
||||
ename: err.constructor.name,
|
||||
evalue: err.message,
|
||||
traceback: [],
|
||||
});
|
||||
} else if (typeof err == "string") {
|
||||
await broadcast("error", {
|
||||
ename: "Error",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue