blob: d36c010b8d024f022665ecca9bcf7801c7d78d76 [file] [log] [blame]
Jeff Brown928e0542011-01-10 11:17:36 -08001/*
2 * Copyright (C) 2011 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 "InputWindow"
18
19#include "JNIHelp.h"
20#include "jni.h"
21#include <android_runtime/AndroidRuntime.h>
22
23#include <android_view_InputChannel.h>
Jeff Brownfbf09772011-01-16 14:06:57 -080024#include <android/graphics/Region.h>
Jeff Brown928e0542011-01-10 11:17:36 -080025#include "com_android_server_InputWindow.h"
26#include "com_android_server_InputWindowHandle.h"
27
28namespace android {
29
30static struct {
31 jclass clazz;
32
33 jfieldID inputWindowHandle;
34 jfieldID inputChannel;
35 jfieldID name;
36 jfieldID layoutParamsFlags;
37 jfieldID layoutParamsType;
38 jfieldID dispatchingTimeoutNanos;
39 jfieldID frameLeft;
40 jfieldID frameTop;
41 jfieldID frameRight;
42 jfieldID frameBottom;
Dianne Hackborne2515ee2011-04-27 18:52:56 -040043 jfieldID scaleFactor;
Jeff Brownfbf09772011-01-16 14:06:57 -080044 jfieldID touchableRegion;
Jeff Brown928e0542011-01-10 11:17:36 -080045 jfieldID visible;
46 jfieldID canReceiveKeys;
47 jfieldID hasFocus;
48 jfieldID hasWallpaper;
49 jfieldID paused;
50 jfieldID layer;
51 jfieldID ownerPid;
52 jfieldID ownerUid;
53} gInputWindowClassInfo;
54
55
56// --- Global functions ---
57
58void android_server_InputWindow_toNative(
59 JNIEnv* env, jobject inputWindowObj, InputWindow* outInputWindow) {
60 jobject inputWindowHandleObj = env->GetObjectField(inputWindowObj,
61 gInputWindowClassInfo.inputWindowHandle);
62 if (inputWindowHandleObj) {
63 outInputWindow->inputWindowHandle =
64 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
65 env->DeleteLocalRef(inputWindowHandleObj);
66 } else {
67 outInputWindow->inputWindowHandle = NULL;
68 }
69
70 jobject inputChannelObj = env->GetObjectField(inputWindowObj,
71 gInputWindowClassInfo.inputChannel);
72 if (inputChannelObj) {
73 outInputWindow->inputChannel =
74 android_view_InputChannel_getInputChannel(env, inputChannelObj);
75 env->DeleteLocalRef(inputChannelObj);
76 } else {
77 outInputWindow->inputChannel = NULL;
78 }
79
80 jstring nameObj = jstring(env->GetObjectField(inputWindowObj,
81 gInputWindowClassInfo.name));
82 if (nameObj) {
83 const char* nameStr = env->GetStringUTFChars(nameObj, NULL);
84 outInputWindow->name.setTo(nameStr);
85 env->ReleaseStringUTFChars(nameObj, nameStr);
86 env->DeleteLocalRef(nameObj);
87 } else {
88 LOGE("InputWindow.name should not be null.");
89 outInputWindow->name.setTo("unknown");
90 }
91
92 outInputWindow->layoutParamsFlags = env->GetIntField(inputWindowObj,
93 gInputWindowClassInfo.layoutParamsFlags);
94 outInputWindow->layoutParamsType = env->GetIntField(inputWindowObj,
95 gInputWindowClassInfo.layoutParamsType);
96 outInputWindow->dispatchingTimeout = env->GetLongField(inputWindowObj,
97 gInputWindowClassInfo.dispatchingTimeoutNanos);
98 outInputWindow->frameLeft = env->GetIntField(inputWindowObj,
99 gInputWindowClassInfo.frameLeft);
100 outInputWindow->frameTop = env->GetIntField(inputWindowObj,
101 gInputWindowClassInfo.frameTop);
102 outInputWindow->frameRight = env->GetIntField(inputWindowObj,
103 gInputWindowClassInfo.frameRight);
104 outInputWindow->frameBottom = env->GetIntField(inputWindowObj,
105 gInputWindowClassInfo.frameBottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400106 outInputWindow->scaleFactor = env->GetFloatField(inputWindowObj,
107 gInputWindowClassInfo.scaleFactor);
Jeff Brownfbf09772011-01-16 14:06:57 -0800108
109 jobject regionObj = env->GetObjectField(inputWindowObj,
110 gInputWindowClassInfo.touchableRegion);
111 if (regionObj) {
112 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
113 outInputWindow->touchableRegion.set(*region);
114 env->DeleteLocalRef(regionObj);
115 } else {
116 outInputWindow->touchableRegion.setEmpty();
117 }
118
Jeff Brown928e0542011-01-10 11:17:36 -0800119 outInputWindow->visible = env->GetBooleanField(inputWindowObj,
120 gInputWindowClassInfo.visible);
121 outInputWindow->canReceiveKeys = env->GetBooleanField(inputWindowObj,
122 gInputWindowClassInfo.canReceiveKeys);
123 outInputWindow->hasFocus = env->GetBooleanField(inputWindowObj,
124 gInputWindowClassInfo.hasFocus);
125 outInputWindow->hasWallpaper = env->GetBooleanField(inputWindowObj,
126 gInputWindowClassInfo.hasWallpaper);
127 outInputWindow->paused = env->GetBooleanField(inputWindowObj,
128 gInputWindowClassInfo.paused);
129 outInputWindow->layer = env->GetIntField(inputWindowObj,
130 gInputWindowClassInfo.layer);
131 outInputWindow->ownerPid = env->GetIntField(inputWindowObj,
132 gInputWindowClassInfo.ownerPid);
133 outInputWindow->ownerUid = env->GetIntField(inputWindowObj,
134 gInputWindowClassInfo.ownerUid);
135}
136
137
138// --- JNI ---
139
140#define FIND_CLASS(var, className) \
141 var = env->FindClass(className); \
142 LOG_FATAL_IF(! var, "Unable to find class " className); \
143 var = jclass(env->NewGlobalRef(var));
144
145#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
146 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
147 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
148
149int register_android_server_InputWindow(JNIEnv* env) {
Dianne Hackborna924dc0d2011-02-17 14:22:17 -0800150 FIND_CLASS(gInputWindowClassInfo.clazz, "com/android/server/wm/InputWindow");
Jeff Brown928e0542011-01-10 11:17:36 -0800151
152 GET_FIELD_ID(gInputWindowClassInfo.inputWindowHandle, gInputWindowClassInfo.clazz,
Dianne Hackborna924dc0d2011-02-17 14:22:17 -0800153 "inputWindowHandle", "Lcom/android/server/wm/InputWindowHandle;");
Jeff Brown928e0542011-01-10 11:17:36 -0800154
155 GET_FIELD_ID(gInputWindowClassInfo.inputChannel, gInputWindowClassInfo.clazz,
156 "inputChannel", "Landroid/view/InputChannel;");
157
158 GET_FIELD_ID(gInputWindowClassInfo.name, gInputWindowClassInfo.clazz,
159 "name", "Ljava/lang/String;");
160
161 GET_FIELD_ID(gInputWindowClassInfo.layoutParamsFlags, gInputWindowClassInfo.clazz,
162 "layoutParamsFlags", "I");
163
164 GET_FIELD_ID(gInputWindowClassInfo.layoutParamsType, gInputWindowClassInfo.clazz,
165 "layoutParamsType", "I");
166
167 GET_FIELD_ID(gInputWindowClassInfo.dispatchingTimeoutNanos, gInputWindowClassInfo.clazz,
168 "dispatchingTimeoutNanos", "J");
169
170 GET_FIELD_ID(gInputWindowClassInfo.frameLeft, gInputWindowClassInfo.clazz,
171 "frameLeft", "I");
172
173 GET_FIELD_ID(gInputWindowClassInfo.frameTop, gInputWindowClassInfo.clazz,
174 "frameTop", "I");
175
176 GET_FIELD_ID(gInputWindowClassInfo.frameRight, gInputWindowClassInfo.clazz,
177 "frameRight", "I");
178
179 GET_FIELD_ID(gInputWindowClassInfo.frameBottom, gInputWindowClassInfo.clazz,
180 "frameBottom", "I");
181
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400182 GET_FIELD_ID(gInputWindowClassInfo.scaleFactor, gInputWindowClassInfo.clazz,
183 "scaleFactor", "F");
184
Jeff Brownfbf09772011-01-16 14:06:57 -0800185 GET_FIELD_ID(gInputWindowClassInfo.touchableRegion, gInputWindowClassInfo.clazz,
186 "touchableRegion", "Landroid/graphics/Region;");
Jeff Brown928e0542011-01-10 11:17:36 -0800187
188 GET_FIELD_ID(gInputWindowClassInfo.visible, gInputWindowClassInfo.clazz,
189 "visible", "Z");
190
191 GET_FIELD_ID(gInputWindowClassInfo.canReceiveKeys, gInputWindowClassInfo.clazz,
192 "canReceiveKeys", "Z");
193
194 GET_FIELD_ID(gInputWindowClassInfo.hasFocus, gInputWindowClassInfo.clazz,
195 "hasFocus", "Z");
196
197 GET_FIELD_ID(gInputWindowClassInfo.hasWallpaper, gInputWindowClassInfo.clazz,
198 "hasWallpaper", "Z");
199
200 GET_FIELD_ID(gInputWindowClassInfo.paused, gInputWindowClassInfo.clazz,
201 "paused", "Z");
202
203 GET_FIELD_ID(gInputWindowClassInfo.layer, gInputWindowClassInfo.clazz,
204 "layer", "I");
205
206 GET_FIELD_ID(gInputWindowClassInfo.ownerPid, gInputWindowClassInfo.clazz,
207 "ownerPid", "I");
208
209 GET_FIELD_ID(gInputWindowClassInfo.ownerUid, gInputWindowClassInfo.clazz,
210 "ownerUid", "I");
211 return 0;
212}
213
214} /* namespace android */