1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00
denoland-deno/runtime/js/90_deno_ns.js

193 lines
5.4 KiB
JavaScript
Raw Normal View History

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core } from "ext:core/mod.js";
import {
op_net_listen_udp,
op_net_listen_unixpacket,
op_runtime_memory_usage,
} from "ext:core/ops";
import * as timers from "ext:deno_web/02_timers.js";
import * as httpClient from "ext:deno_fetch/22_http_client.js";
import * as console from "ext:deno_console/01_console.js";
import * as ffi from "ext:deno_ffi/00_ffi.js";
import * as net from "ext:deno_net/01_net.js";
import * as tls from "ext:deno_net/02_tls.js";
import * as serve from "ext:deno_http/00_serve.ts";
import * as http from "ext:deno_http/01_http.js";
import * as websocket from "ext:deno_http/02_websocket.ts";
import * as errors from "ext:runtime/01_errors.js";
import * as version from "ext:runtime/01_version.ts";
import * as permissions from "ext:runtime/10_permissions.js";
import * as io from "ext:deno_io/12_io.js";
import * as fs from "ext:deno_fs/30_fs.js";
import * as os from "ext:runtime/30_os.js";
import * as fsEvents from "ext:runtime/40_fs_events.js";
import * as process from "ext:runtime/40_process.js";
import * as signals from "ext:runtime/40_signals.js";
import * as tty from "ext:runtime/40_tty.js";
import * as kv from "ext:deno_kv/01_db.ts";
import * as cron from "ext:deno_cron/01_cron.ts";
feat:: External webgpu surfaces / BYOW (#21835) This PR contains the implementation of the External webgpu surfaces / BYOW proposal. BYOW stands for "Bring your own window". Closes #21713 Adds `Deno.UnsafeWindowSurface` ( `--unstable-webgpu` API) to the `Deno` namespace: ```typescript class UnsafeWindowSurface { constructor( system: "cocoa" | "x11" | "win32", winHandle: Deno.PointerValue, displayHandle: Deno.PointerValue | null ); getContext(type: "webgpu"): GPUCanvasContext; present(): void; } ``` For the initial pass, I've opted to support the three major windowing systems. The parameters correspond to the table below: | system | winHandle | displayHandle | | ----------------- | ---------- | ------- | | "cocoa" (macOS) | `NSView*` | - | | "win32" (Windows) | `HWND` | `HINSTANCE` | | "x11" (Linux) | Xlib `Window` | Xlib `Display*` | Ecosystem support: - [x] deno_sdl2 (sdl2) - [mod.ts#L1209](https://github.com/littledivy/deno_sdl2/blob/7e177bc6524750a8849c25ce421798b2e71ec943/mod.ts#L1209) - [x] dwm (glfw) - https://github.com/deno-windowing/dwm/issues/29 - [ ] pane (winit) <details> <summary>Example</summary> ```typescript // A simple clear screen pass, colors based on mouse position. import { EventType, WindowBuilder } from "https://deno.land/x/sdl2@0.7.0/mod.ts"; const window = new WindowBuilder("sdl2 + deno + webgpu", 640, 480).build(); const [system, windowHandle, displayHandle] = window.rawHandle(); const adapter = await navigator.gpu.requestAdapter(); const device = await adapter.requestDevice(); const context = Deno.createWindowSurface(system, windowHandle, displayHandle); context.configure({ device: device, format: "bgra8unorm", height: 480, width: 640, }); let r = 0.0; let g = 0.0; let b = 0.0; for (const event of window.events()) { if (event.type === EventType.Quit) { break; } else if (event.type === EventType.Draw) { const textureView = context.getCurrentTexture().createView(); const renderPassDescriptor: GPURenderPassDescriptor = { colorAttachments: [ { view: textureView, clearValue: { r, g, b, a: 1.0 }, loadOp: "clear", storeOp: "store", }, ], }; const commandEncoder = device.createCommandEncoder(); const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor); passEncoder.end(); device.queue.submit([commandEncoder.finish()]); Deno.presentGPUCanvasContext(context); } if (event.type === EventType.MouseMotion) { r = event.x / 640; g = event.y / 480; b = 1.0 - r - g; } } ``` You can find more examples in the linked tracking issue. </details> --------- Signed-off-by: Divy Srivastava <dj.srivastava23@gmail.com>
2024-01-19 12:19:14 -05:00
import * as webgpuSurface from "ext:deno_webgpu/02_surface.js";
import * as telemetry from "ext:runtime/telemetry.js";
const denoNs = {
Process: process.Process,
run: process.run,
isatty: tty.isatty,
writeFileSync: fs.writeFileSync,
writeFile: fs.writeFile,
writeTextFileSync: fs.writeTextFileSync,
writeTextFile: fs.writeTextFile,
readTextFile: fs.readTextFile,
readTextFileSync: fs.readTextFileSync,
readFile: fs.readFile,
readFileSync: fs.readFileSync,
watchFs: fsEvents.watchFs,
chmodSync: fs.chmodSync,
chmod: fs.chmod,
chown: fs.chown,
chownSync: fs.chownSync,
copyFileSync: fs.copyFileSync,
cwd: fs.cwd,
makeTempDirSync: fs.makeTempDirSync,
makeTempDir: fs.makeTempDir,
makeTempFileSync: fs.makeTempFileSync,
makeTempFile: fs.makeTempFile,
memoryUsage: () => op_runtime_memory_usage(),
mkdirSync: fs.mkdirSync,
mkdir: fs.mkdir,
chdir: fs.chdir,
copyFile: fs.copyFile,
readDirSync: fs.readDirSync,
readDir: fs.readDir,
readLinkSync: fs.readLinkSync,
readLink: fs.readLink,
realPathSync: fs.realPathSync,
realPath: fs.realPath,
removeSync: fs.removeSync,
remove: fs.remove,
renameSync: fs.renameSync,
rename: fs.rename,
version: version.version,
build: core.build,
statSync: fs.statSync,
lstatSync: fs.lstatSync,
stat: fs.stat,
lstat: fs.lstat,
truncateSync: fs.truncateSync,
truncate: fs.truncate,
errors: errors.errors,
inspect: console.inspect,
env: os.env,
exit: os.exit,
execPath: os.execPath,
SeekMode: io.SeekMode,
FsFile: fs.FsFile,
open: fs.open,
openSync: fs.openSync,
create: fs.create,
createSync: fs.createSync,
stdin: io.stdin,
stdout: io.stdout,
stderr: io.stderr,
connect: net.connect,
listen: net.listen,
loadavg: os.loadavg,
connectTls: tls.connectTls,
listenTls: tls.listenTls,
startTls: tls.startTls,
symlink: fs.symlink,
symlinkSync: fs.symlinkSync,
link: fs.link,
linkSync: fs.linkSync,
permissions: permissions.permissions,
Permissions: permissions.Permissions,
PermissionStatus: permissions.PermissionStatus,
serveHttp: http.serveHttp,
serve: serve.serve,
resolveDns: net.resolveDns,
upgradeWebSocket: websocket.upgradeWebSocket,
utime: fs.utime,
utimeSync: fs.utimeSync,
kill: process.kill,
addSignalListener: signals.addSignalListener,
removeSignalListener: signals.removeSignalListener,
refTimer: timers.refTimer,
unrefTimer: timers.unrefTimer,
osRelease: os.osRelease,
osUptime: os.osUptime,
hostname: os.hostname,
systemMemoryInfo: os.systemMemoryInfo,
networkInterfaces: os.networkInterfaces,
consoleSize: tty.consoleSize,
gid: os.gid,
uid: os.uid,
Command: process.Command,
ChildProcess: process.ChildProcess,
dlopen: ffi.dlopen,
UnsafeCallback: ffi.UnsafeCallback,
UnsafePointer: ffi.UnsafePointer,
UnsafePointerView: ffi.UnsafePointerView,
UnsafeFnPointer: ffi.UnsafeFnPointer,
umask: fs.umask,
HttpClient: httpClient.HttpClient,
createHttpClient: httpClient.createHttpClient,
};
// NOTE(bartlomieju): keep IDs in sync with `runtime/lib.rs`
const unstableIds = {
broadcastChannel: 1,
cron: 2,
ffi: 3,
fs: 4,
http: 5,
kv: 6,
net: 7,
nodeGlobals: 8,
otel: 9,
process: 10,
temporal: 11,
unsafeProto: 12,
webgpu: 13,
workerOptions: 14,
};
const denoNsUnstableById = { __proto__: null };
// denoNsUnstableById[unstableIds.broadcastChannel] = { __proto__: null }
denoNsUnstableById[unstableIds.cron] = {
cron: cron.cron,
};
denoNsUnstableById[unstableIds.kv] = {
openKv: kv.openKv,
AtomicOperation: kv.AtomicOperation,
Kv: kv.Kv,
KvU64: kv.KvU64,
KvListIterator: kv.KvListIterator,
};
denoNsUnstableById[unstableIds.net] = {
listenDatagram: net.createListenDatagram(
op_net_listen_udp,
op_net_listen_unixpacket,
),
};
// denoNsUnstableById[unstableIds.unsafeProto] = { __proto__: null }
feat:: External webgpu surfaces / BYOW (#21835) This PR contains the implementation of the External webgpu surfaces / BYOW proposal. BYOW stands for "Bring your own window". Closes #21713 Adds `Deno.UnsafeWindowSurface` ( `--unstable-webgpu` API) to the `Deno` namespace: ```typescript class UnsafeWindowSurface { constructor( system: "cocoa" | "x11" | "win32", winHandle: Deno.PointerValue, displayHandle: Deno.PointerValue | null ); getContext(type: "webgpu"): GPUCanvasContext; present(): void; } ``` For the initial pass, I've opted to support the three major windowing systems. The parameters correspond to the table below: | system | winHandle | displayHandle | | ----------------- | ---------- | ------- | | "cocoa" (macOS) | `NSView*` | - | | "win32" (Windows) | `HWND` | `HINSTANCE` | | "x11" (Linux) | Xlib `Window` | Xlib `Display*` | Ecosystem support: - [x] deno_sdl2 (sdl2) - [mod.ts#L1209](https://github.com/littledivy/deno_sdl2/blob/7e177bc6524750a8849c25ce421798b2e71ec943/mod.ts#L1209) - [x] dwm (glfw) - https://github.com/deno-windowing/dwm/issues/29 - [ ] pane (winit) <details> <summary>Example</summary> ```typescript // A simple clear screen pass, colors based on mouse position. import { EventType, WindowBuilder } from "https://deno.land/x/sdl2@0.7.0/mod.ts"; const window = new WindowBuilder("sdl2 + deno + webgpu", 640, 480).build(); const [system, windowHandle, displayHandle] = window.rawHandle(); const adapter = await navigator.gpu.requestAdapter(); const device = await adapter.requestDevice(); const context = Deno.createWindowSurface(system, windowHandle, displayHandle); context.configure({ device: device, format: "bgra8unorm", height: 480, width: 640, }); let r = 0.0; let g = 0.0; let b = 0.0; for (const event of window.events()) { if (event.type === EventType.Quit) { break; } else if (event.type === EventType.Draw) { const textureView = context.getCurrentTexture().createView(); const renderPassDescriptor: GPURenderPassDescriptor = { colorAttachments: [ { view: textureView, clearValue: { r, g, b, a: 1.0 }, loadOp: "clear", storeOp: "store", }, ], }; const commandEncoder = device.createCommandEncoder(); const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor); passEncoder.end(); device.queue.submit([commandEncoder.finish()]); Deno.presentGPUCanvasContext(context); } if (event.type === EventType.MouseMotion) { r = event.x / 640; g = event.y / 480; b = 1.0 - r - g; } } ``` You can find more examples in the linked tracking issue. </details> --------- Signed-off-by: Divy Srivastava <dj.srivastava23@gmail.com>
2024-01-19 12:19:14 -05:00
denoNsUnstableById[unstableIds.webgpu] = {
UnsafeWindowSurface: webgpuSurface.UnsafeWindowSurface,
};
// denoNsUnstableById[unstableIds.workerOptions] = { __proto__: null }
denoNsUnstableById[unstableIds.otel] = {
tracing: telemetry.tracing,
metrics: telemetry.metrics,
};
export { denoNs, denoNsUnstableById, unstableIds };