Rename "object" to "path" in preparation for image objects
This commit is contained in:
parent
a078766dc6
commit
a5d373cb91
|
@ -144,7 +144,7 @@ impl CanvasRenderingContext2D {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn fill_path(&mut self, path: Path2D) {
|
pub fn fill_path(&mut self, path: Path2D) {
|
||||||
let paint_id = self.scene.push_paint(&self.current_state.fill_paint);
|
let paint_id = self.scene.push_paint(&self.current_state.fill_paint);
|
||||||
self.scene.push_object(PathObject::new(path.into_outline(), paint_id, String::new()))
|
self.scene.push_path(PathObject::new(path.into_outline(), paint_id, String::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -153,7 +153,7 @@ impl CanvasRenderingContext2D {
|
||||||
let stroke_width = f32::max(self.current_state.line_width, HAIRLINE_STROKE_WIDTH);
|
let stroke_width = f32::max(self.current_state.line_width, HAIRLINE_STROKE_WIDTH);
|
||||||
let mut stroke_to_fill = OutlineStrokeToFill::new(path.into_outline(), stroke_width);
|
let mut stroke_to_fill = OutlineStrokeToFill::new(path.into_outline(), stroke_width);
|
||||||
stroke_to_fill.offset();
|
stroke_to_fill.offset();
|
||||||
self.scene.push_object(PathObject::new(stroke_to_fill.outline, paint_id, String::new()))
|
self.scene.push_path(PathObject::new(stroke_to_fill.outline, paint_id, String::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -56,14 +56,14 @@ impl<'a> SceneBuilder<'a> {
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
|
|
||||||
let bounding_quad = self.built_options.bounding_quad();
|
let bounding_quad = self.built_options.bounding_quad();
|
||||||
let object_count = self.scene.objects.len();
|
let path_count = self.scene.paths.len();
|
||||||
self.listener.send(RenderCommand::Start { bounding_quad, object_count });
|
self.listener.send(RenderCommand::Start { bounding_quad, path_count });
|
||||||
|
|
||||||
self.listener.send(RenderCommand::AddShaders(self.scene.build_shaders()));
|
self.listener.send(RenderCommand::AddShaders(self.scene.build_shaders()));
|
||||||
|
|
||||||
let effective_view_box = self.scene.effective_view_box(self.built_options);
|
let effective_view_box = self.scene.effective_view_box(self.built_options);
|
||||||
let alpha_tiles = executor.flatten_into_vector(object_count, |object_index| {
|
let alpha_tiles = executor.flatten_into_vector(path_count, |path_index| {
|
||||||
self.build_object(object_index, effective_view_box, &self.built_options, &self.scene)
|
self.build_path(path_index, effective_view_box, &self.built_options, &self.scene)
|
||||||
});
|
});
|
||||||
|
|
||||||
self.finish_building(alpha_tiles);
|
self.finish_building(alpha_tiles);
|
||||||
|
@ -72,17 +72,17 @@ impl<'a> SceneBuilder<'a> {
|
||||||
self.listener.send(RenderCommand::Finish { build_time });
|
self.listener.send(RenderCommand::Finish { build_time });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_object(
|
fn build_path(
|
||||||
&self,
|
&self,
|
||||||
object_index: usize,
|
path_index: usize,
|
||||||
view_box: RectF32,
|
view_box: RectF32,
|
||||||
built_options: &PreparedRenderOptions,
|
built_options: &PreparedRenderOptions,
|
||||||
scene: &Scene,
|
scene: &Scene,
|
||||||
) -> Vec<AlphaTileBatchPrimitive> {
|
) -> Vec<AlphaTileBatchPrimitive> {
|
||||||
let object = &scene.objects[object_index];
|
let path_object = &scene.paths[path_index];
|
||||||
let outline = scene.apply_render_options(object.outline(), built_options);
|
let outline = scene.apply_render_options(path_object.outline(), built_options);
|
||||||
|
|
||||||
let mut tiler = Tiler::new(self, &outline, view_box, object_index as u16);
|
let mut tiler = Tiler::new(self, &outline, view_box, path_index as u16);
|
||||||
tiler.generate_tiles();
|
tiler.generate_tiles();
|
||||||
|
|
||||||
self.listener.send(RenderCommand::AddFills(tiler.built_object.fills));
|
self.listener.send(RenderCommand::AddFills(tiler.built_object.fills));
|
||||||
|
@ -107,8 +107,8 @@ impl<'a> SceneBuilder<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pack_alpha_tiles(&mut self, alpha_tiles: Vec<AlphaTileBatchPrimitive>) {
|
fn pack_alpha_tiles(&mut self, alpha_tiles: Vec<AlphaTileBatchPrimitive>) {
|
||||||
let object_count = self.scene.objects.len() as u32;
|
let path_count = self.scene.paths.len() as u32;
|
||||||
let solid_tiles = self.z_buffer.build_solid_tiles(0..object_count);
|
let solid_tiles = self.z_buffer.build_solid_tiles(0..path_count);
|
||||||
if !solid_tiles.is_empty() {
|
if !solid_tiles.is_empty() {
|
||||||
self.listener.send(RenderCommand::SolidTile(solid_tiles));
|
self.listener.send(RenderCommand::SolidTile(solid_tiles));
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ where
|
||||||
let origin = window_rect.origin() + Point2DI32::new(PADDING, PADDING + FONT_ASCENT);
|
let origin = window_rect.origin() + Point2DI32::new(PADDING, PADDING + FONT_ASCENT);
|
||||||
self.ui_presenter.draw_text(
|
self.ui_presenter.draw_text(
|
||||||
device,
|
device,
|
||||||
&format!("Objects: {}", mean_cpu_sample.stats.object_count),
|
&format!("Paths: {}", mean_cpu_sample.stats.path_count),
|
||||||
origin,
|
origin,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
|
@ -236,11 +236,11 @@ where
|
||||||
|
|
||||||
pub fn render_command(&mut self, command: &RenderCommand) {
|
pub fn render_command(&mut self, command: &RenderCommand) {
|
||||||
match *command {
|
match *command {
|
||||||
RenderCommand::Start { bounding_quad, object_count } => {
|
RenderCommand::Start { bounding_quad, path_count } => {
|
||||||
if self.use_depth {
|
if self.use_depth {
|
||||||
self.draw_stencil(&bounding_quad);
|
self.draw_stencil(&bounding_quad);
|
||||||
}
|
}
|
||||||
self.stats.object_count = object_count;
|
self.stats.path_count = path_count;
|
||||||
}
|
}
|
||||||
RenderCommand::AddShaders(ref shaders) => self.upload_shaders(shaders),
|
RenderCommand::AddShaders(ref shaders) => self.upload_shaders(shaders),
|
||||||
RenderCommand::AddFills(ref fills) => self.add_fills(fills),
|
RenderCommand::AddFills(ref fills) => self.add_fills(fills),
|
||||||
|
@ -1545,7 +1545,7 @@ impl Default for RenderMode {
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
pub struct RenderStats {
|
pub struct RenderStats {
|
||||||
pub object_count: usize,
|
pub path_count: usize,
|
||||||
pub fill_count: usize,
|
pub fill_count: usize,
|
||||||
pub alpha_tile_count: usize,
|
pub alpha_tile_count: usize,
|
||||||
pub solid_tile_count: usize,
|
pub solid_tile_count: usize,
|
||||||
|
@ -1555,7 +1555,7 @@ impl Add<RenderStats> for RenderStats {
|
||||||
type Output = RenderStats;
|
type Output = RenderStats;
|
||||||
fn add(self, other: RenderStats) -> RenderStats {
|
fn add(self, other: RenderStats) -> RenderStats {
|
||||||
RenderStats {
|
RenderStats {
|
||||||
object_count: self.object_count + other.object_count,
|
path_count: self.path_count + other.path_count,
|
||||||
solid_tile_count: self.solid_tile_count + other.solid_tile_count,
|
solid_tile_count: self.solid_tile_count + other.solid_tile_count,
|
||||||
alpha_tile_count: self.alpha_tile_count + other.alpha_tile_count,
|
alpha_tile_count: self.alpha_tile_count + other.alpha_tile_count,
|
||||||
fill_count: self.fill_count + other.fill_count,
|
fill_count: self.fill_count + other.fill_count,
|
||||||
|
@ -1567,7 +1567,7 @@ impl Div<usize> for RenderStats {
|
||||||
type Output = RenderStats;
|
type Output = RenderStats;
|
||||||
fn div(self, divisor: usize) -> RenderStats {
|
fn div(self, divisor: usize) -> RenderStats {
|
||||||
RenderStats {
|
RenderStats {
|
||||||
object_count: self.object_count / divisor,
|
path_count: self.path_count / divisor,
|
||||||
solid_tile_count: self.solid_tile_count / divisor,
|
solid_tile_count: self.solid_tile_count / divisor,
|
||||||
alpha_tile_count: self.alpha_tile_count / divisor,
|
alpha_tile_count: self.alpha_tile_count / divisor,
|
||||||
fill_count: self.fill_count / divisor,
|
fill_count: self.fill_count / divisor,
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub(crate) struct BuiltObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum RenderCommand {
|
pub enum RenderCommand {
|
||||||
Start { object_count: usize, bounding_quad: BoundingQuad },
|
Start { path_count: usize, bounding_quad: BoundingQuad },
|
||||||
AddShaders(Vec<ObjectShader>),
|
AddShaders(Vec<ObjectShader>),
|
||||||
AddFills(Vec<FillBatchPrimitive>),
|
AddFills(Vec<FillBatchPrimitive>),
|
||||||
FlushFills,
|
FlushFills,
|
||||||
|
|
|
@ -24,7 +24,7 @@ use std::io::{self, Write};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Scene {
|
pub struct Scene {
|
||||||
pub(crate) objects: Vec<PathObject>,
|
pub(crate) paths: Vec<PathObject>,
|
||||||
paints: Vec<Paint>,
|
paints: Vec<Paint>,
|
||||||
paint_cache: HashMap<Paint, PaintId>,
|
paint_cache: HashMap<Paint, PaintId>,
|
||||||
bounds: RectF32,
|
bounds: RectF32,
|
||||||
|
@ -35,7 +35,7 @@ impl Scene {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new() -> Scene {
|
pub fn new() -> Scene {
|
||||||
Scene {
|
Scene {
|
||||||
objects: vec![],
|
paths: vec![],
|
||||||
paints: vec![],
|
paints: vec![],
|
||||||
paint_cache: HashMap::new(),
|
paint_cache: HashMap::new(),
|
||||||
bounds: RectF32::default(),
|
bounds: RectF32::default(),
|
||||||
|
@ -43,9 +43,9 @@ impl Scene {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_object(&mut self, object: PathObject) {
|
pub fn push_path(&mut self, path: PathObject) {
|
||||||
self.bounds = self.bounds.union_rect(object.outline.bounds());
|
self.bounds = self.bounds.union_rect(path.outline.bounds());
|
||||||
self.objects.push(object);
|
self.paths.push(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||||
|
@ -61,8 +61,8 @@ impl Scene {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn object_count(&self) -> usize {
|
pub fn path_count(&self) -> usize {
|
||||||
self.objects.len()
|
self.paths.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -86,13 +86,10 @@ impl Scene {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_shaders(&self) -> Vec<ObjectShader> {
|
pub fn build_shaders(&self) -> Vec<ObjectShader> {
|
||||||
self.objects
|
self.paths
|
||||||
.iter()
|
.iter()
|
||||||
.map(|object| {
|
.map(|path_object| {
|
||||||
let paint = &self.paints[object.paint.0 as usize];
|
ObjectShader { fill_color: self.paints[path_object.paint.0 as usize].color }
|
||||||
ObjectShader {
|
|
||||||
fill_color: paint.color,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -151,16 +148,16 @@ impl Scene {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn monochrome_color(&self) -> Option<ColorU> {
|
pub fn monochrome_color(&self) -> Option<ColorU> {
|
||||||
if self.objects.is_empty() {
|
if self.paths.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let first_paint_id = self.objects[0].paint;
|
|
||||||
|
let first_paint_id = self.paths[0].paint;
|
||||||
if self
|
if self
|
||||||
.objects
|
.paths
|
||||||
.iter()
|
.iter()
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.any(|object| object.paint != first_paint_id)
|
.any(|path_object| path_object.paint != first_paint_id) {
|
||||||
{
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(self.paints[first_paint_id.0 as usize].color)
|
Some(self.paints[first_paint_id.0 as usize].color)
|
||||||
|
@ -194,16 +191,16 @@ impl Scene {
|
||||||
self.view_box.size().x(),
|
self.view_box.size().x(),
|
||||||
self.view_box.size().y()
|
self.view_box.size().y()
|
||||||
)?;
|
)?;
|
||||||
for object in &self.objects {
|
for path_object in &self.paths {
|
||||||
let paint = &self.paints[object.paint.0 as usize];
|
let paint = &self.paints[path_object.paint.0 as usize];
|
||||||
write!(writer, " <path")?;
|
write!(writer, " <path")?;
|
||||||
if !object.name.is_empty() {
|
if !path_object.name.is_empty() {
|
||||||
write!(writer, " id=\"{}\"", object.name)?;
|
write!(writer, " id=\"{}\"", path_object.name)?;
|
||||||
}
|
}
|
||||||
writeln!(
|
writeln!(
|
||||||
writer,
|
writer,
|
||||||
" fill=\"{:?}\" d=\"{:?}\" />",
|
" fill=\"{:?}\" d=\"{:?}\" />",
|
||||||
paint.color, object.outline
|
paint.color, path_object.outline
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
writeln!(writer, "</svg>")?;
|
writeln!(writer, "</svg>")?;
|
||||||
|
|
|
@ -122,11 +122,8 @@ impl BuiltSVG {
|
||||||
let path = Transform2DF32PathIter::new(path, &transform);
|
let path = Transform2DF32PathIter::new(path, &transform);
|
||||||
let outline = Outline::from_segments(path);
|
let outline = Outline::from_segments(path);
|
||||||
|
|
||||||
self.scene.push_object(PathObject::new(
|
let name = format!("Fill({})", node.id());
|
||||||
outline,
|
self.scene.push_path(PathObject::new(outline, style, name));
|
||||||
style,
|
|
||||||
format!("Fill({})", node.id()),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref stroke) = path.stroke {
|
if let Some(ref stroke) = path.stroke {
|
||||||
|
@ -144,11 +141,8 @@ impl BuiltSVG {
|
||||||
let mut outline = stroke_to_fill.outline;
|
let mut outline = stroke_to_fill.outline;
|
||||||
outline.transform(&transform);
|
outline.transform(&transform);
|
||||||
|
|
||||||
self.scene.push_object(PathObject::new(
|
let name = format!("Stroke({})", node.id());
|
||||||
outline,
|
self.scene.push_path(PathObject::new(outline, style, name));
|
||||||
style,
|
|
||||||
format!("Stroke({})", node.id()),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NodeKind::Path(..) => {}
|
NodeKind::Path(..) => {}
|
||||||
|
|
|
@ -74,7 +74,7 @@ impl SceneExt for Scene {
|
||||||
outline = stroke_to_fill.outline;
|
outline = stroke_to_fill.outline;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.push_object(PathObject::new(outline, paint_id, String::new()));
|
self.push_path(PathObject::new(outline, paint_id, String::new()));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue