Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/engine/src/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Unit {
pub struct TaskInfo {
pub id: u64,
/// A stable id: `import`, `export`, `scan`, `previews`, `smartPreviews`, `lightroom`, `merge`, `download`,
/// `faces`, `denoise`, `findMissing`, `applePhotos`, `cache`, `focus`.
/// `faces`, `denoise`, `findMissing`, `applePhotos`, `cache`, `focus`, `original`.
pub kind: &'static str,
/// English; the frontend translates it.
pub label: String,
Expand Down
49 changes: 42 additions & 7 deletions crates/engine/src/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ impl MediaCache {

fn trim_full(&mut self) {
while self.full.len() > self.full_capacity {
let oldest = self.full.iter().enumerate().min_by_key(|(_, e)| e.2).map(|(i, _)| i).unwrap_or(0);
// the photo on screen keeps its original: one decoded in the background for the photo before can end after it
let oldest = self.full.iter().enumerate().min_by_key(|(_, e)| (Some(e.0) == self.on_screen, e.2)).map(|(i, _)| i).unwrap_or(0);
self.full.remove(oldest);
}
}
Expand All @@ -541,22 +542,26 @@ impl MediaCache {
/// Evict least recently used entries across the source caches and the rendered previews
/// until they fit the budget. The newest preview-level source (the photo on screen, or the
/// one just decoded) is never evicted here, nor is the original of the photo on screen
/// ([`Self::set_on_screen`]).
/// ([`Self::set_on_screen`]); while a photo is on screen, the originals of others go first.
pub fn enforce_budget(&mut self) {
// The on-screen original is never evicted here, so it does not count either: counted, a 64 MP original (760 MiB)
// nearly fills the default share (768 MiB) alone and everything else went instead — the photo's preview and
// thumbnail sources and the neighbours' were decoded again from the raw on every edit, zoom-out and step.
let pinned: usize = self.full.iter().filter(|e| Some(e.0) == self.on_screen).map(|e| e.1.bytes()).sum();
let mut held = self.held().saturating_sub(pinned);
// In Detail the original of a photo no longer shown goes first: at 64 MP it is ~0.8 GB, and by recency the
// previews of the photo now shown and of its neighbours went before it (each decoded from the raw again).
let others_first = self.on_screen.is_some();
while held > self.budget {
let newest_preview = self.previews.iter().map(|e| e.2).max();
// (order, which cache, tick)
let candidates = [
self.thumbs.oldest_tick().map(|t| (t, 0)),
self.previews.iter().filter(|e| Some(e.2) != newest_preview).map(|e| e.2).min().map(|t| (t, 1)),
self.full.iter().filter(|e| Some(e.0) != self.on_screen).map(|e| e.2).min().map(|t| (t, 2)),
self.rendered.oldest_tick().map(|t| (t, 3)),
self.thumbs.oldest_tick().map(|t| (t, 0, t)),
self.previews.iter().filter(|e| Some(e.2) != newest_preview).map(|e| e.2).min().map(|t| (t, 1, t)),
self.full.iter().filter(|e| Some(e.0) != self.on_screen).map(|e| e.2).min().map(|t| (if others_first { 0 } else { t }, 2, t)),
self.rendered.oldest_tick().map(|t| (t, 3, t)),
];
let Some((tick, which)) = candidates.into_iter().flatten().min() else { break };
let Some((_, which, tick)) = candidates.into_iter().flatten().min() else { break };
let freed = match which {
0 => self.thumbs.pop_oldest(),
1 => self.previews.iter().position(|e| e.2 == tick).map(|i| self.previews.remove(i).1.bytes()),
Expand Down Expand Up @@ -2131,6 +2136,23 @@ mod tests {
}
}

// Given the original of the photo shown until now (decoded in the background after the neighbours' previews), when
// the next photo is shown and the budget can't hold everything, that original goes, not the previews (by recency
// the new photo's own preview went first and was decoded from the raw again)
#[test]
fn the_original_of_the_photo_left_goes_before_the_previews() {
let img = |w: usize| Arc::new(Rgb32f::new(w, w));
let mut m = MediaCache::default();
m.set_budget(20 << 20);
m.set_on_screen(Some(PhotoId(1)));
m.insert(PhotoId(2), SourceLevel::Preview, img(500)); // the neighbours, prefetched
m.insert(PhotoId(3), SourceLevel::Preview, img(500));
m.insert(PhotoId(1), SourceLevel::Full, img(1500)); // 27 MB, kept while on screen
m.set_on_screen(Some(PhotoId(2)));
assert!(!m.has_source(PhotoId(1), SourceLevel::Full));
assert!(m.has_source(PhotoId(2), SourceLevel::Preview) && m.has_source(PhotoId(3), SourceLevel::Preview));
}

// A 64 MP original (797 MB as linear float) is bigger than the default cache share (768 MiB):
// evicted on insert, every pan of a zoomed view decoded the raw again. The original of the photo
// on screen stays, whatever is decoded after it (prefetched neighbours), until another is shown.
Expand All @@ -2152,6 +2174,19 @@ mod tests {
assert!(m.held() <= 20 * mb, "{}", m.held());
}

// Given the original of the photo on screen, when the original of the photo before it arrives after it (its
// background decode can't stop) and only one original is kept, then the late one goes, not the one on screen
#[test]
fn a_late_original_does_not_evict_the_one_on_screen() {
let img = |w: usize| Arc::new(Rgb32f::new(w, w));
let mut m = MediaCache::default();
m.set_on_screen(Some(PhotoId(2)));
m.insert(PhotoId(2), SourceLevel::Full, img(100));
m.insert(PhotoId(1), SourceLevel::Full, img(100));
assert!(m.has_source(PhotoId(2), SourceLevel::Full));
assert!(!m.has_source(PhotoId(1), SourceLevel::Full));
}

#[test]
fn work_gate_waits_for_room() {
use crate::memory::WorkGate;
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,7 @@
"Fill Location": "Ort ausfüllen",
"Fill empty City, State and Country from GPS (offline GeoNames place names)": "Leere Felder Stadt, Bundesland und Land aus GPS ausfüllen (GeoNames-Ortsnamen, offline)",
"Looking up places": "Orte werden nachgeschlagen",
"Preparing full resolution": "Volle Auflösung wird vorbereitet",
"Downloading place names": "Ortsnamen werden heruntergeladen",
"Place names downloaded": "Ortsnamen heruntergeladen",
"Place names download cancelled": "Download der Ortsnamen abgebrochen",
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,7 @@
"Fill Location": "Rellenar ubicación",
"Fill empty City, State and Country from GPS (offline GeoNames place names)": "Rellenar Ciudad, Estado y País vacíos desde el GPS (nombres de lugares de GeoNames, sin conexión)",
"Looking up places": "Buscando lugares",
"Preparing full resolution": "Preparando la resolución completa",
"Downloading place names": "Descargando nombres de lugares",
"Place names downloaded": "Nombres de lugares descargados",
"Place names download cancelled": "Descarga de nombres de lugares cancelada",
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,7 @@
"Fill Location": "Remplir le lieu",
"Fill empty City, State and Country from GPS (offline GeoNames place names)": "Remplir Ville, État et Pays vides depuis le GPS (noms de lieux GeoNames, hors ligne)",
"Looking up places": "Recherche des lieux",
"Preparing full resolution": "Préparation de la pleine résolution",
"Downloading place names": "Téléchargement des noms de lieux",
"Place names downloaded": "Noms de lieux téléchargés",
"Place names download cancelled": "Téléchargement des noms de lieux annulé",
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +1967,7 @@
"Fill Location": "場所を入力",
"Fill empty City, State and Country from GPS (offline GeoNames place names)": "空の市区町村・都道府県・国を GPS から入力 (GeoNames の地名、オフライン)",
"Looking up places": "場所を検索中",
"Preparing full resolution": "フル解像度を準備中",
"Downloading place names": "地名データをダウンロード中",
"Place names downloaded": "地名データをダウンロードしました",
"Place names download cancelled": "地名データのダウンロードを中止しました",
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/locales/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,7 @@
"Fill Location": "Preencher local",
"Fill empty City, State and Country from GPS (offline GeoNames place names)": "Preencher Cidade, Estado e País vazios pelo GPS (nomes de lugares GeoNames, offline)",
"Looking up places": "Procurando lugares",
"Preparing full resolution": "Preparando a resolução total",
"Downloading place names": "Baixando nomes de lugares",
"Place names downloaded": "Nomes de lugares baixados",
"Place names download cancelled": "Download dos nomes de lugares cancelado",
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,7 @@
"Fill Location": "Заполнить место",
"Fill empty City, State and Country from GPS (offline GeoNames place names)": "Заполнить пустые поля «Город», «Регион» и «Страна» по GPS (названия мест GeoNames, офлайн)",
"Looking up places": "Поиск мест",
"Preparing full resolution": "Подготовка полного разрешения",
"Downloading place names": "Загрузка названий мест",
"Place names downloaded": "Названия мест загружены",
"Place names download cancelled": "Загрузка названий мест отменена",
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/locales/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,7 @@
"Fill Location": "Заповнити місце",
"Fill empty City, State and Country from GPS (offline GeoNames place names)": "Заповнити порожні поля «Місто», «Регіон» і «Країна» за GPS (назви місць GeoNames, офлайн)",
"Looking up places": "Пошук місць",
"Preparing full resolution": "Підготовка повної роздільної здатності",
"Downloading place names": "Завантаження назв місць",
"Place names downloaded": "Назви місць завантажено",
"Place names download cancelled": "Завантаження назв місць скасовано",
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/locales/zh-hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,7 @@
"Fill Location": "填写位置",
"Fill empty City, State and Country from GPS (offline GeoNames place names)": "根据 GPS 填写空白的城市、省/州和国家(GeoNames 地名,离线)",
"Looking up places": "正在查找地点",
"Preparing full resolution": "正在准备全分辨率",
"Downloading place names": "正在下载地名数据",
"Place names downloaded": "地名数据已下载",
"Place names download cancelled": "已取消下载地名数据",
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/locales/zh-hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,7 @@
"Fill Location": "填寫位置",
"Fill empty City, State and Country from GPS (offline GeoNames place names)": "根據 GPS 填寫空白的城市、州/省和國家(GeoNames 地名,離線)",
"Looking up places": "正在查找地點",
"Preparing full resolution": "正在準備全解析度",
"Downloading place names": "正在下載地名資料",
"Place names downloaded": "地名資料已下載",
"Place names download cancelled": "已取消下載地名資料",
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ impl Headless {
let (tx, rx) = std::sync::mpsc::channel();
let mut app = app.with_control(rx);
app.headless_host = true;
app.original_prefetch.off = true;
Headless {
app,
view: HeadlessView::new(),
Expand Down
7 changes: 6 additions & 1 deletion crates/ui-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ pub struct LightcraftApp {
pub(crate) drag_scale: region::DragScale,
/// (photo, look, window frame size) a window was refused for: it reads more than one render holds.
pub(crate) window_refused: Option<(lightcraft_catalog::PhotoId, u64, usize)>,
/// The background decode of the Detail photo's original, for a zoom.
pub(crate) original_prefetch: panels::detail::OriginalPrefetch,
pub(crate) region_tiles: std::collections::HashMap<(bool, u64), region::RegionView>,
/// The window render each pane of Compare / Reference asked for last (left, right), as
/// [`Self::region_view`] is for the loupe.
Expand Down Expand Up @@ -582,6 +584,7 @@ impl LightcraftApp {
size_hold: Default::default(),
drag_scale: Default::default(),
window_refused: None,
original_prefetch: Default::default(),
region_tiles: Default::default(),
compare_windows: [None; 2],
compare_tiles: Default::default(),
Expand Down Expand Up @@ -1586,7 +1589,9 @@ impl LightcraftApp {
self.ai_mask_detail(&ctx);
self.place_names_outcome(&ctx);
if self.ui.fullscreen {
// full-screen preview: the photo alone on black
// full-screen preview: the photo alone on black (the active one, in any view; `compare::prepare` doesn't run)
let decoding = self.renderer.is_pending(render::Slot::Prefetch(panels::detail::ORIGINAL_SLOT));
self.original_prefetch.frame(self.session.active(), decoding);
egui::CentralPanel::default()
.frame(egui::Frame::NONE.fill(egui::Color32::BLACK))
.show(ui, |ui| if self.ui.slideshow.is_some() { panels::slideshow::show(self, ui) } else { panels::detail::show(self, ui) });
Expand Down
2 changes: 2 additions & 0 deletions crates/ui-egui/src/panels/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ fn draw_window(p: &egui::Painter, app: &LightcraftApp, pane: u8, id: PhotoId, lo
pub fn prepare(app: &mut LightcraftApp) {
let shown = if app.ui.view == ViewMode::Detail { app.session.active() } else { None };
app.session.media.set_on_screen(shown);
let decoding = app.renderer.is_pending(Slot::Prefetch(super::detail::ORIGINAL_SLOT));
app.original_prefetch.frame(shown, decoding);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if app.ui.view != ViewMode::Detail {
app.region_view = None;
app.region_before_view = None;
Expand Down
Loading
Loading