forked from upstream/atlas-wpe-backend
Compare commits
3
Commits
master
...
pre3-lowmem
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc76215e41 | ||
|
|
05295fc55c | ||
|
|
b11fc4e3fd |
+73
-2
@@ -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. */
|
||||
|
||||
Reference in new issue
Block a user