diff options
author | Ngo Iok Ui (Wu Yu Wei) <yuweiwu@pm.me> | 2025-01-01 17:26:23 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-01 08:26:23 +0000 |
commit | d581acab3bd244e233105edde972a0605224358a (patch) | |
tree | 74573f0f2f97f27d42cda65fb22288ae1c5b6a0f /components/shared/webrender/rendering_context.rs | |
parent | 59c7ac680ee7cd4eba2c9adb119dbcaf69f029cd (diff) | |
download | servo-d581acab3bd244e233105edde972a0605224358a.tar.gz servo-d581acab3bd244e233105edde972a0605224358a.zip |
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>
Diffstat (limited to 'components/shared/webrender/rendering_context.rs')
-rw-r--r-- | components/shared/webrender/rendering_context.rs | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/components/shared/webrender/rendering_context.rs b/components/shared/webrender/rendering_context.rs index d72ab8ed46b..b92adbf4523 100644 --- a/components/shared/webrender/rendering_context.rs +++ b/components/shared/webrender/rendering_context.rs @@ -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(); |