Move compositor module access from window to crate

This commit is contained in:
Richard 2022-04-26 19:18:18 -03:00
parent 5be1ac18fe
commit 984d1f375e
8 changed files with 27 additions and 22 deletions

View file

@ -2,7 +2,7 @@ use crate::{Backend, Color, Error, Renderer, Settings, Viewport};
use core::ffi::c_void;
use glow::HasContext;
use iced_graphics::{Antialiasing, Size};
use iced_graphics::{compositor, Antialiasing, Size};
/// A window graphics backend for iced powered by `glow`.
#[allow(missing_debug_implementations)]
@ -67,10 +67,10 @@ impl iced_graphics::window::GLCompositor for Compositor {
}
}
fn get_information(&self) -> iced_graphics::window::Information {
fn get_information(&self) -> compositor::Information {
let adapter = unsafe { self.gl.get_parameter_string(glow::RENDERER) };
iced_graphics::window::Information {
compositor::Information {
backend: format!("{:?}", self.gl.version()),
adapter,
}

View file

@ -39,6 +39,7 @@ pub use primitive::Primitive;
pub use renderer::Renderer;
pub use transformation::Transformation;
pub use viewport::Viewport;
pub use window::compositor;
pub use iced_native::alignment;
pub use iced_native::{

View file

@ -1,10 +1,10 @@
//! Draw graphics to window surfaces.
mod compositor;
pub mod compositor;
#[cfg(feature = "opengl")]
mod gl_compositor;
pub mod gl_compositor;
pub use compositor::{Compositor, Information, SurfaceError};
pub use compositor::Compositor;
#[cfg(feature = "opengl")]
pub use gl_compositor::GLCompositor;

View file

@ -1,3 +1,5 @@
//! A compositor is responsible for initializing a renderer and managing window
//! surfaces.
use crate::{Color, Error, Viewport};
use raw_window_handle::HasRawWindowHandle;

View file

@ -1,4 +1,6 @@
use crate::window::Information;
//! A compositor is responsible for initializing a renderer and managing window
//! surfaces.
use crate::compositor::Information;
use crate::{Color, Error, Size, Viewport};
use core::ffi::c_void;

View file

@ -1,6 +1,7 @@
use crate::{Backend, Color, Error, Renderer, Settings, Viewport};
use futures::task::SpawnExt;
use iced_graphics::compositor;
use iced_native::futures;
use raw_window_handle::HasRawWindowHandle;
@ -157,10 +158,10 @@ impl iced_graphics::window::Compositor for Compositor {
);
}
fn get_information(&self) -> iced_graphics::window::Information {
fn get_information(&self) -> compositor::Information {
let information = self.adapter.get_info();
iced_graphics::window::Information {
compositor::Information {
adapter: information.name,
backend: format!("{:?}", information.backend),
}
@ -173,7 +174,7 @@ impl iced_graphics::window::Compositor for Compositor {
viewport: &Viewport,
background_color: Color,
overlay: &[T],
) -> Result<(), iced_graphics::window::SurfaceError> {
) -> Result<(), compositor::SurfaceError> {
match surface.get_current_texture() {
Ok(frame) => {
let mut encoder = self.device.create_command_encoder(
@ -241,16 +242,14 @@ impl iced_graphics::window::Compositor for Compositor {
}
Err(error) => match error {
wgpu::SurfaceError::Timeout => {
Err(iced_graphics::window::SurfaceError::Timeout)
Err(compositor::SurfaceError::Timeout)
}
wgpu::SurfaceError::Outdated => {
Err(iced_graphics::window::SurfaceError::Outdated)
}
wgpu::SurfaceError::Lost => {
Err(iced_graphics::window::SurfaceError::Lost)
Err(compositor::SurfaceError::Outdated)
}
wgpu::SurfaceError::Lost => Err(compositor::SurfaceError::Lost),
wgpu::SurfaceError::OutOfMemory => {
Err(iced_graphics::window::SurfaceError::OutOfMemory)
Err(compositor::SurfaceError::OutOfMemory)
}
},
}

View file

@ -13,6 +13,7 @@ use crate::{
use iced_futures::futures;
use iced_futures::futures::channel::mpsc;
use iced_graphics::compositor;
use iced_graphics::window;
use iced_native::program::Program;
use iced_native::user_interface::{self, UserInterface};
@ -426,7 +427,7 @@ async fn run_instance<A, E, C>(
}
Err(error) => match error {
// This is an unrecoverable error.
window::SurfaceError::OutOfMemory => {
compositor::SurfaceError::OutOfMemory => {
panic!("{:?}", error);
}
_ => {
@ -520,7 +521,7 @@ pub fn update<A: Application, E: Executor>(
debug: &mut Debug,
messages: &mut Vec<A::Message>,
window: &winit::window::Window,
graphics_info: &window::Information,
graphics_info: &compositor::Information,
) {
for message in messages.drain(..) {
debug.log_message(&message);
@ -543,7 +544,7 @@ pub fn run_command<Message: 'static + std::fmt::Debug + Send, E: Executor>(
clipboard: &mut Clipboard,
proxy: &mut winit::event_loop::EventLoopProxy<Message>,
window: &winit::window::Window,
graphics_info: &window::Information,
graphics_info: &compositor::Information,
) {
use iced_native::command;
use iced_native::system;

View file

@ -2,7 +2,7 @@
use crate::command::{self, Command};
pub use iced_native::system::*;
use iced_graphics::window;
use iced_graphics::compositor;
/// Query for available system information.
///
@ -17,7 +17,7 @@ pub fn information<Message>(
#[cfg(feature = "sysinfo")]
pub(crate) fn get_information(
graphics_info: &window::Information,
graphics_info: &compositor::Information,
) -> Option<Information> {
use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt};
let mut system = System::new_all();
@ -47,7 +47,7 @@ pub(crate) fn get_information(
#[cfg(not(feature = "sysinfo"))]
pub(crate) fn get_information(
_graphics_info: &window::Information,
_graphics_info: &compositor::Information,
) -> Option<Information> {
None
}