Merge branch 'master' into beacon

This commit is contained in:
Héctor Ramón Jiménez 2025-04-01 02:18:20 +02:00
commit e060129951
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
30 changed files with 915 additions and 633 deletions

View file

@ -7,7 +7,7 @@ use crate::graphics::geometry::stroke::{self, Stroke};
use crate::graphics::geometry::{self, Path, Style};
use crate::graphics::{self, Gradient, Image, Text};
use std::rc::Rc;
use std::sync::Arc;
#[derive(Debug)]
pub enum Geometry {
@ -22,9 +22,9 @@ pub enum Geometry {
#[derive(Debug, Clone)]
pub struct Cache {
pub text: Rc<[Text]>,
pub images: Rc<[graphics::Image]>,
pub primitives: Rc<[Primitive]>,
pub text: Arc<[Text]>,
pub images: Arc<[graphics::Image]>,
pub primitives: Arc<[Primitive]>,
pub clip_bounds: Rectangle,
}
@ -43,9 +43,9 @@ impl Cached for Geometry {
text,
clip_bounds,
} => Cache {
primitives: Rc::from(primitives),
images: Rc::from(images),
text: Rc::from(text),
primitives: Arc::from(primitives),
images: Arc::from(images),
text: Arc::from(text),
clip_bounds,
},
Self::Cache(cache) => cache,

View file

@ -8,7 +8,7 @@ use crate::graphics::layer;
use crate::graphics::text::{Editor, Paragraph, Text};
use crate::graphics::{self, Image};
use std::rc::Rc;
use std::sync::Arc;
pub type Stack = layer::Stack<Layer>;
@ -107,7 +107,7 @@ impl Layer {
pub fn draw_text_cache(
&mut self,
text: Rc<[Text]>,
text: Arc<[Text]>,
clip_bounds: Rectangle,
transformation: Transformation,
) {
@ -163,7 +163,7 @@ impl Layer {
pub fn draw_primitive_cache(
&mut self,
primitives: Rc<[Primitive]>,
primitives: Arc<[Primitive]>,
clip_bounds: Rectangle,
transformation: Transformation,
) {
@ -242,7 +242,7 @@ impl Layer {
Item::Cached(cache_a, bounds_a, transformation_a),
Item::Cached(cache_b, bounds_b, transformation_b),
) => {
Rc::ptr_eq(cache_a, cache_b)
Arc::ptr_eq(cache_a, cache_b)
&& bounds_a == bounds_b
&& transformation_a == transformation_b
}
@ -304,7 +304,7 @@ impl graphics::Layer for Layer {
pub enum Item<T> {
Live(T),
Group(Vec<T>, Rectangle, Transformation),
Cached(Rc<[T]>, Rectangle, Transformation),
Cached(Arc<[T]>, Rectangle, Transformation),
}
impl<T> Item<T> {

View file

@ -357,8 +357,22 @@ impl compositor::Default for Renderer {
}
impl renderer::Headless for Renderer {
fn new(default_font: Font, default_text_size: Pixels) -> Self {
Self::new(default_font, default_text_size)
async fn new(
default_font: Font,
default_text_size: Pixels,
backend: Option<&str>,
) -> Option<Self> {
if backend.is_some_and(|backend| {
!["tiny-skia", "tiny_skia"].contains(&backend)
}) {
return None;
}
Some(Self::new(default_font, default_text_size))
}
fn name(&self) -> String {
"tiny-skia".to_owned()
}
fn screenshot(

View file

@ -113,8 +113,15 @@ impl crate::graphics::Compositor for Compositor {
surface: &mut Self::Surface,
viewport: &Viewport,
background_color: Color,
on_pre_present: impl FnOnce(),
) -> Result<(), compositor::SurfaceError> {
present(renderer, surface, viewport, background_color)
present(
renderer,
surface,
viewport,
background_color,
on_pre_present,
)
}
fn screenshot(
@ -143,6 +150,7 @@ pub fn present(
surface: &mut Surface,
viewport: &Viewport,
background_color: Color,
on_pre_present: impl FnOnce(),
) -> Result<(), compositor::SurfaceError> {
let physical_size = viewport.physical_size();
@ -202,6 +210,7 @@ pub fn present(
background_color,
);
on_pre_present();
buffer.present().map_err(|_| compositor::SurfaceError::Lost)
}