Compare commits

3 Commits
Author SHA1 Message Date
Herman van HazendonkandClaude Opus 4.8 dc76215e41 backend: WebProcess reap-on-nav + low-memory cache model (512MB durability)
Reap the WebProcess on every top-level navigation (bpwpe_reap_on_nav, env BPWPE_REAP_ON_NAV) so a
long-lived card doesn't accumulate heap/cache across a session and thrash under memory pressure — the
fix for pages-stop-loading on 512MB. Cost is one cold WebProcess spawn per navigation. Plus, on the
low-memory path: DOCUMENT_VIEWER cache model (was WEB_BROWSER) and bf-cache disabled, so the WebProcess
footprint stays small. TouchPad (not low-mem, no env) unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-28 10:02:38 +02:00
Herman van HazendonkandClaude Opus 4.8 05295fc55c backend: BPWPE_SCREEN_W/H override for the Pre 3 square-viewport bug
webOS 2.2.4 reports the legacy-compat LOGICAL panel size in luna.conf (320x480) even though the Pre 3
panel is physically 480x800 (it scales legacy apps 1.5x). BrowserPageWPE trusted luna.conf, so the
browser viewport came out 480x480 — pages laid out in half the height and 100vh was wrong. Honour
BPWPE_SCREEN_W / BPWPE_SCREEN_H (set by the Pre 3 device-profile to 480/800) over luna.conf. No env on
the TouchPad -> luna.conf still wins (its values are already the physical size there).

