-
Notifications
You must be signed in to change notification settings - Fork 286
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
Support external image texture/buffer #547
Conversation
@nical @glennw |
@glennw
|
} | ||
|
||
#[repr(C)] | ||
pub struct ExternalImageStruct { |
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.
How about:
struct RgbImage {
size: Size2D<u32>,
stride: u32,
format: ImageFormat,
buffer: *const u8,
}
struct GlHandle {
handle: u32,
}
// YuvImage, DxgiHandle, etc...
enum ExternalImage {
RgbMemory(RgbImage),
YuvMemory(YuvImage),
Gl(GlHandle),
Dxgi(DxgiHandle),
// etc..
}
Using enums this way is a lot more idiomatic in rust, and I think that it'll make it easier to work with internally
Similarly to what @nical said, I think having the source data as a rust enum makes sense. If we do this, we won't even need to add a new public API for adding external images - we could change the last parameter of the existing add_image() function from taking a byte array to take a rust enum, something roughly like:
And then WR would invoke the callback you've added when it encounters an image where the data is ImageData::External. The callback signature would take the ExternalImageHandle as a parameter. Thoughts? |
If we have:
What's the corresponding c++ struct type for rust "repr(C)" ExternalImage enum type?
Otherwise, I will still need to have a big temporary struct ExternalImageStruct which contain all fields from all enum types and convert ExternalImageStruct to ExternalImage in binding code like (this PR already has this approach):
|
@JerryShih and I talked about this offline and we think that as a first step it would be good to simplify this down to only exposing TextureId in the callbacks (we'd do the eventual texture uploads / dxgi glue, etc in gecko for now). This would simplify the callback interface into something that easy to express in both C++ and rust and avoid polluting the API with structures that would be better expressed as rust enums. Also, it would give us more time to figure out a more elaborate API to deal with the external image interface. We should have a vidyo chat about this to figure out what servo and gecko need in the longer term. |
@glennw I don't think we can / want to have the handles (GL/DXGI/etc.) stored in the display list. The thread that produces the display list does not know the value of this handle, which will be created on the compositor/renderer thread later. The idea behind ExternalImageKey is to have something that we can refer to (when creating the display list and in the render backend) before we create the actual handles (on the compositor/render thread). It also has the benefit of letting us change the texture handle associated to a key without rebuilding the frame if only the content of the current image has changed, which is pretty common when watching videos). |
☔ The latest upstream changes (presumably #554) made this pull request unmergeable. Please resolve the merge conflicts. |
@JerryShih @nical Should we close this PR? The basic external native texture support has landed now. |
Thanks. I'm trying to use that interface in Gecko. |
This patch try to support external image in WR (#524).
Then, we could use these two callback function to get/release the external buffer/image from c++.
This change is