Skip to content
Merged
Show file tree
Hide file tree
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
26 changes: 1 addition & 25 deletions ink/jni/internal/jni_jvm_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ static jclass class_color_callbacks = nullptr;
static jmethodID method_color_callbacks_compose_color_long_from_components =
nullptr;

static jclass class_input_tool_type = nullptr;
static jmethodID method_input_tool_type_from = nullptr;

static jclass class_stroke_input = nullptr;
static jmethodID method_stroke_input_update = nullptr;

Expand Down Expand Up @@ -128,9 +125,6 @@ void UnloadJvmInterface(JNIEnv* env) {
DeleteCachedClass(env, class_color_callbacks);
method_color_callbacks_compose_color_long_from_components = nullptr;

DeleteCachedClass(env, class_input_tool_type);
method_input_tool_type_from = nullptr;

DeleteCachedClass(env, class_stroke_input);
method_stroke_input_update = nullptr;
}
Expand Down Expand Up @@ -319,23 +313,6 @@ jmethodID MethodColorCallbacksComposeColorLongFromComponents(JNIEnv* env) {
return method_color_callbacks_compose_color_long_from_components;
}

jclass ClassInputToolType(JNIEnv* env) {
if (class_input_tool_type == nullptr) {
class_input_tool_type =
FindAndCacheClass(env, "androidx/ink/brush/InputToolType");
}
return class_input_tool_type;
}

jmethodID MethodInputToolTypeFromInt(JNIEnv* env) {
if (method_input_tool_type_from == nullptr) {
method_input_tool_type_from =
GetStaticMethodId(env, ClassInputToolType(env), "fromInt",
"(I)Landroidx/ink/brush/InputToolType;");
}
return method_input_tool_type_from;
}

