canvas: Unify retrieving image data from the HTMLImageElement (#37809)

Currently, HTMLImageElement uses as an image source
(ImageBitmapSource, CanvasImageSource, TexImageSource)
in various canvas2D/WebGL operations, and there is a small
inconsistency in how we get the image data of the 'img' element:
usability checking and retrieving the image data from the image cache.

To simplify and avoid state inconsistency between the window's image
cache and the 'img' element, let's retrieve the image data (as a raster)
from the HTMLImageElement itself.

Testing: No expected changes in testing results, except the
'drawimage_svg_image_with_foreign_object_does_not_taint.html'
which is 'false' passed because drawing of the non supported vector
image
is silently skip instead of throwing the 'InvalidState' exception
anymore.

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This commit is contained in:
Andrei Volykhin 2025-07-02 11:13:30 +03:00 committed by GitHub
parent d5b6160119
commit d0579256bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 118 additions and 140 deletions

View file

@ -749,29 +749,3 @@ impl Convert<GLContextAttributes> for WebGLContextAttributes {
}
}
}
pub(crate) mod utils {
use net_traits::image_cache::ImageResponse;
use net_traits::request::CorsSettings;
use servo_url::ServoUrl;
use crate::dom::window::Window;
pub(crate) fn request_image_from_cache(
window: &Window,
url: ServoUrl,
cors_setting: Option<CorsSettings>,
) -> ImageResponse {
let image_cache = window.image_cache();
let result = image_cache.get_image(
url.clone(),
window.origin().immutable().clone(),
cors_setting,
);
match result {
Some(image) => ImageResponse::Loaded(image, url),
None => ImageResponse::None,
}
}
}