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 17:22:07 -05:00
|
|
|
use pathfinder_content::effects::Effects;
|
2020-02-17 17:44:48 -05:00
|
|
|
use pathfinder_content::fill::FillRule;
|
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 {
|
2019-05-10 15:03:38 -04:00
|
|
|
Start { path_count: usize, bounding_quad: BoundingQuad },
|
2019-05-14 14:33:52 -04:00
|
|
|
AddPaintData(PaintData),
|
2019-04-15 16:21:24 -04:00
|
|
|
AddFills(Vec<FillBatchPrimitive>),
|
|
|
|
FlushFills,
|
2020-02-17 17:44:48 -05:00
|
|
|
RenderMaskTiles { tiles: Vec<MaskTile>, fill_rule: FillRule },
|
2020-02-20 17:22:07 -05:00
|
|
|
PushLayer { effects: Effects },
|
2020-02-19 20:44:41 -05:00
|
|
|
PopLayer,
|
2020-02-15 00:37:20 -05:00
|
|
|
DrawAlphaTiles(Vec<AlphaTile>),
|
|
|
|
DrawSolidTiles(Vec<SolidTileVertex>),
|
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 {
|
2019-06-03 15:39:29 -04:00
|
|
|
pub size: Vector2I,
|
2020-02-11 20:20:21 -05:00
|
|
|
pub texels: Vec<ColorU>,
|
2019-05-14 14:33:52 -04: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) => {
|
|
|
|
write!(formatter, "AddPaintData({}x{})", paint_data.size.x(), paint_data.size.y())
|
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-19 20:44:41 -05:00
|
|
|
RenderCommand::PushLayer { .. } => write!(formatter, "PushLayer"),
|
|
|
|
RenderCommand::PopLayer => write!(formatter, "PopLayer"),
|
2020-02-15 00:37:20 -05:00
|
|
|
RenderCommand::DrawAlphaTiles(ref tiles) => {
|
|
|
|
write!(formatter, "DrawAlphaTiles(x{})", tiles.len())
|
2019-05-03 21:51:36 -04:00
|
|
|
}
|
2020-02-15 00:37:20 -05:00
|
|
|
RenderCommand::DrawSolidTiles(ref tiles) => {
|
|
|
|
write!(formatter, "DrawSolidTiles(x{})", tiles.len())
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|