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 | |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 17 | #define LOG_TAG "OpenGLRenderer" |
| 18 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 19 | #include <EGL/egl.h> |
| 20 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 21 | #include "jni.h" |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 22 | #include "GraphicsJNI.h" |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 23 | #include <nativehelper/JNIHelp.h> |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 24 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 25 | #include <android_runtime/AndroidRuntime.h> |
Romain Guy | e5e0c50 | 2011-06-15 15:18:31 -0700 | [diff] [blame] | 26 | #include <android_runtime/android_graphics_SurfaceTexture.h> |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 27 | #include <gui/SurfaceTexture.h> |
| 28 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 29 | #include <androidfw/ResourceTypes.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 30 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 31 | #include <private/hwui/DrawGlInfo.h> |
| 32 | |
| 33 | #include <cutils/properties.h> |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 34 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 35 | #include <SkBitmap.h> |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 36 | #include <SkCanvas.h> |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 37 | #include <SkMatrix.h> |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 38 | #include <SkPaint.h> |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 39 | #include <SkRegion.h> |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 40 | #include <SkScalerContext.h> |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 41 | #include <SkTemplates.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 42 | #include <SkXfermode.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 43 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 44 | #include <DisplayListRenderer.h> |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 45 | #include <LayerRenderer.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 46 | #include <OpenGLRenderer.h> |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 47 | #include <SkiaShader.h> |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 48 | #include <SkiaColorFilter.h> |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 49 | #include <Rect.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 50 | |
Romain Guy | d1d4bb7 | 2012-01-17 17:31:27 -0800 | [diff] [blame] | 51 | #include <TextLayout.h> |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 52 | #include <TextLayoutCache.h> |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 53 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 54 | namespace android { |
| 55 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 56 | using namespace uirenderer; |
| 57 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 58 | /** |
| 59 | * Note: OpenGLRenderer JNI layer is generated and compiled only on supported |
| 60 | * devices. This means all the logic must be compiled only when the |
| 61 | * preprocessor variable USE_OPENGL_RENDERER is defined. |
| 62 | */ |
| 63 | #ifdef USE_OPENGL_RENDERER |
| 64 | |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 65 | // ---------------------------------------------------------------------------- |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 66 | // Defines |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 67 | // ---------------------------------------------------------------------------- |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 68 | |
| 69 | // Debug |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 70 | #define DEBUG_RENDERER 0 |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 71 | |
| 72 | // Debug |
| 73 | #if DEBUG_RENDERER |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 74 | #define RENDERER_LOGD(...) ALOGD(__VA_ARGS__) |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 75 | #else |
| 76 | #define RENDERER_LOGD(...) |
| 77 | #endif |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 78 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 79 | #define MODIFIER_SHADOW 1 |
| 80 | #define MODIFIER_SHADER 2 |
| 81 | #define MODIFIER_COLOR_FILTER 4 |
| 82 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 83 | // ---------------------------------------------------------------------------- |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 84 | |
| 85 | static struct { |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 86 | jmethodID set; |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 87 | } gRectClassInfo; |
| 88 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 89 | // ---------------------------------------------------------------------------- |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 90 | // Caching |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 91 | // ---------------------------------------------------------------------------- |
| 92 | |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 93 | static void android_view_GLES20Canvas_flushCaches(JNIEnv* env, jobject clazz, |
| 94 | Caches::FlushMode mode) { |
| 95 | if (Caches::hasInstance()) { |
| 96 | Caches::getInstance().flush(mode); |
| 97 | } |
| 98 | } |
| 99 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 100 | static void android_view_GLES20Canvas_initCaches(JNIEnv* env, jobject clazz) { |
| 101 | if (Caches::hasInstance()) { |
| 102 | Caches::getInstance().init(); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | static void android_view_GLES20Canvas_terminateCaches(JNIEnv* env, jobject clazz) { |
| 107 | if (Caches::hasInstance()) { |
| 108 | Caches::getInstance().terminate(); |
| 109 | } |
| 110 | } |
| 111 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 112 | // ---------------------------------------------------------------------------- |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 113 | // Constructors |
| 114 | // ---------------------------------------------------------------------------- |
| 115 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 116 | static OpenGLRenderer* android_view_GLES20Canvas_createRenderer(JNIEnv* env, jobject clazz) { |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 117 | RENDERER_LOGD("Create OpenGLRenderer"); |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 118 | return new OpenGLRenderer; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 121 | static void android_view_GLES20Canvas_destroyRenderer(JNIEnv* env, jobject clazz, |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 122 | OpenGLRenderer* renderer) { |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 123 | RENDERER_LOGD("Destroy OpenGLRenderer"); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 124 | delete renderer; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | // ---------------------------------------------------------------------------- |
| 128 | // Setup |
| 129 | // ---------------------------------------------------------------------------- |
| 130 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 131 | static void android_view_GLES20Canvas_setViewport(JNIEnv* env, jobject clazz, |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 132 | OpenGLRenderer* renderer, jint width, jint height) { |
| 133 | renderer->setViewport(width, height); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 136 | static int android_view_GLES20Canvas_prepare(JNIEnv* env, jobject clazz, |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 137 | OpenGLRenderer* renderer, jboolean opaque) { |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 138 | return renderer->prepare(opaque); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 141 | static int android_view_GLES20Canvas_prepareDirty(JNIEnv* env, jobject clazz, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 142 | OpenGLRenderer* renderer, jint left, jint top, jint right, jint bottom, |
| 143 | jboolean opaque) { |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 144 | return renderer->prepareDirty(left, top, right, bottom, opaque); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static void android_view_GLES20Canvas_finish(JNIEnv* env, jobject clazz, |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 148 | OpenGLRenderer* renderer) { |
| 149 | renderer->finish(); |
| 150 | } |
| 151 | |
Romain Guy | 530041d | 2012-01-25 18:56:29 -0800 | [diff] [blame] | 152 | static jint android_view_GLES20Canvas_getStencilSize(JNIEnv* env, jobject clazz) { |
| 153 | return OpenGLRenderer::getStencilSize(); |
| 154 | } |
| 155 | |
| 156 | // ---------------------------------------------------------------------------- |
| 157 | // Functor |
| 158 | // ---------------------------------------------------------------------------- |
| 159 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 160 | static jint android_view_GLES20Canvas_callDrawGLFunction(JNIEnv* env, jobject clazz, |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 161 | OpenGLRenderer* renderer, Functor* functor) { |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 162 | android::uirenderer::Rect dirty; |
| 163 | return renderer->callDrawGLFunction(functor, dirty); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 166 | static void android_view_GLES20Canvas_detachFunctor(JNIEnv* env, |
| 167 | jobject clazz, OpenGLRenderer* renderer, Functor* functor) { |
| 168 | renderer->detachFunctor(functor); |
| 169 | } |
| 170 | |
| 171 | static void android_view_GLES20Canvas_attachFunctor(JNIEnv* env, |
| 172 | jobject clazz, OpenGLRenderer* renderer, Functor* functor) { |
| 173 | renderer->attachFunctor(functor); |
| 174 | } |
| 175 | |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 176 | static jint android_view_GLES20Canvas_invokeFunctors(JNIEnv* env, |
| 177 | jobject clazz, OpenGLRenderer* renderer, jobject dirty) { |
| 178 | android::uirenderer::Rect bounds; |
| 179 | status_t status = renderer->invokeFunctors(bounds); |
| 180 | if (status != DrawGlInfo::kStatusDone && dirty != NULL) { |
| 181 | env->CallVoidMethod(dirty, gRectClassInfo.set, |
| 182 | int(bounds.left), int(bounds.top), int(bounds.right), int(bounds.bottom)); |
| 183 | } |
| 184 | return status; |
| 185 | } |
| 186 | |
| 187 | // ---------------------------------------------------------------------------- |
| 188 | // Misc |
| 189 | // ---------------------------------------------------------------------------- |
| 190 | |
Romain Guy | f61970fc | 2011-07-07 14:10:06 -0700 | [diff] [blame] | 191 | static jint android_view_GLES20Canvas_getMaxTextureWidth(JNIEnv* env, jobject clazz) { |
| 192 | return Caches::getInstance().maxTextureSize; |
| 193 | } |
| 194 | |
| 195 | static jint android_view_GLES20Canvas_getMaxTextureHeight(JNIEnv* env, jobject clazz) { |
| 196 | return Caches::getInstance().maxTextureSize; |
| 197 | } |
| 198 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 199 | // ---------------------------------------------------------------------------- |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 200 | // State |
| 201 | // ---------------------------------------------------------------------------- |
| 202 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 203 | static jint android_view_GLES20Canvas_save(JNIEnv* env, jobject clazz, OpenGLRenderer* renderer, |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 204 | jint flags) { |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 205 | return renderer->save(flags); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 208 | static jint android_view_GLES20Canvas_getSaveCount(JNIEnv* env, jobject clazz, |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 209 | OpenGLRenderer* renderer) { |
| 210 | return renderer->getSaveCount(); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 213 | static void android_view_GLES20Canvas_restore(JNIEnv* env, jobject clazz, |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 214 | OpenGLRenderer* renderer) { |
| 215 | renderer->restore(); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 218 | static void android_view_GLES20Canvas_restoreToCount(JNIEnv* env, jobject clazz, |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 219 | OpenGLRenderer* renderer, jint saveCount) { |
| 220 | renderer->restoreToCount(saveCount); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | // ---------------------------------------------------------------------------- |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 224 | // Layers |
| 225 | // ---------------------------------------------------------------------------- |
| 226 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 227 | static jint android_view_GLES20Canvas_saveLayer(JNIEnv* env, jobject clazz, |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 228 | OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 229 | SkPaint* paint, jint saveFlags) { |
| 230 | return renderer->saveLayer(left, top, right, bottom, paint, saveFlags); |
| 231 | } |
| 232 | |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 233 | static jint android_view_GLES20Canvas_saveLayerClip(JNIEnv* env, jobject clazz, |
| 234 | OpenGLRenderer* renderer, SkPaint* paint, jint saveFlags) { |
| 235 | const android::uirenderer::Rect& bounds(renderer->getClipBounds()); |
| 236 | return renderer->saveLayer(bounds.left, bounds.top, bounds.right, bounds.bottom, |
| 237 | paint, saveFlags); |
| 238 | } |
| 239 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 240 | static jint android_view_GLES20Canvas_saveLayerAlpha(JNIEnv* env, jobject clazz, |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 241 | OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 242 | jint alpha, jint saveFlags) { |
| 243 | return renderer->saveLayerAlpha(left, top, right, bottom, alpha, saveFlags); |
| 244 | } |
| 245 | |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 246 | static jint android_view_GLES20Canvas_saveLayerAlphaClip(JNIEnv* env, jobject clazz, |
| 247 | OpenGLRenderer* renderer, jint alpha, jint saveFlags) { |
| 248 | const android::uirenderer::Rect& bounds(renderer->getClipBounds()); |
| 249 | return renderer->saveLayerAlpha(bounds.left, bounds.top, bounds.right, bounds.bottom, |
| 250 | alpha, saveFlags); |
| 251 | } |
| 252 | |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 253 | // ---------------------------------------------------------------------------- |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 254 | // Clipping |
| 255 | // ---------------------------------------------------------------------------- |
| 256 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 257 | static bool android_view_GLES20Canvas_quickReject(JNIEnv* env, jobject clazz, |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 258 | OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 259 | SkCanvas::EdgeType edge) { |
| 260 | return renderer->quickReject(left, top, right, bottom); |
| 261 | } |
| 262 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 263 | static bool android_view_GLES20Canvas_clipRectF(JNIEnv* env, jobject clazz, |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 264 | OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 265 | SkRegion::Op op) { |
| 266 | return renderer->clipRect(left, top, right, bottom, op); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 269 | static bool android_view_GLES20Canvas_clipRect(JNIEnv* env, jobject clazz, |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 270 | OpenGLRenderer* renderer, jint left, jint top, jint right, jint bottom, |
| 271 | SkRegion::Op op) { |
| 272 | return renderer->clipRect(float(left), float(top), float(right), float(bottom), op); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 273 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 274 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 275 | static bool android_view_GLES20Canvas_getClipBounds(JNIEnv* env, jobject clazz, |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 276 | OpenGLRenderer* renderer, jobject rect) { |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 277 | const android::uirenderer::Rect& bounds(renderer->getClipBounds()); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 278 | |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 279 | env->CallVoidMethod(rect, gRectClassInfo.set, |
| 280 | int(bounds.left), int(bounds.top), int(bounds.right), int(bounds.bottom)); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 281 | |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 282 | return !bounds.isEmpty(); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 285 | // ---------------------------------------------------------------------------- |
| 286 | // Transforms |
| 287 | // ---------------------------------------------------------------------------- |
| 288 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 289 | static void android_view_GLES20Canvas_translate(JNIEnv* env, jobject clazz, |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 290 | OpenGLRenderer* renderer, jfloat dx, jfloat dy) { |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 291 | renderer->translate(dx, dy); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 294 | static void android_view_GLES20Canvas_rotate(JNIEnv* env, jobject clazz, |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 295 | OpenGLRenderer* renderer, jfloat degrees) { |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 296 | renderer->rotate(degrees); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 299 | static void android_view_GLES20Canvas_scale(JNIEnv* env, jobject clazz, |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 300 | OpenGLRenderer* renderer, jfloat sx, jfloat sy) { |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 301 | renderer->scale(sx, sy); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 304 | static void android_view_GLES20Canvas_skew(JNIEnv* env, jobject clazz, |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 305 | OpenGLRenderer* renderer, jfloat sx, jfloat sy) { |
| 306 | renderer->skew(sx, sy); |
| 307 | } |
| 308 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 309 | static void android_view_GLES20Canvas_setMatrix(JNIEnv* env, jobject clazz, |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 310 | OpenGLRenderer* renderer, SkMatrix* matrix) { |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 311 | renderer->setMatrix(matrix); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 314 | static void android_view_GLES20Canvas_getMatrix(JNIEnv* env, jobject clazz, |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 315 | OpenGLRenderer* renderer, SkMatrix* matrix) { |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 316 | renderer->getMatrix(matrix); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 319 | static void android_view_GLES20Canvas_concatMatrix(JNIEnv* env, jobject clazz, |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 320 | OpenGLRenderer* renderer, SkMatrix* matrix) { |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 321 | renderer->concatMatrix(matrix); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | // ---------------------------------------------------------------------------- |
| 325 | // Drawing |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 326 | // ---------------------------------------------------------------------------- |
| 327 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 328 | static void android_view_GLES20Canvas_drawBitmap(JNIEnv* env, jobject clazz, |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 329 | OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer, |
| 330 | jfloat left, jfloat top, SkPaint* paint) { |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 331 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 332 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 333 | |
Romain Guy | dbd77cd | 2010-07-09 10:36:05 -0700 | [diff] [blame] | 334 | renderer->drawBitmap(bitmap, left, top, paint); |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 337 | static void android_view_GLES20Canvas_drawBitmapRect(JNIEnv* env, jobject clazz, |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 338 | OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer, |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 339 | float srcLeft, float srcTop, float srcRight, float srcBottom, |
Romain Guy | dbd77cd | 2010-07-09 10:36:05 -0700 | [diff] [blame] | 340 | float dstLeft, float dstTop, float dstRight, float dstBottom, SkPaint* paint) { |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 341 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 342 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 343 | |
Romain Guy | dbd77cd | 2010-07-09 10:36:05 -0700 | [diff] [blame] | 344 | renderer->drawBitmap(bitmap, srcLeft, srcTop, srcRight, srcBottom, |
| 345 | dstLeft, dstTop, dstRight, dstBottom, paint); |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 346 | } |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 347 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 348 | static void android_view_GLES20Canvas_drawBitmapMatrix(JNIEnv* env, jobject clazz, |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 349 | OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer, SkMatrix* matrix, |
| 350 | SkPaint* paint) { |
| 351 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 352 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 353 | |
Romain Guy | dbd77cd | 2010-07-09 10:36:05 -0700 | [diff] [blame] | 354 | renderer->drawBitmap(bitmap, matrix, paint); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 357 | static void android_view_GLES20Canvas_drawBitmapData(JNIEnv* env, jobject clazz, |
| 358 | OpenGLRenderer* renderer, jintArray colors, jint offset, jint stride, |
| 359 | jfloat left, jfloat top, jint width, jint height, jboolean hasAlpha, SkPaint* paint) { |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 360 | SkBitmap* bitmap = new SkBitmap; |
| 361 | bitmap->setConfig(hasAlpha ? SkBitmap::kARGB_8888_Config : SkBitmap::kRGB_565_Config, |
| 362 | width, height); |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 363 | |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 364 | if (!bitmap->allocPixels()) { |
| 365 | delete bitmap; |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 366 | return; |
| 367 | } |
| 368 | |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 369 | if (!GraphicsJNI::SetPixels(env, colors, offset, stride, 0, 0, width, height, *bitmap)) { |
| 370 | delete bitmap; |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 371 | return; |
| 372 | } |
| 373 | |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 374 | renderer->drawBitmapData(bitmap, left, top, paint); |
| 375 | |
| 376 | // If the renderer is a deferred renderer it will own the bitmap |
| 377 | if (!renderer->isDeferred()) { |
| 378 | delete bitmap; |
| 379 | } |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 382 | static void android_view_GLES20Canvas_drawBitmapMesh(JNIEnv* env, jobject clazz, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 383 | OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer, |
| 384 | jint meshWidth, jint meshHeight, jfloatArray vertices, jint offset, |
| 385 | jintArray colors, jint colorOffset, SkPaint* paint) { |
| 386 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 387 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 388 | |
| 389 | jfloat* verticesArray = vertices ? env->GetFloatArrayElements(vertices, NULL) + offset : NULL; |
| 390 | jint* colorsArray = colors ? env->GetIntArrayElements(colors, NULL) + colorOffset : NULL; |
| 391 | |
| 392 | renderer->drawBitmapMesh(bitmap, meshWidth, meshHeight, verticesArray, colorsArray, paint); |
| 393 | |
| 394 | if (vertices) env->ReleaseFloatArrayElements(vertices, verticesArray, 0); |
| 395 | if (colors) env->ReleaseIntArrayElements(colors, colorsArray, 0); |
| 396 | } |
| 397 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 398 | static void android_view_GLES20Canvas_drawPatch(JNIEnv* env, jobject clazz, |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 399 | OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer, jbyteArray chunks, |
Romain Guy | dbd77cd | 2010-07-09 10:36:05 -0700 | [diff] [blame] | 400 | float left, float top, float right, float bottom, SkPaint* paint) { |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 401 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 402 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 403 | |
Romain Guy | deba785 | 2010-07-07 17:54:48 -0700 | [diff] [blame] | 404 | jbyte* storage = env->GetByteArrayElements(chunks, NULL); |
| 405 | Res_png_9patch* patch = reinterpret_cast<Res_png_9patch*>(storage); |
| 406 | Res_png_9patch::deserialize(patch); |
| 407 | |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 408 | renderer->drawPatch(bitmap, &patch->xDivs[0], &patch->yDivs[0], |
| 409 | &patch->colors[0], patch->numXDivs, patch->numYDivs, patch->numColors, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 410 | left, top, right, bottom, paint); |
Romain Guy | deba785 | 2010-07-07 17:54:48 -0700 | [diff] [blame] | 411 | |
Romain Guy | deba785 | 2010-07-07 17:54:48 -0700 | [diff] [blame] | 412 | env->ReleaseByteArrayElements(chunks, storage, 0); |
| 413 | } |
| 414 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 415 | static void android_view_GLES20Canvas_drawColor(JNIEnv* env, jobject clazz, |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 416 | OpenGLRenderer* renderer, jint color, SkXfermode::Mode mode) { |
| 417 | renderer->drawColor(color, mode); |
| 418 | } |
| 419 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 420 | static void android_view_GLES20Canvas_drawRect(JNIEnv* env, jobject clazz, |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 421 | OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 422 | SkPaint* paint) { |
| 423 | renderer->drawRect(left, top, right, bottom, paint); |
| 424 | } |
| 425 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 426 | static void android_view_GLES20Canvas_drawRoundRect(JNIEnv* env, jobject clazz, |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 427 | OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 428 | jfloat rx, jfloat ry, SkPaint* paint) { |
| 429 | renderer->drawRoundRect(left, top, right, bottom, rx, ry, paint); |
| 430 | } |
| 431 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 432 | static void android_view_GLES20Canvas_drawCircle(JNIEnv* env, jobject clazz, |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 433 | OpenGLRenderer* renderer, jfloat x, jfloat y, jfloat radius, SkPaint* paint) { |
| 434 | renderer->drawCircle(x, y, radius, paint); |
| 435 | } |
| 436 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 437 | static void android_view_GLES20Canvas_drawOval(JNIEnv* env, jobject clazz, |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 438 | OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 439 | SkPaint* paint) { |
| 440 | renderer->drawOval(left, top, right, bottom, paint); |
| 441 | } |
| 442 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 443 | static void android_view_GLES20Canvas_drawArc(JNIEnv* env, jobject clazz, |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 444 | OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 445 | jfloat startAngle, jfloat sweepAngle, jboolean useCenter, SkPaint* paint) { |
| 446 | renderer->drawArc(left, top, right, bottom, startAngle, sweepAngle, useCenter, paint); |
| 447 | } |
| 448 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 449 | static void android_view_GLES20Canvas_drawRects(JNIEnv* env, jobject clazz, |
Romain Guy | a48a1a8 | 2010-08-10 14:59:15 -0700 | [diff] [blame] | 450 | OpenGLRenderer* renderer, SkRegion* region, SkPaint* paint) { |
| 451 | SkRegion::Iterator it(*region); |
| 452 | while (!it.done()) { |
| 453 | const SkIRect& r = it.rect(); |
| 454 | renderer->drawRect(r.fLeft, r.fTop, r.fRight, r.fBottom, paint); |
| 455 | it.next(); |
| 456 | } |
| 457 | } |
| 458 | |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 459 | static void android_view_GLES20Canvas_drawPoints(JNIEnv* env, jobject clazz, |
| 460 | OpenGLRenderer* renderer, jfloatArray points, jint offset, jint count, SkPaint* paint) { |
| 461 | jfloat* storage = env->GetFloatArrayElements(points, NULL); |
| 462 | renderer->drawPoints(storage + offset, count, paint); |
| 463 | env->ReleaseFloatArrayElements(points, storage, 0); |
| 464 | } |
| 465 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 466 | static void android_view_GLES20Canvas_drawPath(JNIEnv* env, jobject clazz, |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 467 | OpenGLRenderer* renderer, SkPath* path, SkPaint* paint) { |
| 468 | renderer->drawPath(path, paint); |
| 469 | } |
| 470 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 471 | static void android_view_GLES20Canvas_drawLines(JNIEnv* env, jobject clazz, |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 472 | OpenGLRenderer* renderer, jfloatArray points, jint offset, jint count, SkPaint* paint) { |
| 473 | jfloat* storage = env->GetFloatArrayElements(points, NULL); |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 474 | renderer->drawLines(storage + offset, count, paint); |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 475 | env->ReleaseFloatArrayElements(points, storage, 0); |
| 476 | } |
| 477 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 478 | // ---------------------------------------------------------------------------- |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 479 | // Shaders and color filters |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 480 | // ---------------------------------------------------------------------------- |
| 481 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 482 | static void android_view_GLES20Canvas_resetModifiers(JNIEnv* env, jobject clazz, |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 483 | OpenGLRenderer* renderer, jint modifiers) { |
| 484 | if (modifiers & MODIFIER_SHADOW) renderer->resetShadow(); |
| 485 | if (modifiers & MODIFIER_SHADER) renderer->resetShader(); |
| 486 | if (modifiers & MODIFIER_COLOR_FILTER) renderer->resetColorFilter(); |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 489 | static void android_view_GLES20Canvas_setupShader(JNIEnv* env, jobject clazz, |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 490 | OpenGLRenderer* renderer, SkiaShader* shader) { |
| 491 | renderer->setupShader(shader); |
Romain Guy | 7fac2e1 | 2010-07-16 17:10:13 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 494 | static void android_view_GLES20Canvas_setupColorFilter(JNIEnv* env, jobject clazz, |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 495 | OpenGLRenderer* renderer, SkiaColorFilter* filter) { |
| 496 | renderer->setupColorFilter(filter); |
| 497 | } |
| 498 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 499 | static void android_view_GLES20Canvas_setupShadow(JNIEnv* env, jobject clazz, |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 500 | OpenGLRenderer* renderer, jfloat radius, jfloat dx, jfloat dy, jint color) { |
| 501 | renderer->setupShadow(radius, dx, dy, color); |
| 502 | } |
| 503 | |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 504 | // ---------------------------------------------------------------------------- |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 505 | // Draw filters |
| 506 | // ---------------------------------------------------------------------------- |
| 507 | |
| 508 | static void android_view_GLES20Canvas_setupPaintFilter(JNIEnv* env, jobject clazz, |
| 509 | OpenGLRenderer* renderer, jint clearBits, jint setBits) { |
| 510 | renderer->setupPaintFilter(clearBits, setBits); |
| 511 | } |
| 512 | |
| 513 | static void android_view_GLES20Canvas_resetPaintFilter(JNIEnv* env, jobject clazz, |
| 514 | OpenGLRenderer* renderer) { |
| 515 | renderer->resetPaintFilter(); |
| 516 | } |
| 517 | |
| 518 | // ---------------------------------------------------------------------------- |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 519 | // Text |
| 520 | // ---------------------------------------------------------------------------- |
| 521 | |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 522 | static void renderText(OpenGLRenderer* renderer, const jchar* text, int count, |
| 523 | jfloat x, jfloat y, int flags, SkPaint* paint) { |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 524 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, |
| 525 | text, 0, count, count, flags); |
Fabrice Di Meglio | 2ea75880 | 2011-05-12 17:42:06 -0700 | [diff] [blame] | 526 | if (value == NULL) { |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 527 | return; |
Fabrice Di Meglio | 2ea75880 | 2011-05-12 17:42:06 -0700 | [diff] [blame] | 528 | } |
Fabrice Di Meglio | 5c863f7 | 2011-10-05 18:11:59 -0700 | [diff] [blame] | 529 | const jchar* glyphs = value->getGlyphs(); |
| 530 | size_t glyphsCount = value->getGlyphsCount(); |
Fabrice Di Meglio | 79df532 | 2011-09-19 15:17:56 -0700 | [diff] [blame] | 531 | int bytesCount = glyphsCount * sizeof(jchar); |
| 532 | renderer->drawText((const char*) glyphs, bytesCount, glyphsCount, x, y, paint); |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 535 | static void renderTextOnPath(OpenGLRenderer* renderer, const jchar* text, int count, |
| 536 | SkPath* path, jfloat hOffset, jfloat vOffset, int flags, SkPaint* paint) { |
| 537 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, |
| 538 | text, 0, count, count, flags); |
| 539 | if (value == NULL) { |
| 540 | return; |
| 541 | } |
| 542 | const jchar* glyphs = value->getGlyphs(); |
| 543 | size_t glyphsCount = value->getGlyphsCount(); |
| 544 | int bytesCount = glyphsCount * sizeof(jchar); |
| 545 | renderer->drawTextOnPath((const char*) glyphs, bytesCount, glyphsCount, path, |
| 546 | hOffset, vOffset, paint); |
| 547 | } |
| 548 | |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 549 | static void renderTextRun(OpenGLRenderer* renderer, const jchar* text, |
| 550 | jint start, jint count, jint contextCount, jfloat x, jfloat y, |
| 551 | int flags, SkPaint* paint) { |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 552 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, |
| 553 | text, start, count, contextCount, flags); |
Fabrice Di Meglio | 2ea75880 | 2011-05-12 17:42:06 -0700 | [diff] [blame] | 554 | if (value == NULL) { |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 555 | return; |
Fabrice Di Meglio | 2ea75880 | 2011-05-12 17:42:06 -0700 | [diff] [blame] | 556 | } |
Fabrice Di Meglio | 5c863f7 | 2011-10-05 18:11:59 -0700 | [diff] [blame] | 557 | const jchar* glyphs = value->getGlyphs(); |
| 558 | size_t glyphsCount = value->getGlyphsCount(); |
Fabrice Di Meglio | 79df532 | 2011-09-19 15:17:56 -0700 | [diff] [blame] | 559 | int bytesCount = glyphsCount * sizeof(jchar); |
| 560 | renderer->drawText((const char*) glyphs, bytesCount, glyphsCount, x, y, paint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 563 | static void android_view_GLES20Canvas_drawTextArray(JNIEnv* env, jobject clazz, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 564 | OpenGLRenderer* renderer, jcharArray text, jint index, jint count, |
| 565 | jfloat x, jfloat y, jint flags, SkPaint* paint) { |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 566 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 567 | renderText(renderer, textArray + index, count, x, y, flags, paint); |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 568 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 569 | } |
| 570 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 571 | static void android_view_GLES20Canvas_drawText(JNIEnv* env, jobject clazz, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 572 | OpenGLRenderer* renderer, jstring text, jint start, jint end, |
| 573 | jfloat x, jfloat y, jint flags, SkPaint* paint) { |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 574 | const jchar* textArray = env->GetStringChars(text, NULL); |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 575 | renderText(renderer, textArray + start, end - start, x, y, flags, paint); |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 576 | env->ReleaseStringChars(text, textArray); |
| 577 | } |
| 578 | |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 579 | static void android_view_GLES20Canvas_drawTextArrayOnPath(JNIEnv* env, jobject clazz, |
| 580 | OpenGLRenderer* renderer, jcharArray text, jint index, jint count, |
| 581 | SkPath* path, jfloat hOffset, jfloat vOffset, jint flags, SkPaint* paint) { |
| 582 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 583 | renderTextOnPath(renderer, textArray + index, count, path, |
| 584 | hOffset, vOffset, flags, paint); |
| 585 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 586 | } |
| 587 | |
| 588 | static void android_view_GLES20Canvas_drawTextOnPath(JNIEnv* env, jobject clazz, |
| 589 | OpenGLRenderer* renderer, jstring text, jint start, jint end, |
| 590 | SkPath* path, jfloat hOffset, jfloat vOffset, jint flags, SkPaint* paint) { |
| 591 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 592 | renderTextOnPath(renderer, textArray + start, end - start, path, |
| 593 | hOffset, vOffset, flags, paint); |
| 594 | env->ReleaseStringChars(text, textArray); |
| 595 | } |
| 596 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 597 | static void android_view_GLES20Canvas_drawTextRunArray(JNIEnv* env, jobject clazz, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 598 | OpenGLRenderer* renderer, jcharArray text, jint index, jint count, |
| 599 | jint contextIndex, jint contextCount, jfloat x, jfloat y, jint dirFlags, |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 600 | SkPaint* paint) { |
| 601 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 602 | renderTextRun(renderer, textArray + contextIndex, index - contextIndex, |
| 603 | count, contextCount, x, y, dirFlags, paint); |
| 604 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 605 | } |
| 606 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 607 | static void android_view_GLES20Canvas_drawTextRun(JNIEnv* env, jobject clazz, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 608 | OpenGLRenderer* renderer, jstring text, jint start, jint end, |
| 609 | jint contextStart, int contextEnd, jfloat x, jfloat y, jint dirFlags, |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 610 | SkPaint* paint) { |
| 611 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 612 | jint count = end - start; |
| 613 | jint contextCount = contextEnd - contextStart; |
| 614 | renderTextRun(renderer, textArray + contextStart, start - contextStart, |
| 615 | count, contextCount, x, y, dirFlags, paint); |
| 616 | env->ReleaseStringChars(text, textArray); |
| 617 | } |
| 618 | |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 619 | static void renderPosText(OpenGLRenderer* renderer, const jchar* text, int count, |
| 620 | const jfloat* positions, jint dirFlags, SkPaint* paint) { |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 621 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, |
| 622 | text, 0, count, count, dirFlags); |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 623 | if (value == NULL) { |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 624 | return; |
| 625 | } |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 626 | const jchar* glyphs = value->getGlyphs(); |
| 627 | size_t glyphsCount = value->getGlyphsCount(); |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 628 | if (count < int(glyphsCount)) glyphsCount = count; |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 629 | int bytesCount = glyphsCount * sizeof(jchar); |
| 630 | |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 631 | renderer->drawPosText((const char*) glyphs, bytesCount, glyphsCount, positions, paint); |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | static void android_view_GLES20Canvas_drawPosTextArray(JNIEnv* env, jobject clazz, |
| 635 | OpenGLRenderer* renderer, jcharArray text, jint index, jint count, |
| 636 | jfloatArray pos, SkPaint* paint) { |
| 637 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 638 | jfloat* positions = env->GetFloatArrayElements(pos, NULL); |
| 639 | |
| 640 | renderPosText(renderer, textArray + index, count, positions, kBidi_LTR, paint); |
| 641 | |
| 642 | env->ReleaseFloatArrayElements(pos, positions, JNI_ABORT); |
| 643 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 644 | } |
| 645 | |
| 646 | static void android_view_GLES20Canvas_drawPosText(JNIEnv* env, jobject clazz, |
| 647 | OpenGLRenderer* renderer, jstring text, jint start, jint end, |
| 648 | jfloatArray pos, SkPaint* paint) { |
| 649 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 650 | jfloat* positions = env->GetFloatArrayElements(pos, NULL); |
| 651 | |
| 652 | renderPosText(renderer, textArray + start, end - start, positions, kBidi_LTR, paint); |
| 653 | |
| 654 | env->ReleaseFloatArrayElements(pos, positions, JNI_ABORT); |
| 655 | env->ReleaseStringChars(text, textArray); |
| 656 | } |
| 657 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 658 | // ---------------------------------------------------------------------------- |
| 659 | // Display lists |
| 660 | // ---------------------------------------------------------------------------- |
| 661 | |
Chet Haase | 5977baa | 2011-01-05 18:01:22 -0800 | [diff] [blame] | 662 | static DisplayList* android_view_GLES20Canvas_getDisplayList(JNIEnv* env, |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 663 | jobject clazz, DisplayListRenderer* renderer, DisplayList* displayList) { |
| 664 | return renderer->getDisplayList(displayList); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 667 | static jint android_view_GLES20Canvas_getDisplayListSize(JNIEnv* env, |
| 668 | jobject clazz, DisplayList* displayList) { |
| 669 | return displayList->getSize(); |
| 670 | } |
| 671 | |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 672 | static void android_view_GLES20Canvas_setDisplayListName(JNIEnv* env, |
| 673 | jobject clazz, DisplayList* displayList, jstring name) { |
| 674 | if (name != NULL) { |
| 675 | const char* textArray = env->GetStringUTFChars(name, NULL); |
| 676 | displayList->setName(textArray); |
| 677 | env->ReleaseStringUTFChars(name, textArray); |
| 678 | } |
| 679 | } |
| 680 | |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 681 | static OpenGLRenderer* android_view_GLES20Canvas_createDisplayListRenderer(JNIEnv* env, |
| 682 | jobject clazz) { |
| 683 | return new DisplayListRenderer; |
| 684 | } |
| 685 | |
| 686 | static void android_view_GLES20Canvas_resetDisplayListRenderer(JNIEnv* env, |
Chet Haase | 5977baa | 2011-01-05 18:01:22 -0800 | [diff] [blame] | 687 | jobject clazz, DisplayListRenderer* renderer) { |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 688 | renderer->reset(); |
Chet Haase | 5977baa | 2011-01-05 18:01:22 -0800 | [diff] [blame] | 689 | } |
| 690 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 691 | static void android_view_GLES20Canvas_destroyDisplayList(JNIEnv* env, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 692 | jobject clazz, DisplayList* displayList) { |
Romain Guy | bb0acdf | 2012-03-05 13:44:35 -0800 | [diff] [blame] | 693 | DisplayList::destroyDisplayListDeferred(displayList); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 696 | static jint android_view_GLES20Canvas_drawDisplayList(JNIEnv* env, |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 697 | jobject clazz, OpenGLRenderer* renderer, DisplayList* displayList, |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 698 | jobject dirty, jint flags) { |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 699 | android::uirenderer::Rect bounds; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 700 | status_t status = renderer->drawDisplayList(displayList, bounds, flags); |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 701 | if (status != DrawGlInfo::kStatusDone && dirty != NULL) { |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 702 | env->CallVoidMethod(dirty, gRectClassInfo.set, |
| 703 | int(bounds.left), int(bounds.top), int(bounds.right), int(bounds.bottom)); |
| 704 | } |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 705 | return status; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 708 | static void android_view_GLES20Canvas_outputDisplayList(JNIEnv* env, |
| 709 | jobject clazz, OpenGLRenderer* renderer, DisplayList* displayList) { |
| 710 | renderer->outputDisplayList(displayList); |
| 711 | } |
| 712 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 713 | // ---------------------------------------------------------------------------- |
| 714 | // Layers |
| 715 | // ---------------------------------------------------------------------------- |
| 716 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 717 | static void android_view_GLES20Canvas_interrupt(JNIEnv* env, jobject clazz, |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 718 | OpenGLRenderer* renderer) { |
| 719 | renderer->interrupt(); |
| 720 | } |
| 721 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 722 | static void android_view_GLES20Canvas_resume(JNIEnv* env, jobject clazz, |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 723 | OpenGLRenderer* renderer) { |
| 724 | renderer->resume(); |
| 725 | } |
| 726 | |
| 727 | static OpenGLRenderer* android_view_GLES20Canvas_createLayerRenderer(JNIEnv* env, |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 728 | jobject clazz, Layer* layer) { |
| 729 | if (layer) { |
| 730 | return new LayerRenderer(layer); |
| 731 | } |
| 732 | return NULL; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 733 | } |
| 734 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 735 | static Layer* android_view_GLES20Canvas_createTextureLayer(JNIEnv* env, jobject clazz, |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 736 | jboolean isOpaque, jintArray layerInfo) { |
| 737 | Layer* layer = LayerRenderer::createTextureLayer(isOpaque); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 738 | |
| 739 | if (layer) { |
| 740 | jint* storage = env->GetIntArrayElements(layerInfo, NULL); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 741 | storage[0] = layer->getTexture(); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 742 | env->ReleaseIntArrayElements(layerInfo, storage, 0); |
| 743 | } |
| 744 | |
| 745 | return layer; |
| 746 | } |
| 747 | |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 748 | static Layer* android_view_GLES20Canvas_createLayer(JNIEnv* env, jobject clazz, |
| 749 | jint width, jint height, jboolean isOpaque, jintArray layerInfo) { |
| 750 | Layer* layer = LayerRenderer::createLayer(width, height, isOpaque); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 751 | |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 752 | if (layer) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 753 | jint* storage = env->GetIntArrayElements(layerInfo, NULL); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 754 | storage[0] = layer->getWidth(); |
| 755 | storage[1] = layer->getHeight(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 756 | env->ReleaseIntArrayElements(layerInfo, storage, 0); |
| 757 | } |
| 758 | |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 759 | return layer; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 760 | } |
| 761 | |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 762 | static void android_view_GLES20Canvas_resizeLayer(JNIEnv* env, jobject clazz, |
| 763 | Layer* layer, jint width, jint height, jintArray layerInfo) { |
| 764 | LayerRenderer::resizeLayer(layer, width, height); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 765 | |
| 766 | jint* storage = env->GetIntArrayElements(layerInfo, NULL); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 767 | storage[0] = layer->getWidth(); |
| 768 | storage[1] = layer->getHeight(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 769 | env->ReleaseIntArrayElements(layerInfo, storage, 0); |
| 770 | } |
| 771 | |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 772 | static void android_view_GLES20Canvas_setOpaqueLayer(JNIEnv* env, jobject clazz, |
| 773 | Layer* layer, jboolean isOpaque) { |
| 774 | if (layer) { |
| 775 | layer->setBlend(!isOpaque); |
| 776 | } |
| 777 | } |
| 778 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 779 | static void android_view_GLES20Canvas_updateTextureLayer(JNIEnv* env, jobject clazz, |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 780 | Layer* layer, jint width, jint height, jboolean isOpaque, jobject surface) { |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 781 | float transform[16]; |
Romain Guy | e5e0c50 | 2011-06-15 15:18:31 -0700 | [diff] [blame] | 782 | sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, surface)); |
| 783 | |
Mathias Agopian | df07148 | 2012-05-18 16:58:00 -0700 | [diff] [blame] | 784 | if (surfaceTexture->updateTexImage() == NO_ERROR) { |
| 785 | surfaceTexture->getTransformMatrix(transform); |
| 786 | GLenum renderTarget = surfaceTexture->getCurrentTextureTarget(); |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 787 | |
Mathias Agopian | df07148 | 2012-05-18 16:58:00 -0700 | [diff] [blame] | 788 | LayerRenderer::updateTextureLayer(layer, width, height, isOpaque, renderTarget, transform); |
| 789 | } |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 792 | static void android_view_GLES20Canvas_updateRenderLayer(JNIEnv* env, jobject clazz, |
| 793 | Layer* layer, OpenGLRenderer* renderer, DisplayList* displayList, |
| 794 | jint left, jint top, jint right, jint bottom) { |
| 795 | layer->updateDeferred(renderer, displayList, left, top, right, bottom); |
| 796 | } |
| 797 | |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 798 | static void android_view_GLES20Canvas_setTextureLayerTransform(JNIEnv* env, jobject clazz, |
| 799 | Layer* layer, SkMatrix* matrix) { |
| 800 | |
| 801 | layer->getTransform().load(*matrix); |
| 802 | } |
| 803 | |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 804 | static void android_view_GLES20Canvas_destroyLayer(JNIEnv* env, jobject clazz, Layer* layer) { |
| 805 | LayerRenderer::destroyLayer(layer); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 806 | } |
| 807 | |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 808 | static void android_view_GLES20Canvas_destroyLayerDeferred(JNIEnv* env, |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 809 | jobject clazz, Layer* layer) { |
| 810 | LayerRenderer::destroyLayerDeferred(layer); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 811 | } |
| 812 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 813 | static void android_view_GLES20Canvas_drawLayer(JNIEnv* env, jobject clazz, |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 814 | OpenGLRenderer* renderer, Layer* layer, jfloat x, jfloat y, SkPaint* paint) { |
| 815 | renderer->drawLayer(layer, x, y, paint); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 816 | } |
| 817 | |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 818 | static jboolean android_view_GLES20Canvas_copyLayer(JNIEnv* env, jobject clazz, |
| 819 | Layer* layer, SkBitmap* bitmap) { |
| 820 | return LayerRenderer::copyLayer(layer, bitmap); |
| 821 | } |
| 822 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 823 | #endif // USE_OPENGL_RENDERER |
| 824 | |
| 825 | // ---------------------------------------------------------------------------- |
| 826 | // Common |
| 827 | // ---------------------------------------------------------------------------- |
| 828 | |
| 829 | static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz) { |
| 830 | #ifdef USE_OPENGL_RENDERER |
Jesse Hall | 4406345 | 2011-12-01 11:27:45 -0800 | [diff] [blame] | 831 | char prop[PROPERTY_VALUE_MAX]; |
| 832 | if (property_get("ro.kernel.qemu", prop, NULL) == 0) { |
| 833 | // not in the emulator |
| 834 | return JNI_TRUE; |
| 835 | } |
| 836 | // In the emulator this property will be set to 1 when hardware GLES is |
| 837 | // enabled, 0 otherwise. On old emulator versions it will be undefined. |
| 838 | property_get("ro.kernel.qemu.gles", prop, "0"); |
| 839 | return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE; |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 840 | #else |
| 841 | return JNI_FALSE; |
| 842 | #endif |
| 843 | } |
| 844 | |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 845 | // ---------------------------------------------------------------------------- |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 846 | // Logging |
| 847 | // ---------------------------------------------------------------------------- |
| 848 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 849 | static void |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 850 | android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) { |
Chet Haase | 905787a | 2011-04-01 14:33:02 -0700 | [diff] [blame] | 851 | #ifdef USE_OPENGL_RENDERER |
Elliott Hughes | a3804cf | 2011-04-11 16:50:19 -0700 | [diff] [blame] | 852 | int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); |
Chet Haase | 0865d33 | 2011-04-01 14:33:02 -0700 | [diff] [blame] | 853 | android::uirenderer::DisplayList::outputLogBuffer(fd); |
Chet Haase | 905787a | 2011-04-01 14:33:02 -0700 | [diff] [blame] | 854 | #endif // USE_OPENGL_RENDERER |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | // ---------------------------------------------------------------------------- |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 858 | // JNI Glue |
| 859 | // ---------------------------------------------------------------------------- |
| 860 | |
| 861 | const char* const kClassPathName = "android/view/GLES20Canvas"; |
| 862 | |
| 863 | static JNINativeMethod gMethods[] = { |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 864 | { "nIsAvailable", "()Z", (void*) android_view_GLES20Canvas_isAvailable }, |
| 865 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 866 | #ifdef USE_OPENGL_RENDERER |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 867 | { "nFlushCaches", "(I)V", (void*) android_view_GLES20Canvas_flushCaches }, |
| 868 | { "nInitCaches", "()V", (void*) android_view_GLES20Canvas_initCaches }, |
| 869 | { "nTerminateCaches", "()V", (void*) android_view_GLES20Canvas_terminateCaches }, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 870 | |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 871 | { "nCreateRenderer", "()I", (void*) android_view_GLES20Canvas_createRenderer }, |
| 872 | { "nDestroyRenderer", "(I)V", (void*) android_view_GLES20Canvas_destroyRenderer }, |
| 873 | { "nSetViewport", "(III)V", (void*) android_view_GLES20Canvas_setViewport }, |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 874 | { "nPrepare", "(IZ)I", (void*) android_view_GLES20Canvas_prepare }, |
| 875 | { "nPrepareDirty", "(IIIIIZ)I", (void*) android_view_GLES20Canvas_prepareDirty }, |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 876 | { "nFinish", "(I)V", (void*) android_view_GLES20Canvas_finish }, |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 877 | |
Romain Guy | 530041d | 2012-01-25 18:56:29 -0800 | [diff] [blame] | 878 | { "nGetStencilSize", "()I", (void*) android_view_GLES20Canvas_getStencilSize }, |
| 879 | |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 880 | { "nCallDrawGLFunction", "(II)I", (void*) android_view_GLES20Canvas_callDrawGLFunction }, |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 881 | { "nDetachFunctor", "(II)V", (void*) android_view_GLES20Canvas_detachFunctor }, |
| 882 | { "nAttachFunctor", "(II)V", (void*) android_view_GLES20Canvas_attachFunctor }, |
| 883 | { "nInvokeFunctors", "(ILandroid/graphics/Rect;)I", |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 884 | (void*) android_view_GLES20Canvas_invokeFunctors }, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 885 | |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 886 | { "nSave", "(II)I", (void*) android_view_GLES20Canvas_save }, |
| 887 | { "nRestore", "(I)V", (void*) android_view_GLES20Canvas_restore }, |
| 888 | { "nRestoreToCount", "(II)V", (void*) android_view_GLES20Canvas_restoreToCount }, |
| 889 | { "nGetSaveCount", "(I)I", (void*) android_view_GLES20Canvas_getSaveCount }, |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 890 | |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 891 | { "nSaveLayer", "(IFFFFII)I", (void*) android_view_GLES20Canvas_saveLayer }, |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 892 | { "nSaveLayer", "(III)I", (void*) android_view_GLES20Canvas_saveLayerClip }, |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 893 | { "nSaveLayerAlpha", "(IFFFFII)I", (void*) android_view_GLES20Canvas_saveLayerAlpha }, |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 894 | { "nSaveLayerAlpha", "(III)I", (void*) android_view_GLES20Canvas_saveLayerAlphaClip }, |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 895 | |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 896 | { "nQuickReject", "(IFFFFI)Z", (void*) android_view_GLES20Canvas_quickReject }, |
| 897 | { "nClipRect", "(IFFFFI)Z", (void*) android_view_GLES20Canvas_clipRectF }, |
| 898 | { "nClipRect", "(IIIIII)Z", (void*) android_view_GLES20Canvas_clipRect }, |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 899 | |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 900 | { "nTranslate", "(IFF)V", (void*) android_view_GLES20Canvas_translate }, |
| 901 | { "nRotate", "(IF)V", (void*) android_view_GLES20Canvas_rotate }, |
| 902 | { "nScale", "(IFF)V", (void*) android_view_GLES20Canvas_scale }, |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 903 | { "nSkew", "(IFF)V", (void*) android_view_GLES20Canvas_skew }, |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 904 | |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 905 | { "nSetMatrix", "(II)V", (void*) android_view_GLES20Canvas_setMatrix }, |
| 906 | { "nGetMatrix", "(II)V", (void*) android_view_GLES20Canvas_getMatrix }, |
| 907 | { "nConcatMatrix", "(II)V", (void*) android_view_GLES20Canvas_concatMatrix }, |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 908 | |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 909 | { "nDrawBitmap", "(II[BFFI)V", (void*) android_view_GLES20Canvas_drawBitmap }, |
| 910 | { "nDrawBitmap", "(II[BFFFFFFFFI)V",(void*) android_view_GLES20Canvas_drawBitmapRect }, |
| 911 | { "nDrawBitmap", "(II[BII)V", (void*) android_view_GLES20Canvas_drawBitmapMatrix }, |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 912 | { "nDrawBitmap", "(I[IIIFFIIZI)V", (void*) android_view_GLES20Canvas_drawBitmapData }, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 913 | |
| 914 | { "nDrawBitmapMesh", "(II[BII[FI[III)V",(void*) android_view_GLES20Canvas_drawBitmapMesh }, |
| 915 | |
| 916 | { "nDrawPatch", "(II[B[BFFFFI)V", (void*) android_view_GLES20Canvas_drawPatch }, |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 917 | |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 918 | { "nDrawColor", "(III)V", (void*) android_view_GLES20Canvas_drawColor }, |
| 919 | { "nDrawRect", "(IFFFFI)V", (void*) android_view_GLES20Canvas_drawRect }, |
Romain Guy | a48a1a8 | 2010-08-10 14:59:15 -0700 | [diff] [blame] | 920 | { "nDrawRects", "(III)V", (void*) android_view_GLES20Canvas_drawRects }, |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 921 | { "nDrawRoundRect", "(IFFFFFFI)V", (void*) android_view_GLES20Canvas_drawRoundRect }, |
| 922 | { "nDrawCircle", "(IFFFI)V", (void*) android_view_GLES20Canvas_drawCircle }, |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 923 | { "nDrawOval", "(IFFFFI)V", (void*) android_view_GLES20Canvas_drawOval }, |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 924 | { "nDrawArc", "(IFFFFFFZI)V", (void*) android_view_GLES20Canvas_drawArc }, |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 925 | { "nDrawPoints", "(I[FIII)V", (void*) android_view_GLES20Canvas_drawPoints }, |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 926 | |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 927 | { "nDrawPath", "(III)V", (void*) android_view_GLES20Canvas_drawPath }, |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 928 | { "nDrawLines", "(I[FIII)V", (void*) android_view_GLES20Canvas_drawLines }, |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 929 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 930 | { "nResetModifiers", "(II)V", (void*) android_view_GLES20Canvas_resetModifiers }, |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 931 | { "nSetupShader", "(II)V", (void*) android_view_GLES20Canvas_setupShader }, |
| 932 | { "nSetupColorFilter", "(II)V", (void*) android_view_GLES20Canvas_setupColorFilter }, |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 933 | { "nSetupShadow", "(IFFFI)V", (void*) android_view_GLES20Canvas_setupShadow }, |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 934 | |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 935 | { "nSetupPaintFilter", "(III)V", (void*) android_view_GLES20Canvas_setupPaintFilter }, |
| 936 | { "nResetPaintFilter", "(I)V", (void*) android_view_GLES20Canvas_resetPaintFilter }, |
| 937 | |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 938 | { "nDrawText", "(I[CIIFFII)V", (void*) android_view_GLES20Canvas_drawTextArray }, |
| 939 | { "nDrawText", "(ILjava/lang/String;IIFFII)V", |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 940 | (void*) android_view_GLES20Canvas_drawText }, |
| 941 | |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 942 | { "nDrawTextOnPath", "(I[CIIIFFII)V", (void*) android_view_GLES20Canvas_drawTextArrayOnPath }, |
| 943 | { "nDrawTextOnPath", "(ILjava/lang/String;IIIFFII)V", |
| 944 | (void*) android_view_GLES20Canvas_drawTextOnPath }, |
| 945 | |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 946 | { "nDrawTextRun", "(I[CIIIIFFII)V", (void*) android_view_GLES20Canvas_drawTextRunArray }, |
| 947 | { "nDrawTextRun", "(ILjava/lang/String;IIIIFFII)V", |
| 948 | (void*) android_view_GLES20Canvas_drawTextRun }, |
| 949 | |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 950 | { "nDrawPosText", "(I[CII[FI)V", (void*) android_view_GLES20Canvas_drawPosTextArray }, |
| 951 | { "nDrawPosText", "(ILjava/lang/String;II[FI)V", |
| 952 | (void*) android_view_GLES20Canvas_drawPosText }, |
| 953 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 954 | { "nGetClipBounds", "(ILandroid/graphics/Rect;)Z", |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 955 | (void*) android_view_GLES20Canvas_getClipBounds }, |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 956 | |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 957 | { "nGetDisplayList", "(II)I", (void*) android_view_GLES20Canvas_getDisplayList }, |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 958 | { "nDestroyDisplayList", "(I)V", (void*) android_view_GLES20Canvas_destroyDisplayList }, |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 959 | { "nGetDisplayListSize", "(I)I", (void*) android_view_GLES20Canvas_getDisplayListSize }, |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 960 | { "nSetDisplayListName", "(ILjava/lang/String;)V", |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 961 | (void*) android_view_GLES20Canvas_setDisplayListName }, |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 962 | { "nDrawDisplayList", "(IILandroid/graphics/Rect;I)I", |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 963 | (void*) android_view_GLES20Canvas_drawDisplayList }, |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 964 | |
| 965 | { "nCreateDisplayListRenderer", "()I", (void*) android_view_GLES20Canvas_createDisplayListRenderer }, |
| 966 | { "nResetDisplayListRenderer", "(I)V", (void*) android_view_GLES20Canvas_resetDisplayListRenderer }, |
| 967 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 968 | { "nOutputDisplayList", "(II)V", (void*) android_view_GLES20Canvas_outputDisplayList }, |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 969 | { "nInterrupt", "(I)V", (void*) android_view_GLES20Canvas_interrupt }, |
| 970 | { "nResume", "(I)V", (void*) android_view_GLES20Canvas_resume }, |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 971 | |
| 972 | { "nCreateLayerRenderer", "(I)I", (void*) android_view_GLES20Canvas_createLayerRenderer }, |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 973 | { "nCreateLayer", "(IIZ[I)I", (void*) android_view_GLES20Canvas_createLayer }, |
| 974 | { "nResizeLayer", "(III[I)V" , (void*) android_view_GLES20Canvas_resizeLayer }, |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 975 | { "nSetOpaqueLayer", "(IZ)V", (void*) android_view_GLES20Canvas_setOpaqueLayer }, |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 976 | { "nCreateTextureLayer", "(Z[I)I", (void*) android_view_GLES20Canvas_createTextureLayer }, |
| 977 | { "nUpdateTextureLayer", "(IIIZLandroid/graphics/SurfaceTexture;)V", |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 978 | (void*) android_view_GLES20Canvas_updateTextureLayer }, |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 979 | { "nUpdateRenderLayer", "(IIIIIII)V", (void*) android_view_GLES20Canvas_updateRenderLayer }, |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 980 | { "nDestroyLayer", "(I)V", (void*) android_view_GLES20Canvas_destroyLayer }, |
| 981 | { "nDestroyLayerDeferred", "(I)V", (void*) android_view_GLES20Canvas_destroyLayerDeferred }, |
| 982 | { "nDrawLayer", "(IIFFI)V", (void*) android_view_GLES20Canvas_drawLayer }, |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 983 | { "nCopyLayer", "(II)Z", (void*) android_view_GLES20Canvas_copyLayer }, |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 984 | |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 985 | { "nSetTextureLayerTransform", "(II)V", (void*) android_view_GLES20Canvas_setTextureLayerTransform }, |
| 986 | |
Romain Guy | f61970fc | 2011-07-07 14:10:06 -0700 | [diff] [blame] | 987 | { "nGetMaximumTextureWidth", "()I", (void*) android_view_GLES20Canvas_getMaxTextureWidth }, |
| 988 | { "nGetMaximumTextureHeight", "()I", (void*) android_view_GLES20Canvas_getMaxTextureHeight }, |
| 989 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 990 | #endif |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 991 | }; |
| 992 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 993 | static JNINativeMethod gActivityThreadMethods[] = { |
| 994 | { "dumpGraphicsInfo", "(Ljava/io/FileDescriptor;)V", |
| 995 | (void*) android_app_ActivityThread_dumpGraphics } |
| 996 | }; |
| 997 | |
| 998 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 999 | #ifdef USE_OPENGL_RENDERER |
| 1000 | #define FIND_CLASS(var, className) \ |
| 1001 | var = env->FindClass(className); \ |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 1002 | LOG_FATAL_IF(! var, "Unable to find class " className); |
| 1003 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 1004 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \ |
| 1005 | var = env->GetMethodID(clazz, methodName, methodDescriptor); \ |
| 1006 | LOG_FATAL_IF(! var, "Unable to find method " methodName); |
| 1007 | #else |
| 1008 | #define FIND_CLASS(var, className) |
| 1009 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) |
| 1010 | #endif |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 1011 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1012 | int register_android_view_GLES20Canvas(JNIEnv* env) { |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 1013 | jclass clazz; |
| 1014 | FIND_CLASS(clazz, "android/graphics/Rect"); |
| 1015 | GET_METHOD_ID(gRectClassInfo.set, clazz, "set", "(IIII)V"); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 1016 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1017 | return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); |
| 1018 | } |
| 1019 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1020 | const char* const kActivityThreadPathName = "android/app/ActivityThread"; |
| 1021 | |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 1022 | int register_android_app_ActivityThread(JNIEnv* env) { |
| 1023 | return AndroidRuntime::registerNativeMethods(env, kActivityThreadPathName, |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1024 | gActivityThreadMethods, NELEM(gActivityThreadMethods)); |
| 1025 | } |
| 1026 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1027 | }; |