The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Hackborn | 4c7cc34 | 2010-12-16 16:37:39 -0800 | [diff] [blame] | 20 | #include <cutils/properties.h> |
| 21 | |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 22 | #include <surfaceflinger/SurfaceComposerClient.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include <ui/PixelFormat.h> |
| 24 | #include <ui/DisplayInfo.h> |
| 25 | |
| 26 | #include "jni.h" |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 27 | #include "JNIHelp.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <android_runtime/AndroidRuntime.h> |
| 29 | #include <utils/misc.h> |
Dianne Hackborn | 4c7cc34 | 2010-12-16 16:37:39 -0800 | [diff] [blame] | 30 | #include <utils/Log.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
| 32 | // ---------------------------------------------------------------------------- |
| 33 | |
| 34 | namespace android { |
| 35 | |
| 36 | // ---------------------------------------------------------------------------- |
| 37 | |
| 38 | struct offsets_t { |
| 39 | jfieldID display; |
| 40 | jfieldID pixelFormat; |
| 41 | jfieldID fps; |
| 42 | jfieldID density; |
| 43 | jfieldID xdpi; |
| 44 | jfieldID ydpi; |
| 45 | }; |
| 46 | static offsets_t offsets; |
| 47 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | // ---------------------------------------------------------------------------- |
| 49 | |
| 50 | static 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 Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 56 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | 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 Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 66 | static jint android_view_Display_getRawWidth( |
Dianne Hackborn | 99aac7b | 2011-02-25 17:33:02 -0800 | [diff] [blame] | 67 | JNIEnv* env, jobject clazz) |
| 68 | { |
| 69 | DisplayID dpy = env->GetIntField(clazz, offsets.display); |
| 70 | return SurfaceComposerClient::getDisplayWidth(dpy); |
| 71 | } |
| 72 | |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 73 | static jint android_view_Display_getRawHeight( |
Dianne Hackborn | 99aac7b | 2011-02-25 17:33:02 -0800 | [diff] [blame] | 74 | JNIEnv* env, jobject clazz) |
| 75 | { |
| 76 | DisplayID dpy = env->GetIntField(clazz, offsets.display); |
| 77 | return SurfaceComposerClient::getDisplayHeight(dpy); |
| 78 | } |
| 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | static 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 | |
| 87 | static jint android_view_Display_getDisplayCount( |
| 88 | JNIEnv* env, jclass clazz) |
| 89 | { |
| 90 | return SurfaceComposerClient::getNumberOfDisplays(); |
| 91 | } |
| 92 | |
| 93 | // ---------------------------------------------------------------------------- |
| 94 | |
| 95 | const char* const kClassPathName = "android/view/Display"; |
| 96 | |
| 97 | static void nativeClassInit(JNIEnv* env, jclass clazz); |
| 98 | |
| 99 | static 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 Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 106 | { "getRawWidth", "()I", |
| 107 | (void*)android_view_Display_getRawWidth }, |
| 108 | { "getRawHeight", "()I", |
| 109 | (void*)android_view_Display_getRawHeight }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | { "getOrientation", "()I", |
Dianne Hackborn | 99aac7b | 2011-02-25 17:33:02 -0800 | [diff] [blame] | 111 | (void*)android_view_Display_getOrientation } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | void 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 | |
| 124 | int register_android_view_Display(JNIEnv* env) |
| 125 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | return AndroidRuntime::registerNativeMethods(env, |
| 127 | kClassPathName, gMethods, NELEM(gMethods)); |
| 128 | } |
| 129 | |
| 130 | }; |