This is last step toward enabling the default rustc
`unsafe_op_in_unsafe_fn` warning for the script crate. It wraps the
remaining unsafe code in `unsafe {}` and removes the line disabling this
warning from `script`'s `Cargo.toml`. In addition, two variables are
renamed from `v` to something slightly more descriptive.
Testing: This should not change behavior so is covered by existing
tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.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>
Canvas expects input data to be in RGBA premultiplied format and
WebRender already supports RGBA and BGRA data as long as they are
premultiplied. Pre-multiplying up front allows:
- Avoiding many conversions when painting images to canvas.
- Passing the `RasterImage` IpcSharedMemory of the image instead of
creating
a new one with the premultiplied data every time we upload to
WebRender. This is a big deal for animated gifs, because before every
frame was creating a new shared memory segment.
It seems that for rasterized SVGs were were already putting
premultplied data into the `RasterImage` so it's quite likely SVGs were
being composited incorrectly.
Testing: This causes 8 tests to start passing and 2 tests to fail in the
WebGL conformance suite.
The failures are due to the fact that premultiplying alpha is lossy when
alpha is 0. In that case,
the resulting color of a blend operation might be wrong. This is
typically only a problem if you
use RGBA data as RGB data, which is pretty unusual. In the case that you
are blending with
RGBA the final color values will be 0 or close to 0 anyway. Gecko solves
this issue by having a
cacheable surface generation API that can fetch both premulitplied and
unpremulitplied data
from things like image elements. We do not have that yet, but I argue
that this change
is important anyway due to the amount that it reduces memory and file
descriptor usage
as well as the cost of copying image data so much in memory.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This splits `Snapshot` into two structs:
- `Snapshot`: A non-serializable owned image buffer that might contain
either shared memory or a `Vec<u8>`. When mutated the shared memory
version is converted into a `Vec<u8>` avoiding a copy of the data
until absolutely necessary.
- `SharedSnapshot`: A serialzable version of `Snapshot` that contains
only shared memory and is suitable for sending across IPC channels.
This version is cheaply convertible from and to owned `Snapshot`s as
long as the source is also a shared memory `Snapshot`.
In addition, it does copyless conversions of `RasterImage` into
`Snapshot`s (including for frame offsets in animated images). Finally,
there are a few minor changes to try harder not to have to do a
`transform()` operation.
Testing: This should not change observable behavior, so is covered by
existing
tests. It should come with a mild performance improvement and open up
the
opportunity for others.
Fixes: #36594.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
I think this is the correct solution? GlobalScope::get_cx() doesn't take
a self parameter anymore.
Testing: WebGL tests should suffice.
Fixes: #39228
Signed-off-by: lumiscosity <averyrudelphe@gmail.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>
Adds epoch to each WR image op command that is sent to compositor. The
renderer now has a `FrameDelayer` data structure that is responsible for
tracking when a frame is ready to be displayed. When asking canvases to
update their rendering, they are given an optional `Epoch` which denotes
the `Document`'s canvas epoch. When all image updates for that `Epoch`
are seen in the renderer, the frame can be displayed.
Testing: Existing WPT tests
Fixes: #35733
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Move interfaces defined by the WebGL spec to the `script/dom/webgl/
`module from `script/dom/`.
`script/dom/webgl*.rs` -> `script/dom/webgl/`
`script/dom/webgl_extensions` -> `script/dom/webgl/extensions`
`script/dom/webgl_validations` -> `script/dom/webgl/validations`
Testing: No changes, just a refactoring
Fixes (partially): #38901
Signed-off-by: Andrei Volykhin <volykhin.andrei@huawei.com>
Co-authored-by: Andrei Volykhin <volykhin.andrei@huawei.com>