feat: wire compositor pipeline + fix 50 type errors#20
feat: wire compositor pipeline + fix 50 type errors#20LayerDynamics wants to merge 4 commits intomainfrom
Conversation
…gine - Wire PaintLayer tree into CompositorThread via updateLayerTree() in RenderingOrchestrator - CPU composite now uses LayerTree path when available, falls back to RenderToPixels - getPixels() auto-composites when layerTree exists but no prior composite() call - Fix script execution timing (emitStage used Date.now() as startTime, duration was always ~0) - Fix 50 type errors: DOMElement→HTMLCanvasElement casts, Uint8Array buffer compatibility, FFI return type casts, Console cast through unknown, override modifier, null assertions - Add 10 compositor pipeline integration tests - Add 6 E2E rendering pipeline tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reviewer's GuideWires the paint layer tree into the compositor pipeline for CPU compositing, fixes script timing and multiple type/FFI issues, and adds integration tests to cover the compositor and end-to-end rendering paths. Sequence diagram for CPU compositing with wired paint layer treesequenceDiagram
participant RenderingOrchestrator
participant PaintPipeline
participant CompositorThread
participant LayerTree
participant RenderToPixels
participant Canvas2D
RenderingOrchestrator->>PaintPipeline: paint(dom, rootRenderObject, options)
PaintPipeline-->>RenderingOrchestrator: paintResult(displayList, layerTree)
RenderingOrchestrator->>CompositorThread: updateLayerTree(paintResult.layerTree)
CompositorThread->>CompositorThread: store layerTree
alt CPU mode
RenderingOrchestrator->>CompositorThread: composite()
alt layerTree exists
CompositorThread->>Canvas2D: getContext(2d)
CompositorThread->>Canvas2D: clearRect()
CompositorThread->>LayerTree: paintDirtyLayers()
CompositorThread->>LayerTree: composite(ctx)
LayerTree-->>CompositorThread: pixels on canvas
CompositorThread->>CompositorThread: cpuCanvas = canvas
else no layerTree
CompositorThread->>RenderToPixels: paint(lastRenderObject, width, height, false)
RenderToPixels-->>CompositorThread: paintResult(canvas)
CompositorThread->>CompositorThread: cpuCanvas = paintResult.canvas
end
else GPU mode
RenderingOrchestrator->>CompositorThread: composite()
CompositorThread->>CompositorThread: GPU compositing path
end
note over CompositorThread,Canvas2D: getPixels() now auto-calls composite() if layerTree or lastRenderObject is available
Class diagram for RenderingOrchestrator and CompositorThread layer-aware CPU compositingclassDiagram
class RenderingOrchestrator {
+enableJavaScript boolean
+compositor CompositorThread
+renderDocument(url, options) Promise~void~
+emitStage(id string, label string, state string, startTime number, endTime number, duration number, data any) void
}
class CompositorThread {
-cpuRenderMode boolean
-canvas HTMLCanvasElement
-cpuCanvas HTMLCanvasElement
-layerTree PaintLayerTree
-renderToPixels RenderToPixels
-lastRenderObject RenderObject
-frameCount number
+isCPUMode() boolean
+updateLayerTree(layerTree PaintLayerTree) void
+setRenderTree(rootRenderObject RenderObject) void
+composite() void
+getPixels() Uint8Array
}
class PaintLayerTree {
+paintDirtyLayers() void
+composite(ctx CanvasRenderingContext2D) void
+getBounds() DOMRect
}
class RenderToPixels {
+paint(rootRenderObject RenderObject, width Pixels, height Pixels, incremental boolean) RenderToPixelsResult
-createCanvas(width Pixels, height Pixels) HTMLCanvasElement
}
class RenderToPixelsResult {
+canvas HTMLCanvasElement
}
class RenderObject
class CanvasRenderingContext2D
class HTMLCanvasElement
class Pixels
class DOMRect
RenderingOrchestrator --> CompositorThread : uses
RenderingOrchestrator --> PaintLayerTree : receives from paint pipeline
CompositorThread --> PaintLayerTree : updateLayerTree(layerTree)
CompositorThread --> RenderToPixels : fallback CPU paint
RenderToPixelsResult --> HTMLCanvasElement : canvas
CompositorThread --> HTMLCanvasElement : canvas, cpuCanvas
PaintLayerTree --> CanvasRenderingContext2D : composite(ctx)
CompositorThread --> RenderObject : lastRenderObject
RenderToPixels --> RenderObject : paint(rootRenderObject)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly advances the browser's rendering capabilities by integrating the PaintLayer tree directly into the CompositorThread. This enables a more sophisticated, layer-aware CPU compositing process, which optimizes how visual elements are rendered and managed. Beyond this core rendering enhancement, the changes also address numerous type safety issues across the codebase, ensuring greater stability and maintainability. The addition of new integration tests provides comprehensive validation for the updated rendering pipeline and overall system behavior. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Several changes resolve type errors by broad
any/unknowncasts (e.g.encode()inserialxbindings,console as unknown as Record,EscPosctor, WebGPU FFI returns,doc as unknown as { documentElement?: unknown }); consider tightening these to more specific interfaces or discriminated unions so that the unsafe boundaries remain small and well-typed. - The
ComputePipeline.executepath now falls back topipeline as unknown as GPUComputePipelinewhennativePipelineis missing; it would be safer to adjust thePipelineResult/config types so thatnativePipelineis always present (or explicitly optional with a clear invariant) instead of relying on a cast. - The new test helpers for
createCPUCanvasand the variousdocument.createElement("canvas") as unknown as ...usages rely on partial canvas/2D-context stubs; consider centralizing these into a shared test utility type that explicitly documents the supported surface area, to reduce duplication and accidental divergence from the real API.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Several changes resolve type errors by broad `any`/`unknown` casts (e.g. `encode()` in `serialx` bindings, `console as unknown as Record`, `EscPos` ctor, WebGPU FFI returns, `doc as unknown as { documentElement?: unknown }`); consider tightening these to more specific interfaces or discriminated unions so that the unsafe boundaries remain small and well-typed.
- The `ComputePipeline.execute` path now falls back to `pipeline as unknown as GPUComputePipeline` when `nativePipeline` is missing; it would be safer to adjust the `PipelineResult`/config types so that `nativePipeline` is always present (or explicitly optional with a clear invariant) instead of relying on a cast.
- The new test helpers for `createCPUCanvas` and the various `document.createElement("canvas") as unknown as ...` usages rely on partial canvas/2D-context stubs; consider centralizing these into a shared test utility type that explicitly documents the supported surface area, to reduce duplication and accidental divergence from the real API.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request is a significant update that wires the paint layer tree into the compositor pipeline, enabling layer-aware CPU compositing and fixing a script execution timing bug. It's impressive that you've also resolved 50 type errors across the codebase, which greatly improves maintainability. The addition of 16 new integration tests for the compositor and end-to-end rendering pipelines is excellent and provides good coverage for the new features.
My review includes a couple of suggestions to further improve type safety in dom.ts and bindings.ts, which could prevent future issues and make the code even more robust. Overall, this is a high-quality contribution.
Note: Security Review did not run due to the size of the PR.
| // Auto-generated with deno_bindgen | ||
| function encode(v: string | Uint8Array): Uint8Array { | ||
| // deno-lint-ignore no-explicit-any | ||
| function encode(v: string | Uint8Array): any { |
There was a problem hiding this comment.
Changing the return type of the encode function to any weakens type safety. The function's implementation appears to always return a Uint8Array, so the original return type Uint8Array was more accurate.
While this change likely resolves a TypeScript error, it's better to address the root cause of the type mismatch where encode is called, rather than using any. This would improve code clarity and prevent potential runtime errors if the implementation of encode were to change in the future.
| const [tx0, ty0] = transformPoint(seg.x!, seg.y!); | ||
| const [tx1, ty1] = transformPoint(seg.x! + sw, seg.y!); | ||
| const [tx2, ty2] = transformPoint(seg.x! + sw, seg.y! + sh); | ||
| const [tx3, ty3] = transformPoint(seg.x!, seg.y! + sh); |
There was a problem hiding this comment.
The use of non-null assertions (!) on seg.x and seg.y suggests that the type definition for _currentPath might be too loose. Currently, it's Array<{ type: string; x?: number; y?: number; w?: number; h?: number }>, which doesn't guarantee that x and y are present for a rect segment.
While the rect method implementation ensures these properties exist, relying on ! can make the code more brittle.
To improve type safety and remove the need for assertions, consider using a discriminated union for the path segments. This would make the type of each segment explicit and allow the compiler to enforce that rect segments always have x and y.
Example of a stricter type definition:
type PathSegment =
| { type: "rect"; x: number; y: number; w: number; h: number }
| { type: "move"; x: number; y: number }
| { type: "line"; x: number; y: number };
// Then _currentPath would be:
_currentPath: PathSegment[] = [];With this change, you could safely access seg.x and seg.y within if (seg.type === "rect") without needing non-null assertions.
…zation Two-phase text rendering: bitmap font fallback (5x7 ASCII glyphs with descenders) for immediate results, plus real anti-aliased glyph rendering via fontdue WASM bindings (denosaurs/font) using system TTF/OTF fonts. - RenderingPipeline: fillText/strokeText/measureText with FontEngine integration - FontEngine: system font discovery, CSS font-family resolution, glyph caching - RenderTreeBuilder: user-agent stylesheet defaults (block elements, margins, font sizes) - RenderingOrchestrator: baseline calculation fix, NaN font-size guard Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- HTMLTokenizer: full named entity table (252 entities) replacing literal '&' fallback - HTMLTreeBuilder: add getAttribute/setAttribute/hasAttribute/removeAttribute to SimpleDOMNode - RenderTreeBuilder: presentational HTML attributes (bgcolor, color, width, height, align, valign, cellpadding, cellspacing, border, font tag size/color/face) - RenderTreeBuilder: fix table display values (table/table-row/table-cell) taking precedence over generic block; add center tag as block element - LayoutEngine: table-row/table-row-group skip re-layout to preserve table positioning; table-cell contents laid out as block flow Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
TLS Handshake: - Wrap Deno.connectTls in 10s timeout with resource leak cleanup - Custom TLS fallback wrapped in 5s timeout for fail-fast - readExactly uses overall deadline + per-iteration timer cleanup - receiveEncryptedHandshakeMessages loops until Finished (max 10) - Throw on message cap exhaustion without Finished Layout Performance: - Remove redundant grandchild doLayout loop (O(n²) → O(n)) - hasDescendantsNeedingLayout propagated flag for O(1) dirty check - Skip clean subtrees during recursive layout Paint Optimization: - Skip legacy PaintContext pass for DOMs >5000 nodes - displayListTruncated flag on RenderingResult - RenderToPixels layer tree is primary paint path Request Pipeline: - Internal AbortController cancels doRequest on timeout - Growing buffer replaces O(n²) chunk concatenation - ConnectionManager used for acquire/release - Incremental header/chunked-terminator scanning Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
updateLayerTree()now called in RenderingOrchestrator after paint, connecting the paint layer tree → compositor layer manager → tiling/GPU uploadgetPixels()to auto-composite when layerTree existsdeno task browser:checktype errors across 13 files (DOMElement casts, Uint8Array buffer compat, FFI return types, etc.)Test plan
deno test --allow-all browser/tests/integration/compositor_pipeline.test.ts— 10 passdeno test --allow-all browser/tests/integration/e2e_rendering_pipeline.test.ts— 6 passdeno test --allow-all browser/tests/integration/layout_paint_chain.test.ts— 10 passdeno test --allow-all browser/tests/engine/rendering/paint/— 256 passdeno task browser:check— 0 errors (was 50)🤖 Generated with Claude Code
Summary by Sourcery
Wire the paint layer tree into the compositor pipeline so CPU compositing can use layer-aware rendering, while tightening types across rendering, JavaScript, WebGPU, and FFI layers and adding integration coverage for the end-to-end rendering pipeline.
New Features:
Bug Fixes:
Enhancements:
Build:
deno task browser:checktype errors to restore a clean type-checking build.Tests: