diff --git a/sixtyfps_runtime/corelib/graphics.rs b/sixtyfps_runtime/corelib/graphics.rs index b70a11857..1051c5001 100644 --- a/sixtyfps_runtime/corelib/graphics.rs +++ b/sixtyfps_runtime/corelib/graphics.rs @@ -11,10 +11,7 @@ LICENSE END */ /*! Graphics Abstractions. - This module contains the abstractions and convenience types to allow the runtime - library to instruct different graphics backends to render the tree of items. - - The entry trait is [GraphicsBackend]. + This module contains the abstractions and convenience types used for rendering. The run-time library also makes use of [RenderingCache] to store the rendering primitives created by the backend in a type-erased manner. @@ -305,25 +302,6 @@ pub trait FontMetrics { 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; - - /// Returns the window that the backend is associated with. - fn window(&self) -> &winit::window::Window; -} - #[repr(C)] #[derive(FieldOffsets, Default, SixtyFPSElement, Clone, Debug, PartialEq)] #[pin] diff --git a/sixtyfps_runtime/rendering_backends/gl/graphics_window.rs b/sixtyfps_runtime/rendering_backends/gl/graphics_window.rs index 47d7b5deb..6cd0d7fde 100644 --- a/sixtyfps_runtime/rendering_backends/gl/graphics_window.rs +++ b/sixtyfps_runtime/rendering_backends/gl/graphics_window.rs @@ -8,7 +8,6 @@ Please contact info@sixtyfps.io for more information. LICENSE END */ //! 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::pin::Pin; @@ -25,6 +24,7 @@ use corelib::window::{ComponentWindow, GenericWindow}; use corelib::Property; 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 WindowFactoryFn = diff --git a/sixtyfps_runtime/rendering_backends/gl/lib.rs b/sixtyfps_runtime/rendering_backends/gl/lib.rs index ae91e76b1..d0d188ab8 100644 --- a/sixtyfps_runtime/rendering_backends/gl/lib.rs +++ b/sixtyfps_runtime/rendering_backends/gl/lib.rs @@ -15,7 +15,7 @@ use std::{ }; 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::items::ImageFit; @@ -270,9 +270,9 @@ impl GLRenderer { 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 { let (size, scale_factor) = { 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) { self.canvas.borrow_mut().flush(); @@ -324,9 +326,7 @@ impl GLRenderer { .map_or(false, |cached_image_rc| Rc::strong_count(&cached_image_rc) > 1) }); } -} -impl GraphicsBackend for GLRenderer { fn window(&self) -> &winit::window::Window { #[cfg(not(target_arch = "wasm32"))] return self.windowed_context.as_ref().unwrap().window(); @@ -334,6 +334,8 @@ impl GraphicsBackend for GLRenderer { 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 { Box::new(GLFontMetrics { request,