summaryrefslogtreecommitdiffstats
path: root/services/jni
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-07-23 19:26:30 -0700
committerJeff Brown <jeffbrown@google.com>2012-07-25 18:56:16 -0700
commitfa25bf5382467b1018bd9af7f1cb30a23d7d59f7 (patch)
tree2b65e9c19319112d1873db55a02303a43d68547a /services/jni
parentbbcb123d4923b0c2f36af7b2ade82f5d7832357d (diff)
downloadframeworks_base-fa25bf5382467b1018bd9af7f1cb30a23d7d59f7.zip
frameworks_base-fa25bf5382467b1018bd9af7f1cb30a23d7d59f7.tar.gz
frameworks_base-fa25bf5382467b1018bd9af7f1cb30a23d7d59f7.tar.bz2
Add display manager skeleton.
The purpose of this change is to remove direct reliance on SurfaceFlinger for describing the size and characteristics of displays. This patch also starts to make a distinction between logical displays and physical display devices. Currently, the window manager owns the concept of a logical display whereas the new display manager owns the concept of a physical display device. Change-Id: I7e0761f83f033be6c06fd1041280c21500bcabc0
Diffstat (limited to 'services/jni')
-rw-r--r--services/jni/Android.mk1
-rw-r--r--services/jni/com_android_server_display_SurfaceFlingerDisplayAdapter.cpp94
-rw-r--r--services/jni/onload.cpp2
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);