Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions ink/brush/internal/jni/brush_paint_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ BrushPaint::TextureOrigin JIntToOrigin(jint val) {
return static_cast<BrushPaint::TextureOrigin>(val);
}

BrushPaint::TextureMapping JIntToMapping(jint val) {
return static_cast<BrushPaint::TextureMapping>(val);
}

BrushPaint::TextureWrap JIntToWrap(jint val) {
return static_cast<BrushPaint::TextureWrap>(val);
}
Expand Down Expand Up @@ -212,24 +208,41 @@ 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),
.wrap_y = JIntToWrap(wrap_y),
.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,
Expand All @@ -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<jint>(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<jint>(CastToTextureLayer(native_pointer).origin);
}
Expand All @@ -316,12 +329,12 @@ JNI_METHOD(brush, TextureLayerNative, jint, getMappingInt)
return static_cast<jint>(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<jint>(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<jint>(CastToTextureLayer(native_pointer).wrap_y);
}
Expand Down
Loading