2019-01-14 17:20:36 -05:00
|
|
|
// pathfinder/renderer/src/gpu_data.rs
|
|
|
|
//
|
2020-02-20 17:22:07 -05:00
|
|
|
// Copyright © 2020 The Pathfinder Project Developers.
|
2019-01-14 17:20:36 -05:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! Packed data ready to be sent to the GPU.
|
|
|
|
|
2019-04-30 22:13:28 -04:00
|
|
|
use crate::options::BoundingQuad;
|
2020-02-11 20:20:21 -05:00
|
|
|
use pathfinder_color::ColorU;
|
2020-02-20 18:52:40 -05:00
|
|
|
use pathfinder_content::effects::{BlendMode, Effects};
|
2020-02-17 17:44:48 -05:00
|
|
|
use pathfinder_content::fill::FillRule;
|
2020-02-22 00:42:15 -05:00
|
|
|
use pathfinder_content::pattern::RenderTargetId;
|
2019-06-21 13:06:19 -04:00
|
|
|
use pathfinder_geometry::line_segment::{LineSegmentU4, LineSegmentU8};
|
2020-02-04 01:24:34 -05:00
|
|
|
use pathfinder_geometry::vector::Vector2I;
|
2019-03-29 22:11:38 -04:00
|
|
|
use std::fmt::{Debug, Formatter, Result as DebugResult};
|
2019-04-30 22:13:28 -04:00
|
|
|
use std::time::Duration;
|
2019-01-14 17:20:36 -05:00
|
|
|
|
2019-03-29 22:11:38 -04:00
|
|
|
pub enum RenderCommand {
|
2020-02-22 00:42:15 -05:00
|
|
|
// Starts rendering a frame.
|
2020-02-22 17:39:03 -05:00
|
|
|
Start {
|
|
|
|
/// The number of paths that will be rendered.
|
|
|
|
path_count: usize,
|
|
|
|
|
|
|
|
/// A bounding quad for the scene.
|
|
|
|
bounding_quad: BoundingQuad,
|
|
|
|
|
|
|
|
/// Whether the framebuffer we're rendering to must be readable.
|
|
|
|
///
|
|
|
|
/// This is needed if a path that renders directly to the output framebuffer (i.e. not to a
|
|
|
|
/// render target) uses one of the more exotic blend modes.
|
|
|
|
needs_readable_framebuffer: bool,
|
|
|
|
},
|
2020-02-22 00:42:15 -05:00
|
|
|
|
|
|
|
// Uploads paint data for use with subsequent rendering commands to the GPU.
|
2019-05-14 14:33:52 -04:00
|
|
|
AddPaintData(PaintData),
|
2020-02-22 00:42:15 -05:00
|
|
|
|
|
|
|
// Adds fills to the queue.
|
2019-04-15 16:21:24 -04:00
|
|
|
AddFills(Vec<FillBatchPrimitive>),
|
2020-02-22 00:42:15 -05:00
|
|
|
|
|
|
|
// Flushes the queue of fills.
|
2019-04-15 16:21:24 -04:00
|
|
|
FlushFills,
|
2020-02-22 00:42:15 -05:00
|
|
|
|
|
|
|
// Render fills to a set of mask tiles.
|
2020-02-17 17:44:48 -05:00
|
|
|
RenderMaskTiles { tiles: Vec<MaskTile>, fill_rule: FillRule },
|
2020-02-22 00:42:15 -05:00
|
|
|
|
|
|
|
// Pushes a render target onto the stack. Draw commands go to the render target on top of the
|
|
|
|
// stack.
|
|
|
|
PushRenderTarget(RenderTargetId),
|
|
|
|
|
|
|
|
// Pops a render target from the stack.
|
|
|
|
PopRenderTarget,
|
|
|
|
|
|
|
|
// Draws a batch of alpha tiles to the render target on top of the stack.
|
|
|
|
DrawAlphaTiles { tiles: Vec<AlphaTile>, paint_page: PaintPageId, blend_mode: BlendMode },
|
|
|
|
|
|
|
|
// Draws a batch of solid tiles to the render target on top of the stack.
|
2020-02-21 17:46:10 -05:00
|
|
|
DrawSolidTiles(SolidTileBatch),
|
2020-02-22 00:42:15 -05:00
|
|
|
|
|
|
|
// Draws an entire render target to the render target on top of the stack.
|
|
|
|
//
|
|
|
|
// FIXME(pcwalton): This draws the entire render target, so it's inefficient. We should get rid
|
|
|
|
// of this command and transition all uses to `DrawAlphaTiles`/`DrawSolidTiles`. The reason it
|
|
|
|
// exists is that we don't have logic to create tiles for blur bounding regions yet.
|
|
|
|
DrawRenderTarget { render_target: RenderTargetId, effects: Effects },
|
|
|
|
|
|
|
|
// Presents a rendered frame.
|
2019-04-30 22:13:28 -04:00
|
|
|
Finish { build_time: Duration },
|
2019-01-14 17:20:36 -05:00
|
|
|
}
|
|
|
|
|
2019-05-14 14:33:52 -04:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct PaintData {
|
2020-02-21 17:46:10 -05:00
|
|
|
pub pages: Vec<PaintPageData>,
|
|
|
|
}
|
|
|
|
|
2020-02-22 00:42:15 -05:00
|
|
|
#[derive(Clone, Copy, PartialEq, Debug)]
|
|
|
|
pub struct PaintPageId(pub u32);
|
|
|
|
|
2020-02-21 17:46:10 -05:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct PaintPageData {
|
2019-06-03 15:39:29 -04:00
|
|
|
pub size: Vector2I,
|
2020-02-22 00:42:15 -05:00
|
|
|
pub contents: PaintPageContents,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum PaintPageContents {
|
|
|
|
Texels(Vec<ColorU>),
|
|
|
|
RenderTarget(RenderTargetId),
|
2019-05-14 14:33:52 -04:00
|
|
|
}
|
|
|
|
|
2020-02-21 17:46:10 -05:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct SolidTileBatch {
|
|
|
|
pub vertices: Vec<SolidTileVertex>,
|
2020-02-22 00:42:15 -05:00
|
|
|
pub paint_page: PaintPageId,
|
2020-02-21 17:46:10 -05:00
|
|
|
}
|
|
|
|
|
2019-01-14 17:20:36 -05:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
pub struct FillObjectPrimitive {
|
|
|
|
pub px: LineSegmentU4,
|
|
|
|
pub subpx: LineSegmentU8,
|
|
|
|
pub tile_x: i16,
|
|
|
|
pub tile_y: i16,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
2019-04-15 16:21:24 -04:00
|
|
|
#[repr(C)]
|
|
|
|
pub struct TileObjectPrimitive {
|
|
|
|
/// If `u16::MAX`, then this is a solid tile.
|
|
|
|
pub alpha_tile_index: u16,
|
|
|
|
pub backdrop: i8,
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME(pcwalton): Move `subpx` before `px` and remove `repr(packed)`.
|
|
|
|
#[derive(Clone, Copy, Debug, Default)]
|
2019-01-15 13:52:37 -05:00
|
|
|
#[repr(packed)]
|
2019-01-14 17:20:36 -05:00
|
|
|
pub struct FillBatchPrimitive {
|
|
|
|
pub px: LineSegmentU4,
|
|
|
|
pub subpx: LineSegmentU8,
|
2019-03-22 17:28:18 -04:00
|
|
|
pub alpha_tile_index: u16,
|
2019-01-14 17:20:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
2019-01-14 22:32:53 -05:00
|
|
|
#[repr(C)]
|
2020-02-07 14:46:20 -05:00
|
|
|
pub struct SolidTileVertex {
|
2019-01-14 17:20:36 -05:00
|
|
|
pub tile_x: i16,
|
|
|
|
pub tile_y: i16,
|
2020-02-07 14:46:20 -05:00
|
|
|
pub color_u: u16,
|
|
|
|
pub color_v: u16,
|
2019-04-03 14:58:45 -04:00
|
|
|
pub object_index: u16,
|
2019-06-05 17:35:46 -04:00
|
|
|
pub pad: u16,
|
2019-01-14 17:20:36 -05:00
|
|
|
}
|
|
|
|
|
2020-02-15 00:55:37 -05:00
|
|
|
#[derive(Clone, Copy, Debug, Default)]
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct MaskTile {
|
|
|
|
pub upper_left: MaskTileVertex,
|
|
|
|
pub upper_right: MaskTileVertex,
|
|
|
|
pub lower_left: MaskTileVertex,
|
|
|
|
pub lower_right: MaskTileVertex,
|
|
|
|
}
|
|
|
|
|
2019-04-15 16:21:24 -04:00
|
|
|
#[derive(Clone, Copy, Debug, Default)]
|
2019-01-14 22:32:53 -05:00
|
|
|
#[repr(C)]
|
2020-02-07 14:46:20 -05:00
|
|
|
pub struct AlphaTile {
|
|
|
|
pub upper_left: AlphaTileVertex,
|
|
|
|
pub upper_right: AlphaTileVertex,
|
|
|
|
pub lower_left: AlphaTileVertex,
|
|
|
|
pub lower_right: AlphaTileVertex,
|
|
|
|
}
|
|
|
|
|
2020-02-15 00:55:37 -05:00
|
|
|
#[derive(Clone, Copy, Debug, Default)]
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct MaskTileVertex {
|
|
|
|
pub mask_u: u16,
|
|
|
|
pub mask_v: u16,
|
2020-02-16 16:45:15 -05:00
|
|
|
pub fill_u: u16,
|
|
|
|
pub fill_v: u16,
|
2020-02-15 00:55:37 -05:00
|
|
|
pub backdrop: i16,
|
|
|
|
pub object_index: u16,
|
|
|
|
}
|
|
|
|
|
2020-02-07 14:46:20 -05:00
|
|
|
#[derive(Clone, Copy, Debug, Default)]
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct AlphaTileVertex {
|
|
|
|
pub tile_x: i16,
|
|
|
|
pub tile_y: i16,
|
|
|
|
pub mask_u: u16,
|
|
|
|
pub mask_v: u16,
|
2020-02-14 14:50:34 -05:00
|
|
|
pub color_u: u16,
|
|
|
|
pub color_v: u16,
|
2019-04-03 14:58:45 -04:00
|
|
|
pub object_index: u16,
|
2020-02-15 00:55:37 -05:00
|
|
|
pub pad: u16,
|
2019-01-14 17:20:36 -05:00
|
|
|
}
|
|
|
|
|
2019-03-29 22:11:38 -04:00
|
|
|
impl Debug for RenderCommand {
|
|
|
|
fn fmt(&self, formatter: &mut Formatter) -> DebugResult {
|
|
|
|
match *self {
|
2019-04-30 22:13:28 -04:00
|
|
|
RenderCommand::Start { .. } => write!(formatter, "Start"),
|
2019-05-14 14:33:52 -04:00
|
|
|
RenderCommand::AddPaintData(ref paint_data) => {
|
2020-02-21 17:46:10 -05:00
|
|
|
write!(formatter, "AddPaintData(x{})", paint_data.pages.len())
|
2019-04-30 22:13:28 -04:00
|
|
|
}
|
2019-04-15 16:21:24 -04:00
|
|
|
RenderCommand::AddFills(ref fills) => write!(formatter, "AddFills(x{})", fills.len()),
|
|
|
|
RenderCommand::FlushFills => write!(formatter, "FlushFills"),
|
2020-02-17 17:44:48 -05:00
|
|
|
RenderCommand::RenderMaskTiles { ref tiles, fill_rule } => {
|
|
|
|
write!(formatter, "RenderMaskTiles(x{}, {:?})", tiles.len(), fill_rule)
|
2020-02-15 00:55:37 -05:00
|
|
|
}
|
2020-02-22 00:42:15 -05:00
|
|
|
RenderCommand::PushRenderTarget(render_target_id) => {
|
|
|
|
write!(formatter, "PushRenderTarget({:?})", render_target_id)
|
|
|
|
}
|
|
|
|
RenderCommand::PopRenderTarget => write!(formatter, "PopRenderTarget"),
|
|
|
|
RenderCommand::DrawRenderTarget { render_target, .. } => {
|
|
|
|
write!(formatter, "DrawRenderTarget({:?})", render_target)
|
|
|
|
}
|
2020-02-21 17:46:10 -05:00
|
|
|
RenderCommand::DrawAlphaTiles { ref tiles, paint_page, blend_mode } => {
|
|
|
|
write!(formatter,
|
2020-02-22 00:42:15 -05:00
|
|
|
"DrawAlphaTiles(x{}, {:?}, {:?})",
|
2020-02-21 17:46:10 -05:00
|
|
|
tiles.len(),
|
|
|
|
paint_page,
|
|
|
|
blend_mode)
|
2019-05-03 21:51:36 -04:00
|
|
|
}
|
2020-02-21 17:46:10 -05:00
|
|
|
RenderCommand::DrawSolidTiles(ref batch) => {
|
|
|
|
write!(formatter,
|
2020-02-22 00:42:15 -05:00
|
|
|
"DrawSolidTiles(x{}, {:?})",
|
2020-02-21 17:46:10 -05:00
|
|
|
batch.vertices.len(),
|
|
|
|
batch.paint_page)
|
2019-05-03 21:51:36 -04:00
|
|
|
}
|
2019-04-30 22:13:28 -04:00
|
|
|
RenderCommand::Finish { .. } => write!(formatter, "Finish"),
|
2019-01-14 17:20:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|