aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-01-27 18:58:34 +0100
committerGitHub <noreply@github.com>2024-01-27 17:58:34 +0000
commitbc211f8ff387ea59bc8af7bb7394c7be7ca69597 (patch)
tree853b9a211de6e63d4d31295200bb86afb9c442a9 /components
parentbbe505e52b611e682c6f3b34411a07c00a34f2b7 (diff)
downloadservo-bc211f8ff387ea59bc8af7bb7394c7be7ca69597.tar.gz
servo-bc211f8ff387ea59bc8af7bb7394c7be7ca69597.zip
gfx: Rename `WebrenderSurfman` to `RenderingContext` and move to `gfx` (#31184)
This is a small cleanup that moves and renames this class. The rename is simply because we are exposing a lot about the details of Servo's rendering in the API and it makes sense to start thinking about abstracting that away a bit. This also moves the struct to `gfx`, which does have an effect on Servo's dependency graph. This adds a new dependency on gfx to `compositing`, but `compositing` had a transitive dependency on gfx before through `canvas`.
Diffstat (limited to 'components')
-rw-r--r--components/canvas/Cargo.toml1
-rw-r--r--components/canvas/webgl_mode/inprocess.rs8
-rw-r--r--components/compositing/Cargo.toml2
-rw-r--r--components/compositing/compositor.rs22
-rw-r--r--components/compositing/lib.rs4
-rw-r--r--components/compositing/windowing.rs6
-rw-r--r--components/gfx/Cargo.toml1
-rw-r--r--components/gfx/lib.rs6
-rw-r--r--components/gfx/rendering_context.rs (renamed from components/webrender_surfman/lib.rs)16
-rw-r--r--components/servo/Cargo.toml1
-rw-r--r--components/servo/lib.rs19
-rw-r--r--components/shared/compositing/Cargo.toml1
-rw-r--r--components/webrender_surfman/Cargo.toml15
13 files changed, 41 insertions, 61 deletions
diff --git a/components/canvas/Cargo.toml b/components/canvas/Cargo.toml
index 8c42dc8b8c0..692d2efdfce 100644
--- a/components/canvas/Cargo.toml
+++ b/components/canvas/Cargo.toml
@@ -41,7 +41,6 @@ surfman = { workspace = true }
time = { workspace = true, optional = true }
webrender = { workspace = true }
webrender_api = { workspace = true }
-webrender_surfman = { path = "../webrender_surfman" }
webrender_traits = { workspace = true }
webxr-api = { git = "https://github.com/servo/webxr", features = ["ipc"] }
webxr = { git = "https://github.com/servo/webxr", features = ["ipc"] }
diff --git a/components/canvas/webgl_mode/inprocess.rs b/components/canvas/webgl_mode/inprocess.rs
index 749f0062aeb..ba9cee6ac02 100644
--- a/components/canvas/webgl_mode/inprocess.rs
+++ b/components/canvas/webgl_mode/inprocess.rs
@@ -8,13 +8,13 @@ use std::sync::{Arc, Mutex};
use canvas_traits::webgl::{webgl_channel, WebGLContextId, WebGLMsg, WebGLThreads};
use euclid::default::Size2D;
use fnv::FnvHashMap;
+use gfx::rendering_context::RenderingContext;
use log::debug;
use sparkle::gl::GlType;
use surfman::chains::{SwapChainAPI, SwapChains, SwapChainsAPI};
use surfman::{Device, SurfaceInfo, SurfaceTexture};
use webrender::RenderApiSender;
use webrender_api::DocumentId;
-use webrender_surfman::WebrenderSurfman;
use webrender_traits::{
WebrenderExternalImageApi, WebrenderExternalImageRegistry, WebrenderImageSource,
};
@@ -32,7 +32,7 @@ pub struct WebGLComm {
impl WebGLComm {
/// Creates a new `WebGLComm` object.
pub fn new(
- surfman: WebrenderSurfman,
+ surfman: RenderingContext,
webrender_api_sender: RenderApiSender,
webrender_doc: DocumentId,
external_images: Arc<Mutex<WebrenderExternalImageRegistry>>,
@@ -72,13 +72,13 @@ impl WebGLComm {
/// Bridge between the webrender::ExternalImage callbacks and the WebGLThreads.
struct WebGLExternalImages {
- surfman: WebrenderSurfman,
+ surfman: RenderingContext,
swap_chains: SwapChains<WebGLContextId, Device>,
locked_front_buffers: FnvHashMap<WebGLContextId, SurfaceTexture>,
}
impl WebGLExternalImages {
- fn new(surfman: WebrenderSurfman, swap_chains: SwapChains<WebGLContextId, Device>) -> Self {
+ fn new(surfman: RenderingContext, swap_chains: SwapChains<WebGLContextId, Device>) -> Self {
Self {
surfman,
swap_chains,
diff --git a/components/compositing/Cargo.toml b/components/compositing/Cargo.toml
index 861164b6cc0..10c651bcb81 100644
--- a/components/compositing/Cargo.toml
+++ b/components/compositing/Cargo.toml
@@ -22,6 +22,7 @@ crossbeam-channel = { workspace = true }
embedder_traits = { workspace = true }
euclid = { workspace = true }
fnv = { workspace = true }
+gfx = { path = "../gfx" }
gfx_traits = { workspace = true }
gleam = { workspace = true }
image = { workspace = true }
@@ -42,7 +43,6 @@ style_traits = { workspace = true }
time = { workspace = true }
webrender = { workspace = true }
webrender_api = { workspace = true }
-webrender_surfman = { path = "../webrender_surfman" }
webxr = { git = "https://github.com/servo/webxr" }
[build-dependencies]
diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs
index 5ef8ffc20a6..37ac7feb35a 100644
--- a/components/compositing/compositor.rs
+++ b/components/compositing/compositor.rs
@@ -21,6 +21,7 @@ use crossbeam_channel::Sender;
use embedder_traits::Cursor;
use euclid::{Point2D, Rect, Scale, Transform3D, Vector2D};
use fnv::{FnvHashMap, FnvHashSet};
+use gfx::rendering_context::RenderingContext;
use gfx_traits::{Epoch, FontData, WebRenderEpochToU16};
use image::{DynamicImage, ImageFormat};
use ipc_channel::ipc;
@@ -54,7 +55,6 @@ use webrender_api::{
ReferenceFrameKind, ScrollClamping, ScrollLocation, SpaceAndClipInfo, SpatialId,
TransformStyle, ZoomFactor,
};
-use webrender_surfman::WebrenderSurfman;
use crate::gl::RenderTargetInfo;
use crate::touch::{TouchAction, TouchHandler};
@@ -199,7 +199,7 @@ pub struct IOCompositor<Window: WindowMethods + ?Sized> {
webrender_api: RenderApi,
/// The surfman instance that webrender targets
- webrender_surfman: WebrenderSurfman,
+ rendering_context: RenderingContext,
/// The GL bindings for webrender
webrender_gl: Rc<dyn gleam::gl::Gl>,
@@ -403,7 +403,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
webrender: state.webrender,
webrender_document: state.webrender_document,
webrender_api: state.webrender_api,
- webrender_surfman: state.webrender_surfman,
+ rendering_context: state.rendering_context,
webrender_gl: state.webrender_gl,
webxr_main_thread: state.webxr_main_thread,
pending_paint_metrics: HashMap::new(),
@@ -449,7 +449,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
}
pub fn deinit(self) {
- if let Err(err) = self.webrender_surfman.make_gl_context_current() {
+ if let Err(err) = self.rendering_context.make_gl_context_current() {
warn!("Failed to make GL context current: {:?}", err);
}
self.webrender.deinit();
@@ -506,7 +506,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
/// We need to unbind the surface so that we don't try to use it again.
pub fn invalidate_native_surface(&mut self) {
debug!("Invalidating native surface in compositor");
- if let Err(e) = self.webrender_surfman.unbind_native_surface_from_context() {
+ if let Err(e) = self.rendering_context.unbind_native_surface_from_context() {
warn!("Unbinding native surface from context failed ({:?})", e);
}
}
@@ -517,11 +517,11 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
#[allow(unsafe_code)]
pub fn replace_native_surface(&mut self, native_widget: *mut c_void, coords: DeviceIntSize) {
debug!("Replacing native surface in compositor: {native_widget:?}");
- let connection = self.webrender_surfman.connection();
+ let connection = self.rendering_context.connection();
let native_widget =
unsafe { connection.create_native_widget_from_ptr(native_widget, coords.to_untyped()) };
if let Err(e) = self
- .webrender_surfman
+ .rendering_context
.bind_native_surface_to_context(native_widget)
{
warn!("Binding native surface to context failed ({:?})", e);
@@ -1721,7 +1721,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
let size = self.embedder_coordinates.framebuffer.to_u32();
- if let Err(err) = self.webrender_surfman.make_gl_context_current() {
+ if let Err(err) = self.rendering_context.make_gl_context_current() {
warn!("Failed to make GL context current: {:?}", err);
}
self.assert_no_gl_error();
@@ -1765,7 +1765,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
} else {
// Bind the webrender framebuffer
let framebuffer_object = self
- .webrender_surfman
+ .rendering_context
.context_surface_info()
.unwrap_or(None)
.map(|info| info.framebuffer_object)
@@ -1941,7 +1941,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
}
pub fn present(&mut self) {
- if let Err(err) = self.webrender_surfman.present() {
+ if let Err(err) = self.rendering_context.present() {
warn!("Failed to present surface: {:?}", err);
}
self.waiting_on_present = false;
@@ -2049,7 +2049,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
self.webxr_main_thread.run_one_frame();
// The WebXR thread may make a different context current
- let _ = self.webrender_surfman.make_gl_context_current();
+ let _ = self.rendering_context.make_gl_context_current();
if !self.pending_scroll_zoom_events.is_empty() && !self.waiting_for_results_of_scroll {
self.process_pending_scroll_events()
diff --git a/components/compositing/lib.rs b/components/compositing/lib.rs
index 58a9398556f..a3ae2b48b3b 100644
--- a/components/compositing/lib.rs
+++ b/components/compositing/lib.rs
@@ -8,10 +8,10 @@ use std::rc::Rc;
use compositing_traits::{CompositorProxy, CompositorReceiver, ConstellationMsg};
use crossbeam_channel::Sender;
+use gfx::rendering_context::RenderingContext;
use profile_traits::{mem, time};
use webrender::RenderApi;
use webrender_api::DocumentId;
-use webrender_surfman::WebrenderSurfman;
pub use crate::compositor::{CompositeTarget, IOCompositor, ShutdownState};
@@ -36,7 +36,7 @@ pub struct InitialCompositorState {
pub webrender: webrender::Renderer,
pub webrender_document: DocumentId,
pub webrender_api: RenderApi,
- pub webrender_surfman: WebrenderSurfman,
+ pub rendering_context: RenderingContext,
pub webrender_gl: Rc<dyn gleam::gl::Gl>,
pub webxr_main_thread: webxr::MainThreadRegistry,
}
diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs
index 1508d6dac70..7dfc7d6bf9e 100644
--- a/components/compositing/windowing.rs
+++ b/components/compositing/windowing.rs
@@ -9,6 +9,7 @@ use std::time::Duration;
use embedder_traits::{EmbedderProxy, EventLoopWaker};
use euclid::Scale;
+use gfx::rendering_context::RenderingContext;
use keyboard_types::KeyboardEvent;
use libc::c_void;
use msg::constellation_msg::{PipelineId, TopLevelBrowsingContextId, TraversalDirection};
@@ -19,7 +20,6 @@ use servo_url::ServoUrl;
use style_traits::DevicePixel;
use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePoint};
use webrender_api::ScrollLocation;
-use webrender_surfman::WebrenderSurfman;
#[derive(Clone)]
pub enum MouseWindowEvent {
@@ -177,8 +177,8 @@ pub trait WindowMethods {
fn get_native_display(&self) -> NativeDisplay;
/// Get the GL api
fn get_gl_api(&self) -> GlApi;
- /// Get the webrender surfman instance
- fn webrender_surfman(&self) -> WebrenderSurfman;
+ /// Get the RenderingContext instance.
+ fn rendering_context(&self) -> RenderingContext;
}
pub trait EmbedderMethods {
diff --git a/components/gfx/Cargo.toml b/components/gfx/Cargo.toml
index 47abe285644..b184e6b9fa0 100644
--- a/components/gfx/Cargo.toml
+++ b/components/gfx/Cargo.toml
@@ -33,6 +33,7 @@ servo_arc = { path = "../servo_arc" }
servo_atoms = { path = "../atoms" }
servo_url = { path = "../url" }
smallvec = { workspace = true, features = ["union"] }
+surfman = { workspace = true }
style = { path = "../style", features = ["servo"] }
ucd = "0.1.1"
unicode-bidi = { workspace = true, features = ["with_serde"] }
diff --git a/components/gfx/lib.rs b/components/gfx/lib.rs
index c13d9663079..aee2d56c7d1 100644
--- a/components/gfx/lib.rs
+++ b/components/gfx/lib.rs
@@ -4,15 +4,11 @@
#![deny(unsafe_code)]
-// Fonts
pub mod font;
pub mod font_cache_thread;
pub mod font_context;
pub mod font_template;
-
-// Platform-specific implementations.
#[allow(unsafe_code)]
mod platform;
-
-// Text
+pub mod rendering_context;
pub mod text;
diff --git a/components/webrender_surfman/lib.rs b/components/gfx/rendering_context.rs
index 8e4dc75cb79..4e78ba9117c 100644
--- a/components/webrender_surfman/lib.rs
+++ b/components/gfx/rendering_context.rs
@@ -16,19 +16,19 @@ use surfman::{
SurfaceTexture, SurfaceType,
};
-/// A bridge between webrender and surfman
-// TODO: move this into a different crate so that script doesn't depend on surfman
+/// A Servo rendering context, which holds all of the information needed
+/// to render Servo's layout, and bridges WebRender and surfman.
#[derive(Clone)]
-pub struct WebrenderSurfman(Rc<WebrenderSurfmanData>);
+pub struct RenderingContext(Rc<RenderingContextData>);
-struct WebrenderSurfmanData {
+struct RenderingContextData {
device: RefCell<Device>,
context: RefCell<Context>,
// We either render to a swap buffer or to a native widget
swap_chain: Option<SwapChain<Device>>,
}
-impl Drop for WebrenderSurfmanData {
+impl Drop for RenderingContextData {
fn drop(&mut self) {
let ref mut device = self.device.borrow_mut();
let ref mut context = self.context.borrow_mut();
@@ -39,7 +39,7 @@ impl Drop for WebrenderSurfmanData {
}
}
-impl WebrenderSurfman {
+impl RenderingContext {
pub fn create(
connection: &Connection,
adapter: &Adapter,
@@ -82,12 +82,12 @@ impl WebrenderSurfman {
};
let device = RefCell::new(device);
let context = RefCell::new(context);
- let data = WebrenderSurfmanData {
+ let data = RenderingContextData {
device,
context,
swap_chain,
};
- Ok(WebrenderSurfman(Rc::new(data)))
+ Ok(RenderingContext(Rc::new(data)))
}
pub fn create_surface_texture(
diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml
index 325c1897083..29ae33c0d5e 100644
--- a/components/servo/Cargo.toml
+++ b/components/servo/Cargo.toml
@@ -79,7 +79,6 @@ webdriver_server = { path = "../webdriver_server", optional = true }
webgpu = { path = "../webgpu" }
webrender = { workspace = true }
webrender_api = { workspace = true }
-webrender_surfman = { path = "../webrender_surfman" }
webrender_traits = { workspace = true }
webxr = { git = "https://github.com/servo/webxr" }
webxr-api = { git = "https://github.com/servo/webxr" }
diff --git a/components/servo/lib.rs b/components/servo/lib.rs
index fdddd33e1df..5f1a09d8e71 100644
--- a/components/servo/lib.rs
+++ b/components/servo/lib.rs
@@ -61,6 +61,7 @@ use euclid::Scale;
))]
use gaol::sandbox::{ChildSandbox, ChildSandboxMethods};
use gfx::font_cache_thread::FontCacheThread;
+pub use gfx::rendering_context;
pub use gleam::gl;
use ipc_channel::ipc::{self, IpcSender};
use log::{error, trace, warn, Log, Metadata, Record};
@@ -89,7 +90,7 @@ pub use {
keyboard_types, layout_thread_2013, layout_thread_2020, media, msg, net, net_traits, profile,
profile_traits, script, script_layout_interface, script_traits, servo_config as config,
servo_config, servo_geometry, servo_url as url, servo_url, style, style_traits, webgpu,
- webrender_api, webrender_surfman, webrender_traits,
+ webrender_api, webrender_traits,
};
#[cfg(feature = "webdriver")]
@@ -259,22 +260,22 @@ where
};
// Initialize surfman
- let webrender_surfman = window.webrender_surfman();
+ let rendering_context = window.rendering_context();
// Get GL bindings
- let webrender_gl = match webrender_surfman.connection().gl_api() {
- GLApi::GL => unsafe { gl::GlFns::load_with(|s| webrender_surfman.get_proc_address(s)) },
+ let webrender_gl = match rendering_context.connection().gl_api() {
+ GLApi::GL => unsafe { gl::GlFns::load_with(|s| rendering_context.get_proc_address(s)) },
GLApi::GLES => unsafe {
- gl::GlesFns::load_with(|s| webrender_surfman.get_proc_address(s))
+ gl::GlesFns::load_with(|s| rendering_context.get_proc_address(s))
},
};
// Make sure the gl context is made current.
- webrender_surfman.make_gl_context_current().unwrap();
+ rendering_context.make_gl_context_current().unwrap();
debug_assert_eq!(webrender_gl.get_error(), gleam::gl::NO_ERROR,);
// Bind the webrender framebuffer
- let framebuffer_object = webrender_surfman
+ let framebuffer_object = rendering_context
.context_surface_info()
.unwrap_or(None)
.map(|info| info.framebuffer_object)
@@ -369,7 +370,7 @@ where
webxr_layer_grand_manager,
image_handler,
} = WebGLComm::new(
- webrender_surfman.clone(),
+ rendering_context.clone(),
webrender_api.create_sender(),
webrender_document,
external_images.clone(),
@@ -468,7 +469,7 @@ where
webrender,
webrender_document,
webrender_api,
- webrender_surfman,
+ rendering_context,
webrender_gl,
webxr_main_thread,
},
diff --git a/components/shared/compositing/Cargo.toml b/components/shared/compositing/Cargo.toml
index 809826c25d0..b35e7560f3e 100644
--- a/components/shared/compositing/Cargo.toml
+++ b/components/shared/compositing/Cargo.toml
@@ -25,4 +25,3 @@ script_traits = { workspace = true }
servo_url = { path = "../../url" }
style_traits = { workspace = true }
webrender_api = { workspace = true }
-webrender_surfman = { path = "../../webrender_surfman" }
diff --git a/components/webrender_surfman/Cargo.toml b/components/webrender_surfman/Cargo.toml
deleted file mode 100644
index b84cf344220..00000000000
--- a/components/webrender_surfman/Cargo.toml
+++ /dev/null
@@ -1,15 +0,0 @@
-[package]
-name = "webrender_surfman"
-version = "0.0.1"
-authors = ["The Servo Project Developers"]
-license = "MPL-2.0"
-edition = "2018"
-publish = false
-
-[lib]
-name = "webrender_surfman"
-path = "lib.rs"
-
-[dependencies]
-euclid = { workspace = true }
-surfman = { workspace = true }