1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Add opt-in puffin feature to egui-extras (#3307)

* Add opt-in `puffin` feature to `egui-extras`

Image loading can be slow.

Related to https://github.com/emilk/egui/pull/3297

* Silence warning
This commit is contained in:
Emil Ernerfeldt
2023-09-05 14:11:29 +02:00
committed by GitHub
parent 67168be069
commit 707ca04c08
4 changed files with 45 additions and 3 deletions

View File

@@ -203,6 +203,7 @@ use egui::ColorImage;
/// On invalid image or unsupported image format.
#[cfg(feature = "image")]
pub fn load_image_bytes(image_bytes: &[u8]) -> Result<egui::ColorImage, String> {
crate::profile_function!();
let image = image::load_from_memory(image_bytes).map_err(|err| err.to_string())?;
let size = [image.width() as _, image.height() as _];
let image_buffer = image.to_rgba8();
@@ -235,6 +236,7 @@ pub fn load_svg_bytes_with_size(
svg_bytes: &[u8],
fit_to: FitTo,
) -> Result<egui::ColorImage, String> {
crate::profile_function!();
let opt = usvg::Options::default();
let rtree = usvg::Tree::from_data(svg_bytes, &opt).map_err(|err| err.to_string())?;

View File

@@ -28,6 +28,38 @@ pub use crate::sizing::Size;
pub use crate::strip::*;
pub use crate::table::*;
// ---------------------------------------------------------------------------
mod profiling_scopes {
#![allow(unused_macros)]
#![allow(unused_imports)]
/// Profiling macro for feature "puffin"
macro_rules! profile_function {
($($arg: tt)*) => {
#[cfg(not(target_arch = "wasm32"))] // Disabled on web because of the coarse 1ms clock resolution there.
#[cfg(feature = "puffin")]
puffin::profile_function!($($arg)*);
};
}
pub(crate) use profile_function;
/// Profiling macro for feature "puffin"
macro_rules! profile_scope {
($($arg: tt)*) => {
#[cfg(not(target_arch = "wasm32"))] // Disabled on web because of the coarse 1ms clock resolution there.
#[cfg(feature = "puffin")]
puffin::profile_scope!($($arg)*);
};
}
pub(crate) use profile_scope;
}
#[allow(unused_imports)]
pub(crate) use profiling_scopes::*;
// ---------------------------------------------------------------------------
/// Log an error with either `log` or `eprintln`
macro_rules! log_err {
($fmt: literal, $($arg: tt)*) => {{