Actually remove the GraphicsBackend completely

It is not longer in used for the abstraction between backend,
we'll make a new trait for it later
This commit is contained in:
Olivier Goffart 2021-01-14 17:46:30 +01:00
parent 7931896027
commit aa7f362f10
3 changed files with 9 additions and 29 deletions

View file

@ -11,10 +11,7 @@ LICENSE END */
/*! /*!
Graphics Abstractions. Graphics Abstractions.
This module contains the abstractions and convenience types to allow the runtime This module contains the abstractions and convenience types used for rendering.
library to instruct different graphics backends to render the tree of items.
The entry trait is [GraphicsBackend].
The run-time library also makes use of [RenderingCache] to store the rendering primitives The run-time library also makes use of [RenderingCache] to store the rendering primitives
created by the backend in a type-erased manner. created by the backend in a type-erased manner.
@ -305,25 +302,6 @@ pub trait FontMetrics {
fn height(&self) -> f32; fn height(&self) -> f32;
} }
/// GraphicsBackend is the trait that the the SixtyFPS run-time uses to convert [HighLevelRenderingPrimitive]
/// to an internal representation that is optimal for the backend, in order to render it later. The internal
/// representation is opaque but must be provided via the [GraphicsBackend::LowLevelRenderingPrimitive] associated type.
///
/// The backend operates in two modes:
/// 1. It can be used to create new rendering primitives, by calling [GraphicsBackend::new_rendering_primitives_builder]. This is
/// usually an expensive step, that involves uploading data to the GPU or performing other pre-calculations.
///
/// 1. A series of low-level rendering primitives can be rendered into a frame, that's started using [GraphicsBackend::new_frame].
/// The low-level rendering primitives are intended to be fast and ready for rendering.
pub trait GraphicsBackend: Sized {
/// Returns a FontMetrics trait object that can be used to measure text and that matches the given font request as
/// closely as possible.
fn font_metrics(&mut self, request: FontRequest) -> Box<dyn FontMetrics>;
/// Returns the window that the backend is associated with.
fn window(&self) -> &winit::window::Window;
}
#[repr(C)] #[repr(C)]
#[derive(FieldOffsets, Default, SixtyFPSElement, Clone, Debug, PartialEq)] #[derive(FieldOffsets, Default, SixtyFPSElement, Clone, Debug, PartialEq)]
#[pin] #[pin]

View file

@ -8,7 +8,6 @@
Please contact info@sixtyfps.io for more information. Please contact info@sixtyfps.io for more information.
LICENSE END */ LICENSE END */
//! This module contains the GraphicsWindow that used to be within corelib. //! This module contains the GraphicsWindow that used to be within corelib.
//! FIXME The GraphicsWindow probably does not need to be generic
use core::cell::{Cell, RefCell}; use core::cell::{Cell, RefCell};
use core::pin::Pin; use core::pin::Pin;
@ -25,6 +24,7 @@ use corelib::window::{ComponentWindow, GenericWindow};
use corelib::Property; use corelib::Property;
use sixtyfps_corelib as corelib; use sixtyfps_corelib as corelib;
/// FIXME! this is some remains from a time where the GLRenderer was called the backend
type Backend = super::GLRenderer; type Backend = super::GLRenderer;
type WindowFactoryFn = type WindowFactoryFn =

View file

@ -15,7 +15,7 @@ use std::{
}; };
use sixtyfps_corelib::graphics::{ use sixtyfps_corelib::graphics::{
Color, FontMetrics, FontRequest, GraphicsBackend, Point, Rect, RenderingCache, Resource, Color, FontMetrics, FontRequest, Point, Rect, RenderingCache, Resource,
}; };
use sixtyfps_corelib::item_rendering::{CachedRenderingData, ItemRenderer}; use sixtyfps_corelib::item_rendering::{CachedRenderingData, ItemRenderer};
use sixtyfps_corelib::items::ImageFit; use sixtyfps_corelib::items::ImageFit;
@ -270,9 +270,9 @@ impl GLRenderer {
loaded_fonts: Default::default(), loaded_fonts: Default::default(),
} }
} }
}
impl GLRenderer { /// Returns a new item renderer instance. At this point rendering begins and the backend ensures that the
/// window background was cleared with the specified clear_color.
fn new_renderer(&mut self, clear_color: &Color) -> GLItemRenderer { fn new_renderer(&mut self, clear_color: &Color) -> GLItemRenderer {
let (size, scale_factor) = { let (size, scale_factor) = {
let window = self.window(); let window = self.window();
@ -307,6 +307,8 @@ impl GLRenderer {
} }
} }
/// Complete the item rendering by calling this function. This will typically flush any remaining/pending
/// commands to the underlying graphics subsystem.
fn flush_renderer(&mut self, _renderer: GLItemRenderer) { fn flush_renderer(&mut self, _renderer: GLItemRenderer) {
self.canvas.borrow_mut().flush(); self.canvas.borrow_mut().flush();
@ -324,9 +326,7 @@ impl GLRenderer {
.map_or(false, |cached_image_rc| Rc::strong_count(&cached_image_rc) > 1) .map_or(false, |cached_image_rc| Rc::strong_count(&cached_image_rc) > 1)
}); });
} }
}
impl GraphicsBackend for GLRenderer {
fn window(&self) -> &winit::window::Window { fn window(&self) -> &winit::window::Window {
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
return self.windowed_context.as_ref().unwrap().window(); return self.windowed_context.as_ref().unwrap().window();
@ -334,6 +334,8 @@ impl GraphicsBackend for GLRenderer {
return &self.window; return &self.window;
} }
/// Returns a FontMetrics trait object that can be used to measure text and that matches the given font request as
/// closely as possible.
fn font_metrics(&mut self, request: FontRequest) -> Box<dyn FontMetrics> { fn font_metrics(&mut self, request: FontRequest) -> Box<dyn FontMetrics> {
Box::new(GLFontMetrics { Box::new(GLFontMetrics {
request, request,