1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 22:01:47 +03:00

remove byte-swapping workaround for opengl

We handle this with a temporary buffer for the upload, which is
a little gross but avoids leaking that implementation aspect
out to the rest of the code.
This commit is contained in:
Wez Furlong 2019-10-27 10:07:14 -07:00
parent 3a7f4cdff2
commit 4116d7d523
3 changed files with 27 additions and 40 deletions

View File

@ -34,7 +34,6 @@ pub struct GlyphCache<T: Texture2d> {
glyph_cache: HashMap<GlyphKey, Rc<CachedGlyph<T>>>,
pub atlas: Atlas<T>,
fonts: Rc<FontConfiguration>,
byte_swap: bool,
image_cache: HashMap<usize, Sprite<T>>,
}
@ -48,7 +47,6 @@ impl GlyphCache<ImageTexture> {
glyph_cache: HashMap::new(),
image_cache: HashMap::new(),
atlas,
byte_swap: true,
}
}
}
@ -73,7 +71,6 @@ impl GlyphCache<SrgbTexture2d> {
glyph_cache: HashMap::new(),
image_cache: HashMap::new(),
atlas,
byte_swap: false,
})
}
}
@ -133,21 +130,12 @@ impl<T: Texture2d> GlyphCache<T> {
scale,
}
} else {
let raw_im = if self.byte_swap {
Image::with_rgba32(
glyph.width as usize,
glyph.height as usize,
4 * glyph.width as usize,
&glyph.data,
)
} else {
Image::with_bgra32(
glyph.width as usize,
glyph.height as usize,
4 * glyph.width as usize,
&glyph.data,
)
};
let raw_im = Image::with_rgba32(
glyph.width as usize,
glyph.height as usize,
4 * glyph.width as usize,
&glyph.data,
);
let bearing_x = glyph.bearing_x * scale;
let bearing_y = glyph.bearing_y * scale;
@ -176,31 +164,18 @@ impl<T: Texture2d> GlyphCache<T> {
Ok(Rc::new(glyph))
}
pub fn cached_image(
&mut self,
image_data: &Arc<ImageData>,
byte_swap: bool,
) -> Fallible<Sprite<T>> {
pub fn cached_image(&mut self, image_data: &Arc<ImageData>) -> Fallible<Sprite<T>> {
if let Some(sprite) = self.image_cache.get(&image_data.id()) {
return Ok(sprite.clone());
}
let decoded_image = image::load_from_memory(image_data.data())?.to_bgra();
let (width, height) = decoded_image.dimensions();
let image = if byte_swap {
Image::with_rgba32(
width as usize,
height as usize,
4 * width as usize,
&decoded_image.to_vec(),
)
} else {
::window::bitmaps::Image::from_raw(
width as usize,
height as usize,
decoded_image.to_vec(),
)
};
let image = ::window::bitmaps::Image::from_raw(
width as usize,
height as usize,
decoded_image.to_vec(),
);
let sprite = self.atlas.allocate(&image)?;

View File

@ -853,7 +853,7 @@ impl TermWindow {
if let Ok(sprite) = gl_state
.glyph_cache
.borrow_mut()
.cached_image(image.image_data(), true)
.cached_image(image.image_data())
{
let width = sprite.coords.size.width;
let height = sprite.coords.size.height;
@ -1144,7 +1144,7 @@ impl TermWindow {
if let Ok(sprite) = software
.glyph_cache
.borrow_mut()
.cached_image(image.image_data(), false)
.cached_image(image.image_data())
{
let width = sprite.coords.size.width;
let height = sprite.coords.size.height;

View File

@ -47,8 +47,20 @@ pub trait Texture2d {
impl Texture2d for SrgbTexture2d {
fn write(&self, rect: Rect, im: &dyn BitmapImage) {
let (im_width, im_height) = im.image_dimensions();
// This is a little unfortunate: glium only exposes GL_RGBA
// surfaces but our data is GL_BGRA. We need to allocate
// a temporary buffer to hold the transformed data just for
// the duration of the write request.
let source = glium::texture::RawImage2d {
data: std::borrow::Cow::Borrowed(im.pixels()),
data: im
.pixels()
.iter()
.map(|&p| {
let (r, g, b, a) = Color(p).as_rgba();
Color::rgba(b, g, r, a).0
})
.collect(),
width: im_width as u32,
height: im_height as u32,
format: glium::texture::ClientFormat::U8U8U8U8,