mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
webgpu: Fix HTML event loop integration (#34631)
* webgpu: Fix HTML event loop integration Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Bring back self.drawing_buffer.borrow().cleared Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Rc webgpu_contexts Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
4ddcba240b
commit
b7e528d2ff
5 changed files with 57 additions and 24 deletions
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::cell::Cell;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
|
@ -106,6 +106,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, DomObject};
|
|||
use crate::dom::bindings::root::{Dom, DomRoot, DomSlice, LayoutDom, MutNullableDom};
|
||||
use crate::dom::bindings::str::{DOMString, USVString};
|
||||
use crate::dom::bindings::trace::{HashMapTracedValues, NoTrace};
|
||||
use crate::dom::bindings::weakref::WeakRef;
|
||||
use crate::dom::bindings::xmlname::XMLName::Invalid;
|
||||
use crate::dom::bindings::xmlname::{
|
||||
namespace_from_domstring, validate_and_extract, xml_name_type,
|
||||
|
@ -255,6 +256,9 @@ pub enum DeclarativeRefresh {
|
|||
CreatedAfterLoad,
|
||||
}
|
||||
|
||||
pub(crate) type WebGPUContextsMap =
|
||||
Rc<RefCell<HashMapTracedValues<WebGPUContextId, WeakRef<GPUCanvasContext>>>>;
|
||||
|
||||
/// <https://dom.spec.whatwg.org/#document>
|
||||
#[dom_struct]
|
||||
pub struct Document {
|
||||
|
@ -450,9 +454,10 @@ pub struct Document {
|
|||
/// List of all WebGL context IDs that need flushing.
|
||||
dirty_webgl_contexts:
|
||||
DomRefCell<HashMapTracedValues<WebGLContextId, Dom<WebGLRenderingContext>>>,
|
||||
/// List of all WebGPU context IDs that need flushing.
|
||||
/// List of all WebGPU contexts.
|
||||
#[cfg(feature = "webgpu")]
|
||||
dirty_webgpu_contexts: DomRefCell<HashMapTracedValues<WebGPUContextId, Dom<GPUCanvasContext>>>,
|
||||
#[ignore_malloc_size_of = "Rc are hard"]
|
||||
webgpu_contexts: WebGPUContextsMap,
|
||||
/// <https://w3c.github.io/slection-api/#dfn-selection>
|
||||
selection: MutNullableDom<Selection>,
|
||||
/// A timeline for animations which is used for synchronizing animations.
|
||||
|
@ -2999,20 +3004,19 @@ impl Document {
|
|||
}
|
||||
|
||||
#[cfg(feature = "webgpu")]
|
||||
pub fn add_dirty_webgpu_canvas(&self, context: &GPUCanvasContext) {
|
||||
self.dirty_webgpu_contexts
|
||||
.borrow_mut()
|
||||
.entry(context.context_id())
|
||||
.or_insert_with(|| Dom::from_ref(context));
|
||||
pub fn webgpu_contexts(&self) -> WebGPUContextsMap {
|
||||
self.webgpu_contexts.clone()
|
||||
}
|
||||
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
#[cfg(feature = "webgpu")]
|
||||
pub fn flush_dirty_webgpu_canvases(&self) {
|
||||
self.dirty_webgpu_contexts
|
||||
pub fn update_rendering_of_webgpu_canvases(&self) {
|
||||
self.webgpu_contexts
|
||||
.borrow_mut()
|
||||
.drain()
|
||||
.for_each(|(_, context)| context.update_rendering_of_webgpu_canvas());
|
||||
.iter()
|
||||
.filter_map(|(_, context)| context.root())
|
||||
.filter(|context| context.onscreen())
|
||||
.for_each(|context| context.update_rendering_of_webgpu_canvas());
|
||||
}
|
||||
|
||||
pub fn id_map(&self) -> Ref<HashMapTracedValues<Atom, Vec<Dom<Element>>>> {
|
||||
|
@ -3386,7 +3390,7 @@ impl Document {
|
|||
media_controls: DomRefCell::new(HashMap::new()),
|
||||
dirty_webgl_contexts: DomRefCell::new(HashMapTracedValues::new()),
|
||||
#[cfg(feature = "webgpu")]
|
||||
dirty_webgpu_contexts: DomRefCell::new(HashMapTracedValues::new()),
|
||||
webgpu_contexts: Rc::new(RefCell::new(HashMapTracedValues::new())),
|
||||
selection: MutNullableDom::new(None),
|
||||
animation_timeline: if pref!(layout.animations.test.enabled) {
|
||||
DomRefCell::new(AnimationTimeline::new_for_testing())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue