@@ -24,7 +24,6 @@ use script_traits::{
24
24
} ;
25
25
use servo_geometry:: DeviceIndependentPixel ;
26
26
use style_traits:: { CSSPixel , DevicePixel , PinchZoomFactor } ;
27
- use surfman:: Surface ;
28
27
use webrender:: { RenderApi , Transaction } ;
29
28
use webrender_api:: units:: {
30
29
DeviceIntPoint , DeviceIntRect , DeviceIntSize , DevicePoint , LayoutPoint , LayoutRect , LayoutSize ,
@@ -39,11 +38,11 @@ use webrender_api::{
39
38
use webrender_traits:: display_list:: { HitTestInfo , ScrollTree } ;
40
39
use webrender_traits:: {
41
40
CanvasToCompositorMsg , CompositorHitTestResult , FontToCompositorMsg , ImageUpdate ,
42
- NetToCompositorMsg , RenderingContext , ScriptToCompositorMsg , SerializedImageUpdate ,
43
- UntrustedNodeAddress ,
41
+ NetToCompositorMsg , ScriptToCompositorMsg , SerializedImageUpdate , UntrustedNodeAddress ,
44
42
} ;
45
43
use winit:: window:: WindowId ;
46
44
45
+ use crate :: rendering:: RenderingContext ;
47
46
use crate :: touch:: { TouchAction , TouchHandler } ;
48
47
use crate :: window:: Window ;
49
48
@@ -104,9 +103,6 @@ const MIN_ZOOM: f32 = 0.1;
104
103
/// The compositor will communicate with Servo using messages from the Constellation,
105
104
/// then composite the WebRender frames and present the surface to the window.
106
105
pub struct IOCompositor {
107
- /// All surfaces that Compositor currently owns.
108
- pub surfaces : HashMap < WindowId , Option < Surface > > ,
109
-
110
106
/// The current window that Compositor is handling.
111
107
pub current_window : WindowId ,
112
108
@@ -176,7 +172,7 @@ pub struct IOCompositor {
176
172
/// The webrender interface, if enabled.
177
173
pub webrender_api : RenderApi ,
178
174
179
- /// The surfman instance that webrender targets
175
+ /// The glutin instance that webrender targets
180
176
pub rendering_context : RenderingContext ,
181
177
182
178
/// The GL bindings for webrender
@@ -348,10 +344,7 @@ impl IOCompositor {
348
344
exit_after_load : bool ,
349
345
convert_mouse_to_touch : bool ,
350
346
) -> Self {
351
- let mut surfaces = HashMap :: new ( ) ;
352
- surfaces. insert ( current_window, None ) ;
353
347
let compositor = IOCompositor {
354
- surfaces,
355
348
current_window,
356
349
viewport,
357
350
port : state. receiver ,
@@ -394,15 +387,7 @@ impl IOCompositor {
394
387
}
395
388
396
389
/// Consume compositor itself and deinit webrender.
397
- pub fn deinit ( mut self ) {
398
- if let Err ( err) = self . rendering_context . make_gl_context_current ( ) {
399
- warn ! ( "Failed to make GL context current: {:?}" , err) ;
400
- }
401
- for surface in self . surfaces . values_mut ( ) {
402
- surface
403
- . take ( )
404
- . map ( |s| self . rendering_context . destroy_surface ( s) ) ;
405
- }
390
+ pub fn deinit ( self ) {
406
391
self . webrender . deinit ( ) ;
407
392
}
408
393
@@ -453,34 +438,6 @@ impl IOCompositor {
453
438
self . shutdown_state = ShutdownState :: FinishedShuttingDown ;
454
439
}
455
440
456
- /// The underlying native surface can be lost during servo's lifetime.
457
- /// On Android, for example, this happens when the app is sent to background.
458
- /// We need to unbind the surface so that we don't try to use it again.
459
- pub fn invalidate_native_surface ( & mut self ) {
460
- debug ! ( "Invalidating native surface in compositor" ) ;
461
- if let Err ( e) = self . rendering_context . unbind_native_surface_from_context ( ) {
462
- warn ! ( "Unbinding native surface from context failed ({:?})" , e) ;
463
- }
464
- }
465
-
466
- /// On Android, this function will be called when the app moves to foreground
467
- /// and the system creates a new native surface that needs to bound to the current
468
- /// context.
469
- #[ allow( unsafe_code) ]
470
- #[ allow( clippy:: not_unsafe_ptr_arg_deref) ] // It has an unsafe block inside
471
- pub fn replace_native_surface ( & mut self , native_widget : * mut c_void , coords : DeviceIntSize ) {
472
- debug ! ( "Replacing native surface in compositor: {native_widget:?}" ) ;
473
- let connection = self . rendering_context . connection ( ) ;
474
- let native_widget =
475
- unsafe { connection. create_native_widget_from_ptr ( native_widget, coords. to_untyped ( ) ) } ;
476
- if let Err ( e) = self
477
- . rendering_context
478
- . bind_native_surface_to_context ( native_widget)
479
- {
480
- warn ! ( "Binding native surface to context failed ({:?})" , e) ;
481
- }
482
- }
483
-
484
441
fn handle_browser_message (
485
442
& mut self ,
486
443
msg : CompositorMsg ,
@@ -1282,23 +1239,16 @@ impl IOCompositor {
1282
1239
self . current_window,
1283
1240
window. id( )
1284
1241
) ;
1285
- if let Some ( Some ( new_surface) ) = self . surfaces . insert ( window. id ( ) , None ) {
1286
- // Swap the surface
1287
- self . rendering_context . with_front_buffer ( |_, old_surface| {
1288
- self . surfaces . insert ( self . current_window , Some ( old_surface) ) ;
1289
- new_surface
1290
- } ) ;
1291
- self . current_window = window. id ( ) ;
1292
- self . scale_factor = Scale :: new ( window. scale_factor ( ) as f32 ) ;
1293
- self . resize ( window. size ( ) , window) ;
1294
- }
1242
+ self . current_window = window. id ( ) ;
1243
+ self . scale_factor = Scale :: new ( window. scale_factor ( ) as f32 ) ;
1244
+ self . resize ( window. size ( ) , window) ;
1295
1245
}
1296
1246
}
1297
1247
1298
1248
/// Resize the rendering context and all web views. Return true if the compositor should repaint and present
1299
1249
/// after this.
1300
1250
pub fn resize ( & mut self , size : Size2D < i32 , DevicePixel > , window : & mut Window ) -> bool {
1301
- let need_resize = self . on_resize_window_event ( size) ;
1251
+ let need_resize = self . on_resize_window_event ( size, window ) ;
1302
1252
1303
1253
if let Some ( panel) = & mut window. panel {
1304
1254
let rect = DeviceIntRect :: from_size ( size) ;
@@ -1319,12 +1269,14 @@ impl IOCompositor {
1319
1269
1320
1270
/// Handle the window resize event and return a boolean to tell embedder if it should further
1321
1271
/// handle the resize event.
1322
- pub fn on_resize_window_event ( & mut self , new_viewport : DeviceIntSize ) -> bool {
1272
+ pub fn on_resize_window_event ( & mut self , new_viewport : DeviceIntSize , window : & Window ) -> bool {
1323
1273
if self . shutdown_state != ShutdownState :: NotShuttingDown {
1324
1274
return false ;
1325
1275
}
1326
1276
1327
- let _ = self . rendering_context . resize ( new_viewport. to_untyped ( ) ) ;
1277
+ let _ = self
1278
+ . rendering_context
1279
+ . resize ( & window. surface , new_viewport. to_untyped ( ) ) ;
1328
1280
self . viewport = new_viewport;
1329
1281
let mut transaction = Transaction :: new ( ) ;
1330
1282
transaction. set_document_view ( DeviceIntRect :: from_size ( self . viewport ) ) ;
@@ -1959,8 +1911,8 @@ impl IOCompositor {
1959
1911
}
1960
1912
1961
1913
/// Composite to the given target if any, or the current target otherwise.
1962
- pub fn composite ( & mut self ) {
1963
- match self . composite_specific_target ( ) {
1914
+ pub fn composite ( & mut self , window : & Window ) {
1915
+ match self . composite_specific_target ( window ) {
1964
1916
Ok ( _) => {
1965
1917
if self . exit_after_load {
1966
1918
println ! ( "Shutting down the Constellation after generating an output file or exit flag specified" ) ;
@@ -1974,8 +1926,11 @@ impl IOCompositor {
1974
1926
}
1975
1927
1976
1928
/// Composite to the given target if any, or the current target otherwise.
1977
- fn composite_specific_target ( & mut self ) -> Result < ( ) , UnableToComposite > {
1978
- if let Err ( err) = self . rendering_context . make_gl_context_current ( ) {
1929
+ fn composite_specific_target ( & mut self , window : & Window ) -> Result < ( ) , UnableToComposite > {
1930
+ if let Err ( err) = self
1931
+ . rendering_context
1932
+ . make_gl_context_current ( & window. surface )
1933
+ {
1979
1934
warn ! ( "Failed to make GL context current: {:?}" , err) ;
1980
1935
}
1981
1936
self . assert_no_gl_error ( ) ;
@@ -1999,17 +1954,6 @@ impl IOCompositor {
1999
1954
}
2000
1955
}
2001
1956
2002
- // Bind the webrender framebuffer
2003
- let framebuffer_object = self
2004
- . rendering_context
2005
- . context_surface_info ( )
2006
- . unwrap_or ( None )
2007
- . map ( |info| info. framebuffer_object )
2008
- . unwrap_or ( 0 ) ;
2009
- self . webrender_gl
2010
- . bind_framebuffer ( gl:: FRAMEBUFFER , framebuffer_object) ;
2011
- self . assert_gl_framebuffer_complete ( ) ;
2012
-
2013
1957
profile (
2014
1958
ProfilerCategory :: Compositing ,
2015
1959
None ,
@@ -2071,7 +2015,7 @@ impl IOCompositor {
2071
2015
}
2072
2016
}
2073
2017
2074
- if let Err ( err) = self . rendering_context . present ( ) {
2018
+ if let Err ( err) = self . rendering_context . present ( & window . surface ) {
2075
2019
warn ! ( "Failed to present surface: {:?}" , err) ;
2076
2020
}
2077
2021
self . composition_request = CompositionRequest :: NoCompositingNecessary ;
@@ -2147,19 +2091,21 @@ impl IOCompositor {
2147
2091
self . zoom_action = false ;
2148
2092
}
2149
2093
2150
- match self . composition_request {
2151
- CompositionRequest :: NoCompositingNecessary => { }
2152
- CompositionRequest :: CompositeNow ( _) => self . composite ( ) ,
2153
- }
2094
+ if let Some ( window) = windows. get ( & self . current_window ) {
2095
+ match self . composition_request {
2096
+ CompositionRequest :: NoCompositingNecessary => { }
2097
+ CompositionRequest :: CompositeNow ( _) => self . composite ( window) ,
2098
+ }
2154
2099
2155
- // Run the WebXR main thread
2156
- self . webxr_main_thread . run_one_frame ( ) ;
2100
+ // Run the WebXR main thread
2101
+ self . webxr_main_thread . run_one_frame ( ) ;
2157
2102
2158
- // The WebXR thread may make a different context current
2159
- let _ = self . rendering_context . make_gl_context_current ( ) ;
2103
+ // The WebXR thread may make a different context current
2104
+ let _ = self
2105
+ . rendering_context
2106
+ . make_gl_context_current ( & window. surface ) ;
2160
2107
2161
- if !self . pending_scroll_zoom_events . is_empty ( ) {
2162
- if let Some ( window) = windows. get ( & self . current_window ) {
2108
+ if !self . pending_scroll_zoom_events . is_empty ( ) {
2163
2109
self . process_pending_scroll_events ( window)
2164
2110
}
2165
2111
}
@@ -2175,7 +2121,9 @@ impl IOCompositor {
2175
2121
let need_recomposite = matches ! ( msg, CompositorMsg :: NewWebRenderFrameReady ( _) ) ;
2176
2122
let keep_going = self . handle_browser_message ( msg, windows) ;
2177
2123
if need_recomposite {
2178
- self . composite ( ) ;
2124
+ if let Some ( window) = windows. get ( & self . current_window ) {
2125
+ self . composite ( window) ;
2126
+ }
2179
2127
break ;
2180
2128
}
2181
2129
if !keep_going {
0 commit comments