1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "jni_common.h"
17
18 #include <jni.h>
19 #include <ui/GraphicTypes.h>
20 #include <ui/Rect.h>
21
22 #include "core_jni_helpers.h"
23
24 // ----------------------------------------------------------------------------
25
26 namespace android {
27
28 static struct {
29 jfieldID bottom;
30 jfieldID left;
31 jfieldID right;
32 jfieldID top;
33 } gRectClassInfo;
34
rectFromObj(JNIEnv * env,jobject rectObj)35 Rect JNICommon::rectFromObj(JNIEnv* env, jobject rectObj) {
36 int left = env->GetIntField(rectObj, gRectClassInfo.left);
37 int top = env->GetIntField(rectObj, gRectClassInfo.top);
38 int right = env->GetIntField(rectObj, gRectClassInfo.right);
39 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
40 return Rect(left, top, right, bottom);
41 }
42
register_jni_common(JNIEnv * env)43 int register_jni_common(JNIEnv* env) {
44 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
45 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
46 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
47 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
48 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
49 return 0;
50 }
51
52 } // namespace android
53