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