blob: bb7b5efd4d8c40a07ef19c486418d84a60b65fa5 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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#include <stdio.h>
18#include <assert.h>
19
20#include <ui/SurfaceComposerClient.h>
21#include <ui/PixelFormat.h>
22#include <ui/DisplayInfo.h>
23
24#include "jni.h"
25#include <android_runtime/AndroidRuntime.h>
26#include <utils/misc.h>
27
28// ----------------------------------------------------------------------------
29
30namespace android {
31
32// ----------------------------------------------------------------------------
33
34struct offsets_t {
35 jfieldID display;
36 jfieldID pixelFormat;
37 jfieldID fps;
38 jfieldID density;
39 jfieldID xdpi;
40 jfieldID ydpi;
41};
42static offsets_t offsets;
43
44static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL)
45{
46 jclass npeClazz = env->FindClass(exc);
47 env->ThrowNew(npeClazz, msg);
48}
49
50// ----------------------------------------------------------------------------
51
52static void android_view_Display_init(
53 JNIEnv* env, jobject clazz, jint dpy)
54{
55 DisplayInfo info;
56 status_t err = SurfaceComposerClient::getDisplayInfo(DisplayID(dpy), &info);
57 if (err < 0) {
58 doThrow(env, "java/lang/IllegalArgumentException");
59 return;
60 }
61 env->SetIntField(clazz, offsets.pixelFormat,info.pixelFormatInfo.format);
62 env->SetFloatField(clazz, offsets.fps, info.fps);
63 env->SetFloatField(clazz, offsets.density, info.density);
64 env->SetFloatField(clazz, offsets.xdpi, info.xdpi);
65 env->SetFloatField(clazz, offsets.ydpi, info.ydpi);
66}
67
68static jint android_view_Display_getWidth(
69 JNIEnv* env, jobject clazz)
70{
71 DisplayID dpy = env->GetIntField(clazz, offsets.display);
72 return SurfaceComposerClient::getDisplayWidth(dpy);
73}
74
75static jint android_view_Display_getHeight(
76 JNIEnv* env, jobject clazz)
77{
78 DisplayID dpy = env->GetIntField(clazz, offsets.display);
79 return SurfaceComposerClient::getDisplayHeight(dpy);
80}
81
82static jint android_view_Display_getOrientation(
83 JNIEnv* env, jobject clazz)
84{
85 DisplayID dpy = env->GetIntField(clazz, offsets.display);
86 return SurfaceComposerClient::getDisplayOrientation(dpy);
87}
88
89static jint android_view_Display_getDisplayCount(
90 JNIEnv* env, jclass clazz)
91{
92 return SurfaceComposerClient::getNumberOfDisplays();
93}
94
95// ----------------------------------------------------------------------------
96
97const char* const kClassPathName = "android/view/Display";
98
99static void nativeClassInit(JNIEnv* env, jclass clazz);
100
101static JNINativeMethod gMethods[] = {
102 { "nativeClassInit", "()V",
103 (void*)nativeClassInit },
104 { "getDisplayCount", "()I",
105 (void*)android_view_Display_getDisplayCount },
106 { "init", "(I)V",
107 (void*)android_view_Display_init },
108 { "getWidth", "()I",
109 (void*)android_view_Display_getWidth },
110 { "getHeight", "()I",
111 (void*)android_view_Display_getHeight },
112 { "getOrientation", "()I",
113 (void*)android_view_Display_getOrientation }
114};
115
116void nativeClassInit(JNIEnv* env, jclass clazz)
117{
118 offsets.display = env->GetFieldID(clazz, "mDisplay", "I");
119 offsets.pixelFormat = env->GetFieldID(clazz, "mPixelFormat", "I");
120 offsets.fps = env->GetFieldID(clazz, "mRefreshRate", "F");
121 offsets.density = env->GetFieldID(clazz, "mDensity", "F");
122 offsets.xdpi = env->GetFieldID(clazz, "mDpiX", "F");
123 offsets.ydpi = env->GetFieldID(clazz, "mDpiY", "F");
124}
125
126int register_android_view_Display(JNIEnv* env)
127{
128 return AndroidRuntime::registerNativeMethods(env,
129 kClassPathName, gMethods, NELEM(gMethods));
130}
131
132};
133