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
6 changed files with 120 additions and 156 deletions

No files matched your search

-39
View File
@@ -78,45 +78,6 @@ fully offscreen (`EGL_KHR_surfaceless_context` + FBO, or a pbuffer). This decide
surfaceless/FBO is strongly preferred; if WebKit insists on a window surface we provide a 1x1
pbuffer-config window or the device fbdev native window and still read back via an FBO.
## The "GPU wedge" (atlas-wpe-env#3) — root cause, fixed 2026-08-23
The hang tracked as [atlas-wpe-env#3](https://github.com/Herrie82/atlas-wpe-env/issues/3) — after
GPU-heavy work (site menus, rotation, a few minutes of navigation) no page ever loads again, the
BrowserServer main thread sits in `futex_wait_queue_me` / `__skb_recv_datagram`, the WPEWebProcess is
idle — was never a GPU hang. It was three bugs on the UIProcess (BrowserServer) side — two in this file's
**frame channel**, one in BrowserPageWPE.cpp:
1. **Stale close of the fd handed to WebKit.** `view_get_renderer_host_fd()` returns one end of a
`socketpair`. WebKit wraps the return value `UnixFileDescriptor::Adopt` (`PageClientImpl::
hostFileDescriptor()`), ships it to the WebProcess and **closes it** — on another thread, within
milliseconds. The backend kept the number and closed it again when the first frame arrived. By then
the number had been reused (strace on-device: the very next `socketpair` got it back 80 ms later),
so that close hit a live fd — another channel's `sock_ui`, or a WebKit IPC socket. The channel's
`g_unix_fd_add` source then polled a foreign socket: a blocking `recv()` racing the IPC thread parks
the main loop in `__skb_recv_datagram`; a stolen IPC datagram leaves a sync reply that never comes
(`futex_wait_queue_me`); a closed IPC socket looks to WebKit like a crashed WebProcess, so it spawns
replacements while BS stays stuck. Fix: the returned end is WebKit's — never touched again; the
channel is reaped on HUP/EOF; `recv()` is `MSG_DONTWAIT`.
2. **Unread FRAME_ACK backlog.** The UIProcess answered every frame with an ack that the WebProcess
never read. Unread datagrams stay charged to the *sender's* socket buffer, so after a few hundred
frames on one page (an animated menu, a video, a long scroll session) the blocking `send(ack)`
parked the main loop forever — right after a perfectly good frame, which is exactly how the wedge
presented. Fix: the WebProcess drains acks before each FRAME_READY and the ack send is
`MSG_DONTWAIT`.
3. **SIGUSR1 stolen from JavaScriptCore** (`BrowserPageWPE.cpp`, not this file). A debug trigger for
the autonomous scroll test did `g_unix_signal_add(SIGUSR1, …)` once a page was live. WTF/JSC uses
SIGUSR1 (`sigThreadSuspendResume`) to suspend threads for conservative GC stack scanning, and glib's
`sigaction` replaced WTF's handler. The next concurrent GC of the UIProcess JSC VM (the one behind
`webkit_web_view_evaluate_javascript`'s JSCValues) then hung the collector in `Thread::suspend →
sem_wait(globalSemaphoreForSuspendResume)` waiting for a handler that no longer ran, and the main
thread's next heap entry parked in `JSC::Heap::acquireAccessSlow` — the `futex_wait_queue_me` wedge
caught on-device 2026-08-23 *after* fixes 1+2 were in. Fix: the SIGUSR1 hook is gone (the
`/tmp/atlas_scrolltest` file trigger remains). Nothing else in the engine may take SIGUSR1; if it ever
must, set `JSC_SIGNAL_FOR_GC=<signo>` in the boot wrapper instead.
None of this needs the watchdog that used to abort+respawn the engine; that watchdog is off (0.9.10).
## Build
`libWPEBackend-atlas.so`, linked against `libwpe-1.0`, `libEGL`/`libGLESv2` (stubs at build,
+89 -50
View File
@@ -22,6 +22,7 @@
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <sys/time.h>
#include <glib-unix.h> // g_unix_signal_add — SIGUSR1 kicks the autonomous scroll test
#include <sys/socket.h> // atlas-sensord Unix-socket client (DeviceOrientation/Motion)
#include <sys/un.h>
#include <cstring>
@@ -76,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
@@ -130,7 +173,8 @@ static inline bool bpwpe_dead(BrowserPageWPE* p) { return g_livePages.find(p) ==
struct ScrollTestState { bool active; int cy, dir, step, maxCy, steps, renders, uncovered; long maxStallMs; guint tick; };
static ScrollTestState g_st = {false,0,1,120,0,0,0,0,0,0};
static BrowserPageWPE* g_testablePage = nullptr; // last page to attach buffers = the scroll-test target
static gboolean scrolltest_poll(gpointer); // fwd — file trigger for the autonomous tests
static gboolean on_sigusr1(gpointer); // fwd
static gboolean scrolltest_poll(gpointer); // fwd — file trigger (app-spawned BS masks SIGUSR1)
BrowserPageWPE::BrowserPageWPE(BrowserServer* server, YapProxy* proxy)
: m_server(server), m_proxy(proxy), m_identifier(0)
@@ -778,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
@@ -794,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;
@@ -893,27 +947,6 @@ void BrowserPageWPE::ensureWebView()
WLOG("ensureWebView layout %dx%d -> render %dx%d (screen=%d contentZoom=%.3f)",
renderW, renderH, m_renderWidth, m_renderHeight, screenW, (double)m_renderWidth/renderW);
/* VIEWPORT vs PAN BUFFER. renderH above is a PAINT extent (~4 screens) that the adapter pans
* within — it is not what the user can see. WebKit, left alone, uses the view height as the initial
* containing block, so a quirks-mode `height: 100%` layout (the classic centring table, e.g.
* home.jonandnic.com) resolves 100% to ~3072px and puts its "centred" content about a screen and a
* half below the fold. That is the "pages load halfway down" bug.
*
* Tell the WebProcess the real screen height so it can cap the ICB to one screen while still
* painting the whole buffer (WebCore/rendering/RenderView.cpp, atlasICBHeightCap()). Only meaningful
* when the buffer is actually taller than the screen; mult=1 needs no cap.
*
* setenv, not IPC: the WebProcess inherits our environment at spawn, and the engine runs
* WEBKIT_USE_SINGLE_WEB_PROCESS=1, so this is read once by the one process that matters. screenH
* comes from luna.conf DisplayHeight, which does not change on rotate (only the width does), so the
* value stays correct for the life of the process. */
if (screenH > 0 && renderH > screenH) {
char icb[16];
snprintf(icb, sizeof(icb), "%d", screenH);
setenv("ATLAS_ICB_HEIGHT", icb, 1);
WLOG("ICB height capped to screen: ATLAS_ICB_HEIGHT=%d (buffer %d)", screenH, renderH);
}
m_viewBackend = wpe_atlas_view_backend_create(renderW, renderH, scaledW, scaledH,
&BrowserPageWPE::onFrame, this);
WebKitWebViewBackend* vb = webkit_web_view_backend_new(m_viewBackend, nullptr, nullptr);
@@ -937,15 +970,12 @@ void BrowserPageWPE::ensureWebView()
}
/* This page has a live WebView -> it's the scroll-test target (NOT a startPage/tab that only
* attached buffers with screenH=0). Install the file-trigger poll once. NO SIGUSR1 hook here:
* WTF/JSC uses SIGUSR1 to suspend threads for conservative GC scanning, and g_unix_signal_add()
* replaced that handler — the collector then waited forever for the main thread to answer and the
* main thread deadlocked on the heap (JSC::Heap::acquireAccessSlow). That was one of the two
* "GPU wedge" (#3) mechanisms. */
* attached buffers with screenH=0). Install the trigger once (poll works despite masked SIGUSR1). */
g_testablePage = this;
static bool s_testInstalled = false;
if (!s_testInstalled) {
s_testInstalled = true;
g_unix_signal_add(SIGUSR1, on_sigusr1, nullptr);
g_timeout_add(700, scrolltest_poll, nullptr);
}
@@ -982,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
@@ -1630,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
@@ -1641,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. */
@@ -2402,14 +2451,22 @@ void BrowserPageWPE::updateContentsSize()
-1, nullptr, nullptr, nullptr, &BrowserPageWPE::onContentHeight, this);
}
/* ===================== autonomous scroll test (file trigger) ===================== */
/* ===================== autonomous scroll test (SIGUSR1) ===================== */
static gboolean scrolltest_tick(gpointer)
{
if (!g_testablePage || g_livePages.find(g_testablePage) == g_livePages.end()) { g_st.active = false; return G_SOURCE_REMOVE; }
return g_testablePage->scrollTestStep() ? G_SOURCE_CONTINUE : G_SOURCE_REMOVE;
}
/* File trigger: the host `touch`es /tmp/atlas_scrolltest; polled on the glib loop. (There used to be a
* SIGUSR1 trigger too — removed: SIGUSR1 belongs to JSC's GC thread-suspend, see ensureWebView.) */
static gboolean on_sigusr1(gpointer)
{
if (g_testablePage && g_livePages.find(g_testablePage) != g_livePages.end() && !g_st.active)
g_testablePage->startScrollTest();
else
WLOG("SIGUSR1: no testable page (or a test is already running)");
return G_SOURCE_CONTINUE; /* keep the handler for repeated runs */
}
/* File trigger: the host `touch`es /tmp/atlas_scrolltest; polled on the glib loop (which is clearly
* dispatching — frames render), so it works even though the app-spawned BS has SIGUSR1 masked. */
static gboolean scrolltest_poll(gpointer)
{
if (access("/tmp/atlas_scrolltest", F_OK) == 0) {
@@ -2761,24 +2818,6 @@ static gboolean atlas_img_decide_dest(WebKitDownload* dl, gchar*, gpointer ud) {
webkit_download_set_destination(dl, static_cast<AtlasImgDl*>(ud)->dest.c_str()); return TRUE;
}
/* Clear the resource caches of every live page. Replaces QWebSettings::clearMemoryCaches(), which
* does not exist in this port (QtWebKit is headers-only here, so the call linked to address 0 and
* crashed). WPE 2.0 routes cache clearing through the network session's website-data manager. */
void BrowserPageWPE::clearAllCaches()
{
for (BrowserPageWPE* p : g_livePages) {
if (!p || !p->m_webView) continue;
WebKitNetworkSession* session = webkit_web_view_get_network_session(p->m_webView);
if (!session) continue;
WebKitWebsiteDataManager* mgr = webkit_network_session_get_website_data_manager(session);
if (!mgr) continue;
webkit_website_data_manager_clear(mgr,
static_cast<WebKitWebsiteDataTypes>(WEBKIT_WEBSITE_DATA_MEMORY_CACHE | WEBKIT_WEBSITE_DATA_DISK_CACHE),
0, nullptr, nullptr, nullptr);
}
WLOG("clearAllCaches: cleared memory+disk cache for %zu live page(s)", g_livePages.size());
}
void BrowserPageWPE::saveImageAtPointAsync(int32_t queryNum, int32_t x, int32_t y, const char* dir)
{
m_saveImgQuery = queryNum;
-5
View File
@@ -158,11 +158,6 @@ public:
* the image asynchronously and answer via m_server->msgHitTestResponse / msgSaveImageAtPointResponse. */
void hitTestAsync(int32_t queryNum, int32_t cx, int32_t cy);
void saveImageAtPointAsync(int32_t queryNum, int32_t x, int32_t y, const char* dir);
/* BrowserServer::clearCache() used QWebSettings::clearMemoryCaches(), a QtWebKit call with no
* library behind it in the WPE port - it linked to address 0 and SIGSEGV'd the engine. Reached
* from Preferences > Clear Cache, the asyncCmdClearCache IPC, AND automatically on a device
* locale change. Clears every live page's caches through the WPE 2.0 website-data manager. */
static void clearAllCaches();
void respondSaveImage(int32_t query, bool ok, const char* path); // Feature 9: called from the image-download callback
/* A payload starting with \x02 is an AUTOFILL request ("\x02" user "\x02" pass), routed through this
* existing command to avoid new IPC. Otherwise it's a plain InsertText into the focused field. */
+2 -27
View File
@@ -1,27 +1,8 @@
#!/bin/bash
# Cross-compile the Atlas WPE backend to libWPEBackend-atlas.so (musl/ARM softfp).
set -e
# Toolchain env. Honour an already-sourced cross environment (STAGING/CC/TARGET exported); otherwise
# source one. WPE_ENV overrides; the default sits next to this checkout so the script works from any
# clone rather than only from the tree it was written in.
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
if [ -z "${STAGING:-}" ] || [ -z "${CC:-}" ]; then
ENV_SH="${WPE_ENV:-$SCRIPT_DIR/../atlas-wpe-env/env-atlas-cross.sh}"
[ -f "$ENV_SH" ] || { echo "build.sh: no cross env found at $ENV_SH - source it first or set WPE_ENV" >&2; exit 1; }
. "$ENV_SH"
fi
cd "$SCRIPT_DIR"
# pkg-config: wpe-1.0/egl/glesv2/glib live in the staged webkitdeps tree (Debian multiarch layout),
# not in $STAGING/lib/pkgconfig, so the plain cross env does not resolve them. Mirror what
# cmake/atlas-arm-toolchain.cmake sets so this builds against exactly what WebKit built against -
# and never against the host's /usr.
if ! pkg-config --exists wpe-1.0 2>/dev/null; then
WKDEPS="${ATLAS_WEBKITDEPS:-$STAGING/webkitdeps}"
export PKG_CONFIG_SYSROOT_DIR="$WKDEPS"
export PKG_CONFIG_LIBDIR="$WKDEPS/usr/lib/arm-linux-gnueabihf/pkgconfig:$WKDEPS/usr/share/pkgconfig:$STAGING/lib/pkgconfig"
unset PKG_CONFIG_PATH
fi
WPE=/home/herrie/webos/wpe; . "${WPE_ENV:-$WPE/env-glibc-gcc125.sh}"
cd "$WPE/backend-atlas"
PKGS="wpe-1.0 glib-2.0 egl glesv2"
CF=$(pkg-config --cflags $PKGS)
LF=$(pkg-config --libs $PKGS)
@@ -36,12 +17,6 @@ echo " exports _wpe_loader_interface: $($TARGET-nm -D libWPEBackend-atlas.so |
echo " NEEDED: $($TARGET-readelf -d libWPEBackend-atlas.so | grep -oE '\[lib[^]]+\]' | tr '\n' ' ')"
echo "=== building frame-dump test harness ==="
# Optional: needs wpe-webkit-2.0 + libpng16 staged. The backend itself is the deliverable, so a
# missing harness dependency must not fail the build.
if ! pkg-config --exists wpe-webkit-2.0 libpng16 2>/dev/null; then
echo " skipped (wpe-webkit-2.0/libpng16 not in PKG_CONFIG_LIBDIR)"
exit 0
fi
HCF=$(pkg-config --cflags wpe-webkit-2.0 wpe-1.0 glib-2.0 libpng16)
HLF=$(pkg-config --libs wpe-webkit-2.0 glib-2.0 libpng16)
$CC $CFLAGS -std=gnu11 -Wall $HCF \
@@ -1,6 +1,9 @@
--- a/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp
+++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp
@@ -687,6 +687,24 @@
@@ ogg block closing brace, before "if (matroskaSupported)" @@
if (auto result = factories.hasElementForMediaType(ElementFactories::Type::VideoDecoder, "video/x-theora"_s)) {
m_decoderMimeTypeSet.add("video/ogg"_s);
m_decoderCodecMap.add("theora"_s, result);
}
}
@@ -23,5 +26,3 @@
+ }
+
if (matroskaSupported) {
m_decoderMimeTypeSet.add("video/x-matroska"_s);
+25 -32
View File
@@ -104,7 +104,7 @@ static struct atlas_view* g_atlas_views = NULL; /* P2 wpe->view registry (few
* (which stalled loads with "bad SETUP" after a cross-site jump). Lives until its process exits. */
struct atlas_conn {
struct atlas_view* v;
int sock_ui; /* our end. The peer end is handed to WebKit in view_get_renderer_host_fd and is not ours */
int sock_ui, sock_web;
guint io_source;
};
@@ -192,49 +192,46 @@ static int view_get_renderer_host_fd(void* data)
}
struct atlas_conn* c = (struct atlas_conn*)calloc(1, sizeof(*c));
if (!c) { close(sv[0]); close(sv[1]); return -1; }
c->v = v; c->sock_ui = sv[0];
c->v = v; c->sock_ui = sv[0]; c->sock_web = sv[1];
/* tell THIS WebProcess where the shared frame buffer is (+ the fit-to-screen output size) */
struct atlas_msg m = { .type = MSG_SETUP, .shmid = (uint32_t)v->shmid,
.width = v->width, .height = v->height, .slot = 0,
.swidth = v->swidth, .sheight = v->sheight };
if (send(c->sock_ui, &m, sizeof(m), MSG_NOSIGNAL) != (ssize_t)sizeof(m))
if (send(c->sock_ui, &m, sizeof(m), 0) != (ssize_t)sizeof(m))
ATLAS_LOG("send(SETUP) failed: %s", strerror(errno));
/* receive THIS process's MSG_FRAME_READY on the UIProcess main loop */
c->io_source = g_unix_fd_add(c->sock_ui, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, atlas_view_on_readable, c);
c->io_source = g_unix_fd_add(c->sock_ui, G_IO_IN | G_IO_HUP | G_IO_ERR, atlas_view_on_readable, c);
/* sv[1] now belongs to WebKit: PageClientImpl::hostFileDescriptor() ADOPTS it, sends it to the
* WebProcess and closes it (another thread, within ms). Closing it here later — as the old
* "close sock_web on first frame" did — closed whatever had since reused the number (another
* channel's sock_ui, a WebKit IPC socket): the main loop then parked in recv()/a lost IPC reply.
* That was the GPU "wedge" (atlas-wpe-env#3). The pair still HUPs when the WebProcess exits. */
return sv[1];
/* Keep OUR sock_web open for now — WebKit dup()s the returned fd for the WebProcess
* (asynchronously), so closing it here would hand the process a dead fd (kills even the 1st
* load). It's dropped in atlas_view_on_readable on the process's FIRST message (which proves the
* dup already happened), so the socketpair can then HUP on process exit and reap the conn. */
return c->sock_web;
}
static gboolean atlas_view_on_readable(gint fd, GIOCondition cond, gpointer data)
{
struct atlas_conn* c = (struct atlas_conn*)data;
struct atlas_view* v = c->v;
if (cond & G_IO_NVAL) { free(c); return G_SOURCE_REMOVE; } /* fd already closed — not ours to close again */
/* Drain what is readable first (a HUP can arrive together with the last frame), never blocking
* the UI main loop; drop the channel on EOF/error, or on HUP/ERR once nothing is left to read. */
struct atlas_msg m;
ssize_t n = recv(fd, &m, sizeof(m), MSG_DONTWAIT);
if (n < 0 && (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)) {
if (!(cond & (G_IO_HUP | G_IO_ERR))) return G_SOURCE_CONTINUE;
n = 0; /* HUP with the queue drained: treat as EOF */
}
if (n <= 0) { /* this WebProcess exited (or the fd is bad) */
int e = n < 0 ? errno : 0;
if (e) ATLAS_LOG("frame channel fd %d: %s — dropping channel", fd, strerror(e));
if (e != EBADF) close(c->sock_ui);
if (cond & (G_IO_HUP | G_IO_ERR)) { /* this WebProcess exited — drop its channel */
if (c->sock_ui >= 0) close(c->sock_ui);
if (c->sock_web >= 0) close(c->sock_web);
free(c);
return G_SOURCE_REMOVE;
}
struct atlas_msg m;
ssize_t n = recv(fd, &m, sizeof(m), 0);
if (n != (ssize_t)sizeof(m)) return G_SOURCE_CONTINUE;
/* First real message proves WebKit already dup'd sock_web into the WebProcess, so drop OUR ref
* to it now (race-free: the process has its own copy). Without this the kept-open sock_web pins
* the socketpair so it never HUPs -> the conn (FD + io_source) leaks on every cross-site PSON
* spawn; this lets the pair HUP when the process exits, reaping the channel. */
if (c->sock_web >= 0) { close(c->sock_web); c->sock_web = -1; }
if (m.type == MSG_FRAME_READY && v->shm && v->handler) {
uint32_t slot = m.slot % SLOTS;
/* Slot addressing uses the LAYOUT size (allocation granularity); the frame's ACTUAL size
@@ -247,7 +244,7 @@ static gboolean atlas_view_on_readable(gint fd, GIOCondition cond, gpointer data
wpe_view_backend_dispatch_frame_displayed(v->wpe);
struct atlas_msg ack = { .type = MSG_FRAME_ACK, 0, 0, 0, slot };
send(fd, &ack, sizeof(ack), MSG_DONTWAIT | MSG_NOSIGNAL);
send(fd, &ack, sizeof(ack), 0);
}
return G_SOURCE_CONTINUE;
}
@@ -462,7 +459,6 @@ static void target_destroy(void* d)
{
struct atlas_target* t = (struct atlas_target*)d;
if (t->shm && t->shm != (void*)-1) shmdt(t->shm);
if (t->host_fd >= 0) close(t->host_fd); /* ours: WebKit passed hostFD.release() */
free(t->scratch);
free(t->ds_scratch);
free(t);
@@ -1287,15 +1283,12 @@ static void target_frame_rendered(void* d)
rw, rh, _rb, _iv, _iv ? 1000000.0 / _iv : 0.0, s_bgra_readback);
} _pn++; }
_plast = _pt1;
/* Drain the UIProcess's FRAME_ACKs. Nobody waits on them, but unread datagrams stay charged
* to the SENDER's buffer, so left alone they fill it after a few hundred frames and the
* BrowserServer's ack send() would block its main loop forever (the "wedge after a good frame"). */
{ struct atlas_msg a; while (recv(t->host_fd, &a, sizeof(a), MSG_DONTWAIT) > 0) {} }
struct atlas_msg m = { .type = MSG_FRAME_READY, .width = rw, .height = rh, .slot = t->cur_slot };
send(t->host_fd, &m, sizeof(m), MSG_NOSIGNAL);
send(t->host_fd, &m, sizeof(m), 0);
t->cur_slot = (t->cur_slot + 1) % SLOTS;
}
/* let WebKit proceed to the next frame (into the other slot); we don't wait for the ack. */
/* let WebKit proceed to the next frame (into the other slot). With double-buffering we don't
* wait for the UIProcess ack here; drain acks opportunistically for flow control if needed. */
wpe_renderer_backend_egl_target_dispatch_frame_complete(t->wpe);
}
static void target_deinitialize(void* d) { (void)d; }