- canvas
- constellation_traits
- canvas_traits
- constellation
Testing: This should not change any behaviour.
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Follow up of #43526. This addresses Nico's comment:
https://github.com/servo/servo/pull/43526#issuecomment-4104953308
- `bluetooth_traits` -> `servo_bluetooth_traits`
- `base` -> `servo_base`
- `bluetooth` -> `servo_bluetooth`
- `background_hang_monitor` -> `servo_background_hang_monitor`
Testing: This should not change any behaviour.
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Implementing `Drop` for DOM types is being forbidden. This moves the
resource cleanup logic for `GPUShaderModule`, `GPUTexture`, and
`GPUTextureView` to separate helper structs and removes the
`allowDropImpl` flag from the bindings configuration.
Testing: WebGpu tests just cover their cases
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Implementing `Drop` for DOM types is being forbidden. This moves the
resource cleanup logic for `GPUSampler` to a separate
`DroppableGPUSampler` struct and removes the `allowDropImpl` flag from
the bindings configuration.
Testing: WebGpu tests just cover its cases
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
This method is the same as `DOMString::from` with a `String` argument
and `From` and `Into` are preferred when writing modern Rust.
Testing: This should not change behavior and is thus covered by existing
tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Moves the `Drop` logic for `GPURenderPipeline` into a dedicated helper
struct, `DroppableGPURenderPipeline`.
The associated `Bindings.conf` entry is
removed as direct `Drop` is no longer needed for this type.
Testing: WebGpu tests just cover its cases
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Accepting the name of the event as a `DOMString` means that when events
are constructed from within Servo (for instance via input event
handling), the static strings are converted to an owned `String`
wrapped in a `DOMString` and then finally converted to an `Atom` in
`Event`. This makes it so that all non-generated `Event` constructors
accept `Atom`, which can avoid a conversion entirely when the atom
already exists on the Stylo atoms list and eliminate one in-memory copy
in the case that it isn't on the atom list.
Eventually, all event names can be on the atom list and we can eliminate
all copies. This is a tiny optimization, but also makes the code much
friendlier everywhere.
Testing: This should not change behavior so should be covered by
existing test.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Moves the `Drop` logic for `GPURenderPassEncoder` into a dedicated
helper struct, `DroppableGPURenderPassEncoder`. This ensures that DOM
types do not directly implement `Drop`, aligning with the policy for
resource management in the DOM. The associated `Bindings.conf` entry is
removed as direct `Drop` is no longer needed for this type.
Testing: WebGPU tests just cover its cases
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Moves the `Drop` logic for `GPURenderBundle` into a dedicated helper
struct, `DroppableGPURenderBundle`. This change ensures that
`GPURenderBundle` itself does not directly implement `Drop`, aligning
with the policy to prevent direct `Drop` implementations on DOM types.
Removes the `allowDropImpl` configuration for `GPURenderBundle` from
script bindings.
Testing: WebGPU tests cover all related cases
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Moves the `Drop` implementation for `GPUPipelineLayout` to a dedicated
private helper struct, `DroppableGPUPipelineLayout`. This ensures that
DOM types do not directly implement `Drop`, aligning with best practices
for resource management in the DOM. The associated `Bindings.conf` entry
is removed as direct `Drop` is no longer needed for this type.
Testing: WebGpu just coverages cases with proper tests
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Moves the `Drop` implementation for `GPUDevice` into a private
`DroppableGPUDevice` struct.
Also updates `Bindings.conf` to prevent the generation of `Drop`
implementations for `GPUDevice`.
Testing: WebGpu tests just cover the cases
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Moves the drop implementation for `GPUComputePipeline` to a separate
`DroppableGPUComputePipeline` struct.
Removes `allowDropImpl` from the bindings configuration.
Testing: No tests added because of webgpu tests existent coverage
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Moves the drop logic for `GPUComputePassEncoder` to a separate
`DroppableGPUComputePassEncoder` struct.
Testing: Tests that coverages webgpu just exist
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Continuation of https://github.com/servo/servo/pull/42135, switch
Error::Type and Error::Range to also use CStrings internally, as they
are converted to CString for throwing JS exceptions (other get thrown as
DomException object, which uses rust string internally).
Changes in script crate are mechanical.
Testing: Should be covered by WPT tests.
Part of #42126
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Implement MallocSizeOf for most of WebXr. Mostly uncontroversal changes.
Of note:
- Implementation of size_of for euclid::RigidTransform
- Implementation of size_of for euclid::Vector3D
- Join is currently ignored as the type is very complicated.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
*Describe the changes that this pull request makes here. This will be
the commit message.*
Testing: Compilation is the test.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Moves the `Drop` implementation for `GPUCommandBuffer` to a separate
struct, `DroppableGPUCommandBuffer`. Updates bindings config to remove
`allowDropImpl` which is no longer needed.
Testing: No tests added
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
We implemented many more MallocSizeOf tests (even if some such as
channels are zero).
Meaning we can not ignore more of it making the code cleaner.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Testing: Compilation is the test.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
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>
By reporting memory usage of rust objects back to SM it can trigger GC
sooner and release more memory (I hope that we could use this to avoid
OOB in webgpu in the future).
Currently we use simple `size_of::<DomStruct>() +
size_of::<Box<DomStruct>>()` but it's possible to override reported
memory with `update_memory_size(self, nbytes);` on reflector. This is
mostly useful for canvases and buffers which usually have large
associated data.
Testing: None, but I am wondering if we can connect this to
`about:memory`.
Fixes: #42168
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Moves the `Drop` implementation for `GPUCanvasContext` to a new
`DroppableGPUCanvasContext` struct.
This ensures the context destruction logic is correctly handled, as the
`GPUCanvasContext` struct itself is a DOM struct and should not have a
drop implementation. This change aligns with the requirement that DOM
types should not implement Drop.
Testing: No tests added
Fixes: #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Moves the drop logic for `GPUBindGroupLayout` to an inner struct
`DroppableGPUBindGroupLayout`.
Testing: No tests added
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Moves the drop implementation for `GPUBindGroup` to a separate
`DroppableGPUBindGroup` struct.
Testing: No tests added
Fixes: partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Moves the adapter dropping logic from the `GPUAdapter` struct to a new
`DroppableGPUAdapter` struct.
Testing: No tests added.
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
This changes routed_promise to use the GenericCallback functionality.
This mostly effected WebGPU but also Clipboard and Memory Reporting.
We also added a GenericCallback::new_blocking() functionality which
produces a callback and a channel
which then can be blocked on. This was used a couple of times in the
code.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Testing: This should not change functionality.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Changed most #[allow]s to #[expect]s, mainly for
clippy::too_many_arguments
Removed unfulfilled expectations
This is my first opensource contribution, so please let me know if
anything should
be done differently.
Testing: Refactor
Part of: #40838
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: TimurBora <timurborisov5561@gmail.com>
Co-authored-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
In the future, servo components should depend on the generic channels in
base instead of IpcChannels to correctly optimize for multiprocess vs
non-multiprocess mode.
This reexports IpcSharedMemory as GenericSharedMemory in GenericChannel
and changes all dependencies on it.
Currently this is only a type/name change and does not change
functionality. But in the future we would want want to use non-ipc
things for the data.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Testing: This changes types and does not need testing.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
There are two flavours of the mozjs `TypedArray<T>` wrapper for typed
array objects: one stores a `Box<Heap<*mut JSObject>>`, while the other
just has a bare `*mut JSObject`. The second one must only be stored
inside the `CustomAutoRoot` rooting values, but we were using it in many
other places like WebIDL dictionaries without rooting it safely. These
changes make our typed array APIs always use
`RootedTraceableBox<TypedArray<T>>` with the `Box<Heap<*mut JSObject>>`
flavour, which ensures that the JS object stored inside the typed array
wrapper is always visible to the SpiderMonkey GC.
Testing: Adds a new test that crashes without these changes.
Fixes: #41206
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Changed some allow to expects and removed the unfulfilled expectations.
Testing: Refactor
Part of: #40383
Signed-off-by: anonmiraj <nabilmalek48@gmail.com>
I used find and replace to finish the job. All this PR does is replace
all `Error::<error_name>` occurrences with `Error::<error_name>(None)`.
Testing: Refactor
Fixes: #39053
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Removes some unneeded lints, especially `#[allow(unsafe_code)]`.
Testing: Refactor
Part of: #40383
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
This change makes it so that the `HTMLCanvasElement` is responsible for
managing the `ImageKey` for associated `RenderingContext`s. Only
canvases display their contents into WebRender directly, so this makes
it so that keys are not generated for `OffscreenCanvas`.
The main goal here is that `ImageKey`s are always associated with a
particular `WebView`, which isn't possible in the various canvas
backends yet. This is important because each `WebView` may soon have a
different WebRender instance entirely with its own set of `ImageKey`s.
This also allows for clearing `ImageKey`s when canvases are disconnected
from the DOM in a future change. One tricky thing here is placeholder
canvases, which are meant to be driven from workers.
It seems that the implementation isn't correct for these at the moment
as they need to be updated to the specification. Instead, what is
happening is that any existing context / image is completely lost when
converting to an `OffscreenCanvas`.
Testing: This shouldn't change observable behavior, so is covered by
existing tests.
Fixes: This is part of #40261.
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Servo has a lot of comments like this:
```rust
// https://example-spec.com/#do-the-thing
fn do_the_thing() {}
```
and I keep turning these into doc comments whenever I'm working close to
one of them. Doing so allows me to hover over a function call in an IDE
and open its specification without having to jump to the function
definition first. This change fixes all of these comments at once.
This was done using `find components -name '*.rs' -exec perl -i -0777
-pe 's|^([ \t]*)// (https?://.*)\n\1(fn )|\1/// <$2>\n\1$3|mg' {} +`.
Note that these comments should be doc comments even within trait `impl`
blocks, because rustdoc will use them as fallback documentation when the
method definition on the trait does not have documentation.
Testing: Comments only, no testing required
Preparation for https://github.com/servo/servo/pull/39552
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
According to the WebGPU specification there are some missing readonly
attributes (subgroupMinSize, subgroupMaxSize, isFallbackAdapter) for
GPUAdapterInfo IDL interface.
See https://gpuweb.github.io/gpuweb/#gpuadapterinfo
Added the new readonly attributes:
- GPUAdapter 'info' attribute
https://gpuweb.github.io/gpuweb/#dom-gpuadapter-info
- GPUDevice 'adapterInfo' attribute
https://gpuweb.github.io/gpuweb/#dom-gpudevice-adapterinfo
Removed marked as the deprecated the following method and attribute from
GPUAdapter interface:
- 'requestAdapterInfo' method
- 'isFallbackAdapter' attribute
Testing: Improvements in WebGPU CTS expectations
- webgpu:api,operation,adapter,info:adapter_info:*
- webgpu:api,operation,adapter,info:device_matches_adapter:*
- webgpu:api,operation,adapter,info:same_object:*
- webgpu:api,operation,adapter,info:subgroup_sizes:*
- webgpu:api,operation,adapter,requestAdapter:requestAdapter:*
- webgpu:idl,javascript:*
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This implements LazyDOMString (from now on DOMString) as outlined in
https://github.com/servo/servo/issues/39479.
Constructing from a *mut JSString we keep the in a
RootedTraceableBox<Heap<*mut JSString>> and transform
the string into a rust string if necessary via the `make_rust_string`
method.
Methods used in script are implemented on this string. Currently we
transform the string at all times.
But in the future more efficient implementations are possible.
We implement the safety critical sections in a separate module
DOMStringInner which allows simple constructors, `make_rust_string` and
the `bytes` method.
This method returns the new type `EncodedBytes` which contains the
reference to the underlying string in either format.
Testing: WPT tests still seem to work, so this should test this
functionality.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This updates all Rc that were ignored for malloc_size_of to use
conditional_malloc_size_of, unless the type in the Rc itself doesn't
support malloc_size.
Regular expressions used to search for all occurrences:
```
ignore_malloc_size_of = "Rc.*"
ignore_malloc_size_of = "Arc.*"
```
There are a couple left since they have nested Rc, which I don't know
how to fix.
To be able to define these, several new implementations were added to
`malloc_size_of/lib.rs` as well as
`HashMapTracedValues`.
Testing: if it compiles, it's safe
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Add a new super-lightweight layout mode that avoids any layout when
canvas is updated or animated images progress to the next frame. In the
future this can also be used for video elements.
Testing: This is a performance optimization, so shouldn't change any
WPT test results.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Adding an optional message to be attached to an InvalidStateError.
Testing: Only a refactor, no behavior change
Fixes: Partially #39053
Signed-off-by: Excitable Snowball <excitablesnowball@gmail.com>
This is part of the future work of implementing LazyDOMString as
outlined in issue #39479.
We use str() method or direct implementations on DOMString for these
methods. We also change some types.
This is independent of https://github.com/servo/servo/pull/39480
Signed-off-by: Narfinger Narfinger@users.noreply.github.com
Testing: This is essentially just renaming a method and a type and
should not change functionality.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Vello has updated to wgpu v26 recently. It might be a good time for
servo to update as well. This PR should wait for #39015 and #38717
Testing: WebGPU CTS
Fixes: None
---------
Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>
There are many important changes here:
- Generalize the presentation buffer into standalone staging buffers
that hold their own state. This allow them to be used by getImage.
- Move all clear handling to the ScriptThread and send the configuration
on each request present/getimage, thus avoiding any recreate/clearing
messages. This means that we prepare staging buffers lazily, on the
first request.
Try run for this change:
https://github.com/sagudev/servo/actions/runs/17341982368
Testing: This is covered by existing WebGPU CTS tests. There are some
bad expectations updates, but they are also on main (presumably from
last update the rendering work) although I think CTS is actually wrong
(see https://github.com/gpuweb/cts/issues/4440).
Fixes: #36820Fixes: #37705Fixes: #33368 (we now keep reference alive in hashmap)
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Any RenderingContext/OffscreenRenderingContext type has readonly
"canvas" attribute
and associated native-code DOM context objects have reference to target
DOM canvas objects.
https://html.spec.whatwg.org/multipage/canvas.html#renderingcontexthttps://html.spec.whatwg.org/multipage/canvas.html#offscreenrenderingcontext
And currently the reference to DOM canvas object is the rooting pointer
on the stack,
which leads to the circular reference problem.
The SpiderMonkey's (SM) garbage collector will not be able to free the
DOM canvas and context
objects (unreacheble from JS) because of the rooting pointer on stack
(see STACK_ROOTS).
And these objects will be stored until the associated script
runtime/thread will be terminated.
SM -> JS Roots -> DOM Canvas* (on heap) -> DOM Context (on heap)
SM -> Rust Roots -> Dom Canvas* (on stack) <- as "canvas" member field
Let's replace the rooting pointer to the traceble pointer (DomRoot ->
Dom)
in the "canvas" member field of DOM context object, which allows to
broke circular referencing problem.
Testing: No changes in existed tests
Signed-off-by: Andrei Volykhin <volykhin.andrei@huawei.com>
Co-authored-by: Andrei Volykhin <volykhin.andrei@huawei.com>
According to the WebGPU specification there are the dedicated task
source
which is used to queue a global task for a GPUDevice on content
timeline.
https://gpuweb.github.io/gpuweb/#-webgpu-task-source
Tasks on content timeline:
- to fire "uncaptureevent" event
- to resolve GPUDevice.lost promise
Also fixed the "isTrusted" attribute status (false -> true) of the
"uncaptureevent" event by using non JS version of event dispatching.
Testing: No changes in WebGPU CTS expectations
- webgpu:api,operation,uncapturederror:*
- webgpu:api,operation,device,lost:*
- webgpu:api,validation,state,device_lost,destroy:*
Signed-off-by: Andrei Volykhin <volykhin.andrei@huawei.com>
Co-authored-by: Andrei Volykhin <volykhin.andrei@huawei.com>