-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(web): ImageBitmap #21898
feat(web): ImageBitmap #21898
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woah, nice!
ImageBitmap can integrate with WebGPU's copyExternalImageToTexture
- very useful for texture rendering.
@littledivy yes, however this new "canvas" extension will depend on the webgpu extension, so we will need to be careful when adding support for such, and will be tricky especially since webgpu implementation also lives in wgpu. |
# Conflicts: # Cargo.toml # ext/web/16_image_data.js # runtime/build.rs # runtime/js/98_global_scope_shared.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"); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quite a bit duplicate with webgpu. we should look into having a better solution that requires less setup for each lazy loaded file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there WPT we can enable or unit tests that can be added?
@littledivy from the PR description:
I'll some unit tests though |
let view = | ||
RgbaImage::from_vec(args.width, args.height, buf.to_vec()).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The full allocation here will hurt performance. I think you can create a view into the JS slice:
let view: ImageBuffer<Rgba<u8>, &[u8]> = ImageBuffer::from_raw(args.witdh, args.height, buf).unwrap();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sadly I attempted this already, but it wont accept a slice no matter what (even your code, oddly enough, errors out with it wanting a vec), which is weird given that the docs for from_raw
state that a slice can be passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
implements the
ImageBitmap
class andcreateImageBitmap
function from https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html.Prerequisite for #5701
This API by itself is useless without OffscreenCanvas and/or integration into WebPGU, since accessing the data of an
ImageBitmap
directly is not possible.enable some WPTsno WPTs can be enabled due to all relevant WPTs requiring OffscreenCanvas