jclass ClassStrokeInput(JNIEnv* env) {
if (class_stroke_input == nullptr) {
class_stroke_input =
Expand All @@ -347,8 +324,7 @@ jclass ClassStrokeInput(JNIEnv* env) {
jmethodID MethodStrokeInputUpdate(JNIEnv* env) {
if (method_stroke_input_update == nullptr) {
method_stroke_input_update =
GetMethodId(env, ClassStrokeInput(env), "update",
"(FFJLandroidx/ink/brush/InputToolType;FFFF)V");
GetMethodId(env, ClassStrokeInput(env), "update", "(FFJIFFFF)V");
}
return method_stroke_input_update;
}
Expand Down
3 changes: 0 additions & 3 deletions ink/jni/internal/jni_jvm_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ jmethodID MethodMutableParallelogramSetCenterDimensionsRotationInDegreesAndSkew(
jclass ClassColorCallbacks(JNIEnv* env);
jmethodID MethodColorCallbacksComposeColorLongFromComponents(JNIEnv* env);

jclass ClassInputToolType(JNIEnv* env);
jmethodID MethodInputToolTypeFromInt(JNIEnv* env);

jclass ClassStrokeInput(JNIEnv* env);
jmethodID MethodStrokeInputUpdate(JNIEnv* env);

Expand Down
19 changes: 9 additions & 10 deletions ink/strokes/internal/jni/stroke_input_batch_native.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ int StrokeInputBatchNative_getSize(int64_t native_pointer) {
StrokeInputBatchNative_Input StrokeInputBatchNative_getStrokeInput(
int64_t native_pointer, int index) {
StrokeInput input = CastToStrokeInputBatch(native_pointer).Get(index);
return StrokeInputBatchNative_Input{
.tool_type = ToolTypeToInt(input.tool_type),
.x = input.position.x,
.y = input.position.y,
.elapsed_time_millis =
static_cast<int64_t>(input.elapsed_time.ToMillis()),
.stroke_unit_length_cm = input.stroke_unit_length.ToCentimeters(),
.pressure = input.pressure,
.tilt_radians = input.tilt.ValueInRadians(),
.orientation_radians = input.orientation.ValueInRadians()};
return {.tool_type_int = ToolTypeToInt(input.tool_type),
.x = input.position.x,
.y = input.position.y,
.elapsed_time_millis =
static_cast<int64_t>(input.elapsed_time.ToMillis()),
.stroke_unit_length_cm = input.stroke_unit_length.ToCentimeters(),
.pressure = input.pressure,
.tilt_radians = input.tilt.ValueInRadians(),
.orientation_radians = input.orientation.ValueInRadians()};
}

int64_t StrokeInputBatchNative_getDurationMillis(int64_t native_pointer) {
Expand Down
2 changes: 1 addition & 1 deletion ink/strokes/internal/jni/stroke_input_batch_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {
#endif

typedef struct {
int tool_type;
int tool_type_int;
float x;
float y;
int64_t elapsed_time_millis;
Expand Down
29 changes: 6 additions & 23 deletions ink/strokes/internal/jni/stroke_input_jni_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,26 @@

namespace ink::jni {

namespace {

using ::ink::native::IntToToolType;
using ::ink::native::ToolTypeToInt;

jobject ToolTypeToJObjectOrThrow(JNIEnv* env, StrokeInput::ToolType tool_type) {
return env->CallStaticObjectMethod(ClassInputToolType(env),
MethodInputToolTypeFromInt(env),
ToolTypeToInt(tool_type));
}

} // namespace

void UpdateJStrokeInputOrThrow(JNIEnv* env, const StrokeInput& input_in,
jobject j_input_out) {
jobject j_inputtooltype = ToolTypeToJObjectOrThrow(env, input_in.tool_type);
if (env->ExceptionCheck()) return;

jlong elapsed_time_millis = input_in.elapsed_time.ToMillis();
env->CallVoidMethod(
j_input_out, MethodStrokeInputUpdate(env), input_in.position.x,
input_in.position.y, elapsed_time_millis, j_inputtooltype,
input_in.position.y, static_cast<jlong>(input_in.elapsed_time.ToMillis()),
ToolTypeToInt(input_in.tool_type),
input_in.stroke_unit_length.ToCentimeters(), input_in.pressure,
input_in.tilt.ValueInRadians(), input_in.orientation.ValueInRadians());
}

void UpdateJStrokeInputOrThrow(JNIEnv* env,
const StrokeInputBatchNative_Input& input_in,
jobject j_input_out) {
jobject j_inputtooltype =
ToolTypeToJObjectOrThrow(env, IntToToolType(input_in.tool_type));
if (env->ExceptionCheck()) return;

env->CallVoidMethod(j_input_out, MethodStrokeInputUpdate(env), input_in.x,
input_in.y, input_in.elapsed_time_millis, j_inputtooltype,
input_in.stroke_unit_length_cm, input_in.pressure,
input_in.tilt_radians, input_in.orientation_radians);
input_in.y, input_in.elapsed_time_millis,
input_in.tool_type_int, input_in.stroke_unit_length_cm,
input_in.pressure, input_in.tilt_radians,
input_in.orientation_radians);
}

} // namespace ink::jni
4 changes: 0 additions & 4 deletions ink/strokes/internal/jni/stroke_input_native_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ namespace ink::native {
// Convert an int to an StrokeInput::ToolType enum.
//
// This should match the enum in InputToolType.kt.
StrokeInput::ToolType IntToToolType(int val) {
return static_cast<StrokeInput::ToolType>(val);
}

int ToolTypeToInt(StrokeInput::ToolType type) {
switch (type) {
case StrokeInput::ToolType::kMouse:
Expand Down
4 changes: 0 additions & 4 deletions ink/strokes/internal/jni/stroke_input_native_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@

namespace ink::native {

// Converts Kotlin jint representation of InputToolType enum to C++
// StrokeInput::ToolType enum.
StrokeInput::ToolType IntToToolType(int val);

// Converts C++ StrokeInput::ToolType enum to Kotlin int representation of
// InputToolType enum.
int ToolTypeToInt(StrokeInput::ToolType type);
Expand Down
Loading