8000 [Grida Canvas] Core Graphics - Daily RC 246 by softmarshmallow · Pull Request #395 · gridaco/grida · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Grida Canvas] Core Graphics - Daily RC 246 #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 24, 2025
Merged

[Grida Canvas] Core Graphics - Daily RC 246 #395

merged 22 commits into from
Jun 24, 2025

Conversation

softmarshmallow
Copy link
Member
@softmarshmallow softmarshmallow commented Jun 21, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new WebGL/WebAssembly canvas application with interactive scene loading, developer overlays, and input handling for panning and zooming.
    • Added caching for text layouts and vector paths to improve rendering performance.
    • Implemented a new rectangle node type for scene JSON import.
    • Added support for developer tools overlays: tiles, FPS meter, stats, hit testing, and ruler display.
    • Provided a native window application backend for desktop platforms, including event handling and OpenGL context management.
    • New hit testing methods with both bounding box and path-based precision.
  • Bug Fixes

    • Improved hit testing accuracy by switching from bounding box checks to precise path containment.
  • Documentation

    • Updated and expanded documentation for build commands, optimization techniques, and new features.
    • Added new README files for WebAssembly and native examples.
  • Refactor

    • Modularized window and application logic for better platform separation and maintainability.
    • Reorganized project structure, moving and re-exporting modules for clarity.
  • Chores

    • Updated build scripts, Dockerfiles, and Makefiles for Emscripten and native development environments.
    • Adjusted Rust edition and dependency configurations for compatibility and streamlined builds.
  • Tests

    • Added and updated tests for hit testing and resource loading, improving test coverage and reliability.

Copy link
codesandbox bot commented Jun 21, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link
vercel bot commented Jun 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
backgrounds ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2025 5:01am
blog ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2025 5:01am
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2025 5:01am
grida ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2025 5:01am
viewer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2025 5:01am
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
code ⬜️ Ignored (Inspect) Jun 24, 2025 5:01am
legacy ⬜️ Ignored (Inspect) Jun 24, 2025 5:01am

Copy link
coderabbitai bot commented Jun 21, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces a new WebAssembly (WASM) and WebGL application backend, modularizes platform-specific windowing code, and implements efficient caching for text paragraphs and vector paths in the rendering pipeline. It adds new hit testing methods with improved path-based precision, supports rectangle nodes in JSON scene import, and enhances developer tooling overlays. The build system and workspace structure are revised to support Emscripten and WASM targets, including new Dockerfiles, Makefiles, and example projects.

Changes