NOTE: requires a BrowserServer-atlas rebuild to take effect.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-28 08:38:37 +02:00
Herman van HazendonkandClaude Opus 4.8 b11fc4e3fd backend: force viewport-only rendering on low-memory devices (Pre 3)
Adds bpwpe_force_low_mem(): every page renders in SIMPLE (viewport-only) mode when
the device is low-RAM or when forced, WITHOUT needing the per-card "atlas-simple:"
URL marker. This is what lets the unmodified stock webOS Mojo browser UI drive the
WPE engine on a 512MB HP Pre 3 (the Mojo WebView can't emit the marker), and it
belt-and-suspenders the Enyo app path too.

Selection (evaluated once, cached):
  BPWPE_FORCE_SIMPLE=1  -> on (set by the Pre 3 boot wrapper)
  BPWPE_FORCE_SIMPLE=0  -> off (escape hatch, wins over RAM autodetect)
  /tmp/atlas_force_simple present -> on at runtime
  else -> on if /proc/meminfo MemTotal <= ~640MB

The TouchPad (~1GB, no env/file) evaluates false, so its rendering path is byte-
identical. Pair with BPWPE_SIMPLE_SCREENS=1 for exact-viewport (mult=1) buffers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-28 02:25:34 +02:00
+73 -2
View File
@@ -77,6 +77,48 @@ static int lunaConfInt(const char* key)
return val;
}
/* Low-memory device / forced viewport-only rendering. On a 512MB single-core phone (HP Pre 3) the
* multi-screen-tall pan buffer is too heavy, AND the STOCK Mojo browser UI can't send the per-card
* "atlas-simple:" marker. So the backend self-selects SIMPLE (viewport-only) rendering for EVERY page
* when it sees a low-RAM device or is explicitly told to. Evaluated once (cached).
* env BPWPE_FORCE_SIMPLE=1 -> force ON (set by the Pre 3 boot wrapper)
* env BPWPE_FORCE_SIMPLE=0 -> force OFF (escape hatch; wins over the RAM autodetect)
* /tmp/atlas_force_simple -> force ON at runtime (no wrapper restart)
* else -> ON if /proc/meminfo MemTotal <= ~640MB (catches 512MB devices)
* The TouchPad (~1GB MemTotal, no env/file) evaluates to false, so its behavior is unchanged. */
static bool bpwpe_force_low_mem()
{
static int cached = -1;
if (cached >= 0) return cached != 0;
const char* e = getenv("BPWPE_FORCE_SIMPLE");
if (e) { cached = (atoi(e) != 0) ? 1 : 0; return cached != 0; }
if (access("/tmp/atlas_force_simple", F_OK) == 0) { cached = 1; return true; }
long memTotalKb = 0;
FILE* mf = fopen("/proc/meminfo", "r");
if (mf) {
char line[128];
while (fgets(line, sizeof(line), mf))
if (sscanf(line, "MemTotal: %ld kB", &memTotalKb) == 1) break;
fclose(mf);
}
cached = (memTotalKb > 0 && memTotalKb <= 640000) ? 1 : 0; /* 512MB phones ~450-500MB MemTotal */
return cached != 0;
}
/* Reap the WebProcess on every top-level navigation (bound memory to one page instead of letting a
* long-lived card accumulate heap/cache across a session -> the pressure-thrash fix on 512MB). The cold
* WebProcess respawn is the cost. env BPWPE_REAP_ON_NAV=1 (Pre 3 device-profile) / =0 off / else falls
* back to the low-memory autodetect. Evaluated once. */
static bool bpwpe_reap_on_nav()
{
static int cached = -1;
if (cached >= 0) return cached != 0;
const char* e = getenv("BPWPE_REAP_ON_NAV");
if (e) { cached = (atoi(e) != 0) ? 1 : 0; return cached != 0; }
cached = bpwpe_force_low_mem() ? 1 : 0;
return cached != 0;
}
/* ---- Editor-focus → webOS VKB bridge (2.52 / 2.0 API). WPE has no QtWebKit microFocusChanged
* signal; the WebView instead drives a WebKitInputMethodContext when an editable element gains or
* loses focus. We subclass it, override notify_focus_in/out, and forward to the page, which raises
@@ -780,7 +822,10 @@ void BrowserPageWPE::ensureWebView()
* on card close (both fixed), NOT the cache. WEB_BROWSER model keeps a real resource/bf cache (faster
* repeat loads + back/forward); WebKit's memory-pressure settings evict under load. DOCUMENT_VIEWER
* fallback via /tmp/atlas_nocache if memory regresses. */
bool s_cacheOn = (access("/tmp/atlas_nocache", F_OK) != 0);
/* Low-memory: use the DOCUMENT_VIEWER cache model (minimal resource cache, no dead-page retention)
* instead of WEB_BROWSER, so the WebProcess footprint stays small on 512MB — pairs with reap-on-nav
* and the bf-cache disable below. Overridable off the low-mem path via /tmp/atlas_nocache as before. */
bool s_cacheOn = (access("/tmp/atlas_nocache", F_OK) != 0) && !bpwpe_force_low_mem();
webkit_web_context_set_cache_model(ctx, s_cacheOn ? WEBKIT_CACHE_MODEL_WEB_BROWSER : WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
/* Render at the FULL device width. The adapter seeds m_virtualWindowWidth at ~960, which
@@ -796,6 +841,13 @@ void BrowserPageWPE::ensureWebView()
/* Screen dims from webOS config (luna.conf), falling back to the framebuffer — never hardcoded. */
int screenW = lunaConfInt("DisplayWidth");
int screenH = lunaConfInt("DisplayHeight");
/* Device screen-size override (HP Pre 3): webOS 2.2.4 reports the LEGACY-COMPAT logical panel size in
* luna.conf (DisplayWidth=320, DisplayHeight=480) even though the panel is physically 480x800 (it scales
* legacy apps 1.5x). Trusting luna.conf here makes the browser viewport square (480x480) — pages lay out
* in half the height and 100vh is wrong. The Pre 3 boot wrapper's device-profile sets BPWPE_SCREEN_W=480
* / BPWPE_SCREEN_H=800 so we render at the real panel size. No env on the TouchPad -> luna.conf wins. */
{ const char* ew = getenv("BPWPE_SCREEN_W"); if (ew && atoi(ew) > 0) screenW = atoi(ew);
const char* eh = getenv("BPWPE_SCREEN_H"); if (eh && atoi(eh) > 0) screenH = atoi(eh); }
if (screenW <= 0 || screenH <= 0) {
int fbfd = open("/dev/fb0", O_RDONLY);
if (fbfd >= 0) { struct fb_var_screeninfo vi;
@@ -960,7 +1012,9 @@ void BrowserPageWPE::ensureWebView()
* A headless readout for on-device web-compat debugging (why site X rejects us / fails to load) with
* no inspector; off by default so production pays nothing. */
webkit_settings_set_enable_write_console_messages_to_stdout(s, access("/tmp/atlas_console", F_OK) == 0 ? TRUE : FALSE);
webkit_settings_set_enable_page_cache(s, (access("/tmp/atlas_nocache", F_OK) != 0) ? TRUE : FALSE); /* bf-cache = instant back/forward; /dev/shm + leak fixes made the OOM moot. Disable via /tmp/atlas_nocache */
/* bf-cache = instant back/forward, but it retains prior pages in memory. Off in low-memory (keeps the
* WebProcess small on 512MB; back/forward reloads instead) or via /tmp/atlas_nocache. */
webkit_settings_set_enable_page_cache(s, (access("/tmp/atlas_nocache", F_OK) != 0 && !bpwpe_force_low_mem()) ? TRUE : FALSE);
/* Runtime double-gating: these ship as build flags in the engine but WPE defaults them OFF, so the
* embedder must flip them on. EME uses WebKit's built-in ClearKey CDM (no external DRM needed).
* requestIdleCallback + LinkPrefetch are widely-used modern-web APIs defaulted off on WPE — enable via
@@ -1608,6 +1662,13 @@ void BrowserPageWPE::openUrl(const char* url)
WLOG("simple marker -> viewport mode (mult=1); target='%s'", u.c_str());
}
}
/* Low-memory device / forced simple: render EVERY page viewport-only even without the marker.
* This is what lets the unmodified stock Mojo browser (which never sends atlas-simple:) run on a
* 512MB Pre 3, and it belt-and-suspenders the Enyo app too. No-op on the TouchPad (see helper). */
if (!m_simpleMode && bpwpe_force_low_mem()) {
m_simpleMode = true;
WLOG("low-memory device/env -> forcing simple (viewport) mode");
}
/* A pre-warmed (about:blank, non-private) WebView can't serve a private card — tear it down so
* ensureWebView() rebuilds it ephemeral. Non-private navigations reuse the warm WebProcess.
* SAME for a SIMPLE card: the warm WebView was created with the default tall (mult=4) pan buffer
@@ -1619,6 +1680,16 @@ void BrowserPageWPE::openUrl(const char* url)
m_prewarmBlank = false;
if ((m_private || m_simpleMode) && m_webView) { g_object_unref(m_webView); m_webView = nullptr; }
}
/* REAP-ON-NAV (low memory): terminate the existing WebProcess before a new top-level load so the fresh
* page starts with a clean heap/cache instead of the card accumulating memory across the whole session.
* Only when a real WebView is still alive (prewarm teardown above may have cleared it) and we're loading
* a real page (not about:/data:). One cold WebProcess spawn is the cost; see bpwpe_reap_on_nav(). */
if (m_webView && bpwpe_reap_on_nav()
&& u.compare(0, 6, "about:") != 0 && u.compare(0, 5, "data:") != 0) {
WLOG("reap-on-nav: terminating previous WebProcess before loading '%s'", u.c_str());
webkit_web_view_terminate_web_process(m_webView);
g_object_unref(m_webView); m_webView = nullptr;
}
ensureWebView();
/* WebKit needs a scheme or it returns WebKitPolicyError 101 "URL can't be shown".
* The adapter passes the raw typed text (e.g. "cnn.com"), so add http:// if missing. */