-
-
Notifications
You must be signed in to change notification settings - Fork 642
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
Use createImageBitmap when supported #650
Conversation
Bundle size report: Size Change: -32 B
ℹ️ View Details
|
Is this the only place that uses the offscreen camvas check? Can you think why offscreen was checked here? |
No, the OffscreenCanvas check is also used in the raster_dem_tile_source but in this case the check is relevant since the feature is used in the worker. For the getImage function however, I don't see any reason to check the OffscreenCanvas support here and to be reassured mapbox-gl-js relaxed the check too in this commit. Regarding the ImageBitmap support check that you wrote, you may be referring to this commit. I did not find any other occurrence of createImageBitmap in the code. |
Thanks for the clarification, in that case my comments are the following:
I got confused with Thanks! |
80893b7
to
fc980f9
Compare
|
Thanks!! Can we add some tests to this behavior? |
I just tried but it wasn't very convincing. The problem is that it's browser dependent and during unit test the createImageBitmap is not defined. We can mock it with something like Do you have any idea on how to test this? |
You can override |
fc980f9
to
24732b0
Compare
Change log entry? Please also tic the relevant checkboxes in the pr template to make sure this is not copied etc... |
24732b0
to
a3d3b24
Compare
When converting a byte buffer to a CanvasImageSource, maplibre uses either an ImageBitmap if supported or an HTMLImageElement as fallback.
HTMLImageElement has many flaws, such as the transparent pixel hack to avoid memory leaks. Therefore the ImageBitmap seems more reliable and is the preferred image source.
In order to load the byte buffer to an ImageBitmap the library checks if the feature is available on the browser. Currently the function checks if the function createImageBitmap is defined and if the OffscreenCanvas feature is available.
However the OffscreenCanvas is not required to create an ImageBitmap and on browsers like Firefox where createImageBitmap is supported but not OffscreenCanvas (which is still experimental), the image source falls back on HTMLImageElement.
This PR simply checks for the availability of the createImageBitmap function instead of the unneeded OffscreenCanvas feature.
Launch Checklist
maplibre-gl-js
changelog:<changelog>getImage uses createImageBitmap when supported (#650)</changelog>
.