Bench: first screen is a drawn tile; handles checked by identity; clean record
This commit is contained in:
10 files changed
+154
-54
No files matched your search
@@ -6,7 +6,7 @@ use ely_gpui_component::theme::ActiveTheme as _;
|
||||
use gpui::{
|
||||
AnyElement, Context, InteractiveElement as _, IntoElement, MouseButton, ParentElement as _,
|
||||
Pixels, Point, RenderImage, StatefulInteractiveElement as _, Styled as _, Window, canvas, div,
|
||||
img, point, px,
|
||||
point, px,
|
||||
};
|
||||
use image::{Frame, ImageBuffer, Rgba};
|
||||
|
||||
@@ -64,6 +64,21 @@ fn span(from: f32, to: f32, sf: f32, side: i32) -> std::ops::RangeInclusive<i32>
|
||||
first..=last
|
||||
}
|
||||
|
||||
/// Draws `image`, logging failure and first success (PERF-05).
|
||||
fn drawn_tile(image: Arc<RenderImage>, page: usize, view: gpui::Entity<PdfView>) -> gpui::Canvas<()> {
|
||||
canvas(
|
||||
|_, _, _| {},
|
||||
move |bounds, _, window, cx| match window.paint_image(bounds, bounds, Default::default(), image, 0, false) {
|
||||
Ok(()) if !view.read(cx).drawn => {
|
||||
view.update(cx, |view, _| view.drawn = true);
|
||||
log::info!("pdf: first tile drawn, page {page}");
|
||||
}
|
||||
Ok(()) => {}
|
||||
Err(error) => log::error!("pdf: drawing a page failed: {error}"),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// A tile as an image; GPUI takes BGRA.
|
||||
pub(crate) fn picture((w, h): (u32, u32), bgra: Vec<u8>) -> Option<Arc<RenderImage>> {
|
||||
let image = ImageBuffer::<Rgba<u8>, _>::from_raw(w, h, bgra)?;
|
||||
@@ -151,7 +166,7 @@ impl PdfView {
|
||||
seen.insert(key);
|
||||
match self.tiles.get(&key) {
|
||||
Some(image) => tiles.push(
|
||||
img(image.clone())
|
||||
drawn_tile(image.clone(), place.page, cx.entity())
|
||||
.absolute()
|
||||
.left(px(rect[0] as f32 / sf))
|
||||
.top(px(rect[1] as f32 / sf))
|
||||
@@ -279,7 +294,7 @@ impl PdfView {
|
||||
});
|
||||
match painted.map(|bgra| picture((rect[2] as u32, rect[3] as u32), bgra)) {
|
||||
Ok(Some(image)) => {
|
||||
log::debug!("pdf: a tile of page {} drawn", key.page);
|
||||
log::debug!("pdf: a tile of page {} came", key.page);
|
||||
if let Some(old) = view.tiles.insert(key, image) {
|
||||
view.retired.push(old);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ pub struct PdfView {
|
||||
pub tiles: HashMap<TileKey, Arc<RenderImage>>,
|
||||
/// Images no longer drawn, freed at the next render.
|
||||
pub retired: ely_gpui_component::primitives::Retired,
|
||||
/// A tile reached the screen; logged once (PERF-05).
|
||||
pub drawn: bool,
|
||||
/// Tiles the worker could not draw; not asked again.
|
||||
pub failed: HashSet<TileKey>,
|
||||
pub text: HashMap<usize, Arc<Vec<Char>>>,
|
||||
@@ -162,6 +164,7 @@ impl PdfView {
|
||||
scroll: ScrollHandle::new(),
|
||||
tiles: HashMap::new(),
|
||||
retired: Default::default(),
|
||||
drawn: false,
|
||||
failed: HashSet::new(),
|
||||
text: HashMap::new(),
|
||||
asking_text: HashSet::new(),
|
||||
|
||||
Reference in new issue
Block a user