blob: b307a2f9d8f90cc23ac23122be8ea519627df924 [file] [log] [blame]
Chet Haasea1cff502012-02-21 13:43:44 -08001/*
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
39// ----------------------------------------------------------------------------
40// DisplayList view properties
41// ----------------------------------------------------------------------------
42
43static void android_view_GLES20DisplayList_setCaching(JNIEnv* env,
44 jobject clazz, DisplayList* displayList, jboolean caching) {
45 displayList->setCaching(caching);
46}
47
Chet Haase9420abd2012-03-29 16:28:32 -070048static void android_view_GLES20DisplayList_setStaticMatrix(JNIEnv* env,
49 jobject clazz, DisplayList* displayList, SkMatrix* matrix) {
50 displayList->setStaticMatrix(matrix);
51}
52
53static void android_view_GLES20DisplayList_setAnimationMatrix(JNIEnv* env,
54 jobject clazz, DisplayList* displayList, SkMatrix* matrix) {
55 displayList->setAnimationMatrix(matrix);
Chet Haasea1cff502012-02-21 13:43:44 -080056}
57
58static void android_view_GLES20DisplayList_setClipChildren(JNIEnv* env,
59 jobject clazz, DisplayList* displayList, jboolean clipChildren) {
60 displayList->setClipChildren(clipChildren);
61}
62
63static void android_view_GLES20DisplayList_setAlpha(JNIEnv* env,
64 jobject clazz, DisplayList* displayList, float alpha) {
65 displayList->setAlpha(alpha);
66}
67
Chet Haasedb8c9a62012-03-21 18:54:18 -070068static void android_view_GLES20DisplayList_setHasOverlappingRendering(JNIEnv* env,
69 jobject clazz, DisplayList* displayList, bool hasOverlappingRendering) {
70 displayList->setHasOverlappingRendering(hasOverlappingRendering);
71}
72
Chet Haasea1cff502012-02-21 13:43:44 -080073static void android_view_GLES20DisplayList_setTranslationX(JNIEnv* env,
74 jobject clazz, DisplayList* displayList, float tx) {
75 displayList->setTranslationX(tx);
76}
77
78static void android_view_GLES20DisplayList_setTranslationY(JNIEnv* env,
79 jobject clazz, DisplayList* displayList, float ty) {
80 displayList->setTranslationY(ty);
81}
82
83static void android_view_GLES20DisplayList_setRotation(JNIEnv* env,
84 jobject clazz, DisplayList* displayList, float rotation) {
85 displayList->setRotation(rotation);
86}
87
88static void android_view_GLES20DisplayList_setRotationX(JNIEnv* env,
89 jobject clazz, DisplayList* displayList, float rx) {
90 displayList->setRotationX(rx);
91}
92
93static void android_view_GLES20DisplayList_setRotationY(JNIEnv* env,
94 jobject clazz, DisplayList* displayList, float ry) {
95 displayList->setRotationY(ry);
96}
97
98static void android_view_GLES20DisplayList_setScaleX(JNIEnv* env,
99 jobject clazz, DisplayList* displayList, float sx) {
100 displayList->setScaleX(sx);
101}
102
103static void android_view_GLES20DisplayList_setScaleY(JNIEnv* env,
104 jobject clazz, DisplayList* displayList, float sy) {
105 displayList->setScaleY(sy);
106}
107
108static 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
122static void android_view_GLES20DisplayList_setPivotX(JNIEnv* env,
123 jobject clazz, DisplayList* displayList, float px) {
124 displayList->setPivotX(px);
125}
126
127static void android_view_GLES20DisplayList_setPivotY(JNIEnv* env,
128 jobject clazz, DisplayList* displayList, float py) {
129 displayList->setPivotY(py);
130}
131
132static void android_view_GLES20DisplayList_setCameraDistance(JNIEnv* env,
133 jobject clazz, DisplayList* displayList, float distance) {
134 displayList->setCameraDistance(distance);
135}
136
137static void android_view_GLES20DisplayList_setLeft(JNIEnv* env,
138 jobject clazz, DisplayList* displayList, int left) {
139 displayList->setLeft(left);
140}
141
142static void android_view_GLES20DisplayList_setTop(JNIEnv* env,
143 jobject clazz, DisplayList* displayList, int top) {
144 displayList->setTop(top);
145}
146
147static void android_view_GLES20DisplayList_setRight(JNIEnv* env,
148 jobject clazz, DisplayList* displayList, int right) {
149 displayList->setRight(right);
150}
151
152static void android_view_GLES20DisplayList_setBottom(JNIEnv* env,
153 jobject clazz, DisplayList* displayList, int bottom) {
154 displayList->setBottom(bottom);
155}
156
157static void android_view_GLES20DisplayList_setLeftTop(JNIEnv* env,
158 jobject clazz, DisplayList* displayList, int left, int top) {
159 displayList->setLeftTop(left, top);
160}
161
162static 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
168static void android_view_GLES20DisplayList_offsetLeftRight(JNIEnv* env,
169 jobject clazz, DisplayList* displayList, int offset) {
170 displayList->offsetLeftRight(offset);
171}
172
173static 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
184const char* const kClassPathName = "android/view/GLES20DisplayList";
185
186static JNINativeMethod gMethods[] = {
187#ifdef USE_OPENGL_RENDERER
Chet Haase9420abd2012-03-29 16:28:32 -0700188 { "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 Haasedb8c9a62012-03-21 18:54:18 -0700193 { "nSetHasOverlappingRendering", "(IZ)V",
194 (void*) android_view_GLES20DisplayList_setHasOverlappingRendering },
Chet Haase9420abd2012-03-29 16:28:32 -0700195 { "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 Haasea1cff502012-02-21 13:43:44 -0800203 (void*) android_view_GLES20DisplayList_setTransformationInfo },
Chet Haase9420abd2012-03-29 16:28:32 -0700204 { "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 Haasea1cff502012-02-21 13:43:44 -0800213 (void*) android_view_GLES20DisplayList_setLeftTopRightBottom },
Chet Haase9420abd2012-03-29 16:28:32 -0700214 { "nOffsetLeftRight", "(II)V", (void*) android_view_GLES20DisplayList_offsetLeftRight },
215 { "nOffsetTopBottom", "(II)V", (void*) android_view_GLES20DisplayList_offsetTopBottom },
Chet Haasea1cff502012-02-21 13:43:44 -0800216
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
233int register_android_view_GLES20DisplayList(JNIEnv* env) {
234 return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
235}
236
237};
238