Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | #define LOG_TAG "OpenGLRenderer" |
| 18 | |
| 19 | #include <EGL/egl.h> |
| 20 | |
| 21 | #include "jni.h" |
| 22 | #include "GraphicsJNI.h" |
| 23 | #include <nativehelper/JNIHelp.h> |
| 24 | #include <android_runtime/AndroidRuntime.h> |
| 25 | |
| 26 | #include <DisplayListRenderer.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | using namespace uirenderer; |
| 31 | |
| 32 | /** |
| 33 | * Note: OpenGLRenderer JNI layer is generated and compiled only on supported |
| 34 | * devices. This means all the logic must be compiled only when the |
| 35 | * preprocessor variable USE_OPENGL_RENDERER is defined. |
| 36 | */ |
| 37 | #ifdef USE_OPENGL_RENDERER |
| 38 | |
| 39 | // ---------------------------------------------------------------------------- |
| 40 | // DisplayList view properties |
| 41 | // ---------------------------------------------------------------------------- |
| 42 | |
| 43 | static void android_view_GLES20DisplayList_setCaching(JNIEnv* env, |
| 44 | jobject clazz, DisplayList* displayList, jboolean caching) { |
| 45 | displayList->setCaching(caching); |
| 46 | } |
| 47 | |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 48 | static void android_view_GLES20DisplayList_setStaticMatrix(JNIEnv* env, |
| 49 | jobject clazz, DisplayList* displayList, SkMatrix* matrix) { |
| 50 | displayList->setStaticMatrix(matrix); |
| 51 | } |
| 52 | |
| 53 | static void android_view_GLES20DisplayList_setAnimationMatrix(JNIEnv* env, |
| 54 | jobject clazz, DisplayList* displayList, SkMatrix* matrix) { |
| 55 | displayList->setAnimationMatrix(matrix); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static void android_view_GLES20DisplayList_setClipChildren(JNIEnv* env, |
| 59 | jobject clazz, DisplayList* displayList, jboolean clipChildren) { |
| 60 | displayList->setClipChildren(clipChildren); |
| 61 | } |
| 62 | |
| 63 | static void android_view_GLES20DisplayList_setAlpha(JNIEnv* env, |
| 64 | jobject clazz, DisplayList* displayList, float alpha) { |
| 65 | displayList->setAlpha(alpha); |
| 66 | } |
| 67 | |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 68 | static void android_view_GLES20DisplayList_setHasOverlappingRendering(JNIEnv* env, |
| 69 | jobject clazz, DisplayList* displayList, bool hasOverlappingRendering) { |
| 70 | displayList->setHasOverlappingRendering(hasOverlappingRendering); |
| 71 | } |
| 72 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 73 | static void android_view_GLES20DisplayList_setTranslationX(JNIEnv* env, |
| 74 | jobject clazz, DisplayList* displayList, float tx) { |
| 75 | displayList->setTranslationX(tx); |
| 76 | } |
| 77 | |
| 78 | static void android_view_GLES20DisplayList_setTranslationY(JNIEnv* env, |
| 79 | jobject clazz, DisplayList* displayList, float ty) { |
| 80 | displayList->setTranslationY(ty); |
| 81 | } |
| 82 | |
| 83 | static void android_view_GLES20DisplayList_setRotation(JNIEnv* env, |
| 84 | jobject clazz, DisplayList* displayList, float rotation) { |
| 85 | displayList->setRotation(rotation); |
| 86 | } |
| 87 | |
| 88 | static void android_view_GLES20DisplayList_setRotationX(JNIEnv* env, |
| 89 | jobject clazz, DisplayList* displayList, float rx) { |
| 90 | displayList->setRotationX(rx); |
| 91 | } |
| 92 | |
| 93 | static void android_view_GLES20DisplayList_setRotationY(JNIEnv* env, |
| 94 | jobject clazz, DisplayList* displayList, float ry) { |
| 95 | displayList->setRotationY(ry); |
| 96 | } |
| 97 | |
| 98 | static void android_view_GLES20DisplayList_setScaleX(JNIEnv* env, |
| 99 | jobject clazz, DisplayList* displayList, float sx) { |
| 100 | displayList->setScaleX(sx); |
| 101 | } |
| 102 | |
| 103 | static void android_view_GLES20DisplayList_setScaleY(JNIEnv* env, |
| 104 | jobject clazz, DisplayList* displayList, float sy) { |
| 105 | displayList->setScaleY(sy); |
| 106 | } |
| 107 | |
| 108 | static void android_view_GLES20DisplayList_setTransformationInfo(JNIEnv* env, |
| 109 | jobject clazz, DisplayList* displayList, float alpha, |
| 110 | float translationX, float translationY, float rotation, float rotationX, float rotationY, |
| 111 | float scaleX, float scaleY) { |
| 112 | displayList->setAlpha(alpha); |
| 113 | displayList->setTranslationX(translationX); |
| 114 | displayList->setTranslationY(translationY); |
| 115 | displayList->setRotation(rotation); |
| 116 | displayList->setRotationX(rotationX); |
| 117 | displayList->setRotationY(rotationY); |
| 118 | displayList->setScaleX(scaleX); |
| 119 | displayList->setScaleY(scaleY); |
| 120 | } |
| 121 | |
| 122 | static void android_view_GLES20DisplayList_setPivotX(JNIEnv* env, |
| 123 | jobject clazz, DisplayList* displayList, float px) { |
| 124 | displayList->setPivotX(px); |
| 125 | } |
| 126 | |
| 127 | static void android_view_GLES20DisplayList_setPivotY(JNIEnv* env, |
| 128 | jobject clazz, DisplayList* displayList, float py) { |
| 129 | displayList->setPivotY(py); |
| 130 | } |
| 131 | |
| 132 | static void android_view_GLES20DisplayList_setCameraDistance(JNIEnv* env, |
| 133 | jobject clazz, DisplayList* displayList, float distance) { |
| 134 | displayList->setCameraDistance(distance); |
| 135 | } |
| 136 | |
| 137 | static void android_view_GLES20DisplayList_setLeft(JNIEnv* env, |
| 138 | jobject clazz, DisplayList* displayList, int left) { |
| 139 | displayList->setLeft(left); |
| 140 | } |
| 141 | |
| 142 | static void android_view_GLES20DisplayList_setTop(JNIEnv* env, |
| 143 | jobject clazz, DisplayList* displayList, int top) { |
| 144 | displayList->setTop(top); |
| 145 | } |
| 146 | |
| 147 | static void android_view_GLES20DisplayList_setRight(JNIEnv* env, |
| 148 | jobject clazz, DisplayList* displayList, int right) { |
| 149 | displayList->setRight(right); |
| 150 | } |
| 151 | |
| 152 | static void android_view_GLES20DisplayList_setBottom(JNIEnv* env, |
| 153 | jobject clazz, DisplayList* displayList, int bottom) { |
| 154 | displayList->setBottom(bottom); |
| 155 | } |
| 156 | |
| 157 | static void android_view_GLES20DisplayList_setLeftTop(JNIEnv* env, |
| 158 | jobject clazz, DisplayList* displayList, int left, int top) { |
| 159 | displayList->setLeftTop(left, top); |
| 160 | } |
| 161 | |
| 162 | static void android_view_GLES20DisplayList_setLeftTopRightBottom(JNIEnv* env, |
| 163 | jobject clazz, DisplayList* displayList, int left, int top, |
| 164 | int right, int bottom) { |
| 165 | displayList->setLeftTopRightBottom(left, top, right, bottom); |
| 166 | } |
| 167 | |
| 168 | static void android_view_GLES20DisplayList_offsetLeftRight(JNIEnv* env, |
| 169 | jobject clazz, DisplayList* displayList, int offset) { |
| 170 | displayList->offsetLeftRight(offset); |
| 171 | } |
| 172 | |
| 173 | static void android_view_GLES20DisplayList_offsetTopBottom(JNIEnv* env, |
| 174 | jobject clazz, DisplayList* displayList, int offset) { |
| 175 | displayList->offsetTopBottom(offset); |
| 176 | } |
| 177 | |
| 178 | #endif // USE_OPENGL_RENDERER |
| 179 | |
| 180 | // ---------------------------------------------------------------------------- |
| 181 | // JNI Glue |
| 182 | // ---------------------------------------------------------------------------- |
| 183 | |
| 184 | const char* const kClassPathName = "android/view/GLES20DisplayList"; |
| 185 | |
| 186 | static JNINativeMethod gMethods[] = { |
| 187 | #ifdef USE_OPENGL_RENDERER |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 188 | { "nSetCaching", "(IZ)V", (void*) android_view_GLES20DisplayList_setCaching }, |
| 189 | { "nSetStaticMatrix", "(II)V", (void*) android_view_GLES20DisplayList_setStaticMatrix }, |
| 190 | { "nSetAnimationMatrix", "(II)V", (void*) android_view_GLES20DisplayList_setAnimationMatrix }, |
| 191 | { "nSetClipChildren", "(IZ)V", (void*) android_view_GLES20DisplayList_setClipChildren }, |
| 192 | { "nSetAlpha", "(IF)V", (void*) android_view_GLES20DisplayList_setAlpha }, |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 193 | { "nSetHasOverlappingRendering", "(IZ)V", |
| 194 | (void*) android_view_GLES20DisplayList_setHasOverlappingRendering }, |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 195 | { "nSetTranslationX", "(IF)V", (void*) android_view_GLES20DisplayList_setTranslationX }, |
| 196 | { "nSetTranslationY", "(IF)V", (void*) android_view_GLES20DisplayList_setTranslationY }, |
| 197 | { "nSetRotation", "(IF)V", (void*) android_view_GLES20DisplayList_setRotation }, |
| 198 | { "nSetRotationX", "(IF)V", (void*) android_view_GLES20DisplayList_setRotationX }, |
| 199 | { "nSetRotationY", "(IF)V", (void*) android_view_GLES20DisplayList_setRotationY }, |
| 200 | { "nSetScaleX", "(IF)V", (void*) android_view_GLES20DisplayList_setScaleX }, |
| 201 | { "nSetScaleY", "(IF)V", (void*) android_view_GLES20DisplayList_setScaleY }, |
| 202 | { "nSetTransformationInfo","(IFFFFFFFF)V", |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 203 | (void*) android_view_GLES20DisplayList_setTransformationInfo }, |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 204 | { "nSetPivotX", "(IF)V", (void*) android_view_GLES20DisplayList_setPivotX }, |
| 205 | { "nSetPivotY", "(IF)V", (void*) android_view_GLES20DisplayList_setPivotY }, |
| 206 | { "nSetCameraDistance", "(IF)V", (void*) android_view_GLES20DisplayList_setCameraDistance }, |
| 207 | { "nSetLeft", "(II)V", (void*) android_view_GLES20DisplayList_setLeft }, |
| 208 | { "nSetTop", "(II)V", (void*) android_view_GLES20DisplayList_setTop }, |
| 209 | { "nSetRight", "(II)V", (void*) android_view_GLES20DisplayList_setRight }, |
| 210 | { "nSetBottom", "(II)V", (void*) android_view_GLES20DisplayList_setBottom }, |
| 211 | { "nSetLeftTop", "(III)V", (void*) android_view_GLES20DisplayList_setLeftTop }, |
| 212 | { "nSetLeftTopRightBottom","(IIIII)V", |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 213 | (void*) android_view_GLES20DisplayList_setLeftTopRightBottom }, |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 214 | { "nOffsetLeftRight", "(II)V", (void*) android_view_GLES20DisplayList_offsetLeftRight }, |
| 215 | { "nOffsetTopBottom", "(II)V", (void*) android_view_GLES20DisplayList_offsetTopBottom }, |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 216 | |
| 217 | #endif |
| 218 | }; |
| 219 | |
| 220 | #ifdef USE_OPENGL_RENDERER |
| 221 | #define FIND_CLASS(var, className) \ |
| 222 | var = env->FindClass(className); \ |
| 223 | LOG_FATAL_IF(! var, "Unable to find class " className); |
| 224 | |
| 225 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \ |
| 226 | var = env->GetMethodID(clazz, methodName, methodDescriptor); \ |
| 227 | LOG_FATAL_IF(! var, "Unable to find method " methodName); |
| 228 | #else |
| 229 | #define FIND_CLASS(var, className) |
| 230 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) |
| 231 | #endif |
| 232 | |
| 233 | int register_android_view_GLES20DisplayList(JNIEnv* env) { |
| 234 | return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); |
| 235 | } |
| 236 | |
| 237 | }; |
| 238 | |