blob: 366a52e1ba478526d6dfc42db31477a7eaa9fdfe [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
Dianne Hackborn4c7cc342010-12-16 16:37:39 -080020#include <cutils/properties.h>
21
Mathias Agopian000479f2010-02-09 17:46:37 -080022#include <surfaceflinger/SurfaceComposerClient.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023#include <ui/PixelFormat.h>
24#include <ui/DisplayInfo.h>
25
26#include "jni.h"
Elliott Hughes8451b252011-04-07 19:17:57 -070027#include "JNIHelp.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028#include <android_runtime/AndroidRuntime.h>
29#include <utils/misc.h>
Dianne Hackborn4c7cc342010-12-16 16:37:39 -080030#include <utils/Log.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031
32// ----------------------------------------------------------------------------
33
34namespace android {
35
36// ----------------------------------------------------------------------------
37
38struct offsets_t {
39 jfieldID display;
40 jfieldID pixelFormat;
41 jfieldID fps;
42 jfieldID density;
43 jfieldID xdpi;
44 jfieldID ydpi;
45};
46static offsets_t offsets;
47
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048// ----------------------------------------------------------------------------
49
50static void android_view_Display_init(
51 JNIEnv* env, jobject clazz, jint dpy)
52{
53 DisplayInfo info;
54 status_t err = SurfaceComposerClient::getDisplayInfo(DisplayID(dpy), &info);
55 if (err < 0) {
Elliott Hughes8451b252011-04-07 19:17:57 -070056 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 return;
58 }
59 env->SetIntField(clazz, offsets.pixelFormat,info.pixelFormatInfo.format);
60 env->SetFloatField(clazz, offsets.fps, info.fps);
61 env->SetFloatField(clazz, offsets.density, info.density);
62 env->SetFloatField(clazz, offsets.xdpi, info.xdpi);
63 env->SetFloatField(clazz, offsets.ydpi, info.ydpi);
64}
65
Dianne Hackbornec537452011-09-14 19:19:55 -070066static jint android_view_Display_getRawWidthNative(
Dianne Hackborn99aac7b2011-02-25 17:33:02 -080067 JNIEnv* env, jobject clazz)
68{
69 DisplayID dpy = env->GetIntField(clazz, offsets.display);
70 return SurfaceComposerClient::getDisplayWidth(dpy);
71}
72
Dianne Hackbornec537452011-09-14 19:19:55 -070073static jint android_view_Display_getRawHeightNative(
Dianne Hackborn99aac7b2011-02-25 17:33:02 -080074 JNIEnv* env, jobject clazz)
75{
76 DisplayID dpy = env->GetIntField(clazz, offsets.display);
77 return SurfaceComposerClient::getDisplayHeight(dpy);
78}
79
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080static jint android_view_Display_getOrientation(
81 JNIEnv* env, jobject clazz)
82{
83 DisplayID dpy = env->GetIntField(clazz, offsets.display);
84 return SurfaceComposerClient::getDisplayOrientation(dpy);
85}
86
87static jint android_view_Display_getDisplayCount(
88 JNIEnv* env, jclass clazz)
89{
90 return SurfaceComposerClient::getNumberOfDisplays();
91}
92
93// ----------------------------------------------------------------------------
94
95const char* const kClassPathName = "android/view/Display";
96
97static void nativeClassInit(JNIEnv* env, jclass clazz);
98
99static JNINativeMethod gMethods[] = {
100 { "nativeClassInit", "()V",
101 (void*)nativeClassInit },
102 { "getDisplayCount", "()I",
103 (void*)android_view_Display_getDisplayCount },
104 { "init", "(I)V",
105 (void*)android_view_Display_init },
Dianne Hackbornec537452011-09-14 19:19:55 -0700106 { "getRawWidthNative", "()I",
107 (void*)android_view_Display_getRawWidthNative },
108 { "getRawHeightNative", "()I",
109 (void*)android_view_Display_getRawHeightNative },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 { "getOrientation", "()I",
Dianne Hackborn99aac7b2011-02-25 17:33:02 -0800111 (void*)android_view_Display_getOrientation }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112};
113
114void nativeClassInit(JNIEnv* env, jclass clazz)
115{
116 offsets.display = env->GetFieldID(clazz, "mDisplay", "I");
117 offsets.pixelFormat = env->GetFieldID(clazz, "mPixelFormat", "I");
118 offsets.fps = env->GetFieldID(clazz, "mRefreshRate", "F");
119 offsets.density = env->GetFieldID(clazz, "mDensity", "F");
120 offsets.xdpi = env->GetFieldID(clazz, "mDpiX", "F");
121 offsets.ydpi = env->GetFieldID(clazz, "mDpiY", "F");
122}
123
124int register_android_view_Display(JNIEnv* env)
125{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 return AndroidRuntime::registerNativeMethods(env,
127 kClassPathName, gMethods, NELEM(gMethods));
128}
129
130};