Chris Craik | 5438979 | 2013-12-20 13:28:11 -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 <DisplayList.h> |
| 27 | #include <DisplayListRenderer.h> |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | using namespace uirenderer; |
| 32 | |
| 33 | /** |
| 34 | * Note: OpenGLRenderer JNI layer is generated and compiled only on supported |
| 35 | * devices. This means all the logic must be compiled only when the |
| 36 | * preprocessor variable USE_OPENGL_RENDERER is defined. |
| 37 | */ |
| 38 | #ifdef USE_OPENGL_RENDERER |
| 39 | |
| 40 | // ---------------------------------------------------------------------------- |
| 41 | // DisplayList view properties |
| 42 | // ---------------------------------------------------------------------------- |
| 43 | |
| 44 | static void android_view_DisplayList_reset(JNIEnv* env, |
| 45 | jobject clazz, DisplayList* displayList) { |
| 46 | displayList->reset(); |
| 47 | } |
| 48 | |
| 49 | static jint android_view_DisplayList_getDisplayListSize(JNIEnv* env, |
| 50 | jobject clazz, DisplayList* displayList) { |
| 51 | return displayList->getSize(); |
| 52 | } |
| 53 | |
| 54 | static void android_view_DisplayList_setDisplayListName(JNIEnv* env, |
| 55 | jobject clazz, DisplayList* displayList, jstring name) { |
| 56 | if (name != NULL) { |
| 57 | const char* textArray = env->GetStringUTFChars(name, NULL); |
| 58 | displayList->setName(textArray); |
| 59 | env->ReleaseStringUTFChars(name, textArray); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | static void android_view_DisplayList_output(JNIEnv* env, |
| 64 | jobject clazz, DisplayList* displayList) { |
| 65 | displayList->output(); |
| 66 | } |
| 67 | |
| 68 | static void android_view_DisplayList_destroyDisplayList(JNIEnv* env, |
| 69 | jobject clazz, DisplayList* displayList) { |
| 70 | DisplayList::destroyDisplayListDeferred(displayList); |
| 71 | } |
| 72 | |
| 73 | // ---------------------------------------------------------------------------- |
| 74 | // DisplayList view properties |
| 75 | // ---------------------------------------------------------------------------- |
| 76 | |
| 77 | static void android_view_DisplayList_setCaching(JNIEnv* env, |
| 78 | jobject clazz, DisplayList* displayList, jboolean caching) { |
| 79 | displayList->setCaching(caching); |
| 80 | } |
| 81 | |
| 82 | static void android_view_DisplayList_setStaticMatrix(JNIEnv* env, |
| 83 | jobject clazz, DisplayList* displayList, SkMatrix* matrix) { |
| 84 | displayList->setStaticMatrix(matrix); |
| 85 | } |
| 86 | |
| 87 | static void android_view_DisplayList_setAnimationMatrix(JNIEnv* env, |
| 88 | jobject clazz, DisplayList* displayList, SkMatrix* matrix) { |
| 89 | displayList->setAnimationMatrix(matrix); |
| 90 | } |
| 91 | |
| 92 | static void android_view_DisplayList_setClipToBounds(JNIEnv* env, |
| 93 | jobject clazz, DisplayList* displayList, jboolean clipToBounds) { |
| 94 | displayList->setClipToBounds(clipToBounds); |
| 95 | } |
| 96 | |
| 97 | static void android_view_DisplayList_setAlpha(JNIEnv* env, |
| 98 | jobject clazz, DisplayList* displayList, float alpha) { |
| 99 | displayList->setAlpha(alpha); |
| 100 | } |
| 101 | |
| 102 | static void android_view_DisplayList_setHasOverlappingRendering(JNIEnv* env, |
| 103 | jobject clazz, DisplayList* displayList, bool hasOverlappingRendering) { |
| 104 | displayList->setHasOverlappingRendering(hasOverlappingRendering); |
| 105 | } |
| 106 | |
| 107 | static void android_view_DisplayList_setTranslationX(JNIEnv* env, |
| 108 | jobject clazz, DisplayList* displayList, float tx) { |
| 109 | displayList->setTranslationX(tx); |
| 110 | } |
| 111 | |
| 112 | static void android_view_DisplayList_setTranslationY(JNIEnv* env, |
| 113 | jobject clazz, DisplayList* displayList, float ty) { |
| 114 | displayList->setTranslationY(ty); |
| 115 | } |
| 116 | |
| 117 | static void android_view_DisplayList_setTranslationZ(JNIEnv* env, |
| 118 | jobject clazz, DisplayList* displayList, float tz) { |
| 119 | displayList->setTranslationZ(tz); |
| 120 | } |
| 121 | |
| 122 | static void android_view_DisplayList_setRotation(JNIEnv* env, |
| 123 | jobject clazz, DisplayList* displayList, float rotation) { |
| 124 | displayList->setRotation(rotation); |
| 125 | } |
| 126 | |
| 127 | static void android_view_DisplayList_setRotationX(JNIEnv* env, |
| 128 | jobject clazz, DisplayList* displayList, float rx) { |
| 129 | displayList->setRotationX(rx); |
| 130 | } |
| 131 | |
| 132 | static void android_view_DisplayList_setRotationY(JNIEnv* env, |
| 133 | jobject clazz, DisplayList* displayList, float ry) { |
| 134 | displayList->setRotationY(ry); |
| 135 | } |
| 136 | |
| 137 | static void android_view_DisplayList_setScaleX(JNIEnv* env, |
| 138 | jobject clazz, DisplayList* displayList, float sx) { |
| 139 | displayList->setScaleX(sx); |
| 140 | } |
| 141 | |
| 142 | static void android_view_DisplayList_setScaleY(JNIEnv* env, |
| 143 | jobject clazz, DisplayList* displayList, float sy) { |
| 144 | displayList->setScaleY(sy); |
| 145 | } |
| 146 | |
| 147 | static void android_view_DisplayList_setTransformationInfo(JNIEnv* env, |
| 148 | jobject clazz, DisplayList* displayList, float alpha, |
| 149 | float translationX, float translationY, float translationZ, |
| 150 | float rotation, float rotationX, float rotationY, float scaleX, float scaleY) { |
| 151 | displayList->setAlpha(alpha); |
| 152 | displayList->setTranslationX(translationX); |
| 153 | displayList->setTranslationY(translationY); |
| 154 | displayList->setTranslationZ(translationZ); |
| 155 | displayList->setRotation(rotation); |
| 156 | displayList->setRotationX(rotationX); |
| 157 | displayList->setRotationY(rotationY); |
| 158 | displayList->setScaleX(scaleX); |
| 159 | displayList->setScaleY(scaleY); |
| 160 | } |
| 161 | |
| 162 | static void android_view_DisplayList_setPivotX(JNIEnv* env, |
| 163 | jobject clazz, DisplayList* displayList, float px) { |
| 164 | displayList->setPivotX(px); |
| 165 | } |
| 166 | |
| 167 | static void android_view_DisplayList_setPivotY(JNIEnv* env, |
| 168 | jobject clazz, DisplayList* displayList, float py) { |
| 169 | displayList->setPivotY(py); |
| 170 | } |
| 171 | |
| 172 | static void android_view_DisplayList_setCameraDistance(JNIEnv* env, |
| 173 | jobject clazz, DisplayList* displayList, float distance) { |
| 174 | displayList->setCameraDistance(distance); |
| 175 | } |
| 176 | |
| 177 | static void android_view_DisplayList_setLeft(JNIEnv* env, |
| 178 | jobject clazz, DisplayList* displayList, int left) { |
| 179 | displayList->setLeft(left); |
| 180 | } |
| 181 | |
| 182 | static void android_view_DisplayList_setTop(JNIEnv* env, |
| 183 | jobject clazz, DisplayList* displayList, int top) { |
| 184 | displayList->setTop(top); |
| 185 | } |
| 186 | |
| 187 | static void android_view_DisplayList_setRight(JNIEnv* env, |
| 188 | jobject clazz, DisplayList* displayList, int right) { |
| 189 | displayList->setRight(right); |
| 190 | } |
| 191 | |
| 192 | static void android_view_DisplayList_setBottom(JNIEnv* env, |
| 193 | jobject clazz, DisplayList* displayList, int bottom) { |
| 194 | displayList->setBottom(bottom); |
| 195 | } |
| 196 | |
| 197 | static void android_view_DisplayList_setLeftTopRightBottom(JNIEnv* env, |
| 198 | jobject clazz, DisplayList* displayList, int left, int top, |
| 199 | int right, int bottom) { |
| 200 | displayList->setLeftTopRightBottom(left, top, right, bottom); |
| 201 | } |
| 202 | |
| 203 | static void android_view_DisplayList_offsetLeftAndRight(JNIEnv* env, |
| 204 | jobject clazz, DisplayList* displayList, float offset) { |
| 205 | displayList->offsetLeftRight(offset); |
| 206 | } |
| 207 | |
| 208 | static void android_view_DisplayList_offsetTopAndBottom(JNIEnv* env, |
| 209 | jobject clazz, DisplayList* displayList, float offset) { |
| 210 | displayList->offsetTopBottom(offset); |
| 211 | } |
| 212 | |
| 213 | static void android_view_DisplayList_getMatrix(JNIEnv* env, |
| 214 | jobject clazz, DisplayList* displayList, SkMatrix* matrix) { |
| 215 | SkMatrix* source = displayList->getStaticMatrix(); |
| 216 | if (source) { |
| 217 | matrix->setConcat(SkMatrix::I(), *source); |
| 218 | } else { |
| 219 | matrix->setIdentity(); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | static jboolean android_view_DisplayList_hasOverlappingRendering(JNIEnv* env, |
| 224 | jobject clazz, DisplayList* displayList) { |
| 225 | return displayList->hasOverlappingRendering(); |
| 226 | } |
| 227 | |
| 228 | static jfloat android_view_DisplayList_getAlpha(JNIEnv* env, |
| 229 | jobject clazz, DisplayList* displayList) { |
| 230 | return displayList->getAlpha(); |
| 231 | } |
| 232 | |
| 233 | static jfloat android_view_DisplayList_getLeft(JNIEnv* env, |
| 234 | jobject clazz, DisplayList* displayList) { |
| 235 | return displayList->getLeft(); |
| 236 | } |
| 237 | |
| 238 | static jfloat android_view_DisplayList_getTop(JNIEnv* env, |
| 239 | jobject clazz, DisplayList* displayList) { |
| 240 | return displayList->getTop(); |
| 241 | } |
| 242 | |
| 243 | static jfloat android_view_DisplayList_getRight(JNIEnv* env, |
| 244 | jobject clazz, DisplayList* displayList) { |
| 245 | return displayList->getRight(); |
| 246 | } |
| 247 | |
| 248 | static jfloat android_view_DisplayList_getBottom(JNIEnv* env, |
| 249 | jobject clazz, DisplayList* displayList) { |
| 250 | return displayList->getBottom(); |
| 251 | } |
| 252 | |
| 253 | static jfloat android_view_DisplayList_getCameraDistance(JNIEnv* env, |
| 254 | jobject clazz, DisplayList* displayList) { |
| 255 | return displayList->getCameraDistance(); |
| 256 | } |
| 257 | |
| 258 | static jfloat android_view_DisplayList_getScaleX(JNIEnv* env, |
| 259 | jobject clazz, DisplayList* displayList) { |
| 260 | return displayList->getScaleX(); |
| 261 | } |
| 262 | |
| 263 | static jfloat android_view_DisplayList_getScaleY(JNIEnv* env, |
| 264 | jobject clazz, DisplayList* displayList) { |
| 265 | return displayList->getScaleY(); |
| 266 | } |
| 267 | |
| 268 | static jfloat android_view_DisplayList_getTranslationX(JNIEnv* env, |
| 269 | jobject clazz, DisplayList* displayList) { |
| 270 | return displayList->getTranslationX(); |
| 271 | } |
| 272 | |
| 273 | static jfloat android_view_DisplayList_getTranslationY(JNIEnv* env, |
| 274 | jobject clazz, DisplayList* displayList) { |
| 275 | return displayList->getTranslationY(); |
| 276 | } |
| 277 | |
| 278 | static jfloat android_view_DisplayList_getRotation(JNIEnv* env, |
| 279 | jobject clazz, DisplayList* displayList) { |
| 280 | return displayList->getRotation(); |
| 281 | } |
| 282 | |
| 283 | static jfloat android_view_DisplayList_getRotationX(JNIEnv* env, |
| 284 | jobject clazz, DisplayList* displayList) { |
| 285 | return displayList->getRotationX(); |
| 286 | } |
| 287 | |
| 288 | static jfloat android_view_DisplayList_getRotationY(JNIEnv* env, |
| 289 | jobject clazz, DisplayList* displayList) { |
| 290 | return displayList->getRotationY(); |
| 291 | } |
| 292 | |
| 293 | static jfloat android_view_DisplayList_getPivotX(JNIEnv* env, |
| 294 | jobject clazz, DisplayList* displayList) { |
| 295 | return displayList->getPivotX(); |
| 296 | } |
| 297 | |
| 298 | static jfloat android_view_DisplayList_getPivotY(JNIEnv* env, |
| 299 | jobject clazz, DisplayList* displayList) { |
| 300 | return displayList->getPivotY(); |
| 301 | } |
| 302 | |
| 303 | #endif // USE_OPENGL_RENDERER |
| 304 | |
| 305 | // ---------------------------------------------------------------------------- |
| 306 | // JNI Glue |
| 307 | // ---------------------------------------------------------------------------- |
| 308 | |
| 309 | const char* const kClassPathName = "android/view/DisplayList"; |
| 310 | |
| 311 | static JNINativeMethod gMethods[] = { |
| 312 | #ifdef USE_OPENGL_RENDERER |
| 313 | { "nDestroyDisplayList", "(I)V", (void*) android_view_DisplayList_destroyDisplayList }, |
| 314 | { "nGetDisplayListSize", "(I)I", (void*) android_view_DisplayList_getDisplayListSize }, |
| 315 | { "nSetDisplayListName", "(ILjava/lang/String;)V", |
| 316 | (void*) android_view_DisplayList_setDisplayListName }, |
| 317 | { "nOutput", "(I)V", (void*) android_view_DisplayList_output }, |
| 318 | |
| 319 | { "nReset", "(I)V", (void*) android_view_DisplayList_reset }, |
| 320 | { "nSetCaching", "(IZ)V", (void*) android_view_DisplayList_setCaching }, |
| 321 | { "nSetStaticMatrix", "(II)V", (void*) android_view_DisplayList_setStaticMatrix }, |
| 322 | { "nSetAnimationMatrix", "(II)V", (void*) android_view_DisplayList_setAnimationMatrix }, |
| 323 | { "nSetClipToBounds", "(IZ)V", (void*) android_view_DisplayList_setClipToBounds }, |
| 324 | { "nSetAlpha", "(IF)V", (void*) android_view_DisplayList_setAlpha }, |
| 325 | { "nSetHasOverlappingRendering", "(IZ)V", |
| 326 | (void*) android_view_DisplayList_setHasOverlappingRendering }, |
| 327 | { "nSetTranslationX", "(IF)V", (void*) android_view_DisplayList_setTranslationX }, |
| 328 | { "nSetTranslationY", "(IF)V", (void*) android_view_DisplayList_setTranslationY }, |
| 329 | { "nSetTranslationZ", "(IF)V", (void*) android_view_DisplayList_setTranslationZ }, |
| 330 | { "nSetRotation", "(IF)V", (void*) android_view_DisplayList_setRotation }, |
| 331 | { "nSetRotationX", "(IF)V", (void*) android_view_DisplayList_setRotationX }, |
| 332 | { "nSetRotationY", "(IF)V", (void*) android_view_DisplayList_setRotationY }, |
| 333 | { "nSetScaleX", "(IF)V", (void*) android_view_DisplayList_setScaleX }, |
| 334 | { "nSetScaleY", "(IF)V", (void*) android_view_DisplayList_setScaleY }, |
| 335 | { "nSetTransformationInfo","(IFFFFFFFFF)V", |
| 336 | (void*) android_view_DisplayList_setTransformationInfo }, |
| 337 | { "nSetPivotX", "(IF)V", (void*) android_view_DisplayList_setPivotX }, |
| 338 | { "nSetPivotY", "(IF)V", (void*) android_view_DisplayList_setPivotY }, |
| 339 | { "nSetCameraDistance", "(IF)V", (void*) android_view_DisplayList_setCameraDistance }, |
| 340 | { "nSetLeft", "(II)V", (void*) android_view_DisplayList_setLeft }, |
| 341 | { "nSetTop", "(II)V", (void*) android_view_DisplayList_setTop }, |
| 342 | { "nSetRight", "(II)V", (void*) android_view_DisplayList_setRight }, |
| 343 | { "nSetBottom", "(II)V", (void*) android_view_DisplayList_setBottom }, |
| 344 | { "nSetLeftTopRightBottom","(IIIII)V", (void*) android_view_DisplayList_setLeftTopRightBottom }, |
| 345 | { "nOffsetLeftAndRight", "(IF)V", (void*) android_view_DisplayList_offsetLeftAndRight }, |
| 346 | { "nOffsetTopAndBottom", "(IF)V", (void*) android_view_DisplayList_offsetTopAndBottom }, |
| 347 | |
| 348 | { "nGetMatrix", "(II)V", (void*) android_view_DisplayList_getMatrix }, |
| 349 | { "nHasOverlappingRendering", "(I)Z", (void*) android_view_DisplayList_hasOverlappingRendering }, |
| 350 | { "nGetAlpha", "(I)F", (void*) android_view_DisplayList_getAlpha }, |
| 351 | { "nGetLeft", "(I)F", (void*) android_view_DisplayList_getLeft }, |
| 352 | { "nGetTop", "(I)F", (void*) android_view_DisplayList_getTop }, |
| 353 | { "nGetRight", "(I)F", (void*) android_view_DisplayList_getRight }, |
| 354 | { "nGetBottom", "(I)F", (void*) android_view_DisplayList_getBottom }, |
| 355 | { "nGetCameraDistance", "(I)F", (void*) android_view_DisplayList_getCameraDistance }, |
| 356 | { "nGetScaleX", "(I)F", (void*) android_view_DisplayList_getScaleX }, |
| 357 | { "nGetScaleY", "(I)F", (void*) android_view_DisplayList_getScaleY }, |
| 358 | { "nGetTranslationX", "(I)F", (void*) android_view_DisplayList_getTranslationX }, |
| 359 | { "nGetTranslationY", "(I)F", (void*) android_view_DisplayList_getTranslationY }, |
| 360 | { "nGetRotation", "(I)F", (void*) android_view_DisplayList_getRotation }, |
| 361 | { "nGetRotationX", "(I)F", (void*) android_view_DisplayList_getRotationX }, |
| 362 | { "nGetRotationY", "(I)F", (void*) android_view_DisplayList_getRotationY }, |
| 363 | { "nGetPivotX", "(I)F", (void*) android_view_DisplayList_getPivotX }, |
| 364 | { "nGetPivotY", "(I)F", (void*) android_view_DisplayList_getPivotY }, |
| 365 | #endif |
| 366 | }; |
| 367 | |
| 368 | #ifdef USE_OPENGL_RENDERER |
| 369 | #define FIND_CLASS(var, className) \ |
| 370 | var = env->FindClass(className); \ |
| 371 | LOG_FATAL_IF(! var, "Unable to find class " className); |
| 372 | |
| 373 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \ |
| 374 | var = env->GetMethodID(clazz, methodName, methodDescriptor); \ |
| 375 | LOG_FATAL_IF(! var, "Unable to find method " methodName); |
| 376 | #else |
| 377 | #define FIND_CLASS(var, className) |
| 378 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) |
| 379 | #endif |
| 380 | |
| 381 | int register_android_view_DisplayList(JNIEnv* env) { |
| 382 | return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); |
| 383 | } |
| 384 | |
| 385 | }; |
| 386 | |