compositor: only UpdateImages that accepts SmallVec and add helpers for single image (#37730)

Before we only offered helper to add single image (no update or delete)
that got special IPC message, now we simplify this by offering all ops
helpers for dealing with single image (that happens most of the time),
that simply uses `update_images` under the hood. We also optimize for
this use case by using `SmallVec<[ImageUpdate; 1]>` to avoid alloc.

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

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev 2025-06-26 16:57:15 +02:00 committed by GitHub
parent 3c16db2642
commit 4dded465a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 36 additions and 42 deletions

View file

@ -17,6 +17,7 @@ use ipc_channel::ipc::IpcSender;
use log::warn;
use malloc_size_of_derive::MallocSizeOf;
use pixels::RasterImage;
use smallvec::SmallVec;
use strum_macros::IntoStaticStr;
use style_traits::CSSPixel;
use webrender_api::DocumentId;
@ -147,10 +148,8 @@ pub enum CompositorMsg {
/// Create a new image key. The result will be returned via the
/// provided channel sender.
GenerateImageKey(IpcSender<ImageKey>),
/// Add an image with the given data and `ImageKey`.
AddImage(ImageKey, ImageDescriptor, SerializableImageData),
/// Perform a resource update operation.
UpdateImages(Vec<ImageUpdate>),
UpdateImages(SmallVec<[ImageUpdate; 1]>),
/// Generate a new batch of font keys which can be used to allocate
/// keys asynchronously.
@ -307,13 +306,24 @@ impl CrossProcessCompositorApi {
descriptor: ImageDescriptor,
data: SerializableImageData,
) {
if let Err(e) = self.0.send(CompositorMsg::AddImage(key, descriptor, data)) {
warn!("Error sending image update: {}", e);
}
self.update_images([ImageUpdate::AddImage(key, descriptor, data)].into());
}
pub fn update_image(
&self,
key: ImageKey,
descriptor: ImageDescriptor,
data: SerializableImageData,
) {
self.update_images([ImageUpdate::UpdateImage(key, descriptor, data)].into());
}
pub fn delete_image(&self, key: ImageKey) {
self.update_images([ImageUpdate::DeleteImage(key)].into());
}
/// Perform an image resource update operation.
pub fn update_images(&self, updates: Vec<ImageUpdate>) {
pub fn update_images(&self, updates: SmallVec<[ImageUpdate; 1]>) {
if let Err(e) = self.0.send(CompositorMsg::UpdateImages(updates)) {
warn!("error sending image updates: {}", e);
}