DesktopWebview is a high-performance, custom-built toy desktop browser engine written in C++26. It features native windowing via X11 (Linux) and Win32 (Windows) APIs, Vulkan graphics integration, an uncompressed video player, dynamic page scrolling, a custom JavaScript interpretation engine, and a custom lazy PDF rendering engine built entirely from scratch.
DesktopWebview is structured as a pipeline-based browser engine similar to modern rendering engines (like WebKit or Blink), but implemented with a custom software and hardware-accelerated pipeline.
graph TD
URL[URL / File Path] --> Fetcher[Network / File Fetcher]
Fetcher -->|HTML Source| DOMParser[HTML Wrapper / DOM Parser]
Fetcher -->|CSS Files| CSSParser[CSS Parser]
DOMParser --> DOM[DOM Tree]
CSSParser --> Stylesheet[CSS Stylesheet]
DOM --> Layout[Layout Engine]
Stylesheet --> Layout
Layout --> StyledTree[Styled Layout Box Tree]
StyledTree --> Painter[Paint & Compositor Engine]
Painter -->|Display List| Rasterizer[Software Rasterizer / Vulkan GPU]
Rasterizer --> Canvas[Window Surface / Canvas]
subgraph Execution Subsystems
JsEngine[Custom JS Engine] <---> DOM
PdfEngine[Lazy PDF Engine] --> Painter
VideoEngine[FFmpeg Video Decoder] --> Painter
end
- Handles fetching remote files via HTTP/HTTPS (using a custom socket layer built on OpenSSL) and local files via system path resolution.
- Parses HTML documents using a custom Wrapper over
libxml2to build the Document Object Model (DOM) tree. - Manages node hierarchies, attributes, and inner text mutations.
- Parses CSS style rules (supporting margins, paddings, display, widths, heights, colors, and borders).
- Resolves cascades and matches selectors against DOM nodes to construct the Styled Node Tree.
- Translates the Styled Node Tree into a physical layout box hierarchy using block and inline formatting contexts.
- Resolves dimensions (margins, borders, padding, content widths/heights) and computes coordinates in page space.
- Converts layout boxes into a flat list of
DisplayCommanddrawings (SolidRects, borders, text runs, images, and videos). - Composites media resources and handles blitting to a software
Canvasor hardware Vulkan surface. - Accelerated base64 and rendering processing using OpenCL kernels.
- Lexer & Parser: Performs lexical tokenization and parses expressions/statements into Abstract Syntax Trees (AST).
- Environment Scope: Resolves execution frames, scoped variables, arithmetic operations, and string manipulations.
- DOM Bridge: Binds native C++ DOM manipulations (such as
console.log,document.title,document.getElementById, andinnerTextupdates) to JS runtime APIs.
- Structural Parser: Resolves low-level PDF dictionary structures, cross-reference (XRef) tables, and page catalogs.
- Text Extraction Machine: Decompresses page streams via zlib and feeds them to a spec-compliant stack interpreter (
ParseTexttrackingTm,Td,Tf,TJ,Tj,',"), extracting text coordinates in PDF coordinate space. - Lazy On-Demand Renderer:
- Automatically queries MediaBox page sizes via
pdfPageSizes()without allocating pixel memory. - Formats layout nodes with explicit size properties (
pdf://page/N). - Evaluates viewport intersections at render-time, rendering pages on-demand and caching them to a paging map (
m_pdfPages) to ensure stable memory consumption (~10-20MB instead of 7.5GB) and smooth 60 FPS scrolling.
- Automatically queries MediaBox page sizes via
- Parses raw uncompressed video formats (
.rawv) and standard formats via FFmpeg. - Synchronizes video playback using steady-clock timing and outputs PCM audio data via ALSA (Linux) or WASAPI (Windows) backends.
This repository contains a Nix development shell setup (shell.nix) containing all necessary tooling and dependencies.
- Enter the Nix Shell:
nix-shell
- Build the Project:
build-linux
- Run the Browser:
run-linux
- Run Unit Tests:
run-test-linux
- Enter the Nix Shell and configure cross-compilation:
nix-shell --arg strSystem "x86_64-linux" - Compile using the MinGW Toolchain:
build-windows
include/&src/: Core engine implementations (JsEngine, Network, Parser, CSS, Layout, Graphics presentation, PDF parsing, Video/Audio playback).test/: Native unit testing targets verifying JS interpretation, networking, rendering, and PDF stream interpreters.assets/: Default user-agent styles and preloaded page resources.
MIT License — © 2026 Hylmi