From 53f63042845b58d2414bff422b2945bcce85fd10 Mon Sep 17 00:00:00 2001 From: Ink Open Source Date: Mon, 4 May 2026 08:18:11 -0700 Subject: [PATCH] Adjust JNI interface for texture layers PiperOrigin-RevId: 910043085 --- ink/brush/internal/jni/brush_paint_jni.cc | 61 ++++++++++++++--------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/ink/brush/internal/jni/brush_paint_jni.cc b/ink/brush/internal/jni/brush_paint_jni.cc index 576069bc..baff927e 100644 --- a/ink/brush/internal/jni/brush_paint_jni.cc +++ b/ink/brush/internal/jni/brush_paint_jni.cc @@ -71,10 +71,6 @@ BrushPaint::TextureOrigin JIntToOrigin(jint val) { return static_cast(val); } -BrushPaint::TextureMapping JIntToMapping(jint val) { - return static_cast(val); -} - BrushPaint::TextureWrap JIntToWrap(jint val) { return static_cast(val); } @@ -212,17 +208,15 @@ JNI_METHOD(brush, BrushPaintNative, jboolean, isCompatibleWithMeshFormat) // ************ Native Implementation of BrushPaint TextureLayer ************ -// Constructs a native BrushPaint TextureLayer and returns a pointer to it as a -// long. -JNI_METHOD(brush, TextureLayerNative, jlong, create) +// Constructs a native tiling BrushPaint TextureLayer and returns a pointer to +// it as a long. +JNI_METHOD(brush, TilingTextureNative, jlong, create) (JNIEnv* env, jobject thiz, jstring client_texture_id, jfloat size_x, jfloat size_y, jfloat offset_x, jfloat offset_y, jfloat rotation_degrees, - jint animation_frames, jint animation_rows, jint animation_columns, - jlong animation_duration_millis, jint size_unit, jint origin, jint mapping, - jint wrap_x, jint wrap_y, jint blend_mode) { + jint size_unit, jint origin, jint wrap_x, jint wrap_y, jint blend_mode) { BrushPaint::TextureLayer texture_layer{ .client_texture_id = JStringToStdString(env, client_texture_id), - .mapping = JIntToMapping(mapping), + .mapping = BrushPaint::TextureMapping::kTiling, .origin = JIntToOrigin(origin), .size_unit = JIntToSizeUnit(size_unit), .wrap_x = JIntToWrap(wrap_x), @@ -230,6 +224,25 @@ JNI_METHOD(brush, TextureLayerNative, jlong, create) .size = Vec{size_x, size_y}, .offset = Vec{offset_x, offset_y}, .rotation = Angle::Degrees(rotation_degrees), + .blend_mode = JIntToBlendMode(blend_mode), + }; + if (absl::Status status = ValidateBrushPaintTextureLayer(texture_layer); + !status.ok()) { + ThrowExceptionFromStatus(env, status); + return 0; + } + return NewNativeTextureLayer(std::move(texture_layer)); +} + +// Constructs a native stamping BrushPaint TextureLayer and returns a pointer to +// it as a long. +JNI_METHOD(brush, StampingTextureNative, jlong, create) +(JNIEnv* env, jobject thiz, jstring client_texture_id, jint animation_frames, + jint animation_rows, jint animation_columns, jlong animation_duration_millis, + jint blend_mode) { + BrushPaint::TextureLayer texture_layer{ + .client_texture_id = JStringToStdString(env, client_texture_id), + .mapping = BrushPaint::TextureMapping::kStamping, .animation_frames = animation_frames, .animation_rows = animation_rows, .animation_columns = animation_columns, @@ -255,58 +268,58 @@ JNI_METHOD(brush, TextureLayerNative, jstring, getClientTextureId) CastToTextureLayer(native_pointer).client_texture_id.c_str()); } -JNI_METHOD(brush, TextureLayerNative, jfloat, getSizeX) +JNI_METHOD(brush, TilingTextureNative, jfloat, getSizeX) (JNIEnv* env, jobject thiz, jlong native_pointer) { return CastToTextureLayer(native_pointer).size.x; } -JNI_METHOD(brush, TextureLayerNative, jfloat, getSizeY) +JNI_METHOD(brush, TilingTextureNative, jfloat, getSizeY) (JNIEnv* env, jobject thiz, jlong native_pointer) { return CastToTextureLayer(native_pointer).size.y; } -JNI_METHOD(brush, TextureLayerNative, jfloat, getOffsetX) +JNI_METHOD(brush, TilingTextureNative, jfloat, getOffsetX) (JNIEnv* env, jobject thiz, jlong native_pointer) { return CastToTextureLayer(native_pointer).offset.x; } -JNI_METHOD(brush, TextureLayerNative, jfloat, getOffsetY) +JNI_METHOD(brush, TilingTextureNative, jfloat, getOffsetY) (JNIEnv* env, jobject thiz, jlong native_pointer) { return CastToTextureLayer(native_pointer).offset.y; } -JNI_METHOD(brush, TextureLayerNative, jfloat, getRotationDegrees) +JNI_METHOD(brush, TilingTextureNative, jfloat, getRotationDegrees) (JNIEnv* env, jobject thiz, jlong native_pointer) { return CastToTextureLayer(native_pointer).rotation.ValueInDegrees(); } -JNI_METHOD(brush, TextureLayerNative, jint, getAnimationFrames) +JNI_METHOD(brush, StampingTextureNative, jint, getAnimationFrames) (JNIEnv* env, jobject thiz, jlong native_pointer) { return CastToTextureLayer(native_pointer).animation_frames; } -JNI_METHOD(brush, TextureLayerNative, jint, getAnimationRows) +JNI_METHOD(brush, StampingTextureNative, jint, getAnimationRows) (JNIEnv* env, jobject thiz, jlong native_pointer) { return CastToTextureLayer(native_pointer).animation_rows; } -JNI_METHOD(brush, TextureLayerNative, jint, getAnimationColumns) +JNI_METHOD(brush, StampingTextureNative, jint, getAnimationColumns) (JNIEnv* env, jobject thiz, jlong native_pointer) { return CastToTextureLayer(native_pointer).animation_columns; } -JNI_METHOD(brush, TextureLayerNative, jlong, getAnimationDurationMillis) +JNI_METHOD(brush, StampingTextureNative, jlong, getAnimationDurationMillis) (JNIEnv* env, jobject thiz, jlong native_pointer) { return absl::ToInt64Milliseconds( CastToTextureLayer(native_pointer).animation_duration); } -JNI_METHOD(brush, TextureLayerNative, jint, getSizeUnitInt) +JNI_METHOD(brush, TilingTextureNative, jint, getSizeUnitInt) (JNIEnv* env, jobject thiz, jlong native_pointer) { return static_cast(CastToTextureLayer(native_pointer).size_unit); } -JNI_METHOD(brush, TextureLayerNative, jint, getOriginInt) +JNI_METHOD(brush, TilingTextureNative, jint, getOriginInt) (JNIEnv* env, jobject thiz, jlong native_pointer) { return static_cast(CastToTextureLayer(native_pointer).origin); } @@ -316,12 +329,12 @@ JNI_METHOD(brush, TextureLayerNative, jint, getMappingInt) return static_cast(CastToTextureLayer(native_pointer).mapping); } -JNI_METHOD(brush, TextureLayerNative, jint, getWrapXInt) +JNI_METHOD(brush, TilingTextureNative, jint, getWrapXInt) (JNIEnv* env, jobject thiz, jlong native_pointer) { return static_cast(CastToTextureLayer(native_pointer).wrap_x); } -JNI_METHOD(brush, TextureLayerNative, jint, getWrapYInt) +JNI_METHOD(brush, TilingTextureNative, jint, getWrapYInt) (JNIEnv* env, jobject thiz, jlong native_pointer) { return static_cast(CastToTextureLayer(native_pointer).wrap_y); }