Fix interpreter ffi build

Commit 738ac0dc01 increased the size of the ImageInner::StaticTextures variant,
which breaks the size assertions in the interpreter ffi build.

This changes fixes that by reducing the size of the ImageInner variant again by
moving all the fields into a separate struct.
This commit is contained in:
Simon Hausmann 2022-03-03 14:01:05 +01:00
parent 0027cab273
commit f1dae75d53
7 changed files with 29 additions and 23 deletions

View file

@ -90,7 +90,7 @@ mod the_backend {
use i_slint_core::graphics::{Color, Point, Size};
use i_slint_core::window::PlatformWindow;
use i_slint_core::window::Window;
use i_slint_core::ImageInner;
use i_slint_core::{ImageInner, StaticTextures};
thread_local! { static WINDOWS: RefCell<Option<Rc<McuWindow>>> = RefCell::new(None) }
@ -313,7 +313,7 @@ mod the_backend {
unimplemented!()
}
ImageInner::EmbeddedImage(buffer) => buffer.size(),
ImageInner::StaticTextures { original_size, .. } => *original_size,
ImageInner::StaticTextures(StaticTextures { original_size, .. }) => *original_size,
}
}

View file

@ -9,7 +9,7 @@ use core::pin::Pin;
use embedded_graphics::pixelcolor::Rgb888;
use embedded_graphics::prelude::*;
use i_slint_core::graphics::{FontRequest, IntRect, PixelFormat, Rect as RectF};
use i_slint_core::{Color, ImageInner};
use i_slint_core::{Color, ImageInner, StaticTextures};
use crate::fonts::FontMetrics;
use crate::{
@ -378,7 +378,7 @@ impl PrepareScene {
unimplemented!()
}
ImageInner::EmbeddedImage(_) => todo!(),
ImageInner::StaticTextures { size, data, textures, .. } => {
ImageInner::StaticTextures(StaticTextures { size, data, textures, .. }) => {
let sx = geom.width() / (size.width as f32);
let sy = geom.height() / (size.height as f32);
for t in textures.as_slice() {

View file

@ -8,7 +8,7 @@ use embedded_graphics::pixelcolor::Rgb888;
use embedded_graphics::prelude::*;
use embedded_graphics_simulator::SimulatorDisplay;
use i_slint_core::component::ComponentRc;
use i_slint_core::graphics::{Image, ImageInner};
use i_slint_core::graphics::{Image, ImageInner, StaticTextures};
use i_slint_core::input::KeyboardModifiers;
use i_slint_core::items::ItemRef;
use i_slint_core::layout::Orientation;
@ -382,7 +382,7 @@ impl i_slint_core::backend::Backend for SimulatorBackend {
ImageInner::None => Default::default(),
ImageInner::AbsoluteFilePath(_) | ImageInner::EmbeddedData { .. } => unimplemented!(),
ImageInner::EmbeddedImage(buffer) => buffer.size(),
ImageInner::StaticTextures { original_size, .. } => *original_size,
ImageInner::StaticTextures(StaticTextures { original_size, .. }) => *original_size,
}
}
}

View file

@ -7,7 +7,7 @@
use i_slint_core::component::ComponentRc;
use i_slint_core::graphics::{Image, IntSize, Point, Size};
use i_slint_core::window::{PlatformWindow, Window};
use i_slint_core::ImageInner;
use i_slint_core::{ImageInner, StaticTextures};
use image::GenericImageView;
use std::path::Path;
use std::pin::Pin;
@ -71,7 +71,7 @@ impl i_slint_core::backend::Backend for TestingBackend {
)
.map(|img| img.dimensions().into())
.unwrap_or_default(),
ImageInner::StaticTextures { original_size, .. } => *original_size,
ImageInner::StaticTextures(StaticTextures { original_size, .. }) => *original_size,
}
}

View file

@ -159,7 +159,7 @@ pub fn generate(doc: &Document) -> TokenStream {
quote!(slint::re_exports::Color::from_argb_encoded(0))
};
quote!(
const #symbol: slint::re_exports::ImageInner = slint::re_exports::ImageInner::StaticTextures {
const #symbol: slint::re_exports::ImageInner = slint::re_exports::ImageInner::StaticTextures(&slint::re_exports::StaticTextures{
size: slint::re_exports::IntSize::new(#width as _, #height as _),
original_size: slint::re_exports::IntSize::new(#unscaled_width as _, #unscaled_height as _),
data: Slice::from_slice(&[#(#data),*]),
@ -171,7 +171,7 @@ pub fn generate(doc: &Document) -> TokenStream {
index: 0,
}
])
};
});
)
},
crate::embedded_resources::EmbeddedResourcesKind::BitmapFontData(crate::embedded_resources::BitmapFont { family_name, character_map, units_per_em, ascent, descent, glyphs }) => {

View file

@ -217,6 +217,22 @@ pub struct StaticTexture {
pub index: usize,
}
#[repr(C)]
#[derive(Clone, PartialEq, Debug)]
/// A texture is stored in read-only memory and may be composed of sub-textures.
pub struct StaticTextures {
/// The total size of the image (this might not be the size of the full image
/// as some transparent part are not part of any texture)
pub size: IntSize,
/// The size of the image before the compiler applied any scaling
pub original_size: IntSize,
/// The pixel data referenced by the textures
pub data: Slice<'static, u8>,
/// The list of textures
pub textures: Slice<'static, StaticTexture>,
}
/// A resource is a reference to binary data, for example images. They can be accessible on the file
/// system or embedded in the resulting binary. Or they might be URLs to a web server and a downloaded
/// is necessary before they can be used.
@ -234,17 +250,7 @@ pub enum ImageInner {
format: Slice<'static, u8>,
},
EmbeddedImage(SharedImageBuffer),
StaticTextures {
/// The total size of the image (this might not be the size of the full image
/// as some transparent part are not part of any texture)
size: IntSize,
/// The size of the image before the compiler applied any scaling
original_size: IntSize,
/// The pixel data referenced by the textures
data: Slice<'static, u8>,
/// The list of textures
textures: Slice<'static, StaticTexture>,
},
StaticTextures(&'static StaticTextures),
}
impl Default for ImageInner {
@ -395,7 +401,7 @@ impl Image {
}
},
ImageInner::EmbeddedImage(buffer) => buffer.size(),
ImageInner::StaticTextures{original_size, ..} => *original_size,
ImageInner::StaticTextures(StaticTextures { original_size, .. }) => *original_size,
}
}

View file

@ -91,7 +91,7 @@ pub use string::SharedString;
pub use sharedvector::SharedVector;
#[doc(inline)]
pub use graphics::ImageInner;
pub use graphics::{ImageInner, StaticTextures};
#[doc(inline)]
pub use properties::Property;