Skip to content

Add C API for DebugCanvas SKP introspection#174

Draft
mattleibow wants to merge 1 commit into
skiasharpfrom
dev/debugger-c-api
Draft

Add C API for DebugCanvas SKP introspection#174
mattleibow wants to merge 1 commit into
skiasharpfrom
dev/debugger-c-api

Conversation

@mattleibow

Copy link
Copy Markdown
Collaborator

Summary

Adds a C API layer wrapping Skia's DebugCanvas class, enabling SKP file introspection from managed code (C#/SkiaSharp). This is the native component needed for the SkiaSharp WASM Debugger.

New Files

  • include/c/sk_debugger.h — 14 C API function declarations
  • src/c/sk_debugger.cpp — Implementation wrapping DebugCanvas, DrawCommand, SkJSONWriter

Modified Files

  • include/c/sk_types.h — Added sk_debug_canvas_t opaque handle
  • src/c/sk_types_priv.h — Added DEF_CLASS_MAP for DebugCanvas
  • BUILD.gn — Added debugger sources under skia_build_for_debugger flag
  • src/xamarin/SkiaKeeper.c — Added debugger symbol references to prevent dead-stripping

API Surface

Function Purpose
sk_debug_canvas_new/destroy Lifecycle
sk_debug_canvas_load_skp Parse SKP bytes → command list
sk_debug_canvas_get_command_count Number of recorded commands
sk_debug_canvas_draw/draw_to Render all or up to index N
sk_debug_canvas_get_command_list_json Full JSON with command names, paint, coords
sk_debug_canvas_get_command_info_json Matrix + clip state at current position
sk_debug_canvas_set_command_visibility Toggle individual commands
sk_debug_canvas_delete_command Remove a command
sk_debug_canvas_set_overdraw_vis Overdraw visualization mode
sk_debug_canvas_set_clip_viz_color Clip region overlay color
sk_debug_canvas_set_origin_visible Origin crosshair
sk_debug_canvas_get_bounds Canvas dimensions

Build

Gated behind the existing skia_build_for_debugger GN flag — no impact on normal builds.

Add sk_debugger.h/cpp wrapping Skia's DebugCanvas for SKP file
introspection. This enables loading .skp files and decomposing them
into individual draw commands with full JSON metadata.

New C API functions (14 total):
- sk_debug_canvas_new/destroy — lifecycle
- sk_debug_canvas_load_skp — parse SKP bytes into commands
- sk_debug_canvas_get_command_count — query command count
- sk_debug_canvas_draw/draw_to — render all or up to index
- sk_debug_canvas_get_command_list_json — JSON command list
- sk_debug_canvas_get_command_info_json — matrix/clip state
- sk_debug_canvas_set_command_visibility — toggle commands
- sk_debug_canvas_delete_command — remove commands
- sk_debug_canvas_set_overdraw_vis — overdraw visualization
- sk_debug_canvas_set_clip_viz_color — clip region color
- sk_debug_canvas_set_origin_visible — origin crosshair
- sk_debug_canvas_get_bounds — canvas dimensions

Build integration:
- Gated behind existing skia_build_for_debugger GN flag
- BUILD.gn adds debugger sources when flag is true
- SkiaKeeper.c references prevent dead-stripping on all platforms

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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