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

Handle SkColor creation from rgba tuple #2144

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

louix
Copy link
Contributor

@louix louix commented Jan 16, 2024

Skia.Color accepts number[], but the native constructor doesn't actually account for it.

In JsiSkColor::createCtor, if argument[0].isObject() (true for both Array and Float32Array), it's returned as is as the color value.

When the jsi::Value is made into to an SkColor in JsiSkColor::FromValue, the .buffer property (which is of course is not there on an array -- thus undefined) is attempted to be accessed.

I've added support here.

Orthogonally, have you considered using [r: number, g: number, b: number, a: number] instead of number[] for extra type saftey?

Resolves #2113

@louix
Copy link
Contributor Author

louix commented Jan 16, 2024

I've signed the cla. Bit weird it asks for an address.

@wcandillon
Copy link
Contributor

Thanks a lot I'm excited to sanitize the situation there. I added some tests for it at louix#1 but it seems to fail on Android.
I will look into it.

@louix louix force-pushed the main branch 2 times, most recently from afa7967 to f69e537 Compare January 17, 2024 14:51
@louix
Copy link
Contributor Author

louix commented Jan 17, 2024

You were correct about 0-1 vs 0-255!
I changed the JSI side slightly to mimic the web one (Array become Float32Array), and added the offscreen canvas test.

The native side was just returning undefined if it wasn't sure how to handle the value, so you'd get an error where you tried to use the SkColor instead of when you created it.
I added an throw at creation time (and an exhaustive one to the web side to match).

}
return jsi::Value::undefined();
throw jsi::JSError(runtime,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that's fair

@wcandillon
Copy link
Contributor

@louix please give me a bit of time to digest this. Recent work we've done may suggest we need to slightly change how colors are dealt with behind the scene.

@wcandillon
Copy link
Contributor

but either way the tests you've written will be very useful.

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 this pull request may close these issues.

skPaint.setColor throws an error if you pass array of numbers to Skia.Color
2 participants