Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl Hash+Eq for GradientStop #450

Closed
raphlinus opened this issue Jun 24, 2021 · 2 comments · Fixed by #454
Closed

impl Hash+Eq for GradientStop #450

raphlinus opened this issue Jun 24, 2021 · 2 comments · Fixed by #454

Comments

@raphlinus
Copy link
Contributor

I'm implementing gradients in piet-gpu, and one of the things I'm running into is being able to determine whether a gradient ramp is new or already in the cache. There are a number of ways to deal with this, but the most direct is to impl Hash on GradientStop, so it can be used as a key in a hashmap.

This is messy, because a gradient stop contains a float, and also because it means we have to hash color, but I think it's worth it.

Opening an issue first in case people want to discuss.

@cmyr
Copy link
Member

cmyr commented Jun 27, 2021

Actually implementing Eq is the tricky part here, we'd have to decide what that means? I find in general with this sort of thing what I tend to be interested in is a very strict form of equality, approximately equal to, "is this thing a clone or bitwise copy of that thing"? In which case defining Eq in terms of bitwise equality of underlying floats seems reasonable to me.

@raphlinus
Copy link
Contributor Author

Yes, I was thinking bitwise. The actual thing I care about is "will generate an identical GPU-side representation" for which bitwise is appropriate.

raphlinus added a commit that referenced this issue Jun 27, 2021
Implement Hash and Eq traits on gradient stops, which implies doing the
same for colors. This facilitates creating a cache of baked gradient
ramps.

Closes #450
raphlinus added a commit that referenced this issue Jun 28, 2021
Implement Hash and Eq traits on gradient stops, which implies doing the
same for colors. This facilitates creating a cache of baked gradient
ramps.

Closes #450
JAicewizard pushed a commit to JAicewizard/piet that referenced this issue Jun 29, 2021
Implement Hash and Eq traits on gradient stops, which implies doing the
same for colors. This facilitates creating a cache of baked gradient
ramps.

Closes linebender#450
cmyr pushed a commit that referenced this issue Jul 1, 2021
* make image formats optional via features

* make sure image is also imported when importing an image format

* make the features propperly formatted

* fix merge

* Move cairo over to 0.14 version

* Fix clippy issues

* Fix weird addition

* Remove snapshots

* Fix tests

* Fix CI

* Make piet-cairo almost unwrap free

* Make gradient stops hashable (#454)

Implement Hash and Eq traits on gradient stops, which implies doing the
same for colors. This facilitates creating a cache of baked gradient
ramps.

Closes #450

* [cairo] Fix for big-endian systems

Cairo defines pixels as "a 32-bit quantity [...] stored in
native-endian". However, the existing code was treating a pixel as four
8-bit quantities. Put differently, it was hardcoding little endian.

This commit changes the code to first calculate the pixel value as an
u32 and then use u32::to_ne_bytes() to get back to "the world of bytes".
For readability, this is done in a new helper function.

I did not actually check if this fixes anything on big endian, but at
least it does not change anything for little endian according to the
test-pictures examples.

Fixes: #224
Signed-off-by: Uli Schlachter <[email protected]>

* Remove unnecessary dst_off parameter

Signed-off-by: Uli Schlachter <[email protected]>

* Fix clippy warning about single-character names

error: 5 bindings with single-character names in scope
Error:    --> piet-cairo/src/lib.rs:523:47
    |
523 | fn write_rgba(data: &mut [u8], offset: usize, x: usize, r: u8, g: u8, b: u8, a: u8) {
    |                                               ^         ^      ^      ^      ^
    |
    = note: `-D clippy::many-single-char-names` implied by `-D warnings`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names

Signed-off-by: Uli Schlachter <[email protected]>

* Add a simple criterion benchmark

This adds a simple benchmark for piet-cairo's make_image function.

Signed-off-by: Uli Schlachter <[email protected]>

* Fill benchmark image with random data

Signed-off-by: Uli Schlachter <[email protected]>

* Make rustfmt happy

Signed-off-by: Uli Schlachter <[email protected]>

* Try to clarify docs for ImageFormat

The image format is based on individual bytes and thus independent of
the system's endianness. This commit tries to make that more explicit.

This was originally suggested in issue #224.

Signed-off-by: Uli Schlachter <[email protected]>

* Fix issue with benchmarks

* Remove redefinition

* Add safety comment

Co-authored-by: Raph Levien <[email protected]>
Co-authored-by: Uli Schlachter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants