diff options
Diffstat (limited to 'services/jni')
| -rw-r--r-- | services/jni/Android.mk | 1 | ||||
| -rw-r--r-- | services/jni/com_android_server_display_SurfaceFlingerDisplayAdapter.cpp | 94 | ||||
| -rw-r--r-- | services/jni/onload.cpp | 2 |
3 files changed, 97 insertions, 0 deletions
diff --git a/services/jni/Android.mk b/services/jni/Android.mk index d097a93..43e59b2 100644 --- a/services/jni/Android.mk +++ b/services/jni/Android.mk @@ -4,6 +4,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ com_android_server_AlarmManagerService.cpp \ com_android_server_BatteryService.cpp \ + com_android_server_display_SurfaceFlingerDisplayAdapter.cpp \ com_android_server_input_InputApplicationHandle.cpp \ com_android_server_input_InputManagerService.cpp \ com_android_server_input_InputWindowHandle.cpp \ diff --git a/services/jni/com_android_server_display_SurfaceFlingerDisplayAdapter.cpp b/services/jni/com_android_server_display_SurfaceFlingerDisplayAdapter.cpp new file mode 100644 index 0000000..162cbaf --- /dev/null +++ b/services/jni/com_android_server_display_SurfaceFlingerDisplayAdapter.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "SurfaceFlingerDisplayAdapter" + +#include "JNIHelp.h" +#include "jni.h" +#include <android_runtime/AndroidRuntime.h> + +#include <gui/SurfaceComposerClient.h> +#include <ui/DisplayInfo.h> + +#include <utils/Log.h> + +namespace android { + +static struct { + jfieldID width; + jfieldID height; + jfieldID refreshRate; + jfieldID density; + jfieldID xDpi; + jfieldID yDpi; +} gDisplayDeviceInfoClassInfo; + + +static void nativeGetDefaultDisplayDeviceInfo(JNIEnv* env, jclass clazz, jobject infoObj) { + DisplayInfo info; + status_t err = SurfaceComposerClient::getDisplayInfo(0, &info); + if (err < 0) { + jniThrowExceptionFmt(env, "java/lang/RuntimeException", + "Could not get display info. err=%d", err); + return; + } + + bool rotated = (info.orientation == DISPLAY_ORIENTATION_90 + || info.orientation == DISPLAY_ORIENTATION_270); + env->SetIntField(infoObj, gDisplayDeviceInfoClassInfo.width, + rotated ? info.h : info.w); + env->SetIntField(infoObj, gDisplayDeviceInfoClassInfo.height, + rotated ? info.w : info.h); + env->SetFloatField(infoObj, gDisplayDeviceInfoClassInfo.refreshRate, info.fps); + env->SetFloatField(infoObj, gDisplayDeviceInfoClassInfo.density, info.density); + env->SetFloatField(infoObj, gDisplayDeviceInfoClassInfo.xDpi, info.xdpi); + env->SetFloatField(infoObj, gDisplayDeviceInfoClassInfo.yDpi, info.ydpi); +} + + +static JNINativeMethod gSurfaceFlingerDisplayAdapterMethods[] = { + /* name, signature, funcPtr */ + { "nativeGetDefaultDisplayDeviceInfo", + "(Lcom/android/server/display/DisplayDeviceInfo;)V", + (void*) nativeGetDefaultDisplayDeviceInfo }, +}; + +#define FIND_CLASS(var, className) \ + var = env->FindClass(className); \ + LOG_FATAL_IF(! var, "Unable to find class " className); + +#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \ + var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \ + LOG_FATAL_IF(! var, "Unable to find field " fieldName); + +int register_android_server_display_SurfaceFlingerDisplayAdapter(JNIEnv* env) { + int res = jniRegisterNativeMethods(env, + "com/android/server/display/SurfaceFlingerDisplayAdapter", + gSurfaceFlingerDisplayAdapterMethods, NELEM(gSurfaceFlingerDisplayAdapterMethods)); + LOG_FATAL_IF(res < 0, "Unable to register native methods."); + + jclass clazz; + FIND_CLASS(clazz, "com/android/server/display/DisplayDeviceInfo"); + GET_FIELD_ID(gDisplayDeviceInfoClassInfo.width, clazz, "width", "I"); + GET_FIELD_ID(gDisplayDeviceInfoClassInfo.height, clazz, "height", "I"); + GET_FIELD_ID(gDisplayDeviceInfoClassInfo.refreshRate, clazz, "refreshRate", "F"); + GET_FIELD_ID(gDisplayDeviceInfoClassInfo.density, clazz, "density", "F"); + GET_FIELD_ID(gDisplayDeviceInfoClassInfo.xDpi, clazz, "xDpi", "F"); + GET_FIELD_ID(gDisplayDeviceInfoClassInfo.yDpi, clazz, "yDpi", "F"); + return 0; +} + +} /* namespace android */ diff --git a/services/jni/onload.cpp b/services/jni/onload.cpp index 423ebd1..50873fc 100644 --- a/services/jni/onload.cpp +++ b/services/jni/onload.cpp @@ -22,6 +22,7 @@ namespace android { int register_android_server_AlarmManagerService(JNIEnv* env); int register_android_server_BatteryService(JNIEnv* env); +int register_android_server_display_SurfaceFlingerDisplayAdapter(JNIEnv* env); int register_android_server_InputApplicationHandle(JNIEnv* env); int register_android_server_InputWindowHandle(JNIEnv* env); int register_android_server_InputManager(JNIEnv* env); @@ -51,6 +52,7 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) register_android_server_PowerManagerService(env); register_android_server_SerialService(env); + register_android_server_display_SurfaceFlingerDisplayAdapter(env); register_android_server_InputApplicationHandle(env); register_android_server_InputWindowHandle(env); register_android_server_InputManager(env); |
