pub struct Paint {Show 15 fields
painters: Vec<Rc<RefCell<Painter>>>,
pub(crate) paint_proxy: PaintProxy,
pub(crate) event_loop_waker: Box<dyn EventLoopWaker>,
shutdown_state: Rc<Cell<ShutdownState>>,
paint_receiver: RoutedReceiver<PaintMessage>,
pub(crate) embedder_to_constellation_sender: Sender<EmbedderToConstellationMessage>,
webrender_external_image_id_manager: WebRenderExternalImageIdManager,
pub(crate) painter_surfman_details_map: PainterSurfmanDetailsMap,
pub(crate) busy_webgl_contexts_map: WebGLContextBusyMap,
webgl_threads: WebGLThreads,
pub(crate) swap_chains: SwapChains<WebGLContextId, Device>,
time_profiler_chan: ProfilerChan,
_mem_profiler_registration: ProfilerRegistration,
webxr_main_thread: RefCell<MainThreadRegistry>,
webgpu_image_map: OnceCell<WebGpuExternalImageMap>,
}Expand description
Paint is Servo’s rendering subsystem. It has a few responsibilities:
- Maintain a WebRender instance for each
RenderingContextthat Servo knows about.RenderingContexts are per-WebView, but more than oneWebViewcan use the sameRenderingContext. This allows multipleWebViews to share the same WebRender instance which is more efficient. This is useful for tabbed web browsers. - Receive display lists from the layout of all of the currently active
Pipelines (frames). These display lists are sent to WebRender, and new frames are generated. Once the frame is ready thePainterfor the WebRender instance will ask libservo to inform the embedder that a new frame is ready so that it can trigger a paint. - Drive animation and animation callback updates. Animation updates should ideally be
coordinated with the system vsync signal, so the
RefreshDriveris exposed in the API to allow the embedder to do this. ThePainterthen asks itsWebViews to update their rendering, which triggers layouts. - Eagerly handle scrolling and touch events. In order to avoid latency when handling
these kind of actions, each
Painterwill eagerly process touch events and perform panning and zooming operations on their WebRender contents – informing the WebView contents asynchronously.
Paint and all of its contained structs should never block on the Constellation,
because sometimes the Constellation blocks on us.
Fields§
§painters: Vec<Rc<RefCell<Painter>>>All of the [Painters] for this Paint. Each Painter handles painting to
a single RenderingContext.
paint_proxy: PaintProxyA PaintProxy which can be used to allow other parts of Servo to communicate
with this Paint.
event_loop_waker: Box<dyn EventLoopWaker>An EventLoopWaker used to wake up the main embedder event loop when the renderer needs
to run.
shutdown_state: Rc<Cell<ShutdownState>>Tracks whether we are in the process of shutting down, or have shut down and
should shut down Paint. This is shared with the Servo instance.
paint_receiver: RoutedReceiver<PaintMessage>The port on which we receive messages.
embedder_to_constellation_sender: Sender<EmbedderToConstellationMessage>The channel on which messages can be sent to the constellation.
webrender_external_image_id_manager: WebRenderExternalImageIdManagerThe WebRenderExternalImageIdManager used to generate new ExternalImageIds.
painter_surfman_details_map: PainterSurfmanDetailsMapA HashMap of PainterId to the Surfaman types (Device, Adapter) that
are specific to a particular Painter.
busy_webgl_contexts_map: WebGLContextBusyMapA HashMap of WebGLContextId to a usage count. This count indicates when
WebRender is still rendering the context. This is used to ensure properly clean
up of all Surfman Surfaces.
webgl_threads: WebGLThreadsThe WebGLThreads for this renderer.
swap_chains: SwapChains<WebGLContextId, Device>The shared SwapChains used by WebGLThreads for this renderer.
time_profiler_chan: ProfilerChanThe channel on which messages can be sent to the time profiler.
_mem_profiler_registration: ProfilerRegistrationA handle to the memory profiler which will automatically unregister when it’s dropped.
webxr_main_thread: RefCell<MainThreadRegistry>Some XR devices want to run on the main thread.
webgpu_image_map: OnceCell<WebGpuExternalImageMap>An map of external images shared between all WebGpuExternalImages.
Implementations§
Source§impl Paint
impl Paint
pub fn new(state: InitialPaintState) -> Rc<RefCell<Self>>
pub fn register_rendering_context( &mut self, rendering_context: Rc<dyn RenderingContext>, ) -> PainterId
fn remove_painter(&mut self, painter_id: PainterId)
pub(crate) fn maybe_painter<'a>( &'a self, painter_id: PainterId, ) -> Option<Ref<'a, Painter>>
pub(crate) fn painter<'a>(&'a self, painter_id: PainterId) -> Ref<'a, Painter>
pub(crate) fn maybe_painter_mut<'a>( &'a self, painter_id: PainterId, ) -> Option<RefMut<'a, Painter>>
pub(crate) fn painter_mut<'a>( &'a self, painter_id: PainterId, ) -> RefMut<'a, Painter>
pub fn painter_id(&self) -> PainterId
pub fn rendering_context_size( &self, painter_id: PainterId, ) -> Size2D<u32, DevicePixel>
pub fn webgl_threads(&self) -> WebGLThreads
pub fn webrender_external_image_id_manager( &self, ) -> WebRenderExternalImageIdManager
pub fn webxr_running(&self) -> bool
pub fn webxr_main_thread_registry(&self) -> Registry
pub fn webgpu_image_map(&self) -> WebGpuExternalImageMap
pub fn webviews_needing_repaint(&self) -> Vec<WebViewId>
pub fn finish_shutting_down(&self)
fn handle_browser_message(&self, msg: PaintMessage)
pub fn remove_webview(&mut self, webview_id: WebViewId)
fn collect_memory_report(&self, sender: ReportsChan)
Sourcefn handle_browser_message_while_shutting_down(&self, msg: PaintMessage)
fn handle_browser_message_while_shutting_down(&self, msg: PaintMessage)
Handle messages sent to Paint during the shutdown process. In general,
the things Paint can do in this state are limited. It’s very important to
answer any synchronous messages though as other threads might be waiting on the
results to finish their own shut down process. We try to do as little as possible
during this time.
When that involves generating WebRender ids, our approach here is to simply
generate them, but assume they will never be used, since once shutting down
Paint no longer does any WebRender frame generation.
pub fn add_webview( &self, webview: Box<dyn WebViewTrait>, viewport_details: ViewportDetails, )
pub fn show_webview(&self, webview_id: WebViewId) -> Result<(), UnknownWebView>
pub fn hide_webview(&self, webview_id: WebViewId) -> Result<(), UnknownWebView>
pub fn set_hidpi_scale_factor( &self, webview_id: WebViewId, new_scale_factor: Scale<f32, DeviceIndependentPixel, DevicePixel>, )
pub fn resize_rendering_context( &self, webview_id: WebViewId, new_size: PhysicalSize<u32>, )
pub fn set_page_zoom(&self, webview_id: WebViewId, new_zoom: f32)
pub fn page_zoom(&self, webview_id: WebViewId) -> f32
Sourcepub fn render(&self, webview_id: WebViewId)
pub fn render(&self, webview_id: WebViewId)
Render the WebRender scene to the active RenderingContext.
Sourcepub fn receiver(&self) -> &RoutedReceiver<PaintMessage>
pub fn receiver(&self) -> &RoutedReceiver<PaintMessage>
Get the message receiver for this Paint.
pub fn handle_messages(&self, messages: Vec<PaintMessage>)
pub fn perform_updates(&self) -> bool
pub fn toggle_webrender_debug(&self, option: WebRenderDebugOption)
pub fn capture_webrender(&self, webview_id: WebViewId)
pub fn notify_input_event(&self, webview_id: WebViewId, event: InputEventAndId)
pub fn notify_scroll_event( &self, webview_id: WebViewId, scroll: Scroll, point: WebViewPoint, )
pub fn pinch_zoom( &self, webview_id: WebViewId, pinch_zoom_delta: f32, center: DevicePoint, )
pub fn device_pixels_per_page_pixel( &self, webview_id: WebViewId, ) -> Scale<f32, CSSPixel, DevicePixel>
pub(crate) fn shutdown_state(&self) -> ShutdownState
pub fn request_screenshot( &self, webview_id: WebViewId, rect: Option<WebViewRect>, callback: Box<dyn FnOnce(Result<RgbaImage, ScreenshotCaptureError>) + 'static>, )
pub fn notify_input_event_handled( &self, webview_id: WebViewId, input_event_id: InputEventId, result: InputEventResult, )
Sourcefn handle_generate_image_key(
&self,
webview_id: WebViewId,
result_sender: GenericSender<ImageKey>,
)
fn handle_generate_image_key( &self, webview_id: WebViewId, result_sender: GenericSender<ImageKey>, )
Generate an image key from the appropriate Painter or, if it is unknown, generate
a dummy image key. The unknown case needs to be handled because requests for keys
could theoretically come after a Painter has been released. A dummy key is okay
in this case because we will never render again in that case.
Sourcefn handle_generate_image_keys_for_pipeline(
&self,
webview_id: WebViewId,
pipeline_id: PipelineId,
)
fn handle_generate_image_keys_for_pipeline( &self, webview_id: WebViewId, pipeline_id: PipelineId, )
Generate image keys from the appropriate Painter or, if it is unknown, generate
dummy image keys. The unknown case needs to be handled because requests for keys
could theoretically come after a Painter has been released. A dummy key is okay
in this case because we will never render again in that case.
Sourcefn handle_generate_font_keys(
&self,
number_of_font_keys: usize,
number_of_font_instance_keys: usize,
result_sender: GenericSender<(Vec<FontKey>, Vec<FontInstanceKey>)>,
painter_id: PainterId,
)
fn handle_generate_font_keys( &self, number_of_font_keys: usize, number_of_font_instance_keys: usize, result_sender: GenericSender<(Vec<FontKey>, Vec<FontInstanceKey>)>, painter_id: PainterId, )
Generate font keys from the appropriate Painter or, if it is unknown, generate
dummy font keys. The unknown case needs to be handled because requests for keys
could theoretically come after a Painter has been released. A dummy key is okay
in this case because we will never render again in that case.
Auto Trait Implementations§
impl !Freeze for Paint
impl !RefUnwindSafe for Paint
impl !Send for Paint
impl !Sync for Paint
impl Unpin for Paint
impl !UnwindSafe for Paint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more