@@ -9,13 +9,13 @@ use euclid::{
9
9
Angle , Point2D , Rect , RigidTransform3D , Rotation3D , Size2D , Transform3D , UnknownUnit , Vector3D ,
10
10
} ;
11
11
use glow:: { self as gl, Context as Gl , HasContext } ;
12
- use std :: ffi :: c_void ;
12
+ use raw_window_handle :: DisplayHandle ;
13
13
use std:: num:: NonZeroU32 ;
14
14
use std:: rc:: Rc ;
15
15
use surfman:: chains:: { PreserveBuffer , SwapChain , SwapChainAPI , SwapChains , SwapChainsAPI } ;
16
16
use surfman:: {
17
- Adapter , Connection , Context as SurfmanContext , ContextAttributes , Device as SurfmanDevice ,
18
- GLApi , NativeWidget , SurfaceAccess , SurfaceType ,
17
+ Adapter , Connection , Context as SurfmanContext , ContextAttributeFlags , ContextAttributes ,
18
+ Device as SurfmanDevice , GLApi , GLVersion , NativeWidget , SurfaceAccess , SurfaceType ,
19
19
} ;
20
20
use webxr_api:: util:: ClipPlanes ;
21
21
use webxr_api:: {
@@ -52,6 +52,7 @@ pub trait GlWindow {
52
52
fn get_mode ( & self ) -> GlWindowMode {
53
53
GlWindowMode :: Blit
54
54
}
55
+ fn display_handle ( & self ) -> DisplayHandle ;
55
56
}
56
57
57
58
#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
@@ -72,21 +73,26 @@ pub struct GlWindowDiscovery {
72
73
connection : Connection ,
73
74
adapter : Adapter ,
74
75
context_attributes : ContextAttributes ,
75
- factory : Box < dyn Fn ( ) -> Result < Box < dyn GlWindow > , ( ) > > ,
76
+ window : Rc < dyn GlWindow > ,
76
77
}
77
78
78
79
impl GlWindowDiscovery {
79
- pub fn new (
80
- connection : Connection ,
81
- adapter : Adapter ,
82
- context_attributes : ContextAttributes ,
83
- factory : Box < dyn Fn ( ) -> Result < Box < dyn GlWindow > , ( ) > > ,
84
- ) -> GlWindowDiscovery {
80
+ pub fn new ( window : Rc < dyn GlWindow > ) -> GlWindowDiscovery {
81
+ let connection = Connection :: from_display_handle ( window. display_handle ( ) ) . unwrap ( ) ;
82
+ let adapter = connection. create_adapter ( ) . unwrap ( ) ;
83
+ let flags = ContextAttributeFlags :: ALPHA
84
+ | ContextAttributeFlags :: DEPTH
85
+ | ContextAttributeFlags :: STENCIL ;
86
+ let version = match connection. gl_api ( ) {
87
+ GLApi :: GLES => GLVersion { major : 3 , minor : 0 } ,
88
+ GLApi :: GL => GLVersion { major : 3 , minor : 2 } ,
89
+ } ;
90
+ let context_attributes = ContextAttributes { flags, version } ;
85
91
GlWindowDiscovery {
86
92
connection,
87
93
adapter,
88
94
context_attributes,
89
- factory ,
95
+ window ,
90
96
}
91
97
}
92
98
}
@@ -103,7 +109,7 @@ impl DiscoveryAPI<SurfmanGL> for GlWindowDiscovery {
103
109
let connection = self . connection . clone ( ) ;
104
110
let adapter = self . adapter . clone ( ) ;
105
111
let context_attributes = self . context_attributes . clone ( ) ;
106
- let window = ( self . factory ) ( ) . or ( Err ( Error :: NoMatchingDevice ) ) ? ;
112
+ let window = self . window . clone ( ) ;
107
113
xr. run_on_main_thread ( move |grand_manager| {
108
114
GlWindowDevice :: new (
109
115
connection,
@@ -128,7 +134,7 @@ pub struct GlWindowDevice {
128
134
device : SurfmanDevice ,
129
135
context : SurfmanContext ,
130
136
gl : Rc < Gl > ,
131
- window : Box < dyn GlWindow > ,
137
+ window : Rc < dyn GlWindow > ,
132
138
grand_manager : LayerGrandManager < SurfmanGL > ,
133
139
layer_manager : Option < LayerManager > ,
134
140
target_swap_chain : Option < SwapChain < SurfmanDevice > > ,
@@ -339,7 +345,7 @@ impl GlWindowDevice {
339
345
connection : Connection ,
340
346
adapter : Adapter ,
341
347
context_attributes : ContextAttributes ,
342
- window : Box < dyn GlWindow > ,
348
+ window : Rc < dyn GlWindow > ,
343
349
granted_features : Vec < String > ,
344
350
grand_manager : LayerGrandManager < SurfmanGL > ,
345
351
) -> Result < GlWindowDevice , Error > {
0 commit comments