Repository navigation
Support SkMesh API - #1278
Draft
Ivan Matkov (MatkovIvan) wants to merge 2 commits into
Draft
Support SkMesh API#1278Ivan Matkov (MatkovIvan) wants to merge 2 commits into
SkMesh API#1278Ivan Matkov (MatkovIvan) wants to merge 2 commits into
Conversation
Ivan Matkov (MatkovIvan)
force-pushed
the
ivan.matkov/skiko-1154-expose-skmesh
branch
from
August 25, 2026 14:39
9b1cbce to
296eaab
Compare
An SkSL program declares its children as `uniform shader`, `uniform colorFilter` or `uniform blender`, and Skia passes values for them as SkRuntimeEffect::ChildPtr, which holds exactly one of those three. Kotlin had no name for that set, so an API taking a list of children had to either narrow it to one kind or take an untyped pointer. RuntimeEffect.Child is a sealed interface implemented by Shader, ColorFilter and Blender. It closes the set to the three types Skia accepts, so a call site binding children is checked at compile time and the binding can map each value onto the right SkFlattenable subclass. It sits on RuntimeEffect because that is where Skia declares it; the name drops the Ptr suffix, which says nothing in Kotlin about what is a shader, a color filter or a blender. The interface declares no members, so nothing changes for existing callers.
Ivan Matkov (MatkovIvan)
force-pushed
the
ivan.matkov/skiko-1154-expose-skmesh
branch
from
November 24, 2026 09:52
296eaab to
9b82782
Compare
Compose draws custom meshes on Android through android.graphics.Mesh and has no equivalent elsewhere: skiko exposed SkVertices but none of Skia's mesh API, so a mesh whose vertices and colors are computed by SkSL could not be built or drawn at all. This adds the whole path: - MeshSpecification takes the vertex attributes, the varyings and the two SkSL programs, and reports Skia's own message as IllegalArgumentException when it rejects them. A null color space means sRGB, which is what Skia's shorter Make overloads supply. - MeshVertexBuffer and MeshIndexBuffer wrap the CPU-backed buffers from SkMeshes. The GPU-backed ones are Ganesh-only and have no graphite equivalent, so they are left out rather than exposed on some backends. - Mesh covers both the indexed and the non-indexed form, plus the shader, color filter and blender children the programs may declare. - MeshUniformBuilder resolves uniform offsets through the specification and packs the single Data that SkMesh takes, mirroring how RuntimeShaderBuilder handles runtime effect uniforms. Values reach it through two entry points taking an int and a float array: mesh uniforms are packed once per mesh rather than once per draw, so the array costs nothing that matters and halves the C++ that has to get the bounds right. - Canvas.drawMesh takes either a Blender or a BlendMode, the latter building the blender natively to keep it off the per-frame path. The specification also reports what Skia compiled out of the two programs: its attributes, its uniforms with the offset and size of each value, its children with the kind each one accepts, and the varyings by name, which covers the position varying Skia adds when the caller does not supply one. Packing uniform data by hand is what Skia's own API expects, so MeshUniformBuilder is the convenience over that reflection rather than the only way to reach it. The color space is reported too; Skia drops it when the fragment program returns no color, so it is nullable. A Mesh reports the specification, buffers, offsets, counts, uniform data, mode and bounds it was made from. Its children are not reported back: doing so would mean re-wrapping each SkMesh::ChildPtr by inspecting its type, and nothing needs it yet. Absent uniforms are handed to Skia as empty data rather than as null: SkMesh::Make reads the uniform data while validating, so a null there crashes the process whenever the specification declares a uniform. Empty data turns the same mistake into a rejected mesh carrying the size Skia expected. Children cross the binding as parallel arrays of a pointer and the kind it must be upcast from, because SkShader, SkColorFilter and SkBlender reach SkFlattenable at different offsets and the pointer alone cannot say which one it is. The kind is an SkRuntimeEffect::ChildType on both sides, so the values the two ends agree on are Skia's own rather than a third set. The documentation is Skia's own, carried over from SkMesh.h, SkCanvas.h and SkRuntimeEffect.h with the type names mapped, as the existing bindings do. Only what Skia leaves undocumented is written here: the accessors on Mesh, the topology modes, and MeshUniformBuilder, which has no Skia counterpart. The external functions are prefixed with their class name, as Data and RuntimeShaderBuilder already do for their finalizers. Kotlin/Native mangles top-level external functions by signature alone, so an unprefixed _nMake clashes across files even though each one is private. Meshes are rasterized by GPU-backed canvases; a raster surface accepts the draw and produces no pixels for it. The tests that run everywhere therefore assert that the draw reaches Skia and stays inside the mesh bounds, and the one that reads back rasterized pixels runs where TestGlContext does, as the other GPU tests do. The specification reflection, buffers, uniform packing and rejection paths are covered directly on JVM, Kotlin/Native and wasm. Fixes [SKIKO-1154](https://youtrack.jetbrains.com/issue/SKIKO-1154)
Ivan Matkov (MatkovIvan)
force-pushed
the
ivan.matkov/skiko-1154-expose-skmesh
branch
from
November 24, 2026 13:36
9b82782 to
fd2089f
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SKIKO-1154 Expose SkMesh
This adds the mesh API as one Kotlin type per Skia type:
MeshSpecificationcompiles the two SkSL programs and reports Skia's own message as anIllegalArgumentExceptionwhen they are rejected. It also reports what Skia compiled: the attributes, the uniforms with the offset and size of each value, the children, the varyings and the color space.MeshVertexBufferandMeshIndexBufferwrap the CPU-backed buffers fromSkMeshes. They are separate objects, as in Skia, so one buffer can be shared between meshes. The GPU-backed buffers are Ganesh-only with no graphite equivalent, so they are left out rather than exposed on some backends.Meshcovers the indexed and the non-indexed form and reports what it was made from. It is immutable, asSkMeshis.MeshUniformBuilderpacks the singleDatathatSkMeshtakes, asRuntimeShaderBuilderdoes for runtime effect uniforms. It is a convenience overMeshSpecification.uniforms, not the only way to reach it.Canvas.drawMeshtakes either aBlenderor aBlendMode.RuntimeEffect.Childis a new sealed interface implemented byShader,ColorFilterandBlender. It names the set of valuesSkRuntimeEffect::ChildPtrholds, so a mesh binds any of the three kinds of child its programs declare and the call site is checked at compile time. It sits onRuntimeEffectbecause that is where Skia declares it. It declares no members, so nothing changes for existing callers of those three classes.