Skip to content

WIP: Native canvas - #319

Open
Hierifer wants to merge 10 commits into
didi:mainfrom
EchoTechFE:native-canvas
Open

WIP: Native canvas#319
Hierifer wants to merge 10 commits into
didi:mainfrom
EchoTechFE:native-canvas

Conversation

@Hierifer

@Hierifer Hierifer commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

canvas 改用 opengl + nanoVG 实现

huteng and others added 10 commits June 26, 2026 17:01
…ion fix

- iOS: Add baseScale (jsCanvasSize / nativeViewSize) to NativeCanvasView
  to compensate for DPI mismatch when JS sets canvas.width = cssWidth * dpr
  then ctx.scale(dpr, dpr). Applied in draw(), renderToImage(),
  setTransform, and resetTransform.
- iOS: Wire up setCanvasProperty in CanvasManager to store JS canvas
  dimensions on the view.
- HarmonyOS: Add pendingFlushes buffer in DMPCanvasManager to queue
  flush messages that arrive before the Canvas component registers
  (aboutToAppear). Replay queued flushes on register.
- HarmonyOS: Add enhanced diagnostic logging for setCanvasProperty,
  handleFlush, contextCall scale/transform operations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add GL headers and extern "C" to nanovg_gl_utils.h for C/C++ linkage
- Include nanovg_gl.h in canvas_renderer.cpp for GLES2 API symbols
- Fix nanovg_impl.c to include nanovg.c core implementation directly
- Add dimina_canvas2d.h include to js_thread.cpp for dm_canvas_create

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ments

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
# Conflicts:
#	fe/packages/components/src/component/canvas/Canvas.vue
#	fe/packages/container/package.json
#	fe/packages/container/src/pages/miniApp/miniApp.js
#	fe/packages/container/src/pages/miniApp/miniApp.scss
#	fe/packages/render/src/core/runtime.js
#	fe/packages/service/src/api/core/ui/canvas/canvas-node.js
#	fe/packages/service/src/api/core/ui/canvas/index.js
#	fe/packages/service/src/core/runtime.js
#	fe/packages/service/src/instance/component/component.js
#	fe/packages/service/src/instance/page/page.js
#	harmony/dimina/src/main/cpp/CMakeLists.txt
#	harmony/dimina/src/main/ets/Bridges/DMPContainerBridgesModule+NavigationBar.ets
#	harmony/dimina/src/main/ets/DPages/DMPPageTitle.ets
#	iOS/dimina.xcodeproj/xcshareddata/xcschemes/dimina.xcscheme
#	iOS/dimina/DiminaKit/Container/DMPChannelProxy.swift
#	iOS/dimina/DiminaKit/Service/DMPEngine.swift
#	shared/jsapp/wx92269e3b2f304afc/config.json
#	shared/jsapp/wx92269e3b2f304afc/wx92269e3b2f304afc.zip
#	shared/jsapp/wxe5f52902cf4de896/config.json
#	shared/jsapp/wxe5f52902cf4de896/wxe5f52902cf4de896.zip
#	shared/jssdk/config.json
#	shared/jssdk/main.zip
Implement GPU-accelerated Canvas 2D rendering that bypasses the WebView
canvas using NanoVG + OpenGL ES 2.0 with FBO off-screen rendering,
integrated via HarmonyOS XComponent same-layer rendering.

- Shared C library (canvas2d): NanoVG context, EGL surface management,
  FBO off-screen rendering, JSON op parser, stb_image decode/encode
- HarmonyOS bindings: QuickJS thread GL rendering, op queue with deferred
  swap via rAF, image upload pipeline via TSFN, surface rebind/resize
- JS SDK: GLCanvasNode, GLContext2D, NativeImage classes with full
  Canvas 2D API coverage (fill/stroke, paths, text, transforms, images,
  gradients, patterns, compositing, shadows)
- Touch event forwarding from XComponent to WebView <embed> for
  bindtouchstart/move/end support with scroll pass-through
- Canvas spec document (NATIVE_CANVAS_SPEC.md)
- Rename Skia references to GL across all platforms
- iOS __GLCanvas stub (available: false, falls back to WebView canvas)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Port the native canvas rendering pipeline to iOS using ANGLE (OpenGL ES 2.0
→ Metal translation), reusing the shared dimina_canvas2d C library.

iOS-specific changes:
- DMPEngineCanvas.swift: canvas bindings for JSContext (__GLCanvas with
  available=true, op buffering, deferred swap, sync ops, image uploads)
- NativeCanvasGLView.swift: UIView with CAEAGLLayer for ANGLE rendering
- CanvasImageLoader.swift: image download/decode to RGBA for GL upload
- dimina-Bridging-Header.h: expose dimina_canvas2d.h C API to Swift
- DMPEngine.swift: register canvas bindings, add JS thread accessor
- NativeComponentAPI.swift: switch from NativeCanvasView to NativeCanvasGLView

Shared canvas2d changes:
- egl_surface.h/cpp: unify iOS with Android/Harmony using real ANGLE EGL
  (eglGetPlatformDisplayEXT with Metal backend)
- canvas_renderer.cpp: add iOS system font loading (SF Pro, PingFang CJK)
- CMakeLists.txt: add ANGLE_INCLUDE_DIR support for iOS

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the scissor-only clip approach with stencil bit 7 partitioning
in NanoVG's GL backend. NanoVG fill operations now use stencil bits 0-6,
while bit 7 is reserved for the persistent clip mask. This enables
clip() with arc(), bezier, and other non-rect paths.

Key changes:
- Add GLNVG_CLIPFILL command type that writes path interior to stencil bit 7
- Modify glnvg__fill to use 0x7f mask and split fill/clear passes when clipped
- Add clip-aware stencil tests to convexFill, stroke, and triangles
- Implement nvglSetNextFillAsClip/nvglClearClipStencil public API
- restore() flushes frame, clears bit 7, and rebuilds NanoVG state stack
- Add clipActive flag to CanvasDrawState, remove old clipRects approach

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Hierifer Hierifer changed the title WIPNative canvas WIP: Native canvas Aug 25, 2026
? path.replace(`http://127.0.0.1/${appId}/`, '')
: path.replace('http://127.0.0.1/', '');
? path.replace(`http://mp.qiandao.com/${appId}/`, '')
: path.replace('http://mp.qiandao.com/', '');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块注意下不要带上公司标记。

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.

2 participants