From 81b15522fc3faddea404700cb77da356421a4895 Mon Sep 17 00:00:00 2001 From: Samuel Freilich Date: Tue, 19 May 2026 12:19:43 -0700 Subject: [PATCH] Split JNI dependency out of in_progress_stroke_jni_helpers Rename it to in_progress_stroke_native_helpers accordingly. Split out the logic for converting an absl::Span of bytes to a DirectByteBuffer. PiperOrigin-RevId: 917962364 --- ink/geometry/internal/jni/BUILD.bazel | 2 + ink/geometry/internal/jni/mesh_jni.cc | 23 +++----- ink/jni/internal/BUILD.bazel | 16 ++++++ ink/jni/internal/jni_buffer_util.cc | 40 ++++++++++++++ ink/jni/internal/jni_buffer_util.h | 37 +++++++++++++ ink/strokes/internal/jni/BUILD.bazel | 30 +++------- .../internal/jni/in_progress_stroke_jni.cc | 28 ++++++---- ...cc => in_progress_stroke_native_helper.cc} | 55 +++++++------------ ...r.h => in_progress_stroke_native_helper.h} | 40 +++++++------- ... in_progress_stroke_native_helper_test.cc} | 10 ++-- 10 files changed, 174 insertions(+), 107 deletions(-) create mode 100644 ink/jni/internal/jni_buffer_util.cc create mode 100644 ink/jni/internal/jni_buffer_util.h rename ink/strokes/internal/jni/{in_progress_stroke_jni_helper.cc => in_progress_stroke_native_helper.cc} (80%) rename ink/strokes/internal/jni/{in_progress_stroke_jni_helper.h => in_progress_stroke_native_helper.h} (84%) rename ink/strokes/internal/jni/{in_progress_stroke_jni_helper_test.cc => in_progress_stroke_native_helper_test.cc} (96%) diff --git a/ink/geometry/internal/jni/BUILD.bazel b/ink/geometry/internal/jni/BUILD.bazel index 1140f4dc..6f449983 100644 --- a/ink/geometry/internal/jni/BUILD.bazel +++ b/ink/geometry/internal/jni/BUILD.bazel @@ -175,7 +175,9 @@ cc_library( "//ink/geometry:mesh", "//ink/geometry:point", "//ink/geometry:rect", + "//ink/jni/internal:jni_buffer_util", "//ink/jni/internal:jni_defines", + "@com_google_absl//absl/base:nullability", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/types:span", ] + select({ diff --git a/ink/geometry/internal/jni/mesh_jni.cc b/ink/geometry/internal/jni/mesh_jni.cc index ea29f7bf..93f7d4ac 100644 --- a/ink/geometry/internal/jni/mesh_jni.cc +++ b/ink/geometry/internal/jni/mesh_jni.cc @@ -16,6 +16,7 @@ #include +#include "absl/base/nullability.h" #include "absl/log/absl_check.h" #include "absl/types/span.h" #include "ink/geometry/internal/jni/box_jni_helper.h" @@ -23,11 +24,13 @@ #include "ink/geometry/internal/jni/mesh_native_helper.h" #include "ink/geometry/internal/jni/vec_jni_helper.h" #include "ink/geometry/mesh.h" +#include "ink/jni/internal/jni_buffer_util.h" #include "ink/jni/internal/jni_defines.h" namespace { using ::ink::Mesh; +using ::ink::jni::ByteSpanToUnsafelyMutableDirectByteBuffer; using ::ink::jni::CreateJImmutableBoxOrThrow; using ::ink::jni::FillJMutableVecOrThrow; using ::ink::native::CastToMesh; @@ -63,17 +66,14 @@ JNI_METHOD(geometry, MeshNative, jlong, newCopy) // Returns a direct [ByteBuffer] wrapped around the contents of // `ink::Mesh::RawVertexData`. It will be writeable, so be sure to only expose a // read-only wrapper of it. -JNI_METHOD(geometry, JvmMeshNative, jobject, +JNI_METHOD(geometry, JvmMeshNative, absl_nullable jobject, createUnsafelyMutableMeshOwnedRawVertexBuffer) (JNIEnv* env, jobject object, jlong native_pointer) { const Mesh& mesh = CastToMesh(native_pointer); const absl::Span raw_vertex_data = mesh.RawVertexData(); - if (raw_vertex_data.data() == nullptr) return nullptr; - return env->NewDirectByteBuffer( - // NewDirectByteBuffer needs a non-const void*. The resulting buffer is - // writeable, but it will be wrapped at the Kotlin layer in a read-only - // buffer that delegates to this one. - const_cast(raw_vertex_data.data()), raw_vertex_data.size()); + // The resulting buffer will be writeable, but it will be wrapped at the + // Kotlin layer in a read-only buffer that delegates to this one. + return ByteSpanToUnsafelyMutableDirectByteBuffer(env, raw_vertex_data); } // Return the number of bytes per vertex in `createRawVertexBuffer`. @@ -99,13 +99,8 @@ JNI_METHOD(geometry, JvmMeshNative, jobject, ABSL_CHECK_EQ(mesh.IndexStride(), 2u); const absl::Span raw_triangle_index_data = mesh.RawIndexData(); - if (raw_triangle_index_data.data() == nullptr) return nullptr; - return env->NewDirectByteBuffer( - // NewDirectByteBuffer needs a non-const void*. The resulting buffer is - // writeable, but it will be wrapped at the Kotlin layer in a read-only - // buffer that delegates to this one. - const_cast(raw_triangle_index_data.data()), - raw_triangle_index_data.size()); + return ByteSpanToUnsafelyMutableDirectByteBuffer(env, + raw_triangle_index_data); } // Return the number of triangles represented in `createRawTriangleIndexBuffer`. diff --git a/ink/jni/internal/BUILD.bazel b/ink/jni/internal/BUILD.bazel index bc4ea7eb..1eb12942 100644 --- a/ink/jni/internal/BUILD.bazel +++ b/ink/jni/internal/BUILD.bazel @@ -37,6 +37,22 @@ cc_library( }), ) +cc_library( + name = "jni_buffer_util", + srcs = ["jni_buffer_util.cc"], + hdrs = ["jni_buffer_util.h"], + deps = [ + "@com_google_absl//absl/base:nullability", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/types:span", + ] + select({ + "@platforms//os:android": [], + "//conditions:default": [ + "@rules_jni//jni", + ], + }), +) + cc_library( name = "jni_string_util", srcs = ["jni_string_util.cc"], diff --git a/ink/jni/internal/jni_buffer_util.cc b/ink/jni/internal/jni_buffer_util.cc new file mode 100644 index 00000000..eff2baa6 --- /dev/null +++ b/ink/jni/internal/jni_buffer_util.cc @@ -0,0 +1,40 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "ink/jni/internal/jni_buffer_util.h" + +#include + +#include + +#include "absl/base/nullability.h" +#include "absl/log/absl_check.h" +#include "absl/types/span.h" + +namespace ink::jni { + +absl_nullable jobject ByteSpanToUnsafelyMutableDirectByteBuffer( + JNIEnv* env, absl::Span span) { + // span.data() may be nullptr if empty, which NewDirectByteBuffer does not + // permit. + if (span.empty()) return nullptr; + ABSL_CHECK(span.data() != nullptr); + return env->NewDirectByteBuffer( + // NewDirectByteBuffer needs a non-const void*. The resulting buffer is + // writeable, so it must be wrapped at the Kotlin layer in a read-only + // buffer that delegates to this one. + const_cast(span.data()), span.size()); +} + +} // namespace ink::jni diff --git a/ink/jni/internal/jni_buffer_util.h b/ink/jni/internal/jni_buffer_util.h new file mode 100644 index 00000000..af3ef1f9 --- /dev/null +++ b/ink/jni/internal/jni_buffer_util.h @@ -0,0 +1,37 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INK_JNI_INTERNAL_JNI_BUFFER_UTIL_H_ +#define INK_JNI_INTERNAL_JNI_BUFFER_UTIL_H_ + +#include + +#include + +#include "absl/base/nullability.h" +#include "absl/types/span.h" + +namespace ink::jni { + +// Converts a span of bytes to a Java direct ByteBuffer. Returns nullptr +// if the span is empty because the JNI interface does not provide a good way +// to allocate an empty direct byte-buffer. (When a span is empty, its data +// pointer may be nullptr, which NewDirectByteBuffer does not permit even with +// size 0.) +absl_nullable jobject ByteSpanToUnsafelyMutableDirectByteBuffer( + JNIEnv* env, absl::Span span); + +} // namespace ink::jni + +#endif // INK_JNI_INTERNAL_JNI_BUFFER_UTIL_H_ diff --git a/ink/strokes/internal/jni/BUILD.bazel b/ink/strokes/internal/jni/BUILD.bazel index e47f080d..b932d7f5 100644 --- a/ink/strokes/internal/jni/BUILD.bazel +++ b/ink/strokes/internal/jni/BUILD.bazel @@ -90,7 +90,7 @@ cc_library( srcs = ["in_progress_stroke_jni.cc"], tags = ["keep_dep"], deps = [ - ":in_progress_stroke_jni_helper", + ":in_progress_stroke_native_helper", ":stroke_input_batch_native_helper", ":stroke_input_jni_helper", ":stroke_jni_helper", @@ -103,6 +103,7 @@ cc_library( "//ink/geometry/internal/jni:box_accumulator_jni_helper", "//ink/geometry/internal/jni:mesh_format_native_helper", "//ink/geometry/internal/jni:vec_jni_helper", + "//ink/jni/internal:jni_buffer_util", "//ink/jni/internal:jni_defines", "//ink/jni/internal:status_jni_helper", "//ink/strokes:in_progress_stroke", @@ -125,39 +126,26 @@ cc_library( ) cc_library( - name = "in_progress_stroke_jni_helper", - srcs = ["in_progress_stroke_jni_helper.cc"], - hdrs = ["in_progress_stroke_jni_helper.h"], + name = "in_progress_stroke_native_helper", + srcs = ["in_progress_stroke_native_helper.cc"], + hdrs = ["in_progress_stroke_native_helper.h"], deps = [ "//ink/brush", - "//ink/geometry:angle", "//ink/geometry:mutable_mesh", - "//ink/jni/internal:jni_defines", "//ink/strokes:in_progress_stroke", - "//ink/strokes/input:stroke_input", - "//ink/strokes/input:stroke_input_batch", "//ink/types:duration", - "//ink/types:physical_distance", - "@com_google_absl//absl/base:nullability", - "@com_google_absl//absl/container:inlined_vector", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/status", - "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/types:span", - ] + select({ - "@platforms//os:android": [], - "//conditions:default": [ - "@rules_jni//jni", - ], - }), + ], ) cc_test( - name = "in_progress_stroke_jni_helper_test", - srcs = ["in_progress_stroke_jni_helper_test.cc"], + name = "in_progress_stroke_native_helper_test", + srcs = ["in_progress_stroke_native_helper_test.cc"], deps = [ - ":in_progress_stroke_jni_helper", + ":in_progress_stroke_native_helper", "@com_google_googletest//:gtest_main", ], ) diff --git a/ink/strokes/internal/jni/in_progress_stroke_jni.cc b/ink/strokes/internal/jni/in_progress_stroke_jni.cc index 1025b42f..358a9b52 100644 --- a/ink/strokes/internal/jni/in_progress_stroke_jni.cc +++ b/ink/strokes/internal/jni/in_progress_stroke_jni.cc @@ -27,12 +27,13 @@ #include "ink/geometry/internal/jni/vec_jni_helper.h" #include "ink/geometry/mutable_mesh.h" #include "ink/geometry/point.h" +#include "ink/jni/internal/jni_buffer_util.h" #include "ink/jni/internal/jni_defines.h" #include "ink/jni/internal/status_jni_helper.h" #include "ink/strokes/in_progress_stroke.h" #include "ink/strokes/input/stroke_input.h" #include "ink/strokes/input/stroke_input_batch.h" -#include "ink/strokes/internal/jni/in_progress_stroke_jni_helper.h" +#include "ink/strokes/internal/jni/in_progress_stroke_native_helper.h" #include "ink/strokes/internal/jni/stroke_input_batch_native_helper.h" #include "ink/strokes/internal/jni/stroke_input_jni_helper.h" #include "ink/strokes/internal/jni/stroke_jni_helper.h" @@ -44,19 +45,20 @@ using ::ink::InProgressStroke; using ::ink::Point; using ::ink::StrokeInput; using ::ink::StrokeInputBatch; -using ::ink::jni::CastToInProgressStrokeWrapper; -using ::ink::jni::CastToMutableInProgressStrokeWrapper; -using ::ink::jni::DeleteNativeInProgressStroke; +using ::ink::jni::ByteSpanToUnsafelyMutableDirectByteBuffer; using ::ink::jni::FillJBoxAccumulatorOrThrow; using ::ink::jni::FillJMutableVecOrThrow; -using ::ink::jni::InProgressStrokeWrapper; -using ::ink::jni::NewNativeInProgressStroke; using ::ink::jni::NewNativeStroke; using ::ink::jni::ThrowExceptionFromStatus; using ::ink::jni::UpdateJStrokeInputOrThrow; using ::ink::native::CastToBrush; +using ::ink::native::CastToInProgressStrokeWrapper; +using ::ink::native::CastToMutableInProgressStrokeWrapper; using ::ink::native::CastToMutableStrokeInputBatch; using ::ink::native::CastToStrokeInputBatch; +using ::ink::native::DeleteNativeInProgressStroke; +using ::ink::native::InProgressStrokeWrapper; +using ::ink::native::NewNativeInProgressStroke; using ::ink::native::NewNativeMeshFormat; extern "C" { @@ -281,8 +283,11 @@ JNI_METHOD(strokes, InProgressStrokeNative, absl_nullable jobject, getUnsafelyMutableRawVertexData) (JNIEnv* env, jobject thiz, jlong native_pointer, jint coat_index, jint mesh_index) { - return CastToInProgressStrokeWrapper(native_pointer) - .GetUnsafelyMutableRawVertexData(env, coat_index, mesh_index); + // The resulting buffer will be writeable, but it will be wrapped at the + // Kotlin layer in a read-only buffer that delegates to this one. + return ByteSpanToUnsafelyMutableDirectByteBuffer( + env, CastToInProgressStrokeWrapper(native_pointer) + .GetRawVertexData(coat_index, mesh_index)); } // Returns a direct byte buffer of the triangle index data in 16-bit format. @@ -297,8 +302,11 @@ JNI_METHOD(strokes, InProgressStrokeNative, absl_nullable jobject, getUnsafelyMutableRawTriangleIndexData) (JNIEnv* env, jobject thiz, jlong native_pointer, jint coat_index, jint mesh_index) { - return CastToInProgressStrokeWrapper(native_pointer) - .GetUnsafelyMutableRawTriangleIndexData(env, coat_index, mesh_index); + // The resulting buffer will be writeable, but it will be wrapped at the + // Kotlin layer in a read-only buffer that delegates to this one. + return ByteSpanToUnsafelyMutableDirectByteBuffer( + env, CastToInProgressStrokeWrapper(native_pointer) + .GetRawTriangleIndexData(coat_index, mesh_index)); } // Return a newly allocated copy of the given `Mesh`'s `MeshFormat`. diff --git a/ink/strokes/internal/jni/in_progress_stroke_jni_helper.cc b/ink/strokes/internal/jni/in_progress_stroke_native_helper.cc similarity index 80% rename from ink/strokes/internal/jni/in_progress_stroke_jni_helper.cc rename to ink/strokes/internal/jni/in_progress_stroke_native_helper.cc index 72aa9807..244e7170 100644 --- a/ink/strokes/internal/jni/in_progress_stroke_jni_helper.cc +++ b/ink/strokes/internal/jni/in_progress_stroke_native_helper.cc @@ -1,6 +1,4 @@ -#include "ink/strokes/internal/jni/in_progress_stroke_jni_helper.h" - -#include +#include "ink/strokes/internal/jni/in_progress_stroke_native_helper.h" #include #include @@ -8,7 +6,6 @@ #include #include -#include "absl/base/nullability.h" #include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/status/status.h" @@ -17,7 +14,7 @@ #include "ink/geometry/mutable_mesh.h" #include "ink/types/duration.h" -namespace ink::jni { +namespace ink::native { namespace { @@ -26,8 +23,8 @@ using internal::UpdatePartitionedCoatIndices; } // namespace -int InProgressStrokeWrapper::VertexCount(jint coat_index, - jint mesh_partition_index) const { +int InProgressStrokeWrapper::VertexCount(int coat_index, + int mesh_partition_index) const { ABSL_CHECK_LT(coat_index, coat_buffer_partitions_.size()); ABSL_CHECK_LT(mesh_partition_index, coat_buffer_partitions_[coat_index].partitions.size()); @@ -158,22 +155,20 @@ void InProgressStrokeWrapper::UpdateCache(int coat_index) { coat_buffer_partitions_[coat_index]); } -int InProgressStrokeWrapper::MeshPartitionCount(jint coat_index) const { +int InProgressStrokeWrapper::MeshPartitionCount(int coat_index) const { ABSL_CHECK_LT(coat_index, coat_buffer_partitions_.size()); return coat_buffer_partitions_[coat_index].partitions.size(); } -absl_nullable jobject InProgressStrokeWrapper::GetUnsafelyMutableRawVertexData( - JNIEnv* env, int coat_index, jint mesh_partition_index) const { +absl::Span InProgressStrokeWrapper::GetRawVertexData( + int coat_index, int mesh_partition_index) const { ABSL_CHECK_LT(coat_index, coat_buffer_partitions_.size()); ABSL_CHECK_LT(mesh_partition_index, coat_buffer_partitions_[coat_index].partitions.size()); const absl::Span raw_vertex_data = in_progress_stroke_.GetMesh(coat_index).RawVertexData(); - // absl::Span::data() may be nullptr if empty, which NewDirectByteBuffer does - // not permit (even if the size is zero). - if (raw_vertex_data.data() == nullptr) { - return nullptr; + if (raw_vertex_data.empty()) { + return raw_vertex_data; } const PartitionedCoatIndices::Partition& partition = coat_buffer_partitions_[coat_index].partitions[mesh_partition_index]; @@ -184,28 +179,20 @@ absl_nullable jobject InProgressStrokeWrapper::GetUnsafelyMutableRawVertexData( (partition.vertex_buffer_offset + partition.vertex_buffer_size) * vertex_stride, raw_vertex_data.size()); - return env->NewDirectByteBuffer( - // NewDirectByteBuffer needs a non-const void*. The resulting buffer is - // writeable, but it will be wrapped at the Kotlin layer in a read-only - // buffer that delegates to this one. - const_cast(raw_vertex_data.data()) + - partition.vertex_buffer_offset * vertex_stride, - partition.vertex_buffer_size * vertex_stride); + return raw_vertex_data.subspan(partition.vertex_buffer_offset * vertex_stride, + partition.vertex_buffer_size * vertex_stride); } -absl_nullable jobject -InProgressStrokeWrapper::GetUnsafelyMutableRawTriangleIndexData( - JNIEnv* env, int coat_index, jint mesh_partition_index) const { +absl::Span InProgressStrokeWrapper::GetRawTriangleIndexData( + int coat_index, int mesh_partition_index) const { ABSL_CHECK_LT(coat_index, coat_buffer_partitions_.size()); ABSL_CHECK_LT(mesh_partition_index, coat_buffer_partitions_[coat_index].partitions.size()); const PartitionedCoatIndices& cache = coat_buffer_partitions_[coat_index]; const std::vector& triangle_index_data = cache.converted_index_buffer; - // std::vector::data() may be nullptr if empty, which NewDirectByteBuffer - // does not permit (even if the size is zero). - if (triangle_index_data.data() == nullptr) { - return nullptr; + if (triangle_index_data.empty()) { + return absl::Span(); } const PartitionedCoatIndices::Partition& partition = cache.partitions[mesh_partition_index]; @@ -218,14 +205,10 @@ InProgressStrokeWrapper::GetUnsafelyMutableRawTriangleIndexData( next_partition_index_buffer_offset - partition.index_buffer_offset; ABSL_CHECK_LE(partition.index_buffer_offset + partition_index_buffer_size, triangle_index_data.size()); - return env->NewDirectByteBuffer( - // NewDirectByteBuffer needs a non-const void*. The resulting buffer - // is writeable, but it will be wrapped at the Kotlin layer in a - // read-only buffer that delegates to this one. This one needs to be - // compatible with ShortBuffer, which expects 16-bit values. - const_cast(triangle_index_data.data() + - partition.index_buffer_offset), + return absl::Span( + reinterpret_cast(triangle_index_data.data() + + partition.index_buffer_offset), partition_index_buffer_size * sizeof(uint16_t)); } -} // namespace ink::jni +} // namespace ink::native diff --git a/ink/strokes/internal/jni/in_progress_stroke_jni_helper.h b/ink/strokes/internal/jni/in_progress_stroke_native_helper.h similarity index 84% rename from ink/strokes/internal/jni/in_progress_stroke_jni_helper.h rename to ink/strokes/internal/jni/in_progress_stroke_native_helper.h index 9c938234..10eb12cd 100644 --- a/ink/strokes/internal/jni/in_progress_stroke_jni_helper.h +++ b/ink/strokes/internal/jni/in_progress_stroke_native_helper.h @@ -12,15 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef INK_STROKES_INTERNAL_JNI_IN_PROGRESS_STROKE_JNI_HELPER_H_ -#define INK_STROKES_INTERNAL_JNI_IN_PROGRESS_STROKE_JNI_HELPER_H_ - -#include +#ifndef INK_STROKES_INTERNAL_JNI_IN_PROGRESS_STROKE_NATIVE_HELPER_H_ +#define INK_STROKES_INTERNAL_JNI_IN_PROGRESS_STROKE_NATIVE_HELPER_H_ +#include #include #include -#include "absl/base/nullability.h" #include "absl/log/absl_check.h" #include "absl/status/status.h" #include "absl/types/span.h" @@ -28,7 +26,7 @@ #include "ink/strokes/in_progress_stroke.h" #include "ink/types/duration.h" -namespace ink::jni { +namespace ink::native { namespace internal { @@ -102,12 +100,12 @@ class InProgressStrokeWrapper { // index buffers. absl::Status UpdateShape(Duration32 current_elapsed_time); - int MeshPartitionCount(jint coat_index) const; - int VertexCount(jint coat_index, jint mesh_partition_index) const; - absl_nullable jobject GetUnsafelyMutableRawVertexData( - JNIEnv* env, int coat_index, jint mesh_partition_index) const; - absl_nullable jobject GetUnsafelyMutableRawTriangleIndexData( - JNIEnv* env, int coat_index, jint mesh_partition_index) const; + int MeshPartitionCount(int coat_index) const; + int VertexCount(int coat_index, int mesh_partition_index) const; + absl::Span GetRawVertexData(int coat_index, + int mesh_partition_index) const; + absl::Span GetRawTriangleIndexData( + int coat_index, int mesh_partition_index) const; private: void UpdateCaches(); @@ -123,16 +121,16 @@ class InProgressStrokeWrapper { }; // Creates a new heap-allocated `ink::jni::InProgressStrokeWrapper` containing -// an empty `InProgressStroke` and returns a pointer to it as a jlong, suitable -// for wrapping in a Kotlin InProgressStroke. -inline jlong NewNativeInProgressStroke() { - return reinterpret_cast(new InProgressStrokeWrapper()); +// an empty `InProgressStroke` and returns a pointer to it as a int64_t, +// suitable for wrapping in a Kotlin InProgressStroke. +inline int64_t NewNativeInProgressStroke() { + return reinterpret_cast(new InProgressStrokeWrapper()); } // Casts a Kotlin InProgressStroke.nativePointer to a mutable reference to a // C++ InProgressStrokeWrapper. inline InProgressStrokeWrapper& CastToMutableInProgressStrokeWrapper( - jlong native_pointer) { + int64_t native_pointer) { ABSL_CHECK_NE(native_pointer, 0); return *reinterpret_cast(native_pointer); } @@ -140,17 +138,17 @@ inline InProgressStrokeWrapper& CastToMutableInProgressStrokeWrapper( // Casts a Kotlin InProgressStroke.nativePointer to a const reference to a // C++ InProgressStrokeWrapper. inline const InProgressStrokeWrapper& CastToInProgressStrokeWrapper( - jlong native_pointer) { + int64_t native_pointer) { ABSL_CHECK_NE(native_pointer, 0); return *reinterpret_cast(native_pointer); } // Frees a Kotlin InProgressStroke.nativePointer. -inline void DeleteNativeInProgressStroke(jlong native_pointer) { +inline void DeleteNativeInProgressStroke(int64_t native_pointer) { ABSL_CHECK_NE(native_pointer, 0); delete reinterpret_cast(native_pointer); } -} // namespace ink::jni +} // namespace ink::native -#endif // INK_STROKES_INTERNAL_JNI_IN_PROGRESS_STROKE_JNI_HELPER_H_ +#endif // INK_STROKES_INTERNAL_JNI_IN_PROGRESS_STROKE_NATIVE_HELPER_H_ diff --git a/ink/strokes/internal/jni/in_progress_stroke_jni_helper_test.cc b/ink/strokes/internal/jni/in_progress_stroke_native_helper_test.cc similarity index 96% rename from ink/strokes/internal/jni/in_progress_stroke_jni_helper_test.cc rename to ink/strokes/internal/jni/in_progress_stroke_native_helper_test.cc index 191cfa02..15b6f2d7 100644 --- a/ink/strokes/internal/jni/in_progress_stroke_jni_helper_test.cc +++ b/ink/strokes/internal/jni/in_progress_stroke_native_helper_test.cc @@ -1,4 +1,4 @@ -#include "ink/strokes/internal/jni/in_progress_stroke_jni_helper.h" +#include "ink/strokes/internal/jni/in_progress_stroke_native_helper.h" #include #include @@ -7,11 +7,11 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -namespace ink::jni { +namespace ink::native { namespace { -using ::ink::jni::internal::PartitionedCoatIndices; -using ::ink::jni::internal::UpdatePartitionedCoatIndices; +using ::ink::native::internal::PartitionedCoatIndices; +using ::ink::native::internal::UpdatePartitionedCoatIndices; using ::testing::ElementsAre; using ::testing::Field; using ::testing::IsEmpty; @@ -161,4 +161,4 @@ TEST(UpdatePartitionedCoatIndicesTest, } } // namespace -} // namespace ink::jni +} // namespace ink::native