mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
chore: remove WindowMethods::rendering_context
(#34780)
* Create Servo without initial webview ID Signed-off-by: Wu Yuwei <yuweiwu@pm.me> * Add rendering context in App struct Signed-off-by: Wu Yuwei <yuweiwu@pm.me> * Make webview manager optional Signed-off-by: Wu Yuwei <yuweiwu@pm.me> * Move window creation to init Signed-off-by: Wu Yuwei <yuweiwu@pm.me> * Create window from external rendering context Signed-off-by: Wu Yuwei <yuweiwu@pm.me> * Resize surface in compositor Signed-off-by: Wu Yuwei <yuweiwu@pm.me> * Obey clippy Signed-off-by: Wu Yuwei <yuweiwu@pm.me> * Update Android and OHOS Signed-off-by: Wu Yuwei <yuweiwu@pm.me> * Add missing arguent on OHOS Signed-off-by: Wu Yuwei <yuweiwu@pm.me> * Show webview after focused on Android and OH Signed-off-by: Wu Yuwei <yuweiwu@pm.me> * Remove rendering_context in ServoWindowCallbacks Signed-off-by: Wu Yuwei <yuweiwu@pm.me> * Create surface before swapchain in headless mode Signed-off-by: Wu Yuwei <yuweiwu@pm.me> --------- Signed-off-by: Wu Yuwei <yuweiwu@pm.me>
This commit is contained in:
parent
59c7ac680e
commit
d581acab3b
15 changed files with 200 additions and 253 deletions
|
@ -363,33 +363,13 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
composite_target: CompositeTarget,
|
||||
exit_after_load: bool,
|
||||
convert_mouse_to_touch: bool,
|
||||
top_level_browsing_context_id: TopLevelBrowsingContextId,
|
||||
version_string: String,
|
||||
) -> Self {
|
||||
let embedder_coordinates = window.get_coordinates();
|
||||
let mut webviews = WebViewManager::default();
|
||||
webviews
|
||||
.add(
|
||||
top_level_browsing_context_id,
|
||||
WebView {
|
||||
pipeline_id: None,
|
||||
rect: embedder_coordinates.get_viewport().to_f32(),
|
||||
},
|
||||
)
|
||||
.expect("Infallible with a new WebViewManager");
|
||||
let msg = ConstellationMsg::WebViewOpened(top_level_browsing_context_id);
|
||||
if let Err(e) = state.constellation_chan.send(msg) {
|
||||
warn!("Sending event to constellation failed ({:?}).", e);
|
||||
}
|
||||
webviews
|
||||
.show(top_level_browsing_context_id)
|
||||
.expect("Infallible due to add");
|
||||
|
||||
let compositor = IOCompositor {
|
||||
embedder_coordinates: window.get_coordinates(),
|
||||
window,
|
||||
port: state.receiver,
|
||||
webviews,
|
||||
webviews: WebViewManager::default(),
|
||||
pipeline_details: HashMap::new(),
|
||||
composition_request: CompositionRequest::NoCompositingNecessary,
|
||||
touch_handler: TouchHandler::new(),
|
||||
|
@ -1360,7 +1340,11 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
|
||||
if self.embedder_coordinates.viewport != old_coords.viewport {
|
||||
let mut transaction = Transaction::new();
|
||||
transaction.set_document_view(self.embedder_coordinates.get_viewport());
|
||||
let size = self.embedder_coordinates.get_viewport();
|
||||
transaction.set_document_view(size);
|
||||
if let Err(e) = self.rendering_context.resize(size.size().to_untyped()) {
|
||||
warn!("Failed to resize surface: {e:?}");
|
||||
}
|
||||
self.webrender_api
|
||||
.send_transaction(self.webrender_document, transaction);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ use webrender_api::units::{
|
|||
DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel, DevicePoint, DeviceRect,
|
||||
};
|
||||
use webrender_api::ScrollLocation;
|
||||
use webrender_traits::RenderingContext;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum MouseWindowEvent {
|
||||
|
@ -218,8 +217,6 @@ pub trait WindowMethods {
|
|||
/// will want to avoid blocking on UI events, and just
|
||||
/// run the event loop at the vsync interval.
|
||||
fn set_animation_state(&self, _state: AnimationState);
|
||||
/// Get the [`RenderingContext`] of this Window.
|
||||
fn rendering_context(&self) -> RenderingContext;
|
||||
}
|
||||
|
||||
pub trait EmbedderMethods {
|
||||
|
|
|
@ -219,11 +219,6 @@ impl webrender_api::RenderNotifier for RenderNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct InitializedServo<Window: WindowMethods + 'static + ?Sized> {
|
||||
pub servo: Servo<Window>,
|
||||
pub browser_id: TopLevelBrowsingContextId,
|
||||
}
|
||||
|
||||
impl<Window> Servo<Window>
|
||||
where
|
||||
Window: WindowMethods + 'static + ?Sized,
|
||||
|
@ -238,11 +233,12 @@ where
|
|||
)]
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
pub fn new(
|
||||
rendering_context: RenderingContext,
|
||||
mut embedder: Box<dyn EmbedderMethods>,
|
||||
window: Rc<Window>,
|
||||
user_agent: Option<String>,
|
||||
composite_target: CompositeTarget,
|
||||
) -> InitializedServo<Window> {
|
||||
) -> Servo<Window> {
|
||||
// Global configuration options, parsed from the command line.
|
||||
let opts = opts::get();
|
||||
|
||||
|
@ -277,9 +273,6 @@ where
|
|||
.unwrap_or(default_user_agent_string_for(DEFAULT_USER_AGENT).into()),
|
||||
};
|
||||
|
||||
// Initialize surfman
|
||||
let rendering_context = window.rendering_context();
|
||||
|
||||
// Get GL bindings
|
||||
let webrender_gl = match rendering_context.connection().gl_api() {
|
||||
GLApi::GL => unsafe { gl::GlFns::load_with(|s| rendering_context.get_proc_address(s)) },
|
||||
|
@ -302,7 +295,6 @@ where
|
|||
|
||||
// Reserving a namespace to create TopLevelBrowsingContextId.
|
||||
PipelineNamespace::install(PipelineNamespaceId(0));
|
||||
let top_level_browsing_context_id = TopLevelBrowsingContextId::new();
|
||||
|
||||
// Get both endpoints of a special channel for communication between
|
||||
// the client window and the compositor. This channel is unique because
|
||||
|
@ -525,21 +517,16 @@ where
|
|||
composite_target,
|
||||
opts.exit_after_load,
|
||||
opts.debug.convert_mouse_to_touch,
|
||||
top_level_browsing_context_id,
|
||||
embedder.get_version_string().unwrap_or_default(),
|
||||
);
|
||||
|
||||
let servo = Servo {
|
||||
Servo {
|
||||
compositor,
|
||||
constellation_chan,
|
||||
embedder_receiver,
|
||||
messages_for_embedder: Vec::new(),
|
||||
profiler_enabled: false,
|
||||
_js_engine_setup: js_engine_setup,
|
||||
};
|
||||
InitializedServo {
|
||||
servo,
|
||||
browser_id: top_level_browsing_context_id,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -282,6 +282,8 @@ thread_local!(pub static TOP_LEVEL_BROWSING_CONTEXT_ID: Cell<Option<TopLevelBrow
|
|||
Clone, Copy, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
|
||||
)]
|
||||
pub struct TopLevelBrowsingContextId(pub BrowsingContextId);
|
||||
/// An alias to ID of top level browsing context. A web view is usually what people would treat as
|
||||
/// a normal web page.
|
||||
pub type WebViewId = TopLevelBrowsingContextId;
|
||||
|
||||
size_of_test!(TopLevelBrowsingContextId, 8);
|
||||
|
|
|
@ -43,7 +43,7 @@ impl RenderingContext {
|
|||
pub fn create(
|
||||
connection: &Connection,
|
||||
adapter: &Adapter,
|
||||
surface_type: SurfaceType<NativeWidget>,
|
||||
headless: Option<Size2D<i32>>,
|
||||
) -> Result<Self, Error> {
|
||||
let mut device = connection.create_device(adapter)?;
|
||||
let flags = ContextAttributeFlags::ALPHA |
|
||||
|
@ -57,21 +57,16 @@ impl RenderingContext {
|
|||
let context_descriptor = device.create_context_descriptor(&context_attributes)?;
|
||||
let mut context = device.create_context(&context_descriptor, None)?;
|
||||
let surface_access = SurfaceAccess::GPUOnly;
|
||||
let headless = match surface_type {
|
||||
SurfaceType::Widget { .. } => false,
|
||||
SurfaceType::Generic { .. } => true,
|
||||
};
|
||||
let surface = device.create_surface(&context, surface_access, surface_type)?;
|
||||
device
|
||||
.bind_surface_to_context(&mut context, surface)
|
||||
.map_err(|(err, mut surface)| {
|
||||
let _ = device.destroy_surface(&mut context, &mut surface);
|
||||
err
|
||||
})?;
|
||||
|
||||
device.make_context_current(&context)?;
|
||||
|
||||
let swap_chain = if headless {
|
||||
let swap_chain = if let Some(size) = headless {
|
||||
let surface_type = SurfaceType::Generic { size };
|
||||
let surface = device.create_surface(&context, surface_access, surface_type)?;
|
||||
device
|
||||
.bind_surface_to_context(&mut context, surface)
|
||||
.map_err(|(err, mut surface)| {
|
||||
let _ = device.destroy_surface(&mut context, &mut surface);
|
||||
err
|
||||
})?;
|
||||
device.make_context_current(&context)?;
|
||||
Some(SwapChain::create_attached(
|
||||
&mut device,
|
||||
&mut context,
|
||||
|
@ -100,6 +95,20 @@ impl RenderingContext {
|
|||
device.create_surface(context, surface_access, surface_type)
|
||||
}
|
||||
|
||||
pub fn bind_surface(&self, surface: Surface) -> Result<(), Error> {
|
||||
let device = &self.0.device.borrow();
|
||||
let context = &mut self.0.context.borrow_mut();
|
||||
device
|
||||
.bind_surface_to_context(context, surface)
|
||||
.map_err(|(err, mut surface)| {
|
||||
let _ = device.destroy_surface(context, &mut surface);
|
||||
err
|
||||
})?;
|
||||
|
||||
device.make_context_current(context)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn destroy_surface(&self, mut surface: Surface) -> Result<(), Error> {
|
||||
let device = &self.0.device.borrow();
|
||||
let context = &mut self.0.context.borrow_mut();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue