1 /*
2 * Copyright (C) 2017 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
17 #define LOG_TAG "DisplayViewport-JNI"
18
19 #include "JNIHelp.h"
20 #include "core_jni_helpers.h"
21
22 #include <android_hardware_display_DisplayViewport.h>
23 #include <android_runtime/AndroidRuntime.h>
24 #include <android_runtime/Log.h>
25 #include <utils/Log.h>
26
27 #include <ScopedUtfChars.h>
28
29 namespace android {
30
31 // ----------------------------------------------------------------------------
32
33 static struct {
34 jclass clazz;
35
36 jfieldID displayId;
37 jfieldID orientation;
38 jfieldID logicalFrame;
39 jfieldID physicalFrame;
40 jfieldID deviceWidth;
41 jfieldID deviceHeight;
42 jfieldID uniqueId;
43 } gDisplayViewportClassInfo;
44
45 static struct {
46 jfieldID left;
47 jfieldID top;
48 jfieldID right;
49 jfieldID bottom;
50 } gRectClassInfo;
51
52 // ----------------------------------------------------------------------------
53
android_hardware_display_DisplayViewport_toNative(JNIEnv * env,jobject viewportObj,DisplayViewport * viewport)54 status_t android_hardware_display_DisplayViewport_toNative(JNIEnv* env, jobject viewportObj,
55 DisplayViewport* viewport) {
56 viewport->displayId = env->GetIntField(viewportObj, gDisplayViewportClassInfo.displayId);
57 viewport->orientation = env->GetIntField(viewportObj, gDisplayViewportClassInfo.orientation);
58 viewport->deviceWidth = env->GetIntField(viewportObj, gDisplayViewportClassInfo.deviceWidth);
59 viewport->deviceHeight = env->GetIntField(viewportObj, gDisplayViewportClassInfo.deviceHeight);
60
61 jstring uniqueId =
62 jstring(env->GetObjectField(viewportObj, gDisplayViewportClassInfo.uniqueId));
63 if (uniqueId != nullptr) {
64 viewport->uniqueId.setTo(ScopedUtfChars(env, uniqueId).c_str());
65 }
66
67 jobject logicalFrameObj =
68 env->GetObjectField(viewportObj, gDisplayViewportClassInfo.logicalFrame);
69 viewport->logicalLeft = env->GetIntField(logicalFrameObj, gRectClassInfo.left);
70 viewport->logicalTop = env->GetIntField(logicalFrameObj, gRectClassInfo.top);
71 viewport->logicalRight = env->GetIntField(logicalFrameObj, gRectClassInfo.right);
72 viewport->logicalBottom = env->GetIntField(logicalFrameObj, gRectClassInfo.bottom);
73
74 jobject physicalFrameObj =
75 env->GetObjectField(viewportObj, gDisplayViewportClassInfo.physicalFrame);
76 viewport->physicalLeft = env->GetIntField(physicalFrameObj, gRectClassInfo.left);
77 viewport->physicalTop = env->GetIntField(physicalFrameObj, gRectClassInfo.top);
78 viewport->physicalRight = env->GetIntField(physicalFrameObj, gRectClassInfo.right);
79 viewport->physicalBottom = env->GetIntField(physicalFrameObj, gRectClassInfo.bottom);
80
81 return OK;
82 }
83
84 // ----------------------------------------------------------------------------
85
register_android_hardware_display_DisplayViewport(JNIEnv * env)86 int register_android_hardware_display_DisplayViewport(JNIEnv* env) {
87 jclass clazz = FindClassOrDie(env, "android/hardware/display/DisplayViewport");
88 gDisplayViewportClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
89
90 gDisplayViewportClassInfo.displayId = GetFieldIDOrDie(env,
91 gDisplayViewportClassInfo.clazz, "displayId", "I");
92
93 gDisplayViewportClassInfo.orientation = GetFieldIDOrDie(env,
94 gDisplayViewportClassInfo.clazz, "orientation", "I");
95
96 gDisplayViewportClassInfo.deviceWidth = GetFieldIDOrDie(env,
97 gDisplayViewportClassInfo.clazz, "deviceWidth", "I");
98
99 gDisplayViewportClassInfo.deviceHeight = GetFieldIDOrDie(env,
100 gDisplayViewportClassInfo.clazz, "deviceHeight", "I");
101
102 gDisplayViewportClassInfo.logicalFrame = GetFieldIDOrDie(env,
103 gDisplayViewportClassInfo.clazz, "logicalFrame", "Landroid/graphics/Rect;");
104
105 gDisplayViewportClassInfo.physicalFrame = GetFieldIDOrDie(env,
106 gDisplayViewportClassInfo.clazz, "physicalFrame", "Landroid/graphics/Rect;");
107
108 gDisplayViewportClassInfo.uniqueId = GetFieldIDOrDie(env,
109 gDisplayViewportClassInfo.clazz, "uniqueId", "Ljava/lang/String;");
110
111 clazz = FindClassOrDie(env, "android/graphics/Rect");
112 gRectClassInfo.left = GetFieldIDOrDie(env, clazz, "left", "I");
113 gRectClassInfo.top = GetFieldIDOrDie(env, clazz, "top", "I");
114 gRectClassInfo.right = GetFieldIDOrDie(env, clazz, "right", "I");
115 gRectClassInfo.bottom = GetFieldIDOrDie(env, clazz, "bottom", "I");
116
117 return 0;
118 }
119
120 } // namespace android
121