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