mirror of
https://github.com/servo/servo
synced 2026-05-09 00:22:16 +02:00
Reviewable per commits: As noted in https://github.com/servo/servo/pull/42180#discussion_r2749861902 transmuting `&Reflector<AssociatedMemory>` to `&Reflector<()>` will ignore AssociatedMemory information and thus it will not remove extra associated memory. By returning `&Reflector<Self::ReflectorType>` from `DomObject::reflector()` we will preserve this information and thus correctly handle cases with associated memory. We also do not need `overrideMemoryUsage` in bindings.conf anymore. 🎉 Instead of removing associated memory in drop code we should do it as part of finalizers, otherwise we have problems in nested (inherited) structs, where drop is run for both parent and child, but we only added associated memory for child (on init_reflector) which already included size of parent. The only exception here is promise, because it is RCed and not finalized. Testing: Tested locally that it fixes speedometer. Fixes #42269 --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
136 lines
4.5 KiB
Rust
136 lines
4.5 KiB
Rust
/* 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 std::cell::Cell;
|
|
|
|
use canvas_traits::webgl::{WebGLCommand, WebGLSyncId, webgl_channel};
|
|
use dom_struct::dom_struct;
|
|
|
|
use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as constants;
|
|
use crate::dom::bindings::inheritance::Castable;
|
|
use crate::dom::bindings::refcounted::Trusted;
|
|
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object};
|
|
use crate::dom::bindings::root::DomRoot;
|
|
use crate::dom::webgl::webglobject::WebGLObject;
|
|
use crate::dom::webgl::webglrenderingcontext::{Operation, WebGLRenderingContext};
|
|
use crate::script_runtime::CanGc;
|
|
|
|
#[dom_struct]
|
|
pub(crate) struct WebGLSync {
|
|
webgl_object: WebGLObject,
|
|
#[no_trace]
|
|
sync_id: WebGLSyncId,
|
|
marked_for_deletion: Cell<bool>,
|
|
client_wait_status: Cell<Option<u32>>,
|
|
sync_status: Cell<Option<u32>>,
|
|
}
|
|
|
|
impl WebGLSync {
|
|
fn new_inherited(context: &WebGLRenderingContext, sync_id: WebGLSyncId) -> Self {
|
|
Self {
|
|
webgl_object: WebGLObject::new_inherited(context),
|
|
sync_id,
|
|
marked_for_deletion: Cell::new(false),
|
|
client_wait_status: Cell::new(None),
|
|
sync_status: Cell::new(None),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn new(context: &WebGLRenderingContext, can_gc: CanGc) -> DomRoot<Self> {
|
|
let (sender, receiver) = webgl_channel().unwrap();
|
|
context.send_command(WebGLCommand::FenceSync(sender));
|
|
let sync_id = receiver.recv().unwrap();
|
|
|
|
reflect_dom_object(
|
|
Box::new(WebGLSync::new_inherited(context, sync_id)),
|
|
&*context.global(),
|
|
can_gc,
|
|
)
|
|
}
|
|
}
|
|
|
|
impl WebGLSync {
|
|
pub(crate) fn client_wait_sync(
|
|
&self,
|
|
context: &WebGLRenderingContext,
|
|
flags: u32,
|
|
timeout: u64,
|
|
) -> Option<u32> {
|
|
match self.client_wait_status.get() {
|
|
Some(constants::TIMEOUT_EXPIRED) | Some(constants::WAIT_FAILED) | None => {
|
|
let this = Trusted::new(self);
|
|
let context = Trusted::new(context);
|
|
let task = task!(request_client_wait_status: move || {
|
|
let this = this.root();
|
|
let context = context.root();
|
|
let (sender, receiver) = webgl_channel().unwrap();
|
|
context.send_command(WebGLCommand::ClientWaitSync(
|
|
this.sync_id,
|
|
flags,
|
|
timeout,
|
|
sender,
|
|
));
|
|
this.client_wait_status.set(Some(receiver.recv().unwrap()));
|
|
});
|
|
self.global()
|
|
.task_manager()
|
|
.dom_manipulation_task_source()
|
|
.queue(task);
|
|
},
|
|
_ => {},
|
|
}
|
|
self.client_wait_status.get()
|
|
}
|
|
|
|
pub(crate) fn delete(&self, operation_fallibility: Operation) {
|
|
if self.is_valid() {
|
|
self.marked_for_deletion.set(true);
|
|
self.upcast().send_with_fallibility(
|
|
WebGLCommand::DeleteSync(self.sync_id),
|
|
operation_fallibility,
|
|
);
|
|
}
|
|
}
|
|
|
|
pub(crate) fn get_sync_status(
|
|
&self,
|
|
pname: u32,
|
|
context: &WebGLRenderingContext,
|
|
) -> Option<u32> {
|
|
match self.sync_status.get() {
|
|
Some(constants::UNSIGNALED) | None => {
|
|
let this = Trusted::new(self);
|
|
let context = Trusted::new(context);
|
|
let task = task!(request_sync_status: move || {
|
|
let this = this.root();
|
|
let context = context.root();
|
|
let (sender, receiver) = webgl_channel().unwrap();
|
|
context.send_command(WebGLCommand::GetSyncParameter(this.sync_id, pname, sender));
|
|
this.sync_status.set(Some(receiver.recv().unwrap()));
|
|
});
|
|
self.global()
|
|
.task_manager()
|
|
.dom_manipulation_task_source()
|
|
.queue(task);
|
|
},
|
|
_ => {},
|
|
}
|
|
self.sync_status.get()
|
|
}
|
|
|
|
pub(crate) fn is_valid(&self) -> bool {
|
|
!self.marked_for_deletion.get()
|
|
}
|
|
|
|
pub(crate) fn id(&self) -> WebGLSyncId {
|
|
self.sync_id
|
|
}
|
|
}
|
|
|
|
impl Drop for WebGLSync {
|
|
fn drop(&mut self) {
|
|
self.delete(Operation::Fallible);
|
|
}
|
|
}
|