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