Guest User

Untitled

a guest
Jul 15th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.22 KB | None | 0 0
  1. diff --git a/src/api/egl/mod.rs b/src/api/egl/mod.rs
  2. index e85c66f..25a7b65 100644
  3. --- a/src/api/egl/mod.rs
  4. +++ b/src/api/egl/mod.rs
  5. @@ -39,7 +39,7 @@ pub struct Context {
  6. egl: ffi::egl::Egl,
  7. display: ffi::egl::types::EGLDisplay,
  8. context: ffi::egl::types::EGLContext,
  9. - surface: Cell<ffi::egl::types::EGLSurface>,
  10. + //surface: Cell<ffi::egl::types::EGLSurface>,
  11. api: Api,
  12. pixel_format: PixelFormat,
  13. config_id: ffi::egl::types::EGLConfig,
  14. @@ -170,11 +170,12 @@ impl Context {
  15. ) -> Result<ContextPrototype<'a>, CreationError>
  16. {
  17. // calling `eglGetDisplay` or equivalent
  18. - let display = get_native_display(&egl, native_display);
  19. + //let display = get_native_display(&egl, native_display);
  20.  
  21. - if display.is_null() {
  22. - return Err(CreationError::OsError("Could not create EGL display object".to_string()));
  23. - }
  24. + //if display.is_null() {
  25. + // return Err(CreationError::OsError("Could not create EGL display object".to_string()));
  26. + //}
  27. + let display = unsafe { egl.GetDisplay(ffi::egl::DEFAULT_DISPLAY as *mut _) };
  28.  
  29. let egl_version = unsafe {
  30. let mut major: ffi::egl::types::EGLint = mem::uninitialized();
  31. @@ -266,7 +267,7 @@ impl Context {
  32. }
  33.  
  34. pub unsafe fn make_current(&self) -> Result<(), ContextError> {
  35. - let ret = self.egl.MakeCurrent(self.display, self.surface.get(), self.surface.get(), self.context);
  36. + let ret = self.egl.MakeCurrent(self.display, ffi::egl::NO_SURFACE, ffi::egl::NO_SURFACE, self.context);
  37.  
  38. if ret == 0 {
  39. match self.egl.GetError() as u32 {
  40. @@ -294,23 +295,8 @@ impl Context {
  41.  
  42. #[inline]
  43. pub fn swap_buffers(&self) -> Result<(), ContextError> {
  44. - if self.surface.get() == ffi::egl::NO_SURFACE {
  45. return Err(ContextError::ContextLost);
  46. - }
  47. -
  48. - let ret = unsafe {
  49. - self.egl.SwapBuffers(self.display, self.surface.get())
  50. - };
  51. -
  52. - if ret == 0 {
  53. - match unsafe { self.egl.GetError() } as u32 {
  54. - ffi::egl::CONTEXT_LOST => return Err(ContextError::ContextLost),
  55. - err => panic!("eglSwapBuffers failed (eglGetError returned 0x{:x})", err)
  56. - }
  57.  
  58. - } else {
  59. - Ok(())
  60. - }
  61. }
  62.  
  63. #[inline]
  64. @@ -375,7 +361,7 @@ impl Drop for Context {
  65. // we don't call MakeCurrent(0, 0) because we are not sure that the context
  66. // is still the current one
  67. self.egl.DestroyContext(self.display, self.context);
  68. - self.egl.DestroySurface(self.display, self.surface.get());
  69. + //self.egl.DestroySurface(self.display, self.surface.get());
  70. self.egl.Terminate(self.display);
  71. }
  72. }
  73. @@ -403,19 +389,10 @@ impl<'a> ContextPrototype<'a> {
  74. value
  75. }
  76.  
  77. - pub fn finish(self, native_window: ffi::EGLNativeWindowType)
  78. + pub fn finish(self)
  79. -> Result<Context, CreationError>
  80. {
  81. - let surface = unsafe {
  82. - let surface = self.egl.CreateWindowSurface(self.display, self.config_id, native_window,
  83. - ptr::null());
  84. - if surface.is_null() {
  85. - return Err(CreationError::OsError(format!("eglCreateWindowSurface failed")))
  86. - }
  87. - surface
  88. - };
  89. -
  90. - self.finish_impl(surface)
  91. + self.finish_pbuffer((1, 1))
  92. }
  93.  
  94. pub fn finish_pbuffer(self, dimensions: (u32, u32)) -> Result<Context, CreationError> {
  95. @@ -495,7 +472,7 @@ impl<'a> ContextPrototype<'a> {
  96. egl: self.egl,
  97. display: self.display,
  98. context: context,
  99. - surface: Cell::new(surface),
  100. + //surface: Cell::new(surface),
  101. api: self.api,
  102. pixel_format: self.pixel_format,
  103. config_id: self.config_id
  104. diff --git a/src/lib.rs b/src/lib.rs
  105. index d678907..c7754a5 100644
  106. --- a/src/lib.rs
  107. +++ b/src/lib.rs
  108. @@ -178,7 +178,7 @@ pub struct ContextBuilder<'a> {
  109. /// ```
  110. pub struct GlWindow {
  111. context: Context,
  112. - window: Window,
  113. + //window: Window,
  114. }
  115.  
  116. impl<'a> ContextBuilder<'a> {
  117. @@ -339,7 +339,7 @@ impl GlWindow {
  118. /// this function. It is also shareable with headless contexts made with the
  119. /// `shareable_with_windowed_contexts` flag set to `true`.
  120. ///
  121. - /// One limitation of the wayland backend when it comes to shared contexts
  122. + /// One limitation of the wayland backend when it comes to shared contexts
  123. /// is tha both contexts must use the same events loop.
  124. ///
  125. /// Error should be very rare and only occur in case of permission denied,
  126. @@ -354,16 +354,11 @@ impl GlWindow {
  127. let gl_attr = gl_attr.map_sharing(|ctxt| &ctxt.context);
  128. platform::Context::new(window_builder, events_loop, &pf_reqs, &gl_attr)
  129. .map(|(window, context)| GlWindow {
  130. - window: window,
  131. + //window: window,
  132. context: Context { context: context },
  133. })
  134. }
  135.  
  136. - /// Borrow the inner `Window`.
  137. - pub fn window(&self) -> &Window {
  138. - &self.window
  139. - }
  140. -
  141. /// Borrow the inner GL `Context`.
  142. pub fn context(&self) -> &Context {
  143. &self.context
  144. @@ -429,7 +424,7 @@ impl Context {
  145. /// If the flag is not set on the otherhand, the context can only be shared
  146. /// with other contexts made with the flag unset.
  147. ///
  148. - /// One limitation of the wayland backend when it comes to shared contexts
  149. + /// One limitation of the wayland backend when it comes to shared contexts
  150. /// is tha both contexts must use the same events loop.
  151. ///
  152. /// Error should be very rare and only occur in case of permission denied,
  153. @@ -465,13 +460,6 @@ impl GlContext for GlWindow {
  154. }
  155. }
  156.  
  157. -impl std::ops::Deref for GlWindow {
  158. - type Target = Window;
  159. - fn deref(&self) -> &Self::Target {
  160. - &self.window
  161. - }
  162. -}
  163. -
  164. /// Error that can happen while creating a window or a headless renderer.
  165. #[derive(Debug)]
  166. pub enum CreationError {
  167. diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs
  168. index 555d7a4..cc865ca 100644
  169. --- a/src/platform/linux/mod.rs
  170. +++ b/src/platform/linux/mod.rs
  171. @@ -30,9 +30,9 @@ pub enum ContextType {
  172.  
  173. pub enum Context {
  174. WindowedX11(x11::Context),
  175. - HeadlessX11(winit::Window, x11::Context),
  176. + HeadlessX11((), x11::Context),
  177. WindowedWayland(wayland::Context),
  178. - HeadlessWayland(winit::Window, wayland::Context),
  179. + HeadlessWayland((), wayland::Context),
  180. OsMesa(osmesa::OsMesaContext),
  181. }
  182.  
  183. @@ -79,7 +79,7 @@ impl Context {
  184. events_loop: &winit::EventsLoop,
  185. pf_reqs: &PixelFormatRequirements,
  186. gl_attr: &GlAttributes<&Context>,
  187. - ) -> Result<(winit::Window, Self), CreationError>
  188. + ) -> Result<((), Self), CreationError>
  189. {
  190. if events_loop.is_wayland() {
  191. Context::is_compatible(&gl_attr.sharing, ContextType::Wayland)?;
  192. @@ -89,7 +89,7 @@ impl Context {
  193. _ => unreachable!(),
  194. });
  195. wayland::Context::new(window_builder, events_loop, pf_reqs, &gl_attr)
  196. - .map(|(window, context)| (window, Context::WindowedWayland(context)))
  197. + .map(|(window, context)| ((), Context::WindowedWayland(context)))
  198. } else {
  199. Context::is_compatible(&gl_attr.sharing, ContextType::X11)?;
  200. let gl_attr = gl_attr.clone().map_sharing(|ctxt| match ctxt {
  201. diff --git a/src/platform/linux/wayland.rs b/src/platform/linux/wayland.rs
  202. index 071b350..043d771 100644
  203. --- a/src/platform/linux/wayland.rs
  204. +++ b/src/platform/linux/wayland.rs
  205. @@ -8,29 +8,27 @@ use api::egl::{self, ffi, Context as EglContext};
  206. use wayland_client::egl as wegl;
  207.  
  208. pub struct Context {
  209. - egl_surface: Arc<wegl::WlEglSurface>,
  210. + //egl_surface: Arc<wegl::WlEglSurface>,
  211. context: EglContext,
  212. }
  213.  
  214. impl Context {
  215. pub fn new(
  216. - window_builder: winit::WindowBuilder,
  217. - events_loop: &winit::EventsLoop,
  218. + _window_builder: winit::WindowBuilder,
  219. + _events_loop: &winit::EventsLoop,
  220. pf_reqs: &PixelFormatRequirements,
  221. gl_attr: &GlAttributes<&Context>,
  222. - ) -> Result<(winit::Window, Self), CreationError>
  223. + ) -> Result<((), Self), CreationError>
  224. {
  225. - let window = window_builder.build(events_loop)?;
  226. - let logical_size = window.get_inner_size().unwrap();
  227. - let (w, h) = (logical_size.width, logical_size.height);
  228. + let (w, h) = (1, 1);
  229.  
  230. - let surface = window.get_wayland_surface();
  231. - let surface = match surface {
  232. - Some(s) => s,
  233. - None => return Err(CreationError::NotSupported("Wayland not found")),
  234. - };
  235. + //let surface = window.get_wayland_surface();
  236. + //let surface = match surface {
  237. + // Some(s) => s,
  238. + // None => return Err(CreationError::NotSupported("Wayland not found")),
  239. + //};
  240.  
  241. - let egl_surface = unsafe { wegl::WlEglSurface::new_from_raw(surface as *mut _, w as i32, h as i32) };
  242. + //let egl_surface = unsafe { wegl::WlEglSurface::new_from_raw(surface as *mut _, w as i32, h as i32) };
  243. let context = {
  244. let libegl = unsafe { dlopen::dlopen(b"libEGL.so\0".as_ptr() as *const _, dlopen::RTLD_NOW) };
  245. if libegl.is_null() {
  246. @@ -42,21 +40,22 @@ impl Context {
  247. });
  248. let gl_attr = gl_attr.clone().map_sharing(|c| &c.context);
  249. let native_display = egl::NativeDisplay::Wayland(Some(
  250. - window.get_wayland_display().unwrap() as *const _
  251. + //window.get_wayland_display().unwrap() as *const _
  252. + unsafe { egl.GetDisplay(ffi::egl::DEFAULT_DISPLAY as *mut _) as *const _}
  253. ));
  254. EglContext::new(egl, pf_reqs, &gl_attr, native_display)
  255. - .and_then(|p| p.finish(egl_surface.ptr() as *const _))?
  256. + .and_then(|p| p.finish())?
  257. };
  258. let context = Context {
  259. - egl_surface: Arc::new(egl_surface),
  260. + //egl_surface: Arc::new(egl_surface),
  261. context: context,
  262. };
  263. - Ok((window, context))
  264. + Ok(((), context))
  265. }
  266.  
  267. #[inline]
  268. pub fn resize(&self, width: u32, height: u32) {
  269. - self.egl_surface.resize(width as i32, height as i32, 0, 0);
  270. + //self.egl_surface.resize(width as i32, height as i32, 0, 0);
  271. }
  272.  
  273. #[inline]
  274. diff --git a/src/platform/linux/x11.rs b/src/platform/linux/x11.rs
  275. index 606053b..cb43849 100644
  276. --- a/src/platform/linux/x11.rs
  277. +++ b/src/platform/linux/x11.rs
  278. @@ -111,11 +111,11 @@ impl Drop for Context {
  279.  
  280. impl Context {
  281. pub fn new(
  282. - window_builder: winit::WindowBuilder,
  283. + _window_builder: winit::WindowBuilder,
  284. events_loop: &winit::EventsLoop,
  285. pf_reqs: &PixelFormatRequirements,
  286. gl_attr: &GlAttributes<&Context>,
  287. - ) -> Result<(winit::Window, Self), CreationError>
  288. + ) -> Result<((), Self), CreationError>
  289. {
  290. let xconn = match events_loop.get_xlib_xconnection() {
  291. Some(xconn) => xconn,
  292. @@ -154,7 +154,7 @@ impl Context {
  293. pf_reqs,
  294. &builder_glx_u,
  295. screen_id,
  296. - window_builder.window.transparent,
  297. + true,
  298. )?)
  299. } else if let Some(ref egl) = backend.egl {
  300. builder_egl_u = builder.map_sharing(|c| match c.context {
  301. @@ -215,19 +215,14 @@ impl Context {
  302. },
  303. };
  304.  
  305. - let window = window_builder
  306. - .with_x11_visual(&visual_infos as *const _)
  307. - .with_x11_screen(screen_id)
  308. - .build(events_loop)?;
  309. -
  310. - let xlib_window = window.get_xlib_window().unwrap();
  311. + let xlib_window = unsafe { (xconn.xlib.XDefaultRootWindow)(xconn.display) };
  312. // finish creating the OpenGL context
  313. let context = match context {
  314. Prototype::Glx(ctxt) => {
  315. GlContext::Glx(ctxt.finish(xlib_window)?)
  316. },
  317. Prototype::Egl(ctxt) => {
  318. - GlContext::Egl(ctxt.finish(xlib_window as _)?)
  319. + GlContext::Egl(ctxt.finish()?)
  320. },
  321. };
  322.  
  323. @@ -250,7 +245,7 @@ impl Context {
  324. colormap,
  325. };
  326.  
  327. - Ok((window, context))
  328. + Ok(((), context))
  329. }
  330.  
  331. #[inline]
Add Comment
Please, Sign In to add comment