pub struct Display { /* private fields */ }
Expand description
The display used to manage all surfaces.
This type contains all common types that can be shared among surfaces. It also contains
methods for creating new surfaces. Most interactions with theo
will be done through this
type.
The backend used by this type is determined by the DisplayBuilder
used to create it.
By default, it will try to use the following backends in order. If one fails, it will try
the next one.
wgpu
- OpenGL
- Software rasterizer
This type also has properties that are useful for creating new surfaces. For example, you
can use Display::supports_transparency
to check if the display supports transparent
backgrounds.
Examples
use theo::Display;
// Create a new display.
let mut display = unsafe { Display::new(&my_display) }.unwrap();
// Use the display to create a new window.
let mut window_builder = WindowBuilder::new()
.with_transparency(display.supports_transparency());
if cfg!(using_x11) {
if let Some(visual) = display.x11_visual() {
unsafe {
window_builder = window_builder.with_x11_visual(visual.as_ptr());
}
}
}
// Create the window.
let window = window_builder.build();
// Use the window to create a new theo surface.
let surface = unsafe {
display.make_surface(
&window,
window.width(),
window.height(),
).await.unwrap()
};
Implementations§
source§impl Display
impl Display
sourcepub fn builder() -> DisplayBuilder
pub fn builder() -> DisplayBuilder
Create a new DisplayBuilder
.
This is a shorthand that allows the user to avoid having to import the DisplayBuilder
type.
sourcepub unsafe fn new(display: impl HasRawDisplayHandle) -> Result<Self, Error>
pub unsafe fn new(display: impl HasRawDisplayHandle) -> Result<Self, Error>
Create a new, default Display
.
This is a shorthand for DisplayBuilder::new().build()
.
Safety
The display
handle must be a valid display
that isn’t currently suspended.
See the safety requirements of DisplayBuilder::build
for more information.
Example
use theo::Display;
let event_loop = winit::event_loop::EventLoop::new();
let display = unsafe { Display::new(&event_loop) }.unwrap();
sourcepub async unsafe fn make_surface(
&mut self,
window: impl HasRawWindowHandle,
width: u32,
height: u32
) -> Result<Surface, Error>
pub async unsafe fn make_surface( &mut self, window: impl HasRawWindowHandle, width: u32, height: u32 ) -> Result<Surface, Error>
Create a new Surface
from a window.
This function creates the state that theo
associates with a window with the provided
width and height. The Surface
can be used with the Display
to draw to the window.
Asynchronous
This function is asynchronous, as it may be necessary to wait for data to become available.
This is only used for the wgpu
backend, as it requires the adapter to be created
asynchronously. For remaining backends, this future will not return Pending
.
Safety
The window
handle must be a valid window
that isn’t currently suspended. The
width
and height
parameters aren’t necessarily required to be correct, but
it’s recommended that they are in order to avoid visual bugs.
Examples
use theo::Display;
use winit::event_loop::EventLoop;
use winit::window::Window;
let event_loop = EventLoop::new();
let mut display = unsafe { Display::new(&event_loop) }.unwrap();
// In a real-world use case, parameters from the `display` would be used to create the window.
let window = Window::new(&event_loop).unwrap();
let size = window.inner_size();
// Create a new surface from the window.
let surface = unsafe {
display.make_surface(
&window,
size.width,
size.height,
).await.unwrap()
};
source§impl Display
impl Display
sourcepub fn supports_transparency(&self) -> bool
pub fn supports_transparency(&self) -> bool
Whether or not this display supports transparent backgrounds.
If this is true
, then the Surface
s created from this display will support
transparency if the underlying windowing system supports it. You should use this
to decide whether or not to use a transparent background.
Example
use theo::Display;
let event_loop = winit::event_loop::EventLoop::new();
let display = unsafe { Display::new(&event_loop) }.unwrap();
if display.supports_transparency() {
create_transparent_window();
} else {
create_opaque_window();
}
sourcepub fn x11_visual(&self) -> Option<NonNull<()>>
pub fn x11_visual(&self) -> Option<NonNull<()>>
The X11 visual used by this display, if any.
This is useful for creating Surface
s with a specific visual. On X11, you can
use this to create a surface.
Example
use theo::Display;
let event_loop = winit::event_loop::EventLoop::new();
let display = unsafe { Display::new(&event_loop) }.unwrap();
let visual = display.x11_visual().unwrap();
sourcepub async unsafe fn make_surface_from_raw(
&mut self,
window: RawWindowHandle,
width: u32,
height: u32
) -> Result<Surface, Error>
pub async unsafe fn make_surface_from_raw( &mut self, window: RawWindowHandle, width: u32, height: u32 ) -> Result<Surface, Error>
Create a new Surface
from a raw window handle.
This is equivalent to Display::make_surface
, except that it takes a raw window
handle instead of a window. This is useful if you want to create a surface from a
window that doesn’t implement RawWindowHandle
.
Asynchronous
This function is asynchronous, as it may be necessary to wait for data to become available.
This is only used for the wgpu
backend, as it requires the adapter to be created
asynchronously. For remaining backends, this future will not return Pending
.
Safety
The window
handle must be a valid window
that isn’t currently suspended. The
width
and height
parameters aren’t necessarily required to be correct, but
it’s recommended that they are in order to avoid visual bugs.
sourcepub async fn present(&mut self)
pub async fn present(&mut self)
Push the queue and present to all known surfaces.
This is necessary to call after all windows have been drawn to. It should be called once all windows that need to be drawn to have already been drawn to.
Asynchronous
For most backends, this is a no-op. For wgpu
, it submits the queue and then
waits for all of the queues to finish submitting.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Display
impl !Send for Display
impl !Sync for Display
impl Unpin for Display
impl !UnwindSafe for Display
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.