diff --git a/cmake/BoingCuda.cmake b/cmake/BoingCuda.cmake index 53f73e16..6f9bee17 100644 --- a/cmake/BoingCuda.cmake +++ b/cmake/BoingCuda.cmake @@ -6,6 +6,7 @@ # default one, CMAKE_CUDA_HOST_COMPILER (or the CUDAHOSTCXX environment variable) names another. set(WEBFRONT_HOST_LOOP_CUDA "AUTO" CACHE STRING "CUDA renderer of the host-loop example: AUTO (when a working toolkit is found), ON or OFF") set_property(CACHE WEBFRONT_HOST_LOOP_CUDA PROPERTY STRINGS AUTO ON OFF) +set(_WEBFRONT_BOING_CUDA_DIR "${CMAKE_CURRENT_LIST_DIR}") # A macro: enable_language() must run in the scope of the top-level CMakeLists.txt, above every directory whose # targets link the CUDA unit. Defines WebFront_boing, which a target computing the scene links: nothing on a CPU-only @@ -15,6 +16,11 @@ macro(webfront_enable_host_loop_cuda) message(FATAL_ERROR "WEBFRONT_HOST_LOOP_CUDA must be AUTO, ON or OFF, not '${WEBFRONT_HOST_LOOP_CUDA}'") endif() set(WEBFRONT_HOST_LOOP_CUDA_ENABLED OFF) + # Record the choice before enable_language initializes its own compiler-dependent default. + set(_webfront_cuda_architectures_explicit FALSE) + if(DEFINED CMAKE_CUDA_ARCHITECTURES OR (DEFINED ENV{CUDAARCHS} AND NOT "$ENV{CUDAARCHS}" STREQUAL "")) + set(_webfront_cuda_architectures_explicit TRUE) + endif() if(WEBFRONT_HOST_LOOP_CUDA STREQUAL "ON") enable_language(CUDA) set(WEBFRONT_HOST_LOOP_CUDA_ENABLED ON) @@ -27,6 +33,10 @@ macro(webfront_enable_host_loop_cuda) endif() endif() if(WEBFRONT_HOST_LOOP_CUDA_ENABLED) + if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") + include("${_WEBFRONT_BOING_CUDA_DIR}/BoingCudaArchitectures.cmake") + webfront_cuda_select_default("${_webfront_cuda_architectures_explicit}" "${CMAKE_CUDA_COMPILER}") + endif() message(STATUS "Host-loop example: CUDA ${CMAKE_CUDA_COMPILER_VERSION} renderer enabled (${CMAKE_CUDA_COMPILER})") else() message(STATUS "Host-loop example: CPU renderer only (WEBFRONT_HOST_LOOP_CUDA=${WEBFRONT_HOST_LOOP_CUDA}, no working CUDA compiler)") diff --git a/cmake/BoingCudaArchitectures.cmake b/cmake/BoingCudaArchitectures.cmake new file mode 100644 index 00000000..16e4e423 --- /dev/null +++ b/cmake/BoingCudaArchitectures.cmake @@ -0,0 +1,51 @@ +# Select only installed GPUs for which nvcc can emit native machine code. A matching cubin avoids depending on the +# driver's PTX compiler, which may be older than the toolkit. Empty means detection could not make a safe choice. +function(webfront_cuda_native_architectures devices compiler_codes output) + string(REPLACE "\r" "" devices "${devices}") + string(REPLACE "\n" ";" devices "${devices}") + string(REPLACE "\r" "" compiler_codes "${compiler_codes}") + string(REPLACE "\n" ";" compiler_codes "${compiler_codes}") + set(architectures) + foreach(device IN LISTS devices) + string(STRIP "${device}" device) + if(device MATCHES "^([0-9]+)\\.([0-9]+)$") + set(arch "${CMAKE_MATCH_1}${CMAKE_MATCH_2}") + if("sm_${arch}" IN_LIST compiler_codes) + list(APPEND architectures "${arch}") + endif() + endif() + endforeach() + list(REMOVE_DUPLICATES architectures) + set(${output} "${architectures}" PARENT_SCOPE) +endfunction() + +function(webfront_cuda_detect_native compiler output) + set(${output} "" PARENT_SCOPE) + if(CMAKE_CROSSCOMPILING) + return() + endif() + find_program(_webfront_nvidia_smi NAMES nvidia-smi) + if(NOT _webfront_nvidia_smi) + return() + endif() + execute_process(COMMAND "${_webfront_nvidia_smi}" --query-gpu=compute_cap --format=csv,noheader + RESULT_VARIABLE device_result OUTPUT_VARIABLE devices ERROR_QUIET TIMEOUT 5) + execute_process(COMMAND "${compiler}" --list-gpu-code + RESULT_VARIABLE compiler_result OUTPUT_VARIABLE codes ERROR_QUIET TIMEOUT 5) + if(device_result STREQUAL "0" AND compiler_result STREQUAL "0") + webfront_cuda_native_architectures("${devices}" "${codes}" architectures) + set(${output} "${architectures}" PARENT_SCOPE) + endif() +endfunction() + +function(webfront_cuda_select_default explicit_choice compiler) + if(explicit_choice OR CMAKE_CROSSCOMPILING) + return() + endif() + webfront_cuda_detect_native("${compiler}" architectures) + if(architectures) + set(CMAKE_CUDA_ARCHITECTURES "${architectures}" CACHE STRING "CUDA architectures" FORCE) + set(CMAKE_CUDA_ARCHITECTURES "${architectures}" PARENT_SCOPE) + message(STATUS "Host-loop example: native CUDA architectures ${architectures}") + endif() +endfunction() diff --git a/cmake/WKWebViewSupport.cmake b/cmake/WKWebViewSupport.cmake index 6efe1c01..7daf2dbc 100644 --- a/cmake/WKWebViewSupport.cmake +++ b/cmake/WKWebViewSupport.cmake @@ -18,7 +18,7 @@ function(webfront_add_wkwebview_tests) add_executable(wkwebview_lifecycle "${webtest_source_dir}/WKWebViewLifecycle.cpp" "${webtest_source_dir}/WKWebViewHeaderConsumer.cpp") target_link_libraries(wkwebview_lifecycle PRIVATE WebFront WebFront_warnings WebFront_options) - foreach(mode repeated-show main-thread native-close quit navigation-diagnostic startup-timeout settings hidden-scheduling redirect-policy missing-response committed-navigation agent-application download choose-file cancel-choose replaced-download choose-in-blank choose-in-srcdoc close-with-open-panel close-with-save-panel script-dialogs close-with-script-dialog sandboxed-script-dialog) + foreach(mode repeated-show main-thread native-close quit navigation-diagnostic startup-timeout settings translucent-background hidden-scheduling redirect-policy missing-response committed-navigation agent-application download choose-file cancel-choose replaced-download choose-in-blank choose-in-srcdoc close-with-open-panel close-with-save-panel script-dialogs close-with-script-dialog sandboxed-script-dialog load-reveal present-timeout) add_test(NAME WKWebViewLifecycle-${mode} COMMAND wkwebview_lifecycle ${mode}) webfront_set_browser_test_properties("WKWebViewLifecycle-${mode}" "${webtest_source_dir}" 90) endforeach() diff --git a/cmake/WebKitGTKSupport.cmake b/cmake/WebKitGTKSupport.cmake index 3add3cee..d84141a7 100644 --- a/cmake/WebKitGTKSupport.cmake +++ b/cmake/WebKitGTKSupport.cmake @@ -28,7 +28,7 @@ function(webfront_add_webkitgtk_tests) target_link_libraries(webkitgtk_lifecycle PRIVATE WebFront_test_hardening WebFront WebFront_warnings WebFront_options) add_dependencies(webtest webkitgtk_lifecycle) webfront_find_xvfb(display_runner) - foreach(mode sandbox-environment sandbox-recheck no-display worker-thread native-close repeated-show http-error pre-run-failure poll-failure profile-permissions window-title download download-user-dir choose-file cancel-choose close-with-dialog script-dialogs close-with-script-dialog) + foreach(mode sandbox-environment sandbox-recheck no-display worker-thread native-close repeated-show http-error pre-run-failure poll-failure profile-permissions window-title download download-user-dir choose-file cancel-choose close-with-dialog script-dialogs close-with-script-dialog first-frame present-timeout media-scoped) if(mode MATCHES "^(no-display|worker-thread|pre-run-failure|profile-permissions)$") add_test(NAME WebKitGTKAdapter-${mode} COMMAND webkitgtk_lifecycle ${mode}) elseif(display_runner) diff --git a/cmake/WebView2Support.cmake b/cmake/WebView2Support.cmake index 5f7dd632..2229dbd1 100644 --- a/cmake/WebView2Support.cmake +++ b/cmake/WebView2Support.cmake @@ -55,7 +55,7 @@ target_include_directories(WebFront SYSTEM INTERFACE "${WebView2SDK_SOURCE_DIR}/ target_compile_definitions(WebFront INTERFACE WEBFRONT_EMBED_WEBVIEW2) target_link_libraries(WebFront INTERFACE "${WebView2SDK_SOURCE_DIR}/build/native/${_webview2_arch}/WebView2LoaderStatic.lib" - ole32 oleaut32 user32 shell32 shlwapi version) + ole32 oleaut32 user32 gdi32 shell32 shlwapi version) # Register lifecycle coverage once, alongside the shared Jasmine runner; paths are module-relative. function(webfront_add_webview2_tests) @@ -66,7 +66,7 @@ function(webfront_add_webview2_tests) target_link_libraries(webview2_lifecycle PRIVATE WebFront WebFront_warnings WebFront_options) foreach(mode repeated-show native-early-close navigation-diagnostic mta missing-runtime closed-startup-timeout failed-startup-timeout late-navigation-failure runtime-ready - file-choose file-cancel file-download script-dialogs) + file-choose file-cancel file-download script-dialogs first-frame present-timeout) add_test(NAME WebView2Lifecycle-${mode} COMMAND webview2_lifecycle ${mode}) webfront_set_browser_test_properties("WebView2Lifecycle-${mode}" "${webtest_source_dir}" 45) endforeach() diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index bc4d781c..c5f00b09 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,21 @@ these entries stays in the GitHub releases and the Git history. ## Unreleased +### Added +- Skip GStreamer's initialization, and its plugin scan, in WebKitGTK for an application whose pages never use audio or video, with `WindowOptions::media = false`; the default keeps media (#611, `docs/WEBKITGTK.md`). +- WKWebView supports `WindowOptions::background`, translucent colours included, and `WEBFRONT_STARTUP_TRACE=1` (#611, `docs/WKWEBVIEW.md`). +- WebView2 supports `WindowOptions::background` and `WEBFRONT_STARTUP_TRACE=1` (#611, `docs/WEBVIEW2.md`). +- Choose the colour of the WebKitGTK view under the page with `WindowOptions::background` (WebKitGTK; WebView2 and WKWebView are listed above; CEF ignores it), and read the start-up milestones of a WebKitGTK view with `WEBFRONT_STARTUP_TRACE=1` (#611, `docs/WEBKITGTK.md`). + +### Changed +- Reveal the WKWebView window when the document has loaded or after one second (#611, `docs/WKWEBVIEW.md`). +- Reveal the WebView2 window after the first frame or one second (#611, `docs/WEBVIEW2.md`). +- Show the WebKitGTK window when the page reports its first frame, or when a one-second timer fires, even if the page has not painted, instead of at once; the embedded pages, the starter and the examples use the cheap `sans-serif` and `monospace` font stacks (#611, `docs/WEBKITGTK.md`). + +### Fixed +- Remove the white flash of an embedded view between the developer environment's bootstrap page and the project's page, by giving the window the environment's dark colour (`#141821`) when the application sets none; on macOS the view then no longer paints its own white behind it (#611, `docs/WKWEBVIEW.md`). +- Select detected GPU architectures supported by nvcc by default for the host-loop CUDA renderer (`docs/HOST_LOOP_EXAMPLE.md`). + ## [1.0.0] - 2026-11-17 WebFront 1.0 ships with developer environment 1.0.0. This release adds host-loop integration, developer tools and diff --git a/docs/HOST_LOOP_EXAMPLE.md b/docs/HOST_LOOP_EXAMPLE.md index 20664605..9e07071d 100644 --- a/docs/HOST_LOOP_EXAMPLE.md +++ b/docs/HOST_LOOP_EXAMPLE.md @@ -52,6 +52,15 @@ working CUDA compiler, and the example is complete without one. `ON` makes a mis `.cu` unit compiled at C++17, and `CMAKE_CUDA_HOST_COMPILER` names another host compiler when nvcc refuses the default one. At run time the engine is offered only when a device answers. +On a fresh native build, CMake selects installed NVIDIA GPUs that `nvcc` supports and embeds native code for them. This +avoids depending on the driver's PTX compiler, which may be older than the toolkit. If detection is unavailable, CMake +keeps the compiler's default. Explicit `CMAKE_CUDA_ARCHITECTURES` and `CUDAARCHS` choices take precedence; select all +target architectures for a distribution or cross-build. A previous build retains its cached choice: remove that cache +entry to redetect the local GPU. If the redetection fails (`nvidia-smi` unavailable), CMake keeps no architecture in an +already configured build directory: give `CMAKE_CUDA_ARCHITECTURES` explicitly or start from a fresh build directory +before generating `WebFront_boing_cuda`. With a Visual Studio generator, rebuild `WebFront_boing_cuda` after changing it, since +MSBuild may otherwise retain the previous CUDA object. + **The window.** With the platform's native engine in the build (WebKitGTK on Linux, autodetected), the example opens a native window; otherwise, or with `--browser`, it opens the system browser. On a Jetson Orin (L4T R39.2.1, Ubuntu 24.04) the native window opens with no change to the system: no AppArmor profile, no sysctl, no package. diff --git a/docs/WEBKITGTK.md b/docs/WEBKITGTK.md index cab3729a..902c02c9 100644 --- a/docs/WEBKITGTK.md +++ b/docs/WEBKITGTK.md @@ -97,6 +97,48 @@ unit tests cover the policy decision table, null error diagnostics, preserving the first failure when a timeout or callback reports a later error, and the sandbox launcher check described below. +## Startup and first display + +The window is mapped at once, but almost transparent, and becomes opaque when the page reports its first frame (two +animation frames after `DOMContentLoaded`). If no frame is reported, a one-second timer shows it anyway, even when the +server has sent nothing yet, so a window may still appear empty (in the colour of `background`, if any) when the load is +slow; GLib can also run the timer late when other events keep the main loop busy. Without a compositing manager the +opacity is ignored and the window appears immediately, as before. The navigation timeout and its diagnostics are +unchanged. `WindowOptions::background` (`"#rgb"`, `"#rrggbb"` or `"#rrggbbaa"`) is the colour of the view under the page, +so a dark interface does not flash white once the window is shown; only WebKitGTK applies it so far. +`WEBFRONT_STARTUP_TRACE=1` prints the view's milestones (session creation, view created, load started, first frame, +window shown) on standard error, in milliseconds since the process was executed; only the first frame notification of +the session is a milestone (a late one is marked as such), a reload is not. A close request (`requestClose()`) made +before the window is shown still ends the session. + +### Skipping GStreamer + +WebKitGTK initializes GStreamer in the page's process shortly after a page loads, even if it never uses media, and scans +every plugin when the registry is cold (the first launch of a user, and after each update of the system's plugins): up to +1.7 s during which the WebSocket handshake and the frames of the page are blocked. Disabling the media settings of the +view does not prevent it, and WebFront cannot know in advance whether a page will use media. An application whose pages +never use `