Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 "jni.h" |
| 18 | #include <nativehelper/JNIHelp.h> |
| 19 | #include <android_runtime/AndroidRuntime.h> |
| 20 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 21 | #include <SkMatrix.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 22 | #include <SkXfermode.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 23 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 24 | #include <OpenGLRenderer.h> |
| 25 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 26 | namespace android { |
| 27 | |
| 28 | // ---------------------------------------------------------------------------- |
| 29 | // Constructors |
| 30 | // ---------------------------------------------------------------------------- |
| 31 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 32 | static OpenGLRenderer* android_view_GLES20Renderer_createRenderer(JNIEnv* env, jobject canvas) { |
| 33 | return new OpenGLRenderer; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 36 | static void android_view_GLES20Renderer_destroyRenderer(JNIEnv* env, jobject canvas, |
| 37 | OpenGLRenderer* renderer) { |
| 38 | delete renderer; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | // ---------------------------------------------------------------------------- |
| 42 | // Setup |
| 43 | // ---------------------------------------------------------------------------- |
| 44 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 45 | static void android_view_GLES20Renderer_setViewport(JNIEnv* env, jobject canvas, |
| 46 | OpenGLRenderer* renderer, jint width, jint height) { |
| 47 | renderer->setViewport(width, height); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 50 | static void android_view_GLES20Renderer_prepare(JNIEnv* env, jobject canvas, |
| 51 | OpenGLRenderer* renderer) { |
| 52 | renderer->prepare(); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | // ---------------------------------------------------------------------------- |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 56 | // State |
| 57 | // ---------------------------------------------------------------------------- |
| 58 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 59 | static jint android_view_GLES20Renderer_save(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 60 | jint flags) { |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 61 | return renderer->save(flags); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 64 | static jint android_view_GLES20Renderer_getSaveCount(JNIEnv* env, jobject canvas, |
| 65 | OpenGLRenderer* renderer) { |
| 66 | return renderer->getSaveCount(); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 69 | static void android_view_GLES20Renderer_restore(JNIEnv* env, jobject canvas, |
| 70 | OpenGLRenderer* renderer) { |
| 71 | renderer->restore(); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 74 | static void android_view_GLES20Renderer_restoreToCount(JNIEnv* env, jobject canvas, |
| 75 | OpenGLRenderer* renderer, jint saveCount) { |
| 76 | renderer->restoreToCount(saveCount); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | // ---------------------------------------------------------------------------- |
| 80 | // Clipping |
| 81 | // ---------------------------------------------------------------------------- |
| 82 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 83 | static bool android_view_GLES20Renderer_clipRectF(JNIEnv* env, jobject canvas, |
| 84 | OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom) { |
| 85 | return renderer->clipRect(left, top, right, bottom); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 88 | static bool android_view_GLES20Renderer_clipRect(JNIEnv* env, jobject canvas, |
| 89 | OpenGLRenderer* renderer, jint left, jint top, jint right, jint bottom) { |
| 90 | return renderer->clipRect(float(left), float(top), float(right), float(bottom)); |
| 91 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 92 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 93 | // ---------------------------------------------------------------------------- |
| 94 | // Transforms |
| 95 | // ---------------------------------------------------------------------------- |
| 96 | |
| 97 | static void android_view_GLES20Renderer_translate(JNIEnv* env, jobject canvas, |
| 98 | OpenGLRenderer* renderer, jfloat dx, jfloat dy) { |
| 99 | renderer->translate(dx, dy); |
| 100 | } |
| 101 | |
| 102 | static void android_view_GLES20Renderer_rotate(JNIEnv* env, jobject canvas, |
| 103 | OpenGLRenderer* renderer, jfloat degrees) { |
| 104 | renderer->rotate(degrees); |
| 105 | } |
| 106 | |
| 107 | static void android_view_GLES20Renderer_scale(JNIEnv* env, jobject canvas, |
| 108 | OpenGLRenderer* renderer, jfloat sx, jfloat sy) { |
| 109 | renderer->scale(sx, sy); |
| 110 | } |
| 111 | |
| 112 | static void android_view_GLES20Renderer_setMatrix(JNIEnv* env, jobject canvas, |
| 113 | OpenGLRenderer* renderer, SkMatrix* matrix) { |
| 114 | renderer->setMatrix(matrix); |
| 115 | } |
| 116 | |
| 117 | static void android_view_GLES20Renderer_getMatrix(JNIEnv* env, jobject canvas, |
| 118 | OpenGLRenderer* renderer, SkMatrix* matrix) { |
| 119 | renderer->getMatrix(matrix); |
| 120 | } |
| 121 | |
| 122 | static void android_view_GLES20Renderer_concatMatrix(JNIEnv* env, jobject canvas, |
| 123 | OpenGLRenderer* renderer, SkMatrix* matrix) { |
| 124 | renderer->concatMatrix(matrix); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | // ---------------------------------------------------------------------------- |
| 128 | // Drawing |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 129 | // ---------------------------------------------------------------------------- |
| 130 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 131 | static void android_view_GLES20Renderer_drawColor(JNIEnv* env, jobject canvas, |
| 132 | OpenGLRenderer* renderer, jint color, jint mode) { |
| 133 | renderer->drawColor(color, (SkXfermode::Mode) mode); |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | // ---------------------------------------------------------------------------- |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 137 | // JNI Glue |
| 138 | // ---------------------------------------------------------------------------- |
| 139 | |
| 140 | const char* const kClassPathName = "android/view/GLES20Canvas"; |
| 141 | |
| 142 | static JNINativeMethod gMethods[] = { |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 143 | { "nCreateRenderer", "()I", (void*) android_view_GLES20Renderer_createRenderer }, |
| 144 | { "nDestroyRenderer", "(I)V", (void*) android_view_GLES20Renderer_destroyRenderer }, |
| 145 | { "nSetViewport", "(III)V", (void*) android_view_GLES20Renderer_setViewport }, |
| 146 | { "nPrepare", "(I)V", (void*) android_view_GLES20Renderer_prepare }, |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 147 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 148 | { "nSave", "(II)I", (void*) android_view_GLES20Renderer_save }, |
| 149 | { "nRestore", "(I)V", (void*) android_view_GLES20Renderer_restore }, |
| 150 | { "nRestoreToCount", "(II)V", (void*) android_view_GLES20Renderer_restoreToCount }, |
| 151 | { "nGetSaveCount", "(I)I", (void*) android_view_GLES20Renderer_getSaveCount }, |
| 152 | |
| 153 | { "nClipRect", "(IFFFF)Z", (void*) android_view_GLES20Renderer_clipRectF }, |
| 154 | { "nClipRect", "(IIIII)Z", (void*) android_view_GLES20Renderer_clipRect }, |
| 155 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame^] | 156 | { "nTranslate", "(IFF)V", (void*) android_view_GLES20Renderer_translate }, |
| 157 | { "nRotate", "(IF)V", (void*) android_view_GLES20Renderer_rotate }, |
| 158 | { "nScale", "(IFF)V", (void*) android_view_GLES20Renderer_scale }, |
| 159 | |
| 160 | { "nSetMatrix", "(II)V", (void*) android_view_GLES20Renderer_setMatrix }, |
| 161 | { "nGetMatrix", "(II)V", (void*) android_view_GLES20Renderer_getMatrix }, |
| 162 | { "nConcatMatrix", "(II)V", (void*) android_view_GLES20Renderer_concatMatrix }, |
| 163 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 164 | { "nDrawColor", "(III)V", (void*) android_view_GLES20Renderer_drawColor }, |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | int register_android_view_GLES20Canvas(JNIEnv* env) { |
| 168 | return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); |
| 169 | } |
| 170 | |
| 171 | }; |