File(s) / Path(s) Change Summary
.devcontainer/emscripten/Dockerfile, .devcontainer/emscripten/devcontainer.json Added Emscripten devcontainer Dockerfile and VSCode config for Rust/WASM development.
Cargo.toml, crates/grida/Cargo.toml, crates/grida-canvas/Cargo.toml, crates/grida-math2/Cargo.toml Workspace updated: removed grida, added grida-canvas-wasm, edition changed to 2021, dependencies reorganized, WASM features adjusted.
crates/Dockerfile, crates/Makefile, crates/grida-canvas/Makefile Updated build paths, environment variables, and module export names for WASM builds.
crates/grida-canvas-wasm/* New WASM crate: Cargo.toml, FFI main.rs, web demo files (README, index.html, main.js).
crates/skia-safe-wasm-example/* Added Skia WASM example: Cargo.toml, Makefile, README, index.html, main.rs.
crates/grida-canvas/src/cache/paragraph.rs, crates/grida-canvas/src/cache/vector_path.rs, crates/grida-canvas/src/cache/mod.rs, crates/grida-canvas/src/cache/scene.rs Added and integrated paragraph and vector path caching modules, updated SceneCache.
crates/grida-canvas/src/painter/painter.rs Integrated paragraph/path caches into Painter, refactored drawing methods, added tests.
crates/grida-canvas/src/hit_test.rs, crates/grida-canvas/tests/hit_test.rs Added fast and precise (path-based) hit testing methods, updated tests.
crates/grida-canvas/src/node/schema.rs Added Hash/Eq/PartialEq to text/layout enums and FontWeight for cache keying.
crates/grida-canvas/src/repository.rs Added font repository generation counter for cache invalidation.
crates/grida-canvas/src/io/io_json.rs Added rectangle node support for JSON import/export.
crates/grida-canvas/src/window/command.rs Introduced WindowCommand enum for unified window operations.
crates/grida-canvas/src/window/application.rs, application_native.rs, application_native_demo.rs, application_webgl.rs, state.rs Modularized windowing: new application backends for native and WebGL/WASM, state management, demo runners.
crates/grida-canvas/src/window/mod.rs Removed legacy window code, now delegates to submodules and re-exports platform-specific applications.
crates/grida-canvas/src/window/hit_overlay.rs Refactored hit overlay drawing: path-based outlines, camera transforms, text support.
crates/grida-canvas/src/font_loader.rs, crates/grida-canvas/src/image_loader.rs Switched to futures mpsc channels, updated sender types and usages.
crates/grida-canvas/examples/cache_picture.rs, crates/grida-canvas/examples/camera.rs Removed unused gl_rs imports.
crates/grida-canvas/examples/winit_raf.rs Replaced rand with custom pseudo-random function.
crates/grida-canvas/docs/optimization.md Expanded documentation on text and path caching mechanisms.
crates/grida-canvas/AGENTS.md, AGENTS.md Added cargo check to recommended development commands.
crates/grida-canvas/tests/resource_loader.rs Switched async tests from Tokio to futures::executor::block_on.
crates/grida-canvas/src/lib.rs Made window module always public (no longer conditional on target).
crates/grida-canvas/src/runtime/scene.rs Renamed debug tile method for consistency.

Sequence Diagram(s)

WebGL/WASM Application Initialization and Rendering

sequenceDiagram
    participant JS as main.js (Web)
    participant WASM as GridaCanvas WASM Module
    participant WebGL as WebGL2 Context

    JS->>WASM: Load WASM module (GridaCanvas)
    JS->>WebGL: Create WebGL2 context
    JS->>WASM: Register WebGL context
    JS->>WASM: init(width, height)
    WASM->>WASM: Create WebGlApplication
    JS->>WASM: load_scene_json(ptr, len)
    WASM->>WASM: Parse JSON, load scene
    JS->>WASM: set devtools overlays (tiles, FPS, etc.)
    loop User Interaction
        JS->>WASM: pointer_move(x, y) / command(id, a, b)
        WASM->>WASM: Update input/camera state
        JS->>WASM: redraw()
        WASM->>WebGL: Render frame via Skia
    end
    JS->>WASM: resize_surface(new_width, new_height)
    WASM->>WebGL: Resize rendering surface
Loading

Painter Caching Flow

sequenceDiagram
    participant Painter
    participant ParagraphCache
    participant VectorPathCache

    Painter->>ParagraphCache: get_or_create(node_id, text, ...)
    alt Cache hit
        ParagraphCache-->>Painter: Return cached Paragraph
    else Cache miss
        ParagraphCache->>Painter: Build new Paragraph
        ParagraphCache-->>Painter: Cache and return Paragraph
    end

    Painter->>VectorPathCache: get_or_create(node_id, path_data)
    alt Cache hit
        VectorPathCache-->>Painter: Return cached Path
    else Cache miss
        VectorPathCache->>Painter: Parse and cache Path
        VectorPathCache-->>Painter: Return new Path
    end
Loading

Platform-specific Application Initialization

sequenceDiagram
    participant Main
    alt Native
        Main->>application_native_demo: run_demo_window(scene)
        application_native_demo->>application_native: init_native_window()
        application_native->>state: Create GPU/Skia state
        application_native->>Main: Event loop (window events)
    else WASM/WebGL
        Main->>application_webgl: init(width, height)
        application_webgl->>WASM: Setup WebGL context, Skia
        application_webgl->>Main: Expose extern "C" API
    end
Loading

Poem

Hopping through code, the rabbit spies
New caches for text and for paths—how wise!
WASM and WebGL, now hand in paw,
Platform code modular, neat and in awe.
With rectangles and hit tests, overlays so bright,
This codebase leaps forward—what a delight!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64c8ad3 and 97a87b1.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • crates/skia-safe-wasm-example/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (49)
  • .devcontainer/emscripten/Dockerfile (1 hunks)
  • .devcontainer/emscripten/devcontainer.json (1 hunks)
  • AGENTS.md (1 hunks)
  • Cargo.toml (1 hunks)
  • crates/Dockerfile (1 hunks)
  • crates/Makefile (2 hunks)
  • crates/docs/optimization.md (1 hunks)
  • crates/grida-canvas-wasm/Cargo.toml (1 hunks)
  • crates/grida-canvas-wasm/src/main.rs (1 hunks)
  • crates/grida-canvas-wasm/web/README.md (1 hunks)
  • crates/grida-canvas-wasm/web/index.html (1 hunks)
  • crates/grida-canvas-wasm/web/main.js (1 hunks)
  • crates/grida-canvas/AGENTS.md (1 hunks)
  • crates/grida-canvas/Cargo.toml (1 hunks)
  • crates/grida-canvas/Makefile (1 hunks)
  • crates/grida-canvas/examples/cache_picture.rs (0 hunks)
  • crates/grida-canvas/examples/camera.rs (0 hunks)
  • crates/grida-canvas/examples/winit_raf.rs (2 hunks)
  • crates/grida-canvas/src/cache/geometry.rs (1 hunks)
  • crates/grida-canvas/src/cache/mod.rs (1 hunks)
  • crates/grida-canvas/src/cache/paragraph.rs (1 hunks)
  • crates/grida-canvas/src/cache/scene.rs (4 hunks)
  • crates/grida-canvas/src/cache/vector_path.rs (1 hunks)
  • crates/grida-canvas/src/font_loader.rs (2 hunks)
  • crates/grida-canvas/src/hit_test.rs (5 hunks)
  • crates/grida-canvas/src/image_loader.rs (2 hunks)
  • crates/grida-canvas/src/io/io_json.rs (5 hunks)
  • crates/grida-canvas/src/lib.rs (0 hunks)
  • crates/grida-canvas/src/node/schema.rs (5 hunks)
  • crates/grida-canvas/src/painter/painter.rs (10 hunks)
  • crates/grida-canvas/src/repository.rs (6 hunks)
  • crates/grida-canvas/src/runtime/scene.rs (4 hunks)
  • crates/grida-canvas/src/window/application.rs (1 hunks)
  • crates/grida-canvas/src/window/application_native.rs (1 hunks)
  • crates/grida-canvas/src/window/application_native_demo.rs (1 hunks)
  • crates/grida-canvas/src/window/application_webgl.rs (1 hunks)
  • crates/grida-canvas/src/window/command.rs (1 hunks)
  • crates/grida-canvas/src/window/hit_overlay.rs (4 hunks)
  • crates/grida-canvas/src/window/mod.rs (1 hunks)
  • crates/grida-canvas/src/window/state.rs (1 hunks)
  • crates/grida-canvas/tests/hit_test.rs (1 hunks)
  • crates/grida-canvas/tests/resource_loader.rs (1 hunks)
  • crates/grida-math2/Cargo.toml (2 hunks)
  • crates/grida/Cargo.toml (0 hunks)
  • crates/skia-safe-wasm-example/Cargo.toml (1 hunks)
  • crates/skia-safe-wasm-example/Makefile (1 hunks)
  • crates/skia-safe-wasm-example/README.md (1 hunks)
  • crates/skia-safe-wasm-example/src/main.rs (1 hunks)
  • crates/skia-safe-wasm-example/web/index.html (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests 8000
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch canary

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0