mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 05:12:40 +03:00
window: make opengl always required
This commit is contained in:
parent
cf2dcff362
commit
4c22de9f6d
@ -65,7 +65,7 @@ wezterm-font = { path = "../wezterm-font" }
|
||||
wezterm-gui-subcommands = { path = "../wezterm-gui-subcommands" }
|
||||
wezterm-term = { path = "../term", features=["use_serde"] }
|
||||
wezterm-toast-notification = { path = "../wezterm-toast-notification" }
|
||||
window = { path = "../window", features=["opengl", "wayland"]}
|
||||
window = { path = "../window", features=["wayland"]}
|
||||
|
||||
[target."cfg(windows)".dependencies]
|
||||
shared_library = "0.1"
|
||||
|
@ -12,7 +12,7 @@ build = "build.rs"
|
||||
pretty_env_logger = "0.4"
|
||||
|
||||
[build-dependencies]
|
||||
gl_generator = {version="0.14", optional=true}
|
||||
gl_generator = "0.14"
|
||||
|
||||
[dependencies]
|
||||
async-task = "4.0"
|
||||
@ -22,7 +22,7 @@ bitflags = "1.0"
|
||||
euclid = "0.22"
|
||||
guillotiere = "0.6"
|
||||
lazy_static = "1.4"
|
||||
libloading = { version = "0.6", optional=true }
|
||||
libloading = "0.6"
|
||||
line_drawing = "0.8"
|
||||
log = "0.4"
|
||||
metrics = { version="0.12", features=["std"]}
|
||||
@ -30,11 +30,10 @@ palette = "0.5"
|
||||
promise = { path = "../promise" }
|
||||
resize = "0.5"
|
||||
serde = {version="1.0", features = ["rc", "derive"]}
|
||||
glium = { version = "0.29", optional=true, default-features = false}
|
||||
glium = { version = "0.29", default-features = false}
|
||||
wezterm-input-types = { path = "../wezterm-input-types" }
|
||||
|
||||
[features]
|
||||
opengl = ["cgl", "glium", "gl_generator", "libloading"]
|
||||
wayland = ["smithay-client-toolkit", "memmap", "wayland-client", "wayland-egl"]
|
||||
|
||||
[target."cfg(windows)".dependencies]
|
||||
@ -70,4 +69,4 @@ objc = "0.2"
|
||||
clipboard = "0.5"
|
||||
core-foundation = "0.7"
|
||||
core-graphics = "0.19"
|
||||
cgl = { version = "0.3", optional = true }
|
||||
cgl = "0.3"
|
||||
|
135
window/build.rs
135
window/build.rs
@ -1,78 +1,75 @@
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
{
|
||||
use gl_generator::{Api, Fallbacks, Profile, Registry};
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
use gl_generator::{Api, Fallbacks, Profile, Registry};
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
|
||||
let dest = PathBuf::from(&env::var("OUT_DIR").unwrap());
|
||||
let target = env::var("TARGET").unwrap();
|
||||
if !target.contains("macos") {
|
||||
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
|
||||
let reg = Registry::new(
|
||||
Api::Egl,
|
||||
(1, 5),
|
||||
Profile::Core,
|
||||
Fallbacks::All,
|
||||
[
|
||||
"EGL_KHR_create_context",
|
||||
"EGL_EXT_create_context_robustness",
|
||||
"EGL_KHR_create_context_no_error",
|
||||
"EGL_KHR_platform_x11",
|
||||
"EGL_KHR_platform_android",
|
||||
"EGL_KHR_platform_wayland",
|
||||
"EGL_KHR_platform_gbm",
|
||||
"EGL_EXT_platform_base",
|
||||
"EGL_EXT_platform_x11",
|
||||
"EGL_MESA_platform_gbm",
|
||||
"EGL_EXT_platform_wayland",
|
||||
"EGL_EXT_platform_device",
|
||||
"EGL_KHR_swap_buffers_with_damage",
|
||||
],
|
||||
);
|
||||
|
||||
if target.contains("android") || target.contains("ios") {
|
||||
reg.write_bindings(gl_generator::StaticStructGenerator, &mut file)
|
||||
} else {
|
||||
reg.write_bindings(gl_generator::StructGenerator, &mut file)
|
||||
}
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
if target.contains("windows") {
|
||||
let mut file = File::create(&dest.join("wgl_bindings.rs")).unwrap();
|
||||
let reg = Registry::new(Api::Wgl, (1, 0), Profile::Core, Fallbacks::All, []);
|
||||
let dest = PathBuf::from(&env::var("OUT_DIR").unwrap());
|
||||
let target = env::var("TARGET").unwrap();
|
||||
if !target.contains("macos") {
|
||||
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
|
||||
let reg = Registry::new(
|
||||
Api::Egl,
|
||||
(1, 5),
|
||||
Profile::Core,
|
||||
Fallbacks::All,
|
||||
[
|
||||
"EGL_KHR_create_context",
|
||||
"EGL_EXT_create_context_robustness",
|
||||
"EGL_KHR_create_context_no_error",
|
||||
"EGL_KHR_platform_x11",
|
||||
"EGL_KHR_platform_android",
|
||||
"EGL_KHR_platform_wayland",
|
||||
"EGL_KHR_platform_gbm",
|
||||
"EGL_EXT_platform_base",
|
||||
"EGL_EXT_platform_x11",
|
||||
"EGL_MESA_platform_gbm",
|
||||
"EGL_EXT_platform_wayland",
|
||||
"EGL_EXT_platform_device",
|
||||
"EGL_KHR_swap_buffers_with_damage",
|
||||
],
|
||||
);
|
||||
|
||||
if target.contains("android") || target.contains("ios") {
|
||||
reg.write_bindings(gl_generator::StaticStructGenerator, &mut file)
|
||||
} else {
|
||||
reg.write_bindings(gl_generator::StructGenerator, &mut file)
|
||||
.unwrap();
|
||||
|
||||
let mut file = File::create(&dest.join("wgl_extra_bindings.rs")).unwrap();
|
||||
Registry::new(
|
||||
Api::Wgl,
|
||||
(1, 0),
|
||||
Profile::Core,
|
||||
Fallbacks::All,
|
||||
[
|
||||
"WGL_ARB_create_context",
|
||||
"WGL_ARB_create_context_profile",
|
||||
"WGL_ARB_create_context_robustness",
|
||||
"WGL_ARB_context_flush_control",
|
||||
"WGL_ARB_extensions_string",
|
||||
"WGL_ARB_framebuffer_sRGB",
|
||||
"WGL_ARB_multisample",
|
||||
"WGL_ARB_pixel_format",
|
||||
"WGL_ARB_pixel_format_float",
|
||||
"WGL_EXT_create_context_es2_profile",
|
||||
"WGL_EXT_extensions_string",
|
||||
"WGL_EXT_framebuffer_sRGB",
|
||||
"WGL_EXT_swap_control",
|
||||
],
|
||||
)
|
||||
.write_bindings(gl_generator::StructGenerator, &mut file)
|
||||
.unwrap();
|
||||
}
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
if target.contains("windows") {
|
||||
let mut file = File::create(&dest.join("wgl_bindings.rs")).unwrap();
|
||||
let reg = Registry::new(Api::Wgl, (1, 0), Profile::Core, Fallbacks::All, []);
|
||||
|
||||
reg.write_bindings(gl_generator::StructGenerator, &mut file)
|
||||
.unwrap();
|
||||
|
||||
let mut file = File::create(&dest.join("wgl_extra_bindings.rs")).unwrap();
|
||||
Registry::new(
|
||||
Api::Wgl,
|
||||
(1, 0),
|
||||
Profile::Core,
|
||||
Fallbacks::All,
|
||||
[
|
||||
"WGL_ARB_create_context",
|
||||
"WGL_ARB_create_context_profile",
|
||||
"WGL_ARB_create_context_robustness",
|
||||
"WGL_ARB_context_flush_control",
|
||||
"WGL_ARB_extensions_string",
|
||||
"WGL_ARB_framebuffer_sRGB",
|
||||
"WGL_ARB_multisample",
|
||||
"WGL_ARB_pixel_format",
|
||||
"WGL_ARB_pixel_format_float",
|
||||
"WGL_EXT_create_context_es2_profile",
|
||||
"WGL_EXT_extensions_string",
|
||||
"WGL_EXT_framebuffer_sRGB",
|
||||
"WGL_EXT_swap_control",
|
||||
],
|
||||
)
|
||||
.write_bindings(gl_generator::StructGenerator, &mut file)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -16,14 +16,12 @@ impl WindowCallbacks for MyWindow {
|
||||
context.clear(Color::rgb(0x0, 0x0, 0x0));
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
fn paint_opengl(&mut self, frame: &mut glium::Frame) {
|
||||
// Window contents are gray in opengl mode
|
||||
use glium::Surface;
|
||||
frame.clear_color_srgb(0.15, 0.15, 0.15, 1.0);
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
fn opengl_initialize(
|
||||
&mut self,
|
||||
_window: &dyn WindowOps,
|
||||
@ -53,14 +51,7 @@ fn spawn_window() -> anyhow::Result<()> {
|
||||
}),
|
||||
)?;
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
win.enable_opengl();
|
||||
|
||||
#[cfg(not(feature = "opengl"))]
|
||||
eprintln!(
|
||||
"opengl not enabled at compile time: cargo run --feature opengl --example basic_opengl"
|
||||
);
|
||||
|
||||
win.show();
|
||||
win.apply(|myself, _win| {
|
||||
if let Some(myself) = myself.downcast_ref::<MyWindow>() {
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::color::Color;
|
||||
use crate::{Operator, Point, Rect, Size};
|
||||
#[cfg(feature = "opengl")]
|
||||
use glium::texture::SrgbTexture2d;
|
||||
use palette::LinSrgba;
|
||||
use std::cell::RefCell;
|
||||
@ -43,7 +42,6 @@ pub trait Texture2d {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
impl Texture2d for SrgbTexture2d {
|
||||
fn write(&self, rect: Rect, im: &dyn BitmapImage) {
|
||||
let (im_width, im_height) = im.image_dimensions();
|
||||
|
@ -16,15 +16,12 @@ pub const DEFAULT_DPI: f64 = 72.0;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub const DEFAULT_DPI: f64 = 96.0;
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
mod egl;
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
pub use glium;
|
||||
|
||||
pub use bitmaps::{BitmapImage, Image};
|
||||
pub use color::Color;
|
||||
pub use connection::*;
|
||||
pub use glium;
|
||||
pub use os::*;
|
||||
pub use wezterm_input_types::*;
|
||||
|
||||
@ -139,7 +136,6 @@ pub trait WindowCallbacks: Any {
|
||||
|
||||
/// Called when the window has opengl mode enabled and the window
|
||||
/// contents need painting.
|
||||
#[cfg(feature = "opengl")]
|
||||
fn paint_opengl(&mut self, frame: &mut glium::Frame) {
|
||||
use glium::Surface;
|
||||
frame.clear_color_srgb(0.25, 0.125, 0.375, 1.0);
|
||||
@ -147,7 +143,6 @@ pub trait WindowCallbacks: Any {
|
||||
|
||||
/// Called when opengl is initialized by enable_opengl(),
|
||||
/// and also prior to calling opengl_context_lost with and Err value.
|
||||
#[cfg(feature = "opengl")]
|
||||
fn opengl_initialize(
|
||||
&mut self,
|
||||
_window: &dyn WindowOps,
|
||||
@ -157,7 +152,6 @@ pub trait WindowCallbacks: Any {
|
||||
}
|
||||
|
||||
/// Called if the opengl context is lost
|
||||
#[cfg(feature = "opengl")]
|
||||
fn opengl_context_lost(&mut self, _window: &dyn WindowOps) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
@ -238,7 +232,6 @@ pub trait WindowOps {
|
||||
/// Attempt to set up opengl based painting.
|
||||
/// Will call opengl_initialize() in your WindowCallbacks impl to
|
||||
/// inform it of the gl context.
|
||||
#[cfg(feature = "opengl")]
|
||||
fn enable_opengl(&self) -> promise::Future<()>;
|
||||
|
||||
/// Initiate textual transfer from the clipboard
|
||||
|
@ -18,7 +18,6 @@ pub struct Connection {
|
||||
ns_app: id,
|
||||
pub(crate) windows: RefCell<HashMap<usize, Rc<RefCell<WindowInner>>>>,
|
||||
pub(crate) next_window_id: AtomicUsize,
|
||||
#[cfg(feature = "opengl")]
|
||||
pub(crate) gl_connection: RefCell<Option<Rc<crate::egl::GlConnection>>>,
|
||||
}
|
||||
|
||||
@ -35,7 +34,6 @@ impl Connection {
|
||||
ns_app,
|
||||
windows: RefCell::new(HashMap::new()),
|
||||
next_window_id: AtomicUsize::new(1),
|
||||
#[cfg(feature = "opengl")]
|
||||
gl_connection: RefCell::new(None),
|
||||
};
|
||||
Ok(conn)
|
||||
|
@ -85,7 +85,6 @@ impl NSRange {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
mod opengl {
|
||||
use super::*;
|
||||
use cocoa::appkit::{self, NSOpenGLContext, NSOpenGLPixelFormat};
|
||||
@ -389,7 +388,6 @@ impl Window {
|
||||
view_id: None,
|
||||
window_id,
|
||||
screen_changed: false,
|
||||
#[cfg(feature = "opengl")]
|
||||
gl_context_pair: None,
|
||||
text_cursor_position: Rect::new(Point::new(0, 0), Size::new(0, 0)),
|
||||
hscroll_remainder: 0.,
|
||||
@ -570,7 +568,6 @@ impl WindowOps for Window {
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
fn enable_opengl(&self) -> promise::Future<()> {
|
||||
Connection::with_window_inner(self.0, move |inner| {
|
||||
if let Some(window_view) = WindowView::get_this(unsafe { &**inner.view }) {
|
||||
@ -843,7 +840,6 @@ struct Inner {
|
||||
view_id: Option<WeakPtr>,
|
||||
window_id: usize,
|
||||
screen_changed: bool,
|
||||
#[cfg(feature = "opengl")]
|
||||
gl_context_pair: Option<opengl::GlContextPair>,
|
||||
text_cursor_position: Rect,
|
||||
hscroll_remainder: f64,
|
||||
@ -859,7 +855,6 @@ struct Inner {
|
||||
}
|
||||
|
||||
impl Inner {
|
||||
#[cfg(feature = "opengl")]
|
||||
fn enable_opengl(&mut self) -> anyhow::Result<()> {
|
||||
let window = Window(self.window_id);
|
||||
|
||||
@ -1517,14 +1512,11 @@ impl WindowView {
|
||||
}
|
||||
|
||||
extern "C" fn did_resize(this: &mut Object, _sel: Sel, _notification: id) {
|
||||
#[cfg(feature = "opengl")]
|
||||
{
|
||||
if let Some(this) = Self::get_this(this) {
|
||||
let inner = this.inner.borrow_mut();
|
||||
if let Some(this) = Self::get_this(this) {
|
||||
let inner = this.inner.borrow_mut();
|
||||
|
||||
if let Some(gl_context_pair) = inner.gl_context_pair.as_ref() {
|
||||
gl_context_pair.backend.update();
|
||||
}
|
||||
if let Some(gl_context_pair) = inner.gl_context_pair.as_ref() {
|
||||
gl_context_pair.backend.update();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1563,34 +1555,31 @@ impl WindowView {
|
||||
return;
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
{
|
||||
if let Some(gl_context_pair) = inner.gl_context_pair.as_ref() {
|
||||
if gl_context_pair.context.is_context_lost() {
|
||||
log::error!("opengl context was lost; should reinit");
|
||||
drop(inner.gl_context_pair.take());
|
||||
if let Err(e) = inner.enable_opengl() {
|
||||
log::error!("failed to reinit opengl: {}", e);
|
||||
}
|
||||
let view = inner.view_id.as_ref().unwrap().load();
|
||||
drop(inner);
|
||||
drop(this);
|
||||
unsafe {
|
||||
return Self::draw_rect(&mut **view, sel, dirty_rect);
|
||||
}
|
||||
if let Some(gl_context_pair) = inner.gl_context_pair.as_ref() {
|
||||
if gl_context_pair.context.is_context_lost() {
|
||||
log::error!("opengl context was lost; should reinit");
|
||||
drop(inner.gl_context_pair.take());
|
||||
if let Err(e) = inner.enable_opengl() {
|
||||
log::error!("failed to reinit opengl: {}", e);
|
||||
}
|
||||
let view = inner.view_id.as_ref().unwrap().load();
|
||||
drop(inner);
|
||||
drop(this);
|
||||
unsafe {
|
||||
return Self::draw_rect(&mut **view, sel, dirty_rect);
|
||||
}
|
||||
|
||||
let mut frame = glium::Frame::new(
|
||||
Rc::clone(&gl_context_pair.context),
|
||||
(width as u32, height as u32),
|
||||
);
|
||||
|
||||
inner.callbacks.paint_opengl(&mut frame);
|
||||
frame
|
||||
.finish()
|
||||
.expect("frame.finish failed and we don't know how to recover");
|
||||
return;
|
||||
}
|
||||
|
||||
let mut frame = glium::Frame::new(
|
||||
Rc::clone(&gl_context_pair.context),
|
||||
(width as u32, height as u32),
|
||||
);
|
||||
|
||||
inner.callbacks.paint_opengl(&mut frame);
|
||||
frame
|
||||
.finish()
|
||||
.expect("frame.finish failed and we don't know how to recover");
|
||||
return;
|
||||
}
|
||||
|
||||
let mut buffer = this.buffer.borrow_mut();
|
||||
|
@ -34,7 +34,6 @@ pub struct WaylandConnection {
|
||||
// they appear in the struct, so the Display must be at the
|
||||
// bottom of this list, and opengl, which depends on everything
|
||||
// must be ahead of the rest.
|
||||
#[cfg(feature = "opengl")]
|
||||
pub(crate) gl_connection: RefCell<Option<Rc<crate::egl::GlConnection>>>,
|
||||
pub(crate) pointer: PointerDispatcher,
|
||||
pub(crate) keyboard: KeyboardDispatcher,
|
||||
@ -87,7 +86,6 @@ impl WaylandConnection {
|
||||
windows: RefCell::new(HashMap::new()),
|
||||
keyboard,
|
||||
pointer: pointer.unwrap(),
|
||||
#[cfg(feature = "opengl")]
|
||||
gl_connection: RefCell::new(None),
|
||||
})
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ use toolkit::reexports::client::protocol::wl_surface::WlSurface;
|
||||
use toolkit::shm::MemPool;
|
||||
use toolkit::window::{ButtonColorSpec, ColorSpec, ConceptConfig, ConceptFrame, Event};
|
||||
use wayland_client::protocol::wl_data_device_manager::WlDataDeviceManager;
|
||||
#[cfg(feature = "opengl")]
|
||||
use wayland_egl::{is_available as egl_is_available, WlEglSurface};
|
||||
use wezterm_input_types::*;
|
||||
|
||||
@ -98,9 +97,7 @@ pub struct WaylandWindowInner {
|
||||
// wegl_surface is listed before gl_state because it
|
||||
// must be dropped before gl_state otherwise the underlying
|
||||
// libraries will segfault on shutdown
|
||||
#[cfg(feature = "opengl")]
|
||||
wegl_surface: Option<WlEglSurface>,
|
||||
#[cfg(feature = "opengl")]
|
||||
gl_state: Option<Rc<glium::backend::Context>>,
|
||||
}
|
||||
|
||||
@ -245,9 +242,7 @@ impl WaylandWindow {
|
||||
modifiers: Modifiers::NONE,
|
||||
pending_event,
|
||||
pending_mouse,
|
||||
#[cfg(feature = "opengl")]
|
||||
gl_state: None,
|
||||
#[cfg(feature = "opengl")]
|
||||
wegl_surface: None,
|
||||
}));
|
||||
|
||||
@ -489,11 +484,8 @@ impl WaylandWindowInner {
|
||||
self.dimensions = new_dimensions;
|
||||
|
||||
self.callbacks.resize(self.dimensions);
|
||||
#[cfg(feature = "opengl")]
|
||||
{
|
||||
if let Some(wegl_surface) = self.wegl_surface.as_mut() {
|
||||
wegl_surface.resize(pixel_width, pixel_height, 0, 0);
|
||||
}
|
||||
if let Some(wegl_surface) = self.wegl_surface.as_mut() {
|
||||
wegl_surface.resize(pixel_width, pixel_height, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -514,7 +506,6 @@ impl WaylandWindowInner {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
fn enable_opengl(&mut self) -> anyhow::Result<()> {
|
||||
let window = Window::Wayland(WaylandWindow(self.window_id));
|
||||
let wayland_conn = Connection::get().unwrap().wayland();
|
||||
@ -563,31 +554,28 @@ impl WaylandWindowInner {
|
||||
}
|
||||
|
||||
fn do_paint(&mut self) -> anyhow::Result<()> {
|
||||
#[cfg(feature = "opengl")]
|
||||
{
|
||||
if let Some(gl_context) = self.gl_state.as_ref() {
|
||||
if gl_context.is_context_lost() {
|
||||
log::error!("opengl context was lost; should reinit");
|
||||
drop(self.gl_state.take());
|
||||
self.enable_opengl()?;
|
||||
return self.do_paint();
|
||||
}
|
||||
|
||||
let mut frame = glium::Frame::new(
|
||||
Rc::clone(&gl_context),
|
||||
(
|
||||
self.dimensions.pixel_width as u32,
|
||||
self.dimensions.pixel_height as u32,
|
||||
),
|
||||
);
|
||||
|
||||
self.callbacks.paint_opengl(&mut frame);
|
||||
frame.finish()?;
|
||||
// self.damage();
|
||||
self.refresh_frame();
|
||||
self.need_paint = false;
|
||||
return Ok(());
|
||||
if let Some(gl_context) = self.gl_state.as_ref() {
|
||||
if gl_context.is_context_lost() {
|
||||
log::error!("opengl context was lost; should reinit");
|
||||
drop(self.gl_state.take());
|
||||
self.enable_opengl()?;
|
||||
return self.do_paint();
|
||||
}
|
||||
|
||||
let mut frame = glium::Frame::new(
|
||||
Rc::clone(&gl_context),
|
||||
(
|
||||
self.dimensions.pixel_width as u32,
|
||||
self.dimensions.pixel_height as u32,
|
||||
),
|
||||
);
|
||||
|
||||
self.callbacks.paint_opengl(&mut frame);
|
||||
frame.finish()?;
|
||||
// self.damage();
|
||||
self.refresh_frame();
|
||||
self.need_paint = false;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if self.pool.is_used() {
|
||||
@ -777,7 +765,6 @@ impl WindowOps for WaylandWindow {
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
fn enable_opengl(&self) -> promise::Future<()> {
|
||||
WaylandConnection::with_window_inner(self.0, move |inner| inner.enable_opengl())
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ pub struct Connection {
|
||||
event_handle: HANDLE,
|
||||
pub(crate) windows: RefCell<HashMap<HWindow, Rc<RefCell<WindowInner>>>>,
|
||||
timers: RefCell<HashMap<UINT_PTR, UINT_PTR>>,
|
||||
#[cfg(feature = "opengl")]
|
||||
pub(crate) gl_connection: RefCell<Option<Rc<crate::egl::GlConnection>>>,
|
||||
}
|
||||
|
||||
@ -99,7 +98,6 @@ impl Connection {
|
||||
event_handle,
|
||||
windows: RefCell::new(HashMap::new()),
|
||||
timers: RefCell::new(HashMap::new()),
|
||||
#[cfg(feature = "opengl")]
|
||||
gl_connection: RefCell::new(None),
|
||||
})
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![cfg(feature = "opengl")]
|
||||
|
||||
use super::*;
|
||||
use crate::is_swrast_preferred;
|
||||
use glium::backend::Backend;
|
||||
|
@ -45,7 +45,6 @@ pub(crate) struct WindowInner {
|
||||
hwnd: HWindow,
|
||||
callbacks: RefCell<Box<dyn WindowCallbacks>>,
|
||||
bitmap: RefCell<GdiBitmap>,
|
||||
#[cfg(feature = "opengl")]
|
||||
gl_state: Option<Rc<glium::backend::Context>>,
|
||||
/// Fraction of mouse scroll
|
||||
hscroll_remainder: i16,
|
||||
@ -111,7 +110,6 @@ fn take_rc_from_pointer(lparam: LPVOID) -> Rc<RefCell<WindowInner>> {
|
||||
unsafe { Rc::from_raw(std::mem::transmute(lparam)) }
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
fn callback_behavior() -> glium::debug::DebugCallbackBehavior {
|
||||
if cfg!(debug_assertions) && false
|
||||
/* https://github.com/glium/glium/issues/1885 */
|
||||
@ -123,7 +121,6 @@ fn callback_behavior() -> glium::debug::DebugCallbackBehavior {
|
||||
}
|
||||
|
||||
impl WindowInner {
|
||||
#[cfg(feature = "opengl")]
|
||||
fn enable_opengl(&mut self) -> anyhow::Result<()> {
|
||||
let window = Window(self.hwnd);
|
||||
let conn = Connection::get().unwrap();
|
||||
@ -299,7 +296,6 @@ impl Window {
|
||||
hwnd: HWindow(null_mut()),
|
||||
callbacks: RefCell::new(callbacks),
|
||||
bitmap: RefCell::new(GdiBitmap::new_empty()),
|
||||
#[cfg(feature = "opengl")]
|
||||
gl_state: None,
|
||||
vscroll_remainder: 0,
|
||||
hscroll_remainder: 0,
|
||||
@ -512,7 +508,6 @@ impl WindowOps for Window {
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
fn enable_opengl(&self) -> promise::Future<()> {
|
||||
Connection::with_window_inner(self.0, move |inner| inner.enable_opengl())
|
||||
}
|
||||
@ -784,26 +779,23 @@ unsafe fn wm_paint(hwnd: HWND, _msg: UINT, _wparam: WPARAM, _lparam: LPARAM) ->
|
||||
let width = rect_width(&rect) as usize;
|
||||
let height = rect_height(&rect) as usize;
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
{
|
||||
if let Some(gl_context) = inner.gl_state.as_ref() {
|
||||
if gl_context.is_context_lost() {
|
||||
log::error!("opengl context was lost; should reinit");
|
||||
let _ = inner
|
||||
.callbacks
|
||||
.borrow_mut()
|
||||
.opengl_context_lost(&Window(inner.hwnd));
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut frame =
|
||||
glium::Frame::new(Rc::clone(&gl_context), (width as u32, height as u32));
|
||||
|
||||
inner.callbacks.borrow_mut().paint_opengl(&mut frame);
|
||||
frame.finish().expect("frame.finish failed");
|
||||
EndPaint(hwnd, &mut ps);
|
||||
return Some(0);
|
||||
if let Some(gl_context) = inner.gl_state.as_ref() {
|
||||
if gl_context.is_context_lost() {
|
||||
log::error!("opengl context was lost; should reinit");
|
||||
let _ = inner
|
||||
.callbacks
|
||||
.borrow_mut()
|
||||
.opengl_context_lost(&Window(inner.hwnd));
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut frame =
|
||||
glium::Frame::new(Rc::clone(&gl_context), (width as u32, height as u32));
|
||||
|
||||
inner.callbacks.borrow_mut().paint_opengl(&mut frame);
|
||||
frame.finish().expect("frame.finish failed");
|
||||
EndPaint(hwnd, &mut ps);
|
||||
return Some(0);
|
||||
}
|
||||
|
||||
if width > 0 && height > 0 {
|
||||
|
@ -10,7 +10,6 @@ use mio::{Evented, Events, Poll, PollOpt, Ready, Token};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
#[cfg(feature = "opengl")]
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
@ -36,7 +35,6 @@ pub struct XConnection {
|
||||
timers: RefCell<TimerList>,
|
||||
pub(crate) visual: xcb::xproto::Visualtype,
|
||||
pub(crate) depth: u8,
|
||||
#[cfg(feature = "opengl")]
|
||||
pub(crate) gl_connection: RefCell<Option<Rc<crate::egl::GlConnection>>>,
|
||||
}
|
||||
|
||||
@ -413,7 +411,6 @@ impl XConnection {
|
||||
timers: RefCell::new(TimerList::new()),
|
||||
depth,
|
||||
visual,
|
||||
#[cfg(feature = "opengl")]
|
||||
gl_connection: RefCell::new(None),
|
||||
};
|
||||
|
||||
|
@ -50,7 +50,6 @@ pub(crate) struct XWindowInner {
|
||||
cursor: Option<MouseCursor>,
|
||||
cursors: HashMap<Option<MouseCursor>, XcbCursor>,
|
||||
copy_and_paste: CopyAndPaste,
|
||||
#[cfg(feature = "opengl")]
|
||||
gl_state: Option<Rc<glium::backend::Context>>,
|
||||
}
|
||||
|
||||
@ -111,7 +110,6 @@ impl<'a> PaintContext for X11GraphicsContext<'a> {
|
||||
}
|
||||
|
||||
impl XWindowInner {
|
||||
#[cfg(feature = "opengl")]
|
||||
fn enable_opengl(&mut self) -> anyhow::Result<()> {
|
||||
let window = XWindow(self.window_id);
|
||||
let conn = self.conn();
|
||||
@ -159,27 +157,24 @@ impl XWindowInner {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
{
|
||||
if let Some(gl_context) = self.gl_state.as_ref() {
|
||||
if gl_context.is_context_lost() {
|
||||
log::error!("opengl context was lost; should reinit");
|
||||
drop(self.gl_state.take());
|
||||
self.enable_opengl()?;
|
||||
return self.paint();
|
||||
}
|
||||
|
||||
self.expose.clear();
|
||||
|
||||
let mut frame = glium::Frame::new(
|
||||
Rc::clone(&gl_context),
|
||||
(u32::from(self.width), u32::from(self.height)),
|
||||
);
|
||||
|
||||
self.callbacks.paint_opengl(&mut frame);
|
||||
frame.finish()?;
|
||||
return Ok(());
|
||||
if let Some(gl_context) = self.gl_state.as_ref() {
|
||||
if gl_context.is_context_lost() {
|
||||
log::error!("opengl context was lost; should reinit");
|
||||
drop(self.gl_state.take());
|
||||
self.enable_opengl()?;
|
||||
return self.paint();
|
||||
}
|
||||
|
||||
self.expose.clear();
|
||||
|
||||
let mut frame = glium::Frame::new(
|
||||
Rc::clone(&gl_context),
|
||||
(u32::from(self.width), u32::from(self.height)),
|
||||
);
|
||||
|
||||
self.callbacks.paint_opengl(&mut frame);
|
||||
frame.finish()?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let (buf_width, buf_height) = self.buffer_image.image_dimensions();
|
||||
@ -848,7 +843,6 @@ impl XWindow {
|
||||
buffer_image,
|
||||
cursor: None,
|
||||
cursors: HashMap::new(),
|
||||
#[cfg(feature = "opengl")]
|
||||
gl_state: None,
|
||||
}))
|
||||
};
|
||||
@ -1061,7 +1055,6 @@ impl WindowOps for XWindow {
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
fn enable_opengl(&self) -> promise::Future<()> {
|
||||
XConnection::with_window_inner(self.0, move |inner| inner.enable_opengl())
|
||||
}
|
||||
|
@ -213,7 +213,6 @@ impl WindowOps for Window {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
fn enable_opengl(&self) -> promise::Future<()> {
|
||||
match self {
|
||||
Self::X11(x) => x.enable_opengl(),
|
||||
|
Loading…
Reference in New Issue
Block a user