erase generic T from Atlas, Sprite, CachedGlyph etc.
This will make it easier to use the same impl for webgpu and opengl for a bunch of this stuff.
This commit is contained in:
13 files changed
+98
-123
No files matched your search
Generated
+1
@@ -6200,6 +6200,7 @@ dependencies = [
|
||||
"core-foundation 0.7.0",
|
||||
"core-graphics 0.19.2",
|
||||
"dirs-next",
|
||||
"downcast-rs",
|
||||
"euclid",
|
||||
"filedescriptor",
|
||||
"futures-util",
|
||||
|
||||
@@ -7,7 +7,6 @@ use std::ops::Range;
|
||||
use termwiz::surface::CursorShape;
|
||||
use tiny_skia::{FillRule, Paint, Path, PathBuilder, PixmapMut, Stroke, Transform};
|
||||
use wezterm_font::units::{IntPixelLength, PixelLength};
|
||||
use window::bitmaps::Texture2d;
|
||||
use window::{BitmapImage, Image, Point, Rect, Size};
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
@@ -3660,7 +3659,7 @@ impl BlockKey {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Texture2d> GlyphCache<T> {
|
||||
impl GlyphCache {
|
||||
fn draw_polys(
|
||||
&mut self,
|
||||
metrics: &RenderMetrics,
|
||||
@@ -3703,7 +3702,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
shape: Option<CursorShape>,
|
||||
metrics: &RenderMetrics,
|
||||
width: u8,
|
||||
) -> anyhow::Result<Sprite<T>> {
|
||||
) -> anyhow::Result<Sprite> {
|
||||
if let Some(sprite) = self.cursor_glyphs.get(&(shape, width)) {
|
||||
return Ok(sprite.clone());
|
||||
}
|
||||
@@ -3789,7 +3788,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
&mut self,
|
||||
render_metrics: &RenderMetrics,
|
||||
key: SizedBlockKey,
|
||||
) -> anyhow::Result<Sprite<T>> {
|
||||
) -> anyhow::Result<Sprite> {
|
||||
let metrics = match &key.block {
|
||||
BlockKey::PolyWithCustomMetrics {
|
||||
underline_height,
|
||||
|
||||
@@ -134,7 +134,7 @@ impl<'a> std::hash::Hash for (dyn GlyphKeyTrait + 'a) {
|
||||
|
||||
/// Caches a rendered glyph.
|
||||
/// The image data may be None for whitespace glyphs.
|
||||
pub struct CachedGlyph<T: Texture2d> {
|
||||
pub struct CachedGlyph {
|
||||
pub has_color: bool,
|
||||
pub brightness_adjust: f32,
|
||||
pub x_offset: PixelLength,
|
||||
@@ -142,11 +142,11 @@ pub struct CachedGlyph<T: Texture2d> {
|
||||
pub x_advance: PixelLength,
|
||||
pub bearing_x: PixelLength,
|
||||
pub bearing_y: PixelLength,
|
||||
pub texture: Option<Sprite<T>>,
|
||||
pub texture: Option<Sprite>,
|
||||
pub scale: f64,
|
||||
}
|
||||
|
||||
impl<T: Texture2d> std::fmt::Debug for CachedGlyph<T> {
|
||||
impl std::fmt::Debug for CachedGlyph {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
|
||||
fmt.debug_struct("CachedGlyph")
|
||||
.field("has_color", &self.has_color)
|
||||
@@ -247,21 +247,21 @@ impl DecodedImage {
|
||||
|
||||
/// A number of items here are HashMaps rather than LfuCaches;
|
||||
/// eviction is managed by recreating Self when the Atlas is filled
|
||||
pub struct GlyphCache<T: Texture2d> {
|
||||
glyph_cache: HashMap<GlyphKey, Rc<CachedGlyph<T>>>,
|
||||
pub atlas: Atlas<T>,
|
||||
pub struct GlyphCache {
|
||||
glyph_cache: HashMap<GlyphKey, Rc<CachedGlyph>>,
|
||||
pub atlas: Atlas,
|
||||
pub fonts: Rc<FontConfiguration>,
|
||||
pub image_cache: LfuCacheU64<DecodedImage>,
|
||||
frame_cache: HashMap<[u8; 32], Sprite<T>>,
|
||||
line_glyphs: HashMap<LineKey, Sprite<T>>,
|
||||
pub block_glyphs: HashMap<SizedBlockKey, Sprite<T>>,
|
||||
pub cursor_glyphs: HashMap<(Option<CursorShape>, u8), Sprite<T>>,
|
||||
pub color: HashMap<(RgbColor, NotNan<f32>), Sprite<T>>,
|
||||
frame_cache: HashMap<[u8; 32], Sprite>,
|
||||
line_glyphs: HashMap<LineKey, Sprite>,
|
||||
pub block_glyphs: HashMap<SizedBlockKey, Sprite>,
|
||||
pub cursor_glyphs: HashMap<(Option<CursorShape>, u8), Sprite>,
|
||||
pub color: HashMap<(RgbColor, NotNan<f32>), Sprite>,
|
||||
}
|
||||
|
||||
impl GlyphCache<ImageTexture> {
|
||||
impl GlyphCache {
|
||||
pub fn new_in_memory(fonts: &Rc<FontConfiguration>, size: usize) -> anyhow::Result<Self> {
|
||||
let surface = Rc::new(ImageTexture::new(size, size));
|
||||
let surface: Rc<dyn Texture2d> = Rc::new(ImageTexture::new(size, size));
|
||||
let atlas = Atlas::new(&surface).expect("failed to create new texture atlas");
|
||||
|
||||
Ok(Self {
|
||||
@@ -283,13 +283,14 @@ impl GlyphCache<ImageTexture> {
|
||||
}
|
||||
}
|
||||
|
||||
impl GlyphCache<WebGpuTexture> {
|
||||
impl GlyphCache {
|
||||
pub fn new_webgpu(
|
||||
state: &WebGpuState,
|
||||
fonts: &Rc<FontConfiguration>,
|
||||
size: usize,
|
||||
) -> anyhow::Result<Self> {
|
||||
let texture = Rc::new(WebGpuTexture::new(size as u32, size as u32, state));
|
||||
let texture: Rc<dyn Texture2d> =
|
||||
Rc::new(WebGpuTexture::new(size as u32, size as u32, state));
|
||||
let atlas = Atlas::new(&texture).expect("failed to create new texture atlas");
|
||||
|
||||
Ok(Self {
|
||||
@@ -311,7 +312,7 @@ impl GlyphCache<WebGpuTexture> {
|
||||
}
|
||||
}
|
||||
|
||||
impl GlyphCache<SrgbTexture2d> {
|
||||
impl GlyphCache {
|
||||
pub fn new_gl(
|
||||
backend: &Rc<GliumContext>,
|
||||
fonts: &Rc<FontConfiguration>,
|
||||
@@ -334,7 +335,7 @@ impl GlyphCache<SrgbTexture2d> {
|
||||
caps.max_texture_size
|
||||
);
|
||||
}
|
||||
let surface = Rc::new(SrgbTexture2d::empty_with_format(
|
||||
let surface: Rc<dyn Texture2d> = Rc::new(SrgbTexture2d::empty_with_format(
|
||||
backend,
|
||||
glium::texture::SrgbFormat::U8U8U8U8,
|
||||
glium::texture::MipmapsOption::NoMipmap,
|
||||
@@ -362,7 +363,7 @@ impl GlyphCache<SrgbTexture2d> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Texture2d> GlyphCache<T> {
|
||||
impl GlyphCache {
|
||||
/// Resolve a glyph from the cache, rendering the glyph on-demand if
|
||||
/// the cache doesn't already hold the desired glyph.
|
||||
pub fn cached_glyph(
|
||||
@@ -373,7 +374,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
font: &Rc<LoadedFont>,
|
||||
metrics: &RenderMetrics,
|
||||
num_cells: u8,
|
||||
) -> anyhow::Result<Rc<CachedGlyph<T>>> {
|
||||
) -> anyhow::Result<Rc<CachedGlyph>> {
|
||||
let key = BorrowedGlyphKey {
|
||||
font_idx: info.font_idx,
|
||||
glyph_pos: info.glyph_pos,
|
||||
@@ -443,7 +444,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
font: &Rc<LoadedFont>,
|
||||
followed_by_space: bool,
|
||||
num_cells: u8,
|
||||
) -> anyhow::Result<Rc<CachedGlyph<T>>> {
|
||||
) -> anyhow::Result<Rc<CachedGlyph>> {
|
||||
let base_metrics;
|
||||
let idx_metrics;
|
||||
let brightness_adjust;
|
||||
@@ -610,11 +611,11 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
}
|
||||
|
||||
fn cached_image_impl(
|
||||
frame_cache: &mut HashMap<[u8; 32], Sprite<T>>,
|
||||
atlas: &mut Atlas<T>,
|
||||
frame_cache: &mut HashMap<[u8; 32], Sprite>,
|
||||
atlas: &mut Atlas,
|
||||
decoded: &DecodedImage,
|
||||
padding: Option<usize>,
|
||||
) -> anyhow::Result<(Sprite<T>, Option<Instant>)> {
|
||||
) -> anyhow::Result<(Sprite, Option<Instant>)> {
|
||||
let mut handle = DecodedImageHandle {
|
||||
h: decoded.image.data(),
|
||||
current_frame: *decoded.current_frame.borrow(),
|
||||
@@ -683,7 +684,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
&mut self,
|
||||
image_data: &Arc<ImageData>,
|
||||
padding: Option<usize>,
|
||||
) -> anyhow::Result<(Sprite<T>, Option<Instant>)> {
|
||||
) -> anyhow::Result<(Sprite, Option<Instant>)> {
|
||||
let id = image_data.id() as u64;
|
||||
|
||||
if let Some(decoded) = self.image_cache.get(&id) {
|
||||
@@ -697,7 +698,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cached_color(&mut self, color: RgbColor, alpha: f32) -> anyhow::Result<Sprite<T>> {
|
||||
pub fn cached_color(&mut self, color: RgbColor, alpha: f32) -> anyhow::Result<Sprite> {
|
||||
let key = (color, NotNan::new(alpha).unwrap());
|
||||
|
||||
if let Some(s) = self.color.get(&key) {
|
||||
@@ -722,7 +723,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
&mut self,
|
||||
block: BlockKey,
|
||||
metrics: &RenderMetrics,
|
||||
) -> anyhow::Result<Sprite<T>> {
|
||||
) -> anyhow::Result<Sprite> {
|
||||
let key = SizedBlockKey {
|
||||
block,
|
||||
size: metrics.into(),
|
||||
@@ -733,7 +734,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
self.block_sprite(metrics, key)
|
||||
}
|
||||
|
||||
fn line_sprite(&mut self, key: LineKey, metrics: &RenderMetrics) -> anyhow::Result<Sprite<T>> {
|
||||
fn line_sprite(&mut self, key: LineKey, metrics: &RenderMetrics) -> anyhow::Result<Sprite> {
|
||||
let mut buffer = Image::new(
|
||||
metrics.cell_size.width as usize,
|
||||
metrics.cell_size.height as usize,
|
||||
@@ -936,7 +937,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
underline: Underline,
|
||||
overline: bool,
|
||||
metrics: &RenderMetrics,
|
||||
) -> anyhow::Result<Sprite<T>> {
|
||||
) -> anyhow::Result<Sprite> {
|
||||
let effective_underline = match (is_highlited_hyperlink, underline) {
|
||||
(true, Underline::None) => Underline::Single,
|
||||
(true, Underline::Single) => Underline::Double,
|
||||
|
||||
+20
-17
@@ -954,26 +954,29 @@ pub fn run_ls_fonts(config: config::ConfigHandle, cmd: &LsFontsCommand) -> anyho
|
||||
let mut glyph = String::new();
|
||||
|
||||
if let Some(texture) = &cached_glyph.texture {
|
||||
for y in texture.coords.min_y()..texture.coords.max_y() {
|
||||
for &px in texture.texture.image.borrow().horizontal_pixel_range(
|
||||
texture.coords.min_x() as usize,
|
||||
texture.coords.max_x() as usize,
|
||||
y as usize,
|
||||
) {
|
||||
let px = u32::from_be(px);
|
||||
let (b, g, r, a) = (
|
||||
(px >> 8) as u8,
|
||||
(px >> 16) as u8,
|
||||
(px >> 24) as u8,
|
||||
(px & 0xff) as u8,
|
||||
);
|
||||
// Use regular RGB for other terminals, but then
|
||||
// set RGBA for wezterm
|
||||
glyph.push_str(&format!(
|
||||
use window::bitmaps::ImageTexture;
|
||||
if let Some(tex) = texture.texture.downcast_ref::<ImageTexture>() {
|
||||
for y in texture.coords.min_y()..texture.coords.max_y() {
|
||||
for &px in tex.image.borrow().horizontal_pixel_range(
|
||||
texture.coords.min_x() as usize,
|
||||
texture.coords.max_x() as usize,
|
||||
y as usize,
|
||||
) {
|
||||
let px = u32::from_be(px);
|
||||
let (b, g, r, a) = (
|
||||
(px >> 8) as u8,
|
||||
(px >> 16) as u8,
|
||||
(px >> 24) as u8,
|
||||
(px & 0xff) as u8,
|
||||
);
|
||||
// Use regular RGB for other terminals, but then
|
||||
// set RGBA for wezterm
|
||||
glyph.push_str(&format!(
|
||||
"\x1b[38:2::{r}:{g}:{b}m\x1b[38:6::{r}:{g}:{b}:{a}m\u{2588}\x1b[0m"
|
||||
));
|
||||
}
|
||||
glyph.push('\n');
|
||||
}
|
||||
glyph.push('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ use super::utilsprites::{RenderMetrics, UtilSprites};
|
||||
use ::window::bitmaps::atlas::OutOfTextureSpace;
|
||||
use ::window::glium::backend::Context as GliumContext;
|
||||
use ::window::glium::buffer::Mapping;
|
||||
use ::window::glium::texture::SrgbTexture2d;
|
||||
use ::window::glium::{CapabilitiesSource, IndexBuffer, VertexBuffer};
|
||||
use ::window::*;
|
||||
use anyhow::Context;
|
||||
@@ -219,8 +218,8 @@ impl<'a> TripleLayerQuadAllocatorTrait for BorrowedLayers<'a> {
|
||||
|
||||
pub struct RenderState {
|
||||
pub context: Rc<GliumContext>,
|
||||
pub glyph_cache: RefCell<GlyphCache<SrgbTexture2d>>,
|
||||
pub util_sprites: UtilSprites<SrgbTexture2d>,
|
||||
pub glyph_cache: RefCell<GlyphCache>,
|
||||
pub util_sprites: UtilSprites,
|
||||
pub glyph_prog: glium::Program,
|
||||
pub layers: RefCell<Vec<Rc<RenderLayer>>>,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::customglyph::BlockKey;
|
||||
use crate::glyphcache::CachedGlyph;
|
||||
use ::window::bitmaps::Texture2d;
|
||||
use config::TextStyle;
|
||||
use std::rc::Rc;
|
||||
use wezterm_font::shaper::GlyphInfo;
|
||||
@@ -22,25 +21,17 @@ pub struct GlyphPosition {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ShapedInfo<T>
|
||||
where
|
||||
T: Texture2d,
|
||||
T: std::fmt::Debug,
|
||||
{
|
||||
pub glyph: Rc<CachedGlyph<T>>,
|
||||
pub struct ShapedInfo {
|
||||
pub glyph: Rc<CachedGlyph>,
|
||||
pub pos: GlyphPosition,
|
||||
pub block_key: Option<BlockKey>,
|
||||
}
|
||||
|
||||
impl<T> ShapedInfo<T>
|
||||
where
|
||||
T: Texture2d,
|
||||
T: std::fmt::Debug,
|
||||
{
|
||||
impl ShapedInfo {
|
||||
/// Process the results from the shaper, stitching together glyph
|
||||
/// and positioning information
|
||||
pub fn process(infos: &[GlyphInfo], glyphs: &[Rc<CachedGlyph<T>>]) -> Vec<ShapedInfo<T>> {
|
||||
let mut pos: Vec<ShapedInfo<T>> = Vec::with_capacity(infos.len());
|
||||
pub fn process(infos: &[GlyphInfo], glyphs: &[Rc<CachedGlyph>]) -> Vec<ShapedInfo> {
|
||||
let mut pos: Vec<ShapedInfo> = Vec::with_capacity(infos.len());
|
||||
|
||||
for (info, glyph) in infos.iter().zip(glyphs.iter()) {
|
||||
pos.push(ShapedInfo {
|
||||
@@ -123,7 +114,6 @@ impl<'a> std::hash::Hash for (dyn ShapeCacheKeyTrait + 'a) {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::glyphcache::GlyphCache;
|
||||
use crate::shapecache::{GlyphPosition, ShapedInfo};
|
||||
use crate::utilsprites::RenderMetrics;
|
||||
@@ -135,17 +125,13 @@ mod test {
|
||||
use wezterm_font::shaper::PresentationWidth;
|
||||
use wezterm_font::{FontConfiguration, LoadedFont};
|
||||
|
||||
fn cluster_and_shape<T>(
|
||||
fn cluster_and_shape(
|
||||
render_metrics: &RenderMetrics,
|
||||
glyph_cache: &mut GlyphCache<T>,
|
||||
glyph_cache: &mut GlyphCache,
|
||||
style: &TextStyle,
|
||||
font: &Rc<LoadedFont>,
|
||||
text: &str,
|
||||
) -> Vec<GlyphPosition>
|
||||
where
|
||||
T: Texture2d,
|
||||
T: std::fmt::Debug,
|
||||
{
|
||||
) -> Vec<GlyphPosition> {
|
||||
let line = Line::from_text(text, &CellAttributes::default(), SEQ_ZERO, None);
|
||||
eprintln!("{:?}", line);
|
||||
let mut all_infos = vec![];
|
||||
|
||||
@@ -4,8 +4,7 @@ use crate::customglyph::{BlockKey, Poly};
|
||||
use crate::glyphcache::CachedGlyph;
|
||||
use crate::quad::{QuadImpl, QuadTrait, TripleLayerQuadAllocator, TripleLayerQuadAllocatorTrait};
|
||||
use crate::termwindow::{
|
||||
BorrowedLayers, ColorEase, MouseCapture, RenderState, SrgbTexture2d, TermWindowNotif, UIItem,
|
||||
UIItemType,
|
||||
BorrowedLayers, ColorEase, MouseCapture, RenderState, TermWindowNotif, UIItem, UIItemType,
|
||||
};
|
||||
use crate::utilsprites::RenderMetrics;
|
||||
use ::window::{RectF, WindowOps};
|
||||
@@ -486,8 +485,8 @@ pub enum ComputedElementContent {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ElementCell {
|
||||
Sprite(Sprite<SrgbTexture2d>),
|
||||
Glyph(Rc<CachedGlyph<SrgbTexture2d>>),
|
||||
Sprite(Sprite),
|
||||
Glyph(Rc<CachedGlyph>),
|
||||
}
|
||||
|
||||
struct Rects {
|
||||
|
||||
@@ -3,7 +3,6 @@ use super::renderstate::*;
|
||||
use super::utilsprites::RenderMetrics;
|
||||
use crate::colorease::ColorEase;
|
||||
use crate::frontend::{front_end, try_front_end};
|
||||
use crate::glium::texture::SrgbTexture2d;
|
||||
use crate::inputmap::InputMap;
|
||||
use crate::overlay::{
|
||||
confirm_close_pane, confirm_close_tab, confirm_close_window, confirm_quit_program, launcher,
|
||||
@@ -404,8 +403,7 @@ pub struct TermWindow {
|
||||
|
||||
quad_generation: usize,
|
||||
shape_generation: usize,
|
||||
shape_cache:
|
||||
RefCell<LfuCache<ShapeCacheKey, anyhow::Result<Rc<Vec<ShapedInfo<SrgbTexture2d>>>>>>,
|
||||
shape_cache: RefCell<LfuCache<ShapeCacheKey, anyhow::Result<Rc<Vec<ShapedInfo>>>>>,
|
||||
line_to_ele_shape_cache: RefCell<LfuCache<LineToEleShapeCacheKey, LineToElementShapeItem>>,
|
||||
|
||||
line_state_cache: RefCell<LfuCacheU64<Arc<CachedLineState>>>,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use super::box_model::*;
|
||||
use crate::colorease::{ColorEase, ColorEaseUniform};
|
||||
use crate::customglyph::{BlockKey, *};
|
||||
use crate::glium::texture::SrgbTexture2d;
|
||||
use crate::glyphcache::{CachedGlyph, GlyphCache};
|
||||
use crate::quad::{
|
||||
HeapQuadAllocator, QuadAllocator, QuadImpl, QuadTrait, TripleLayerQuadAllocator,
|
||||
@@ -49,7 +48,6 @@ use wezterm_font::units::{IntPixelLength, PixelLength};
|
||||
use wezterm_font::{ClearShapeCache, GlyphInfo, LoadedFont};
|
||||
use wezterm_term::color::{ColorAttribute, ColorPalette, RgbColor};
|
||||
use wezterm_term::{CellAttributes, Line, StableRowIndex};
|
||||
use window::bitmaps::Texture2d;
|
||||
use window::color::LinearRgba;
|
||||
|
||||
pub const TOP_LEFT_ROUNDED_CORNER: &[Poly] = &[Poly {
|
||||
@@ -222,7 +220,7 @@ pub struct LineToElementShape {
|
||||
pub underline_color: LinearRgba,
|
||||
pub x_pos: f32,
|
||||
pub pixel_width: f32,
|
||||
pub glyph_info: Rc<Vec<ShapedInfo<SrgbTexture2d>>>,
|
||||
pub glyph_info: Rc<Vec<ShapedInfo>>,
|
||||
pub cluster: CellCluster,
|
||||
}
|
||||
|
||||
@@ -1900,8 +1898,11 @@ impl super::TermWindow {
|
||||
}
|
||||
|
||||
fn call_draw(&mut self, frame: &mut glium::Frame) -> anyhow::Result<()> {
|
||||
use crate::glium::texture::SrgbTexture2d;
|
||||
let gl_state = self.render_state.as_ref().unwrap();
|
||||
let tex = gl_state.glyph_cache.borrow().atlas.texture();
|
||||
let tex = tex.downcast_ref::<SrgbTexture2d>().unwrap();
|
||||
|
||||
let projection = euclid::Transform3D::<f32, f32, f32>::ortho(
|
||||
-(self.dimensions.pixel_width as f32) / 2.0,
|
||||
self.dimensions.pixel_width as f32 / 2.0,
|
||||
@@ -3103,7 +3104,7 @@ impl super::TermWindow {
|
||||
font: Option<&Rc<LoadedFont>>,
|
||||
gl_state: &RenderState,
|
||||
metrics: &RenderMetrics,
|
||||
) -> anyhow::Result<Rc<CachedGlyph<SrgbTexture2d>>> {
|
||||
) -> anyhow::Result<Rc<CachedGlyph>> {
|
||||
let fa_lock = "\u{f023}";
|
||||
let line = Line::from_text(fa_lock, attrs, 0, None);
|
||||
let cluster = line.cluster(None);
|
||||
@@ -3413,11 +3414,11 @@ impl super::TermWindow {
|
||||
fn glyph_infos_to_glyphs(
|
||||
&self,
|
||||
style: &TextStyle,
|
||||
glyph_cache: &mut GlyphCache<SrgbTexture2d>,
|
||||
glyph_cache: &mut GlyphCache,
|
||||
infos: &[GlyphInfo],
|
||||
font: &Rc<LoadedFont>,
|
||||
metrics: &RenderMetrics,
|
||||
) -> anyhow::Result<Vec<Rc<CachedGlyph<SrgbTexture2d>>>> {
|
||||
) -> anyhow::Result<Vec<Rc<CachedGlyph>>> {
|
||||
let mut glyphs = Vec::with_capacity(infos.len());
|
||||
let mut iter = infos.iter().peekable();
|
||||
while let Some(info) = iter.next() {
|
||||
@@ -3466,7 +3467,7 @@ impl super::TermWindow {
|
||||
gl_state: &RenderState,
|
||||
font: Option<&Rc<LoadedFont>>,
|
||||
metrics: &RenderMetrics,
|
||||
) -> anyhow::Result<Rc<Vec<ShapedInfo<SrgbTexture2d>>>> {
|
||||
) -> anyhow::Result<Rc<Vec<ShapedInfo>>> {
|
||||
let shape_resolve_start = Instant::now();
|
||||
let key = BorrowedShapeCacheKey {
|
||||
style,
|
||||
@@ -3532,7 +3533,7 @@ impl super::TermWindow {
|
||||
fn lookup_cached_shape(
|
||||
&self,
|
||||
key: &dyn ShapeCacheKeyTrait,
|
||||
) -> Option<anyhow::Result<Rc<Vec<ShapedInfo<SrgbTexture2d>>>>> {
|
||||
) -> Option<anyhow::Result<Rc<Vec<ShapedInfo>>>> {
|
||||
match self.shape_cache.borrow_mut().get(key) {
|
||||
Some(Ok(info)) => Some(Ok(Rc::clone(info))),
|
||||
Some(Err(err)) => Some(Err(anyhow!("cached shaper error: {}", err))),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::glyphcache::GlyphCache;
|
||||
use ::window::bitmaps::atlas::{OutOfTextureSpace, Sprite};
|
||||
use ::window::bitmaps::{BitmapImage, Image, Texture2d};
|
||||
use ::window::bitmaps::{BitmapImage, Image};
|
||||
use ::window::color::SrgbaPixel;
|
||||
use ::window::{Point, Rect, Size};
|
||||
use anyhow::Context;
|
||||
@@ -132,14 +132,14 @@ impl RenderMetrics {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UtilSprites<T: Texture2d> {
|
||||
pub white_space: Sprite<T>,
|
||||
pub filled_box: Sprite<T>,
|
||||
pub struct UtilSprites {
|
||||
pub white_space: Sprite,
|
||||
pub filled_box: Sprite,
|
||||
}
|
||||
|
||||
impl<T: Texture2d> UtilSprites<T> {
|
||||
impl UtilSprites {
|
||||
pub fn new(
|
||||
glyph_cache: &mut GlyphCache<T>,
|
||||
glyph_cache: &mut GlyphCache,
|
||||
metrics: &RenderMetrics,
|
||||
) -> Result<Self, OutOfTextureSpace> {
|
||||
let mut buffer = Image::new(
|
||||
|
||||
@@ -25,6 +25,7 @@ async-trait = "0.1"
|
||||
anyhow = "1.0"
|
||||
bytes = "1.0"
|
||||
config = { path = "../config" }
|
||||
downcast-rs = "1.0"
|
||||
thiserror = "1.0"
|
||||
bitflags = "1.3"
|
||||
euclid = "0.22"
|
||||
|
||||
+12
-27
@@ -18,11 +18,8 @@ pub struct OutOfTextureSpace {
|
||||
/// Atlases are bitmaps of srgba data that are sized as a power of 2.
|
||||
/// We allocate sprites out of the available space, using AtlasAllocator
|
||||
/// to manage the available rectangles.
|
||||
pub struct Atlas<T>
|
||||
where
|
||||
T: Texture2d,
|
||||
{
|
||||
texture: Rc<T>,
|
||||
pub struct Atlas {
|
||||
texture: Rc<dyn Texture2d>,
|
||||
|
||||
allocator: SimpleAtlasAllocator,
|
||||
|
||||
@@ -30,11 +27,8 @@ where
|
||||
side: usize,
|
||||
}
|
||||
|
||||
impl<T> Atlas<T>
|
||||
where
|
||||
T: Texture2d,
|
||||
{
|
||||
pub fn new(texture: &Rc<T>) -> Fallible<Self> {
|
||||
impl Atlas {
|
||||
pub fn new(texture: &Rc<dyn Texture2d>) -> Fallible<Self> {
|
||||
ensure!(
|
||||
texture.width() == texture.height(),
|
||||
"texture must be square!"
|
||||
@@ -56,12 +50,12 @@ where
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn texture(&self) -> Rc<T> {
|
||||
pub fn texture(&self) -> Rc<dyn Texture2d> {
|
||||
Rc::clone(&self.texture)
|
||||
}
|
||||
|
||||
/// Reserve space for a sprite of the given size
|
||||
pub fn allocate(&mut self, im: &dyn BitmapImage) -> Result<Sprite<T>, OutOfTextureSpace> {
|
||||
pub fn allocate(&mut self, im: &dyn BitmapImage) -> Result<Sprite, OutOfTextureSpace> {
|
||||
self.allocate_with_padding(im, None)
|
||||
}
|
||||
|
||||
@@ -69,7 +63,7 @@ where
|
||||
&mut self,
|
||||
im: &dyn BitmapImage,
|
||||
padding: Option<usize>,
|
||||
) -> Result<Sprite<T>, OutOfTextureSpace> {
|
||||
) -> Result<Sprite, OutOfTextureSpace> {
|
||||
let (width, height) = im.image_dimensions();
|
||||
|
||||
// If we can't convert the sizes to i32, then we'll never
|
||||
@@ -136,15 +130,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Sprite<T>
|
||||
where
|
||||
T: Texture2d,
|
||||
{
|
||||
pub texture: Rc<T>,
|
||||
pub struct Sprite {
|
||||
pub texture: Rc<dyn Texture2d>,
|
||||
pub coords: Rect,
|
||||
}
|
||||
|
||||
impl<T: Texture2d> std::fmt::Debug for Sprite<T> {
|
||||
impl std::fmt::Debug for Sprite {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
|
||||
fmt.debug_struct("Sprite")
|
||||
.field("coords", &self.coords)
|
||||
@@ -154,10 +145,7 @@ impl<T: Texture2d> std::fmt::Debug for Sprite<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for Sprite<T>
|
||||
where
|
||||
T: Texture2d,
|
||||
{
|
||||
impl Clone for Sprite {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
texture: Rc::clone(&self.texture),
|
||||
@@ -166,10 +154,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Sprite<T>
|
||||
where
|
||||
T: Texture2d,
|
||||
{
|
||||
impl Sprite {
|
||||
/// Returns the texture coordinates of the sprite
|
||||
pub fn texture_coords(&self) -> TextureRect {
|
||||
self.texture.to_texture_coords(self.coords)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::color::{LinearRgba, SrgbaPixel};
|
||||
use crate::{Point, Rect, Size};
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
use glium::texture::SrgbTexture2d;
|
||||
use std::cell::RefCell;
|
||||
|
||||
@@ -12,7 +13,7 @@ pub type TextureSize = euclid::Size2D<f32, TextureUnit>;
|
||||
|
||||
/// Represents a big endian bgra32 bitmap that may not be present
|
||||
/// in local RAM, but may be addressable in eg: video RAM
|
||||
pub trait Texture2d {
|
||||
pub trait Texture2d: Downcast {
|
||||
/// Copy the bits from the source bitmap to the texture at the location
|
||||
/// specified by the rectangle.
|
||||
/// The dimensions of the rectangle must match the source image
|
||||
@@ -40,6 +41,7 @@ pub trait Texture2d {
|
||||
)
|
||||
}
|
||||
}
|
||||
impl_downcast!(Texture2d);
|
||||
|
||||
impl Texture2d for SrgbTexture2d {
|
||||
fn write(&self, rect: Rect, im: &dyn BitmapImage) {
|
||||
|
||||
Reference in new issue
Block a user