Avoid `absl::flat_hash_set` allocations and per-vertex hash lookups when packing `MutableMesh`.

- `MeshFormat::WithoutAttributes`: short-circuit when `attributes_to_remove` is
  empty, and replace the temporary `absl::flat_hash_set` and `std::vector` with
  a stack `std::bitset<256>` (matching `MeshFormat::Create`) and `std::array`.
- `MutableMesh::AsMeshes`: precompute the stack-allocated `kept_attribute_indices`
  once instead of building an `absl::flat_hash_set` and probing it for every
  vertex/attribute pair during finiteness validation and partition bounds
  computation. Reserve `meshes` up front.
- `mesh_internal::CopyAndPackPartitionVertices`: take `omit_attributes` directly
  as a span, precompute stack-allocated `kept_attrs` (index, type, packed offset,
  packed width) before the vertex loop instead of heap-allocating
  `packed_attribute_offsets` and probing a hash set on every vertex/attribute,
  and guard `override_vertex_positions.find(...)` behind
  `!override_vertex_positions.empty()`.
- `RecordCorrectionAndAddNewFlippedTrisToQueue`: reserve `newly_flipped_tris`
  using `candidate.newly_flipped_adjacent_tris.size()` instead of
  `candidate.newly_fixed_adjacent_tris.size()`.
- Add unit tests for `MeshFormat::WithoutAttributes` (empty and duplicate
  attribute lists) and `CopyAndPackPartitionVertices` with omitted attributes,
  plus `BM_AsMeshWithOmittedAttributes` in `mutable_mesh_benchmark.cc`.

PiperOrigin-RevId: 1033025101
9 files changed
tree: 4eeb244fd0ca982ebdddde3e459d7f674f679bff
  1. .github/
  2. ink/
  3. patches/
  4. skia_user_config/
  5. .bazelrc
  6. .gitignore
  7. bazel_build.sh
  8. BUILD.bazel
  9. CODE_OF_CONDUCT.md
  10. CONTRIBUTING.md
  11. fuzztest.bazelrc
  12. LICENSE
  13. MODULE.bazel
  14. MODULE.bazel.lock
  15. ndk_build.sh
  16. README.md
  17. SECURITY.md
README.md

Ink

BazelTest

The Ink library is a freehand stroke generation library. It produces smoothed, modeled stroke shapes with brush effect shaders as mesh-based vector graphics.

This provides the core of the implementation of the Android Jetpack Ink library. While the implementation is well-tested, the developers of this library are not currently making hard guarantees about interface stability.

How to Build and Test

Bazel

Prerequisites:

Ink can be built and tested from the repo root:

bazel test --config=linux ink/...

Library Structure

Ink consists of a set of modules that can be used separately. You should only need to include the parts of the library that you need. The basic dependency structure is:

 ┌──────────┐ ┌───────┐
 │Rendering │ │Storage│
 └────┬─────┘ └──┬────┘
      │          │
      ▼          │
   ┌───────┐     │
   │Strokes│◄────┘
   └───┬───┘
       ▼
   ┌───────┐
   | Brush |
   └─┬────┬┘
     │    │
     │    ▼
     │ ┌────────┐
     │ │Geometry│
     │ └───┬────┘
     │     │
     ▼     ▼
 ┌─────┐ ┌─────┐
 │Color│ │Types│
 └─────┘ └─────┘
  • color: Color spaces, encoding, and format conversion.
  • types: Utility types; time, units, constants, small arrays.
  • geometry: Geometric types (point, segment, triangle, rect, quad), meshes, transforms, utility functions, and algorithms (intersection, envelope).
  • brush: Defines stroke styles and behaviors.
  • strokes: The primary Stroke data type and InProgressStroke builder.
  • rendering: Rendering utilities for strokes. Currently only has support for android.graphics.Mesh based rendering.
  • storage: Protobuf serialization utilities for Stroke and related types.

Contributing

See CONTRIBUTING.md for details on sending a PR.

Contact

Use GitHub Issues to file feedback: https://github.com/google/ink/issues