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:
parent
67168be069
commit
707ca04c08
|
|
@ -1265,6 +1265,7 @@ dependencies = [
|
||||||
"egui",
|
"egui",
|
||||||
"image",
|
"image",
|
||||||
"log",
|
"log",
|
||||||
|
"puffin",
|
||||||
"resvg",
|
"resvg",
|
||||||
"serde",
|
"serde",
|
||||||
"tiny-skia",
|
"tiny-skia",
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,17 @@ default = []
|
||||||
## Enable [`DatePickerButton`] widget.
|
## Enable [`DatePickerButton`] widget.
|
||||||
datepicker = ["chrono"]
|
datepicker = ["chrono"]
|
||||||
|
|
||||||
## Support loading svg images.
|
|
||||||
svg = ["resvg", "tiny-skia", "usvg"]
|
|
||||||
|
|
||||||
## Log warnings using [`log`](https://docs.rs/log) crate.
|
## Log warnings using [`log`](https://docs.rs/log) crate.
|
||||||
log = ["dep:log", "egui/log"]
|
log = ["dep:log", "egui/log"]
|
||||||
|
|
||||||
|
## Enable profiling with the [`puffin`](https://docs.rs/puffin) crate.
|
||||||
|
##
|
||||||
|
## Only enabled on native, because of the low resolution (1ms) of clocks in browsers.
|
||||||
|
puffin = ["dep:puffin", "egui/puffin"]
|
||||||
|
|
||||||
|
## Support loading svg images.
|
||||||
|
svg = ["resvg", "tiny-skia", "usvg"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.22.0", path = "../egui", default-features = false }
|
egui = { version = "0.22.0", path = "../egui", default-features = false }
|
||||||
|
|
@ -65,6 +70,8 @@ image = { version = "0.24", optional = true, default-features = false }
|
||||||
# feature "log"
|
# feature "log"
|
||||||
log = { version = "0.4", optional = true, features = ["std"] }
|
log = { version = "0.4", optional = true, features = ["std"] }
|
||||||
|
|
||||||
|
puffin = { version = "0.16", optional = true }
|
||||||
|
|
||||||
# svg feature
|
# svg feature
|
||||||
resvg = { version = "0.28", optional = true, default-features = false }
|
resvg = { version = "0.28", optional = true, default-features = false }
|
||||||
tiny-skia = { version = "0.8", optional = true, default-features = false } # must be updated in lock-step with resvg
|
tiny-skia = { version = "0.8", optional = true, default-features = false } # must be updated in lock-step with resvg
|
||||||
|
|
|
||||||
|
|
@ -203,6 +203,7 @@ use egui::ColorImage;
|
||||||
/// On invalid image or unsupported image format.
|
/// On invalid image or unsupported image format.
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
pub fn load_image_bytes(image_bytes: &[u8]) -> Result<egui::ColorImage, String> {
|
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 image = image::load_from_memory(image_bytes).map_err(|err| err.to_string())?;
|
||||||
let size = [image.width() as _, image.height() as _];
|
let size = [image.width() as _, image.height() as _];
|
||||||
let image_buffer = image.to_rgba8();
|
let image_buffer = image.to_rgba8();
|
||||||
|
|
@ -235,6 +236,7 @@ pub fn load_svg_bytes_with_size(
|
||||||
svg_bytes: &[u8],
|
svg_bytes: &[u8],
|
||||||
fit_to: FitTo,
|
fit_to: FitTo,
|
||||||
) -> Result<egui::ColorImage, String> {
|
) -> Result<egui::ColorImage, String> {
|
||||||
|
crate::profile_function!();
|
||||||
let opt = usvg::Options::default();
|
let opt = usvg::Options::default();
|
||||||
|
|
||||||
let rtree = usvg::Tree::from_data(svg_bytes, &opt).map_err(|err| err.to_string())?;
|
let rtree = usvg::Tree::from_data(svg_bytes, &opt).map_err(|err| err.to_string())?;
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,38 @@ pub use crate::sizing::Size;
|
||||||
pub use crate::strip::*;
|
pub use crate::strip::*;
|
||||||
pub use crate::table::*;
|
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`
|
/// Log an error with either `log` or `eprintln`
|
||||||
macro_rules! log_err {
|
macro_rules! log_err {
|
||||||
($fmt: literal, $($arg: tt)*) => {{
|
($fmt: literal, $($arg: tt)*) => {{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue