Commit graph

9 commits

Author SHA1 Message Date
sagudev
e0af75f265
canvas: Do not draw arc/ellipse with small sweep (#37630)
While raqote does already passes this test, but small line is still
visible and this PR will fix this. Vello will not work correctly without
this.


![slika](https://github.com/user-attachments/assets/195cd2c8-bea4-46d8-bf34-9c2d0b2e996e)


Testing: `/html/canvas/element/path-objects/2d.path.arc.twopie.1.html`

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-07-01 12:01:15 +00:00
sagudev
4974b4a1f6
canvas: Remove rect -> line handling (#37664)
This causes wrong rendering on vello. Current backends already handle
one dim zero correctly by themself (this was probably needed for azure),
but if we ever needed this, it should be implemented inside faulty
backend.

Testing: Existing WPT tests

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-06-24 14:13:58 +00:00
sagudev
e0f3679d55
canvas: Pass pattern by ref (#37662)
We pass all other options as ref too.

Testing: Just refactor, but the code is covered by WPT tests.

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-06-24 05:20:38 +00:00
sagudev
f370606fa8
canvas: Make draw_options non optional in fill_rect (#37603)
All other draw functions already have them non-optional and we always
passed `Some` anyway.

Testing: Existing WPT tests

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-06-21 09:34:28 +00:00
sagudev
c01f65affb
canvas: Use Cow<[u8]> for bytes() getter (#37249)
I fell into trap of over-generalization in
https://github.com/servo/servo/pull/36793, but
https://github.com/servo/servo/pull/36821 showed `Cow<[u8]>` is all we
need (to reuse existing vec alloc or pass on a slice).

Testing: There are WPT tests, but it's just refactor so rust keeps us
safe.
Split of https://github.com/servo/servo/pull/36821

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-06-04 15:16:28 +00:00
sagudev
fdb9c0af12
canvas: Move generic implementations into GenericPathBuilder trait (#36999)
There is no reason to require this impls, because we already have
written them in generic way.

Testing: Just refactoring, but there are WPT tests

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-05-14 03:51:56 +00:00
sagudev
5cdb0865ba
canvas: rename snapshot(_data) to surface() -> SourceSurface/bytes() -> AsRef<[u8]> (#36793)
`surface()` returns `SourceSurface` which is/was meant as optimization
when passing from canvas to canvas (in vello that would be wgpu texture;
but raquote does not really have this) while bytes returns something
that must impl AsRef<[u8]> (this is more generic then `&[u8]` as it
allows us to have type with drop impl - wgpu's BufferView).

Testing: This is just refactoring (protected by rust), but there are WPT
tests.

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-05-01 14:18:56 +00:00
sagudev
d1f7a90619
canvas: Move CompositionOrBlending and ellipse() from RaqoteBackend to Backend (#36790)
Small fixes of abstraction.

We do not need to generalize `CompositionOrBlending`, because it's from
canvas_traits.
Ellipse impl that uses arc is not backend specific, so it serves as good
trait default.

Reviewable per commit.


Testing: Only refactoring, but there are WPT tests

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-05-01 09:57:20 +00:00
sagudev
be0f4470c7
Use backend trait with associated types for 2d canvas backends abstraction (#36783)
Current abstraction was leaky and very hard to understand/impl because
it was so intervened with actual implementation.

Now we generalize both `CanvasState` and `CanvasData` over `B: Beckend`,
meaning that every type/method must be part of trait interface (that
lives in `beckend.rs`). Using associated trait types instead of `Box<dyn
>` allows us too remove the need for wrapper types (and `to_raquote()`
methods) as we can implement helper traits on (foreign) raquote types.
The only time we actually do dispatch (by enum) is at `Canvas` methods.

Implementation now only need to implement all backend traits and
helpers. I tried to restrain myself from actually cleaning abstraction
(where possible), to keep this change as much mechanical as possible,
but we should absolutely do that as a follow up.

Testing: Rust as we only do refactor, but there are also WPT tests

try run: https://github.com/sagudev/servo/actions/runs/14760658522

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-05-01 04:16:23 +00:00