1
- use crate :: draw;
2
1
use crate :: handler:: {
3
2
GlfwOpenGLHandler , GlfwPlatformHandler , GlfwPlatformTaskHandler , GlfwTextInputHandler ,
4
3
GlfwWindowHandler ,
@@ -10,6 +9,8 @@ use flutter_engine::ffi::{
10
9
FlutterPointerSignalKind ,
11
10
} ;
12
11
use flutter_engine:: plugins:: Plugin ;
12
+ use flutter_engine:: tasks:: TaskRunnerHandler ;
13
+ use flutter_engine:: texture_registry:: Texture ;
13
14
use flutter_engine:: FlutterEngine ;
14
15
use flutter_plugins:: dialog:: DialogPlugin ;
15
16
use flutter_plugins:: isolate:: IsolatePlugin ;
@@ -25,16 +26,13 @@ use flutter_plugins::window::WindowPlugin;
25
26
use glfw:: Context ;
26
27
use lazy_static:: lazy_static;
27
28
use log:: { debug, info} ;
28
- use parking_lot:: { Mutex , MutexGuard } ;
29
+ use parking_lot:: Mutex ;
29
30
use std:: collections:: { HashMap , VecDeque } ;
30
- use std:: ops:: DerefMut ;
31
31
use std:: path:: PathBuf ;
32
32
use std:: sync:: atomic:: { AtomicBool , AtomicU64 , Ordering } ;
33
33
use std:: sync:: mpsc:: { Receiver , SendError , Sender } ;
34
34
use std:: sync:: { mpsc, Arc } ;
35
35
use std:: time:: Instant ;
36
- use flutter_engine:: texture_registry:: Texture ;
37
- use flutter_engine:: tasks:: TaskRunnerHandler ;
38
36
39
37
// seems to be about 2.5 lines of text
40
38
const SCROLL_SPEED : f64 =50.0 ;
@@ -57,18 +55,12 @@ pub enum CreateError {
57
55
58
56
impl std:: fmt:: Display for CreateError {
59
57
fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
60
- use std:: error:: Error ;
61
- f. write_str ( self . description ( ) )
62
- }
63
- }
64
-
65
- impl std:: error:: Error for CreateError {
66
- fn description ( & self ) ->& str {
67
- match * self {
58
+ let msg =match * self {
68
59
CreateError :: WindowCreationFailed =>"Failed to create a window" ,
69
60
CreateError :: WindowAlreadyCreated =>"Window was already created" ,
70
61
CreateError :: MonitorNotFound =>"No monitor with the specified index found" ,
71
- }
62
+ } ;
63
+ f. write_str ( msg)
72
64
}
73
65
}
74
66
@@ -83,7 +75,6 @@ pub struct WindowArgs<'a> {
83
75
pub height : i32 ,
84
76
pub title : & ' a str ,
85
77
pub mode : WindowMode ,
86
- pub bg_color : ( u8 , u8 , u8 ) ,
87
78
}
88
79
89
80
/// Wrap glfw::Window, so that it could be used in a lazy_static HashMap
@@ -111,7 +102,7 @@ pub struct FlutterWindow {
111
102
glfw : glfw:: Glfw ,
112
103
window : Arc < Mutex < glfw:: Window > > ,
113
104
window_receiver : Receiver < ( f64 , glfw:: WindowEvent ) > ,
114
- resource_window : Arc < Mutex < glfw:: Window > > ,
105
+ _resource_window : glfw:: Window ,
115
106
_resource_window_receiver : Receiver < ( f64 , glfw:: WindowEvent ) > ,
116
107
engine : FlutterEngine ,
117
108
pointer_currently_added : AtomicBool ,
@@ -132,8 +123,17 @@ impl FlutterWindow {
132
123
assets_path : PathBuf ,
133
124
arguments : Vec < String > ,
134
125
) ->Result < Self , CreateError > {
126
+ glfw. window_hint ( glfw:: WindowHint :: ContextVersion ( 3 , 2 ) ) ;
127
+ glfw. window_hint ( glfw:: WindowHint :: OpenGlForwardCompat ( true ) ) ;
128
+ glfw. window_hint ( glfw:: WindowHint :: OpenGlProfile (
129
+ glfw:: OpenGlProfileHint :: Core ,
130
+ ) ) ;
131
+ glfw. window_hint ( glfw:: WindowHint :: ContextCreationApi (
132
+ glfw:: ContextCreationApi :: Egl ,
133
+ ) ) ;
134
+
135
135
// Create window
136
- let ( window, receiver) =match window_args. mode {
136
+ let ( mut window, receiver) =match window_args. mode {
137
137
WindowMode :: Windowed => glfw
138
138
. create_window (
139
139
window_args. width as u32 ,
@@ -169,29 +169,19 @@ impl FlutterWindow {
169
169
// Create invisible resource window
170
170
glfw. window_hint ( glfw:: WindowHint :: Decorated ( false ) ) ;
171
171
glfw. window_hint ( glfw:: WindowHint :: Visible ( false ) ) ;
172
- let ( res_window, res_window_recv) = window
172
+ let ( mut res_window, res_window_recv) = window
173
173
. create_shared ( 1 , 1 , "" , glfw:: WindowMode :: Windowed )
174
174
. ok_or ( CreateError :: WindowCreationFailed ) ?;
175
175
glfw. default_window_hints ( ) ;
176
176
177
+ let render_ctx = window. render_context ( ) ;
178
+
177
179
// Wrap
178
180
let window =Arc :: new ( Mutex :: new ( window) ) ;
179
- let res_window =Arc :: new ( Mutex :: new ( res_window) ) ;
180
-
181
- // draw initial screen to avoid blinking
182
- {
183
- let mut window = window. lock ( ) ;
184
- window. make_current ( ) ;
185
- let mut window =MutexGuard :: deref_mut ( & mut window) ;
186
- draw:: init_gl ( & mut window) ;
187
- draw:: draw_bg ( & mut window, window_args. bg_color ) ;
188
- glfw:: make_context_current ( None ) ;
189
- }
190
181
191
182
// Create engine
192
183
let platform_task_handler =Arc :: new ( GlfwPlatformTaskHandler :: new ( ) ) ;
193
- let opengl_handler =
194
- GlfwOpenGLHandler :: new ( glfw. clone ( ) , window. clone ( ) , res_window. clone ( ) ) ;
184
+ let opengl_handler =GlfwOpenGLHandler :: new ( render_ctx, res_window. render_context ( ) ) ;
195
185
196
186
let engine =FlutterEngineBuilder :: new ( )
197
187
. with_platform_handler ( platform_task_handler. clone ( ) )
@@ -244,7 +234,7 @@ impl FlutterWindow {
244
234
glfw : glfw. clone ( ) ,
245
235
window,
246
236
window_receiver : receiver,
247
- resource_window : res_window,
237
+ _resource_window : res_window,
248
238
_resource_window_receiver : res_window_recv,
249
239
engine,
250
240
pointer_currently_added : AtomicBool :: new ( false ) ,
@@ -267,10 +257,6 @@ impl FlutterWindow {
267
257
self . window . clone ( )
268
258
}
269
259
270
- pub fn resource_window ( & self ) ->Arc < Mutex < glfw:: Window > > {
271
- self . resource_window . clone ( )
272
- }
273
-
274
260
pub fn create_texture ( & self ) ->Texture {
275
261
self . engine . create_texture ( )
276
262
}