Remove trait-specific draw logic in iced_native

This commit is contained in:
Héctor Ramón Jiménez 2021-10-14 16:07:22 +07:00
parent 3aae45c191
commit 03b3493138
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
71 changed files with 641 additions and 3126 deletions

View file

@ -8,7 +8,6 @@ use iced_graphics::font;
use iced_graphics::layer::Layer;
use iced_graphics::{Primitive, Viewport};
use iced_native::alignment;
use iced_native::mouse;
use iced_native::{Font, Size};
#[cfg(any(feature = "image_rs", feature = "svg"))]
@ -28,6 +27,7 @@ pub struct Backend {
image_pipeline: image::Pipeline,
default_text_size: u16,
primitive: Primitive,
}
impl Backend {
@ -60,6 +60,7 @@ impl Backend {
image_pipeline,
default_text_size: settings.default_text_size,
primitive: Primitive::None,
}
}
@ -67,16 +68,16 @@ impl Backend {
///
/// The text provided as overlay will be rendered on top of the primitives.
/// This is useful for rendering debug information.
pub fn draw<T: AsRef<str>>(
pub fn present<T: AsRef<str>>(
&mut self,
device: &wgpu::Device,
staging_belt: &mut wgpu::util::StagingBelt,
encoder: &mut wgpu::CommandEncoder,
frame: &wgpu::TextureView,
primitive: &Primitive,
viewport: &Viewport,
(primitive, mouse_interaction): &(Primitive, mouse::Interaction),
overlay_text: &[T],
) -> mouse::Interaction {
) {
log::debug!("Drawing");
let target_size = viewport.physical_size();
@ -102,8 +103,6 @@ impl Backend {
#[cfg(any(feature = "image_rs", feature = "svg"))]
self.image_pipeline.trim_cache();
*mouse_interaction
}
fn flush(

View file

@ -1,7 +1,7 @@
use crate::{Backend, Color, Error, Renderer, Settings, Viewport};
use futures::task::SpawnExt;
use iced_native::{futures, mouse};
use iced_native::futures;
use raw_window_handle::HasRawWindowHandle;
/// A window graphics backend for iced powered by `wgpu`.
@ -132,15 +132,14 @@ impl iced_graphics::window::Compositor for Compositor {
);
}
fn draw<T: AsRef<str>>(
fn present<T: AsRef<str>>(
&mut self,
renderer: &mut Self::Renderer,
surface: &mut Self::Surface,
viewport: &Viewport,
background_color: Color,
output: &<Self::Renderer as iced_native::Renderer>::Output,
overlay: &[T],
) -> Result<mouse::Interaction, iced_graphics::window::SurfaceError> {
) -> Result<(), iced_graphics::window::SurfaceError> {
match surface.get_current_frame() {
Ok(frame) => {
let mut encoder = self.device.create_command_encoder(
@ -180,15 +179,17 @@ impl iced_graphics::window::Compositor for Compositor {
depth_stencil_attachment: None,
});
let mouse_interaction = renderer.backend_mut().draw(
&mut self.device,
&mut self.staging_belt,
&mut encoder,
view,
viewport,
output,
overlay,
);
renderer.present(|backend, primitive| {
backend.present(
&mut self.device,
&mut self.staging_belt,
&mut encoder,
view,
primitive,
viewport,
overlay,
);
});
// Submit work
self.staging_belt.finish();
@ -202,7 +203,7 @@ impl iced_graphics::window::Compositor for Compositor {
self.local_pool.run_until_stalled();
Ok(mouse_interaction)
Ok(())
}
Err(error) => match error {
wgpu::SurfaceError::Timeout => {