2019-01-14 17:20:36 -05:00
|
|
|
// pathfinder/renderer/src/gpu_data.rs
|
|
|
|
//
|
|
|
|
// Copyright © 2019 The Pathfinder Project Developers.
|
|
|
|
//
|
|
|
|
// 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;
|
2019-04-11 22:25:02 -04:00
|
|
|
use crate::tile_map::DenseTileMap;
|
2020-02-11 20:20:21 -05:00
|
|
|
use pathfinder_color::ColorU;
|
2019-06-21 13:06:19 -04:00
|
|
|
use pathfinder_geometry::line_segment::{LineSegmentU4, LineSegmentU8};
|
|
|
|
use pathfinder_geometry::rect::RectF;
|
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
|
|
|
|
|
|
|
#[derive(Debug)]
|
2019-04-15 16:21:24 -04:00
|
|
|
pub(crate) struct BuiltObject {
|
2019-05-29 22:13:42 -04:00
|
|
|
pub bounds: RectF,
|
2019-04-15 16:21:24 -04:00
|
|
|
pub fills: Vec<FillBatchPrimitive>,
|
2020-02-07 14:46:20 -05:00
|
|
|
pub alpha_tiles: Vec<AlphaTile>,
|
2019-04-15 16:21:24 -04:00
|
|
|
pub tiles: DenseTileMap<TileObjectPrimitive>,
|
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-07 14:46:20 -05:00
|
|
|
AlphaTile(Vec<AlphaTile>),
|
|
|
|
SolidTile(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
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Default)]
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct AlphaTileVertex {
|
|
|
|
pub tile_x: i16,
|
|
|
|
pub tile_y: i16,
|
|
|
|
pub color_u: u16,
|
|
|
|
pub color_v: u16,
|
|
|
|
pub mask_u: u16,
|
|
|
|
pub mask_v: u16,
|
|
|
|
pub backdrop: i16,
|
2019-04-03 14:58:45 -04:00
|
|
|
pub object_index: 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"),
|
2019-05-13 21:20:21 -04:00
|
|
|
RenderCommand::AlphaTile(ref tiles) => {
|
|
|
|
write!(formatter, "AlphaTile(x{})", tiles.len())
|
2019-05-03 21:51:36 -04:00
|
|
|
}
|
2019-05-13 21:20:21 -04:00
|
|
|
RenderCommand::SolidTile(ref tiles) => {
|
|
|
|
write!(formatter, "SolidTile(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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|