mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Add a basic caching mechanism for ImageKeys. (#37369)
This creates a new method in shared/compositing/lib to generate image keys that are send over the webview. This does not immediately return the keys but goes over the constellation to receive the keys from the IOCompositor. To make this more efficient, we now cache the keys in image_cache in a simple FIFO order. The old blocking method stays intact for now but got renamed to make the blocking clear. The blocking calls that are left are in: - `components/canvas/canvas_data.rs` - `components/script/dom/htmlmediaelement.rs` Testing: WPT tests should cover this as this doesn't change any functionality. Fixes: Was mentioned in https://github.com/servo/servo/issues/37161#issuecomment-2915750051 and part of https://github.com/servo/servo/issues/37086 --------- Signed-off-by: Narfinger <Narfinger@users.noreply.github.com> Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com> Co-authored-by: gterzian <2792687+gterzian@users.noreply.github.com>
This commit is contained in:
parent
89bfa26f00
commit
ca47cc2fa3
31 changed files with 392 additions and 70 deletions
|
@ -148,6 +148,9 @@ pub enum CompositorMsg {
|
|||
/// Create a new image key. The result will be returned via the
|
||||
/// provided channel sender.
|
||||
GenerateImageKey(IpcSender<ImageKey>),
|
||||
/// The same as the above but it will be forwarded to the pipeline instead
|
||||
/// of send via a channel.
|
||||
GenerateImageKeysForPipeline(PipelineId),
|
||||
/// Perform a resource update operation.
|
||||
UpdateImages(SmallVec<[ImageUpdate; 1]>),
|
||||
|
||||
|
@ -294,12 +297,24 @@ impl CrossProcessCompositorApi {
|
|||
}
|
||||
|
||||
/// Create a new image key. Blocks until the key is available.
|
||||
pub fn generate_image_key(&self) -> Option<ImageKey> {
|
||||
pub fn generate_image_key_blocking(&self) -> Option<ImageKey> {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.0.send(CompositorMsg::GenerateImageKey(sender)).ok()?;
|
||||
receiver.recv().ok()
|
||||
}
|
||||
|
||||
/// Sends a message to the compositor for creating new image keys.
|
||||
/// The compositor will then send a batch of keys over the constellation to the script_thread
|
||||
/// and the appropriate pipeline.
|
||||
pub fn generate_image_key_async(&self, pipeline_id: PipelineId) {
|
||||
if let Err(e) = self
|
||||
.0
|
||||
.send(CompositorMsg::GenerateImageKeysForPipeline(pipeline_id))
|
||||
{
|
||||
warn!("Could not send image keys to Compositor {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_image(
|
||||
&self,
|
||||
key: ImageKey,
|
||||
|
|
|
@ -30,8 +30,8 @@ use serde::{Deserialize, Serialize};
|
|||
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||
pub use structured_data::*;
|
||||
use strum_macros::IntoStaticStr;
|
||||
use webrender_api::ExternalScrollId;
|
||||
use webrender_api::units::LayoutVector2D;
|
||||
use webrender_api::{ExternalScrollId, ImageKey};
|
||||
|
||||
/// Messages to the Constellation from the embedding layer, whether from `ServoRenderer` or
|
||||
/// from `libservo` itself.
|
||||
|
@ -94,6 +94,8 @@ pub enum EmbedderToConstellationMessage {
|
|||
EvaluateJavaScript(WebViewId, JavaScriptEvaluationId, String),
|
||||
/// Create a memory report and return it via the ipc sender
|
||||
CreateMemoryReport(IpcSender<MemoryReportResult>),
|
||||
/// Sends the generated image key to the image cache associated with this pipeline.
|
||||
SendImageKeysForPipeline(PipelineId, Vec<ImageKey>),
|
||||
}
|
||||
|
||||
/// A description of a paint metric that is sent from the Servo renderer to the
|
||||
|
|
|
@ -14,6 +14,7 @@ use pixels::{CorsStatus, ImageMetadata, RasterImage};
|
|||
use profile_traits::mem::Report;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||
use webrender_api::ImageKey;
|
||||
use webrender_api::units::DeviceIntSize;
|
||||
|
||||
use crate::FetchResponseMsg;
|
||||
|
@ -225,6 +226,10 @@ pub trait ImageCache: Sync + Send {
|
|||
/// Create new image cache based on this one, while reusing the existing thread_pool.
|
||||
fn create_new_image_cache(
|
||||
&self,
|
||||
pipeline_id: Option<PipelineId>,
|
||||
compositor_api: CrossProcessCompositorApi,
|
||||
) -> Arc<dyn ImageCache>;
|
||||
|
||||
/// Fills the image cache with a batch of keys.
|
||||
fn fill_key_cache_with_batch_of_keys(&self, image_keys: Vec<ImageKey>);
|
||||
}
|
||||
|
|
|
@ -251,6 +251,8 @@ pub enum ScriptThreadMessage {
|
|||
/// Evaluate the given JavaScript and return a result via a corresponding message
|
||||
/// to the Constellation.
|
||||
EvaluateJavaScript(PipelineId, JavaScriptEvaluationId, String),
|
||||
/// A new batch of keys for the image cache for the specific pipeline.
|
||||
SendImageKeysBatch(PipelineId, Vec<ImageKey>),
|
||||
}
|
||||
|
||||
impl fmt::Debug for ScriptThreadMessage {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue