mirror of
https://github.com/servo/servo.git
synced 2025-08-13 09:25:32 +01:00
Implement GPUSwapChain and GPUCanvasContext and interface with Webrender
This commit is contained in:
parent
73760ea594
commit
71401e0855
28 changed files with 882 additions and 91 deletions
85
components/script/dom/gpuswapchain.rs
Normal file
85
components/script/dom/gpuswapchain.rs
Normal file
|
@ -0,0 +1,85 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::GPUSwapChainBinding::GPUSwapChainMethods;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::gpucanvascontext::GPUCanvasContext;
|
||||
use crate::dom::gputexture::GPUTexture;
|
||||
use dom_struct::dom_struct;
|
||||
use webgpu::{WebGPU, WebGPURequest, WebGPUTexture};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct GPUSwapChain {
|
||||
reflector_: Reflector,
|
||||
#[ignore_malloc_size_of = "channels are hard"]
|
||||
channel: WebGPU,
|
||||
label: DomRefCell<Option<DOMString>>,
|
||||
context: Dom<GPUCanvasContext>,
|
||||
texture: Dom<GPUTexture>,
|
||||
}
|
||||
|
||||
impl GPUSwapChain {
|
||||
fn new_inherited(channel: WebGPU, context: &GPUCanvasContext, texture: &GPUTexture) -> Self {
|
||||
Self {
|
||||
reflector_: Reflector::new(),
|
||||
channel,
|
||||
context: Dom::from_ref(context),
|
||||
texture: Dom::from_ref(texture),
|
||||
label: DomRefCell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
global: &GlobalScope,
|
||||
channel: WebGPU,
|
||||
context: &GPUCanvasContext,
|
||||
texture: &GPUTexture,
|
||||
) -> DomRoot<Self> {
|
||||
reflect_dom_object(
|
||||
Box::new(GPUSwapChain::new_inherited(channel, context, texture)),
|
||||
global,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl GPUSwapChain {
|
||||
pub fn destroy(&self, external_id: u64, image_key: webrender_api::ImageKey) {
|
||||
if let Err(e) = self.channel.0.send(WebGPURequest::DestroySwapChain {
|
||||
external_id,
|
||||
image_key,
|
||||
}) {
|
||||
warn!(
|
||||
"Failed to send DestroySwapChain-ImageKey({:?}) ({})",
|
||||
image_key, e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn texture_id(&self) -> WebGPUTexture {
|
||||
self.texture.id()
|
||||
}
|
||||
}
|
||||
|
||||
impl GPUSwapChainMethods for GPUSwapChain {
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
|
||||
fn GetLabel(&self) -> Option<DOMString> {
|
||||
self.label.borrow().clone()
|
||||
}
|
||||
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
|
||||
fn SetLabel(&self, value: Option<DOMString>) {
|
||||
*self.label.borrow_mut() = value;
|
||||
}
|
||||
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpuswapchain-getcurrenttexture
|
||||
fn GetCurrentTexture(&self) -> DomRoot<GPUTexture> {
|
||||
self.context.mark_as_dirty();
|
||||
//self.context.send_swap_chain_present();
|
||||
DomRoot::from_ref(&*self.texture)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue