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 | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 19 | #include "jni.h" |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 20 | #include "GraphicsJNI.h" |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 21 | #include <nativehelper/JNIHelp.h> |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 22 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 23 | #include <android_runtime/AndroidRuntime.h> |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 24 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 25 | #include <androidfw/ResourceTypes.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 26 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 27 | #include <private/hwui/DrawGlInfo.h> |
| 28 | |
| 29 | #include <cutils/properties.h> |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 30 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 31 | #include <SkBitmap.h> |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 32 | #include <SkCanvas.h> |
Leon Scroggins III | 57ee620 | 2014-06-04 18:51:07 -0400 | [diff] [blame] | 33 | #include <SkImageInfo.h> |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 34 | #include <SkMatrix.h> |
Chris Craik | 2ce9328 | 2014-06-23 17:48:09 -0700 | [diff] [blame] | 35 | #include <SkPorterDuff.h> |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 36 | #include <SkRegion.h> |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 37 | #include <SkScalerContext.h> |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 38 | #include <SkTemplates.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 39 | #include <SkXfermode.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 40 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 41 | #include <DisplayListRenderer.h> |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 42 | #include <Rect.h> |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 43 | #include <RenderNode.h> |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 44 | #include <CanvasProperty.h> |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 45 | #include <Paint.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 46 | |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 47 | #include "MinikinUtils.h" |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 48 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 49 | namespace android { |
| 50 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 51 | using namespace uirenderer; |
| 52 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 53 | /** |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 54 | * Note: DisplayListRenderer JNI layer is generated and compiled only on supported |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 55 | * devices. This means all the logic must be compiled only when the |
| 56 | * preprocessor variable USE_OPENGL_RENDERER is defined. |
| 57 | */ |
| 58 | #ifdef USE_OPENGL_RENDERER |
| 59 | |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 60 | // ---------------------------------------------------------------------------- |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 61 | // Defines |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 62 | // ---------------------------------------------------------------------------- |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 63 | |
| 64 | // Debug |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 65 | #define DEBUG_RENDERER 0 |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 66 | |
| 67 | // Debug |
| 68 | #if DEBUG_RENDERER |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 69 | #define RENDERER_LOGD(...) ALOGD(__VA_ARGS__) |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 70 | #else |
| 71 | #define RENDERER_LOGD(...) |
| 72 | #endif |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 73 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 74 | // ---------------------------------------------------------------------------- |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 75 | |
| 76 | static struct { |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 77 | jmethodID set; |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 78 | } gRectClassInfo; |
| 79 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 80 | // ---------------------------------------------------------------------------- |
| 81 | // Constructors |
| 82 | // ---------------------------------------------------------------------------- |
| 83 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 84 | static void android_view_GLES20Canvas_destroyRenderer(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 85 | jlong rendererPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 86 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
| 87 | RENDERER_LOGD("Destroy DisplayListRenderer"); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 88 | delete renderer; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | // ---------------------------------------------------------------------------- |
| 92 | // Setup |
| 93 | // ---------------------------------------------------------------------------- |
| 94 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 95 | static void android_view_GLES20Canvas_setViewport(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 96 | jlong rendererPtr, jint width, jint height) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 97 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 98 | renderer->setViewport(width, height); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 101 | static void android_view_GLES20Canvas_setHighContrastText(JNIEnv* env, jobject clazz, |
| 102 | jlong rendererPtr, jboolean highContrastText) { |
| 103 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
| 104 | renderer->setHighContrastText(highContrastText); |
| 105 | } |
| 106 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 107 | static void android_view_GLES20Canvas_insertReorderBarrier(JNIEnv* env, jobject clazz, |
| 108 | jlong rendererPtr, jboolean reorderEnable) { |
| 109 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
| 110 | renderer->insertReorderBarrier(reorderEnable); |
| 111 | } |
| 112 | |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 113 | static int android_view_GLES20Canvas_prepare(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 114 | jlong rendererPtr, jboolean opaque) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 115 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 116 | return renderer->prepare(opaque); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 119 | static int android_view_GLES20Canvas_prepareDirty(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 120 | jlong rendererPtr, jint left, jint top, jint right, jint bottom, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 121 | jboolean opaque) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 122 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 123 | return renderer->prepareDirty(left, top, right, bottom, opaque); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void android_view_GLES20Canvas_finish(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 127 | jlong rendererPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 128 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 129 | renderer->finish(); |
| 130 | } |
| 131 | |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 132 | static void android_view_GLES20Canvas_setProperty(JNIEnv* env, |
| 133 | jobject clazz, jstring name, jstring value) { |
| 134 | if (!Caches::hasInstance()) { |
| 135 | ALOGW("can't set property, no Caches instance"); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | if (name == NULL || value == NULL) { |
| 140 | ALOGW("can't set prop, null passed"); |
| 141 | } |
| 142 | |
| 143 | const char* nameCharArray = env->GetStringUTFChars(name, NULL); |
| 144 | const char* valueCharArray = env->GetStringUTFChars(value, NULL); |
| 145 | Caches::getInstance().setTempProperty(nameCharArray, valueCharArray); |
| 146 | env->ReleaseStringUTFChars(name, nameCharArray); |
| 147 | env->ReleaseStringUTFChars(name, valueCharArray); |
| 148 | } |
| 149 | |
Romain Guy | 530041d | 2012-01-25 18:56:29 -0800 | [diff] [blame] | 150 | // ---------------------------------------------------------------------------- |
| 151 | // Functor |
| 152 | // ---------------------------------------------------------------------------- |
| 153 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 154 | static jint android_view_GLES20Canvas_callDrawGLFunction(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 155 | jlong rendererPtr, jlong functorPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 156 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 157 | Functor* functor = reinterpret_cast<Functor*>(functorPtr); |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 158 | android::uirenderer::Rect dirty; |
| 159 | return renderer->callDrawGLFunction(functor, dirty); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 160 | } |
| 161 | |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 162 | // ---------------------------------------------------------------------------- |
| 163 | // Misc |
| 164 | // ---------------------------------------------------------------------------- |
| 165 | |
Romain Guy | f61970fc | 2011-07-07 14:10:06 -0700 | [diff] [blame] | 166 | static jint android_view_GLES20Canvas_getMaxTextureWidth(JNIEnv* env, jobject clazz) { |
| 167 | return Caches::getInstance().maxTextureSize; |
| 168 | } |
| 169 | |
| 170 | static jint android_view_GLES20Canvas_getMaxTextureHeight(JNIEnv* env, jobject clazz) { |
| 171 | return Caches::getInstance().maxTextureSize; |
| 172 | } |
| 173 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 174 | // ---------------------------------------------------------------------------- |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 175 | // State |
| 176 | // ---------------------------------------------------------------------------- |
| 177 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 178 | static jint android_view_GLES20Canvas_save(JNIEnv* env, jobject clazz, jlong rendererPtr, |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 179 | jint flags) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 180 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 181 | return renderer->save(flags); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 184 | static jint android_view_GLES20Canvas_getSaveCount(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 185 | jlong rendererPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 186 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 187 | return renderer->getSaveCount(); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 190 | static void android_view_GLES20Canvas_restore(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 191 | jlong rendererPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 192 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 193 | renderer->restore(); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 196 | static void android_view_GLES20Canvas_restoreToCount(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 197 | jlong rendererPtr, jint saveCount) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 198 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 199 | renderer->restoreToCount(saveCount); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // ---------------------------------------------------------------------------- |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 203 | // Layers |
| 204 | // ---------------------------------------------------------------------------- |
| 205 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 206 | static jint android_view_GLES20Canvas_saveLayer(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 207 | jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 208 | jlong paintPtr, jint saveFlags) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 209 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 210 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 211 | return renderer->saveLayer(left, top, right, bottom, paint, saveFlags); |
| 212 | } |
| 213 | |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 214 | static jint android_view_GLES20Canvas_saveLayerClip(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 215 | jlong rendererPtr, jlong paintPtr, jint saveFlags) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 216 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 217 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 218 | const android::uirenderer::Rect& bounds(renderer->getLocalClipBounds()); |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 219 | return renderer->saveLayer(bounds.left, bounds.top, bounds.right, bounds.bottom, |
| 220 | paint, saveFlags); |
| 221 | } |
| 222 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 223 | static jint android_view_GLES20Canvas_saveLayerAlpha(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 224 | jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom, |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 225 | jint alpha, jint saveFlags) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 226 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 227 | return renderer->saveLayerAlpha(left, top, right, bottom, alpha, saveFlags); |
| 228 | } |
| 229 | |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 230 | static jint android_view_GLES20Canvas_saveLayerAlphaClip(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 231 | jlong rendererPtr, jint alpha, jint saveFlags) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 232 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 233 | const android::uirenderer::Rect& bounds(renderer->getLocalClipBounds()); |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 234 | return renderer->saveLayerAlpha(bounds.left, bounds.top, bounds.right, bounds.bottom, |
| 235 | alpha, saveFlags); |
| 236 | } |
| 237 | |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 238 | // ---------------------------------------------------------------------------- |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 239 | // Clipping |
| 240 | // ---------------------------------------------------------------------------- |
| 241 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 242 | static jboolean android_view_GLES20Canvas_quickReject(JNIEnv* env, jobject clazz, |
| 243 | jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 244 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 245 | const bool result = renderer->quickRejectConservative(left, top, right, bottom); |
| 246 | return result ? JNI_TRUE : JNI_FALSE; |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 249 | static jboolean android_view_GLES20Canvas_clipRectF(JNIEnv* env, jobject clazz, |
| 250 | jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 251 | jint op) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 252 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 253 | const bool result = renderer->clipRect(left, top, right, bottom, |
| 254 | static_cast<SkRegion::Op>(op)); |
| 255 | return result ? JNI_TRUE : JNI_FALSE; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 258 | static jboolean android_view_GLES20Canvas_clipRect(JNIEnv* env, jobject clazz, |
| 259 | jlong rendererPtr, jint left, jint top, jint right, jint bottom, |
| 260 | jint op) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 261 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 262 | const bool result = renderer->clipRect(float(left), float(top), float(right), |
| 263 | float(bottom), |
| 264 | static_cast<SkRegion::Op>(op)); |
| 265 | return result ? JNI_TRUE : JNI_FALSE; |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 266 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 267 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 268 | static jboolean android_view_GLES20Canvas_clipPath(JNIEnv* env, jobject clazz, |
| 269 | jlong rendererPtr, jlong pathPtr, jint op) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 270 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 271 | SkPath* path = reinterpret_cast<SkPath*>(pathPtr); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 272 | const bool result = renderer->clipPath(path, static_cast<SkRegion::Op>(op)); |
| 273 | return result ? JNI_TRUE : JNI_FALSE; |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 276 | static jboolean android_view_GLES20Canvas_clipRegion(JNIEnv* env, jobject clazz, |
| 277 | jlong rendererPtr, jlong regionPtr, jint op) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 278 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 279 | SkRegion* region = reinterpret_cast<SkRegion*>(regionPtr); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 280 | const bool result = renderer->clipRegion(region, static_cast<SkRegion::Op>(op)); |
| 281 | return result ? JNI_TRUE : JNI_FALSE; |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 282 | } |
| 283 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 284 | static jboolean android_view_GLES20Canvas_getClipBounds(JNIEnv* env, jobject clazz, |
| 285 | jlong rendererPtr, jobject rect) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 286 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 287 | const android::uirenderer::Rect& bounds(renderer->getLocalClipBounds()); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 288 | |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 289 | env->CallVoidMethod(rect, gRectClassInfo.set, |
| 290 | int(bounds.left), int(bounds.top), int(bounds.right), int(bounds.bottom)); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 291 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 292 | return !bounds.isEmpty() ? JNI_TRUE : JNI_FALSE; |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 295 | // ---------------------------------------------------------------------------- |
| 296 | // Transforms |
| 297 | // ---------------------------------------------------------------------------- |
| 298 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 299 | static void android_view_GLES20Canvas_translate(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 300 | jlong rendererPtr, jfloat dx, jfloat dy) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 301 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 302 | renderer->translate(dx, dy); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 305 | static void android_view_GLES20Canvas_rotate(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 306 | jlong rendererPtr, jfloat degrees) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 307 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 308 | renderer->rotate(degrees); |
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_scale(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 312 | jlong rendererPtr, jfloat sx, jfloat sy) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 313 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 314 | renderer->scale(sx, sy); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 317 | static void android_view_GLES20Canvas_skew(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 318 | jlong rendererPtr, jfloat sx, jfloat sy) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 319 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 320 | renderer->skew(sx, sy); |
| 321 | } |
| 322 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 323 | static void android_view_GLES20Canvas_setMatrix(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 324 | jlong rendererPtr, jlong matrixPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 325 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 326 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr); |
Derek Sollenberger | 1390882 | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 327 | renderer->setMatrix(matrix ? *matrix : SkMatrix::I()); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 330 | static void android_view_GLES20Canvas_getMatrix(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 331 | jlong rendererPtr, jlong matrixPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 332 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 333 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 334 | renderer->getMatrix(matrix); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 337 | static void android_view_GLES20Canvas_concatMatrix(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 338 | jlong rendererPtr, jlong matrixPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 339 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 340 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr); |
Derek Sollenberger | 1390882 | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 341 | renderer->concatMatrix(*matrix); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | // ---------------------------------------------------------------------------- |
| 345 | // Drawing |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 346 | // ---------------------------------------------------------------------------- |
| 347 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 348 | static void android_view_GLES20Canvas_drawBitmap(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 349 | jlong rendererPtr, jlong bitmapPtr, jbyteArray buffer, |
| 350 | jfloat left, jfloat top, jlong paintPtr) { |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 351 | SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr); |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 352 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 353 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 354 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 355 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 356 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Chris Craik | 7964750 | 2014-08-06 13:42:24 -0700 | [diff] [blame] | 357 | |
| 358 | // apply transform directly to canvas, so it affects shaders correctly |
| 359 | renderer->save(SkCanvas::kMatrix_SaveFlag); |
| 360 | renderer->translate(left, top); |
| 361 | renderer->drawBitmap(bitmap, paint); |
| 362 | renderer->restore(); |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 365 | static void android_view_GLES20Canvas_drawBitmapRect(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 366 | jlong rendererPtr, jlong bitmapPtr, jbyteArray buffer, |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 367 | float srcLeft, float srcTop, float srcRight, float srcBottom, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 368 | float dstLeft, float dstTop, float dstRight, float dstBottom, jlong paintPtr) { |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 369 | SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr); |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 370 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 371 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 372 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 373 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 374 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | dbd77cd | 2010-07-09 10:36:05 -0700 | [diff] [blame] | 375 | renderer->drawBitmap(bitmap, srcLeft, srcTop, srcRight, srcBottom, |
| 376 | dstLeft, dstTop, dstRight, dstBottom, paint); |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 377 | } |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 378 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 379 | static void android_view_GLES20Canvas_drawBitmapMatrix(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 380 | jlong rendererPtr, jlong bitmapPtr, jbyteArray buffer, |
| 381 | jlong matrixPtr, jlong paintPtr) { |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 382 | SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr); |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 383 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 384 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 385 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 386 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 387 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 388 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Chris Craik | 7964750 | 2014-08-06 13:42:24 -0700 | [diff] [blame] | 389 | |
| 390 | // apply transform directly to canvas, so it affects shaders correctly |
| 391 | renderer->save(SkCanvas::kMatrix_SaveFlag); |
| 392 | renderer->concatMatrix(*matrix); |
| 393 | renderer->drawBitmap(bitmap, paint); |
| 394 | renderer->restore(); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 397 | static void android_view_GLES20Canvas_drawBitmapData(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 398 | jlong rendererPtr, jintArray colors, jint offset, jint stride, |
| 399 | jfloat left, jfloat top, jint width, jint height, jboolean hasAlpha, jlong paintPtr) { |
Leon Scroggins III | 57ee620 | 2014-06-04 18:51:07 -0400 | [diff] [blame] | 400 | // Note: If hasAlpha is false, kRGB_565_SkColorType will be used, which will |
| 401 | // correct the alphaType to kOpaque_SkAlphaType. |
Mike Reed | b933055 | 2014-06-16 17:31:48 -0400 | [diff] [blame] | 402 | const SkImageInfo info = SkImageInfo::Make(width, height, |
| 403 | hasAlpha ? kN32_SkColorType : kRGB_565_SkColorType, |
| 404 | kPremul_SkAlphaType); |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 405 | SkBitmap* bitmap = new SkBitmap; |
Mike Reed | b933055 | 2014-06-16 17:31:48 -0400 | [diff] [blame] | 406 | if (!bitmap->allocPixels(info)) { |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 407 | delete bitmap; |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 408 | return; |
| 409 | } |
| 410 | |
Leon Scroggins III | 57ee620 | 2014-06-04 18:51:07 -0400 | [diff] [blame] | 411 | if (!GraphicsJNI::SetPixels(env, colors, offset, stride, 0, 0, width, height, *bitmap)) { |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 412 | delete bitmap; |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 413 | return; |
| 414 | } |
| 415 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 416 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 417 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Chris Craik | 7964750 | 2014-08-06 13:42:24 -0700 | [diff] [blame] | 418 | |
| 419 | // apply transform directly to canvas, so it affects shaders correctly |
| 420 | renderer->save(SkCanvas::kMatrix_SaveFlag); |
| 421 | renderer->translate(left, top); |
| 422 | renderer->drawBitmapData(bitmap, paint); |
| 423 | renderer->restore(); |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 424 | |
Chris Craik | f23b25a | 2014-06-26 15:46:20 -0700 | [diff] [blame] | 425 | // Note - bitmap isn't deleted as DisplayListRenderer owns it now |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 428 | static void android_view_GLES20Canvas_drawBitmapMesh(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 429 | jlong rendererPtr, jlong bitmapPtr, jbyteArray buffer, |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 430 | jint meshWidth, jint meshHeight, jfloatArray vertices, jint offset, jintArray colors, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 431 | jint colorOffset, jlong paintPtr) { |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 432 | SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr); |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 433 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 434 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 435 | |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 436 | jfloat* verticesArray = vertices ? env->GetFloatArrayElements(vertices, NULL) + offset : NULL; |
| 437 | jint* colorsArray = colors ? env->GetIntArrayElements(colors, NULL) + colorOffset : NULL; |
| 438 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 439 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 440 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 441 | renderer->drawBitmapMesh(bitmap, meshWidth, meshHeight, verticesArray, colorsArray, paint); |
| 442 | |
| 443 | if (vertices) env->ReleaseFloatArrayElements(vertices, verticesArray, 0); |
| 444 | if (colors) env->ReleaseIntArrayElements(colors, colorsArray, 0); |
| 445 | } |
| 446 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 447 | static void android_view_GLES20Canvas_drawPatch(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 448 | jlong rendererPtr, jlong bitmapPtr, jbyteArray buffer, jlong patchPtr, |
| 449 | float left, float top, float right, float bottom, jlong paintPtr) { |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 450 | SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr); |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 451 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 452 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 453 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 454 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 455 | Res_png_9patch* patch = reinterpret_cast<Res_png_9patch*>(patchPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 456 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 457 | renderer->drawPatch(bitmap, patch, left, top, right, bottom, paint); |
Romain Guy | deba785 | 2010-07-07 17:54:48 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 460 | static void android_view_GLES20Canvas_drawColor(JNIEnv* env, jobject clazz, |
Chris Craik | 2ce9328 | 2014-06-23 17:48:09 -0700 | [diff] [blame] | 461 | jlong rendererPtr, jint color, jint modeHandle) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 462 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 2ce9328 | 2014-06-23 17:48:09 -0700 | [diff] [blame] | 463 | SkPorterDuff::Mode mode = static_cast<SkPorterDuff::Mode>(modeHandle); |
| 464 | renderer->drawColor(color, SkPorterDuff::ToXfermodeMode(mode)); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 467 | static void android_view_GLES20Canvas_drawRect(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 468 | jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 469 | jlong paintPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 470 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 471 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 472 | renderer->drawRect(left, top, right, bottom, paint); |
| 473 | } |
| 474 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 475 | static void android_view_GLES20Canvas_drawRoundRect(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 476 | jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 477 | jfloat rx, jfloat ry, jlong paintPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 478 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 479 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 480 | renderer->drawRoundRect(left, top, right, bottom, rx, ry, paint); |
| 481 | } |
| 482 | |
Jorim Jaggi | 072707d | 2014-09-15 17:20:08 +0200 | [diff] [blame] | 483 | static void android_view_GLES20Canvas_drawRoundRectProps(JNIEnv* env, jobject clazz, |
| 484 | jlong rendererPtr, jlong leftPropPtr, jlong topPropPtr, jlong rightPropPtr, |
| 485 | jlong bottomPropPtr, jlong rxPropPtr, jlong ryPropPtr, jlong paintPropPtr) { |
| 486 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
| 487 | CanvasPropertyPrimitive* leftProp = reinterpret_cast<CanvasPropertyPrimitive*>(leftPropPtr); |
| 488 | CanvasPropertyPrimitive* topProp = reinterpret_cast<CanvasPropertyPrimitive*>(topPropPtr); |
| 489 | CanvasPropertyPrimitive* rightProp = reinterpret_cast<CanvasPropertyPrimitive*>(rightPropPtr); |
| 490 | CanvasPropertyPrimitive* bottomProp = reinterpret_cast<CanvasPropertyPrimitive*>(bottomPropPtr); |
| 491 | CanvasPropertyPrimitive* rxProp = reinterpret_cast<CanvasPropertyPrimitive*>(rxPropPtr); |
| 492 | CanvasPropertyPrimitive* ryProp = reinterpret_cast<CanvasPropertyPrimitive*>(ryPropPtr); |
| 493 | CanvasPropertyPaint* paintProp = reinterpret_cast<CanvasPropertyPaint*>(paintPropPtr); |
| 494 | renderer->drawRoundRect(leftProp, topProp, rightProp, bottomProp, rxProp, ryProp, paintProp); |
| 495 | } |
| 496 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 497 | static void android_view_GLES20Canvas_drawCircle(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 498 | jlong rendererPtr, jfloat x, jfloat y, jfloat radius, jlong paintPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 499 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 500 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 501 | renderer->drawCircle(x, y, radius, paint); |
| 502 | } |
| 503 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 504 | static void android_view_GLES20Canvas_drawCircleProps(JNIEnv* env, jobject clazz, |
| 505 | jlong rendererPtr, jlong xPropPtr, jlong yPropPtr, jlong radiusPropPtr, jlong paintPropPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 506 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 507 | CanvasPropertyPrimitive* xProp = reinterpret_cast<CanvasPropertyPrimitive*>(xPropPtr); |
| 508 | CanvasPropertyPrimitive* yProp = reinterpret_cast<CanvasPropertyPrimitive*>(yPropPtr); |
| 509 | CanvasPropertyPrimitive* radiusProp = reinterpret_cast<CanvasPropertyPrimitive*>(radiusPropPtr); |
| 510 | CanvasPropertyPaint* paintProp = reinterpret_cast<CanvasPropertyPaint*>(paintPropPtr); |
| 511 | renderer->drawCircle(xProp, yProp, radiusProp, paintProp); |
| 512 | } |
| 513 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 514 | static void android_view_GLES20Canvas_drawOval(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 515 | jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 516 | jlong paintPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 517 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 518 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 519 | renderer->drawOval(left, top, right, bottom, paint); |
| 520 | } |
| 521 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 522 | static void android_view_GLES20Canvas_drawArc(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 523 | jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 524 | jfloat startAngle, jfloat sweepAngle, jboolean useCenter, jlong paintPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 525 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 526 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 527 | renderer->drawArc(left, top, right, bottom, startAngle, sweepAngle, useCenter, paint); |
| 528 | } |
| 529 | |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 530 | static void android_view_GLES20Canvas_drawRegionAsRects(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 531 | jlong rendererPtr, jlong regionPtr, jlong paintPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 532 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 533 | SkRegion* region = reinterpret_cast<SkRegion*>(regionPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 534 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
| 535 | if (paint->getStyle() != Paint::kFill_Style || |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 536 | (paint->isAntiAlias() && !renderer->isCurrentTransformSimple())) { |
| 537 | SkRegion::Iterator it(*region); |
| 538 | while (!it.done()) { |
| 539 | const SkIRect& r = it.rect(); |
| 540 | renderer->drawRect(r.fLeft, r.fTop, r.fRight, r.fBottom, paint); |
| 541 | it.next(); |
| 542 | } |
| 543 | } else { |
| 544 | int count = 0; |
| 545 | Vector<float> rects; |
| 546 | SkRegion::Iterator it(*region); |
| 547 | while (!it.done()) { |
| 548 | const SkIRect& r = it.rect(); |
| 549 | rects.push(r.fLeft); |
| 550 | rects.push(r.fTop); |
| 551 | rects.push(r.fRight); |
| 552 | rects.push(r.fBottom); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 553 | count += 4; |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 554 | it.next(); |
| 555 | } |
| 556 | renderer->drawRects(rects.array(), count, paint); |
Romain Guy | a48a1a8 | 2010-08-10 14:59:15 -0700 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 560 | static void android_view_GLES20Canvas_drawPoints(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 561 | jlong rendererPtr, jfloatArray points, jint offset, jint count, jlong paintPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 562 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 563 | jfloat* storage = env->GetFloatArrayElements(points, NULL); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 564 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 565 | renderer->drawPoints(storage + offset, count, paint); |
| 566 | env->ReleaseFloatArrayElements(points, storage, 0); |
| 567 | } |
| 568 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 569 | static void android_view_GLES20Canvas_drawPath(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 570 | jlong rendererPtr, jlong pathPtr, jlong paintPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 571 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 572 | SkPath* path = reinterpret_cast<SkPath*>(pathPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 573 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 574 | renderer->drawPath(path, paint); |
| 575 | } |
| 576 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 577 | static void android_view_GLES20Canvas_drawLines(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 578 | jlong rendererPtr, jfloatArray points, jint offset, jint count, jlong paintPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 579 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 580 | jfloat* storage = env->GetFloatArrayElements(points, NULL); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 581 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 582 | renderer->drawLines(storage + offset, count, paint); |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 583 | env->ReleaseFloatArrayElements(points, storage, 0); |
| 584 | } |
| 585 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 586 | // ---------------------------------------------------------------------------- |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 587 | // Draw filters |
| 588 | // ---------------------------------------------------------------------------- |
| 589 | |
| 590 | static void android_view_GLES20Canvas_setupPaintFilter(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 591 | jlong rendererPtr, jint clearBits, jint setBits) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 592 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 593 | renderer->setupPaintFilter(clearBits, setBits); |
| 594 | } |
| 595 | |
| 596 | static void android_view_GLES20Canvas_resetPaintFilter(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 597 | jlong rendererPtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 598 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 599 | renderer->resetPaintFilter(); |
| 600 | } |
| 601 | |
| 602 | // ---------------------------------------------------------------------------- |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 603 | // Text |
| 604 | // ---------------------------------------------------------------------------- |
| 605 | |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 606 | class RenderTextFunctor { |
| 607 | public: |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 608 | RenderTextFunctor(const Layout& layout, DisplayListRenderer* renderer, jfloat x, jfloat y, |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 609 | Paint* paint, uint16_t* glyphs, float* pos, float totalAdvance, |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 610 | uirenderer::Rect& bounds) |
| 611 | : layout(layout), renderer(renderer), x(x), y(y), paint(paint), glyphs(glyphs), |
| 612 | pos(pos), totalAdvance(totalAdvance), bounds(bounds) { } |
Raph Levien | 1fc0fa8 | 2014-06-06 18:05:22 -0700 | [diff] [blame] | 613 | void operator()(size_t start, size_t end) { |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 614 | for (size_t i = start; i < end; i++) { |
| 615 | glyphs[i] = layout.getGlyphId(i); |
| 616 | pos[2 * i] = layout.getX(i); |
| 617 | pos[2 * i + 1] = layout.getY(i); |
| 618 | } |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 619 | size_t glyphsCount = end - start; |
| 620 | int bytesCount = glyphsCount * sizeof(jchar); |
| 621 | renderer->drawText((const char*) (glyphs + start), bytesCount, glyphsCount, |
| 622 | x, y, pos + 2 * start, paint, totalAdvance, bounds); |
| 623 | } |
| 624 | private: |
| 625 | const Layout& layout; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 626 | DisplayListRenderer* renderer; |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 627 | jfloat x; |
| 628 | jfloat y; |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 629 | Paint* paint; |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 630 | uint16_t* glyphs; |
| 631 | float* pos; |
| 632 | float totalAdvance; |
| 633 | uirenderer::Rect& bounds; |
| 634 | }; |
| 635 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 636 | static void renderTextLayout(DisplayListRenderer* renderer, Layout* layout, |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 637 | jfloat x, jfloat y, Paint* paint) { |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 638 | size_t nGlyphs = layout->nGlyphs(); |
| 639 | float* pos = new float[nGlyphs * 2]; |
| 640 | uint16_t* glyphs = new uint16_t[nGlyphs]; |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 641 | MinikinRect b; |
| 642 | layout->getBounds(&b); |
| 643 | android::uirenderer::Rect bounds(b.mLeft, b.mTop, b.mRight, b.mBottom); |
| 644 | bounds.translate(x, y); |
| 645 | float totalAdvance = layout->getAdvance(); |
| 646 | |
Raph Levien | f2114d5 | 2014-06-01 15:54:47 -0700 | [diff] [blame] | 647 | RenderTextFunctor f(*layout, renderer, x, y, paint, glyphs, pos, totalAdvance, bounds); |
Raph Levien | 1fc0fa8 | 2014-06-06 18:05:22 -0700 | [diff] [blame] | 648 | MinikinUtils::forFontRun(*layout, paint, f); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 649 | delete[] glyphs; |
| 650 | delete[] pos; |
| 651 | } |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 652 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 653 | static void renderText(DisplayListRenderer* renderer, const jchar* text, int count, |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 654 | jfloat x, jfloat y, int bidiFlags, Paint* paint, TypefaceImpl* typeface) { |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 655 | Layout layout; |
Behdad Esfahbod | 63c5c78 | 2014-07-25 14:54:46 -0400 | [diff] [blame] | 656 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count); |
Raph Levien | 3660789 | 2014-06-25 16:32:13 -0700 | [diff] [blame] | 657 | x += MinikinUtils::xOffsetForTextAlign(paint, layout); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 658 | renderTextLayout(renderer, &layout, x, y, paint); |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 661 | class RenderTextOnPathFunctor { |
| 662 | public: |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 663 | RenderTextOnPathFunctor(const Layout& layout, DisplayListRenderer* renderer, float hOffset, |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 664 | float vOffset, Paint* paint, SkPath* path) |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 665 | : layout(layout), renderer(renderer), hOffset(hOffset), vOffset(vOffset), |
| 666 | paint(paint), path(path) { |
| 667 | } |
| 668 | void operator()(size_t start, size_t end) { |
| 669 | uint16_t glyphs[1]; |
| 670 | for (size_t i = start; i < end; i++) { |
| 671 | glyphs[0] = layout.getGlyphId(i); |
| 672 | float x = hOffset + layout.getX(i); |
| 673 | float y = vOffset + layout.getY(i); |
| 674 | renderer->drawTextOnPath((const char*) glyphs, sizeof(glyphs), 1, path, x, y, paint); |
| 675 | } |
| 676 | } |
| 677 | private: |
| 678 | const Layout& layout; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 679 | DisplayListRenderer* renderer; |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 680 | float hOffset; |
| 681 | float vOffset; |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 682 | Paint* paint; |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 683 | SkPath* path; |
| 684 | }; |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 685 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 686 | static void renderTextOnPath(DisplayListRenderer* renderer, const jchar* text, int count, |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 687 | SkPath* path, jfloat hOffset, jfloat vOffset, int bidiFlags, Paint* paint, |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 688 | TypefaceImpl* typeface) { |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 689 | Layout layout; |
Behdad Esfahbod | 63c5c78 | 2014-07-25 14:54:46 -0400 | [diff] [blame] | 690 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count); |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 691 | hOffset += MinikinUtils::hOffsetForTextAlign(paint, layout, *path); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 692 | Paint::Align align = paint->getTextAlign(); |
| 693 | paint->setTextAlign(Paint::kLeft_Align); |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 694 | |
| 695 | RenderTextOnPathFunctor f(layout, renderer, hOffset, vOffset, paint, path); |
| 696 | MinikinUtils::forFontRun(layout, paint, f); |
| 697 | paint->setTextAlign(align); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 698 | } |
| 699 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 700 | static void renderTextRun(DisplayListRenderer* renderer, const jchar* text, |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 701 | jint start, jint count, jint contextCount, jfloat x, jfloat y, |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 702 | int bidiFlags, Paint* paint, TypefaceImpl* typeface) { |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 703 | Layout layout; |
Behdad Esfahbod | 63c5c78 | 2014-07-25 14:54:46 -0400 | [diff] [blame] | 704 | MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, start, count, contextCount); |
Raph Levien | 3660789 | 2014-06-25 16:32:13 -0700 | [diff] [blame] | 705 | x += MinikinUtils::xOffsetForTextAlign(paint, layout); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 706 | renderTextLayout(renderer, &layout, x, y, paint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 709 | static void android_view_GLES20Canvas_drawTextArray(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 710 | jlong rendererPtr, jcharArray text, jint index, jint count, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 711 | jfloat x, jfloat y, jint bidiFlags, jlong paintPtr, jlong typefacePtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 712 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 713 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 714 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 715 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefacePtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 716 | |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 717 | renderText(renderer, textArray + index, count, x, y, bidiFlags, paint, typeface); |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 718 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 719 | } |
| 720 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 721 | static void android_view_GLES20Canvas_drawText(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 722 | jlong rendererPtr, jstring text, jint start, jint end, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 723 | jfloat x, jfloat y, jint bidiFlags, jlong paintPtr, jlong typefacePtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 724 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 725 | const jchar* textArray = env->GetStringChars(text, NULL); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 726 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 727 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefacePtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 728 | |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 729 | renderText(renderer, textArray + start, end - start, x, y, bidiFlags, paint, typeface); |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 730 | env->ReleaseStringChars(text, textArray); |
| 731 | } |
| 732 | |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 733 | static void android_view_GLES20Canvas_drawTextArrayOnPath(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 734 | jlong rendererPtr, jcharArray text, jint index, jint count, |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 735 | jlong pathPtr, jfloat hOffset, jfloat vOffset, jint bidiFlags, jlong paintPtr, |
| 736 | jlong typefacePtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 737 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 738 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 739 | SkPath* path = reinterpret_cast<SkPath*>(pathPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 740 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 741 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefacePtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 742 | |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 743 | renderTextOnPath(renderer, textArray + index, count, path, |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 744 | hOffset, vOffset, bidiFlags, paint, typeface); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 745 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 746 | } |
| 747 | |
| 748 | static void android_view_GLES20Canvas_drawTextOnPath(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 749 | jlong rendererPtr, jstring text, jint start, jint end, |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 750 | jlong pathPtr, jfloat hOffset, jfloat vOffset, jint bidiFlags, jlong paintPtr, |
| 751 | jlong typefacePtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 752 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 753 | const jchar* textArray = env->GetStringChars(text, NULL); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 754 | SkPath* path = reinterpret_cast<SkPath*>(pathPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 755 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 756 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefacePtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 757 | |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 758 | renderTextOnPath(renderer, textArray + start, end - start, path, |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 759 | hOffset, vOffset, bidiFlags, paint, typeface); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 760 | env->ReleaseStringChars(text, textArray); |
| 761 | } |
| 762 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 763 | static void android_view_GLES20Canvas_drawTextRunArray(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 764 | jlong rendererPtr, jcharArray text, jint index, jint count, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 765 | jint contextIndex, jint contextCount, jfloat x, jfloat y, jboolean isRtl, |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 766 | jlong paintPtr, jlong typefacePtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 767 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 768 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 769 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 770 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefacePtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 771 | |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 772 | int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 773 | renderTextRun(renderer, textArray + contextIndex, index - contextIndex, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 774 | count, contextCount, x, y, bidiFlags, paint, typeface); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 775 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 776 | } |
| 777 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 778 | static void android_view_GLES20Canvas_drawTextRun(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 779 | jlong rendererPtr, jstring text, jint start, jint end, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 780 | jint contextStart, int contextEnd, jfloat x, jfloat y, jboolean isRtl, |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 781 | jlong paintPtr, jlong typefacePtr) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 782 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 783 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 784 | jint count = end - start; |
| 785 | jint contextCount = contextEnd - contextStart; |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 786 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 787 | TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefacePtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 788 | |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 789 | int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 790 | renderTextRun(renderer, textArray + contextStart, start - contextStart, |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 791 | count, contextCount, x, y, bidiFlags, paint, typeface); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 792 | env->ReleaseStringChars(text, textArray); |
| 793 | } |
| 794 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 795 | // ---------------------------------------------------------------------------- |
| 796 | // Display lists |
| 797 | // ---------------------------------------------------------------------------- |
| 798 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 799 | static jlong android_view_GLES20Canvas_finishRecording(JNIEnv* env, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 800 | jobject clazz, jlong rendererPtr) { |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 801 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 802 | return reinterpret_cast<jlong>(renderer->finishRecording()); |
| 803 | } |
| 804 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 805 | static jlong android_view_GLES20Canvas_createDisplayListRenderer(JNIEnv* env, jobject clazz) { |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 806 | return reinterpret_cast<jlong>(new DisplayListRenderer); |
Chet Haase | 5977baa | 2011-01-05 18:01:22 -0800 | [diff] [blame] | 807 | } |
| 808 | |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 809 | static jint android_view_GLES20Canvas_drawRenderNode(JNIEnv* env, |
| 810 | jobject clazz, jlong rendererPtr, jlong renderNodePtr, |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 811 | jobject dirty, jint flags) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 812 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 813 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 814 | android::uirenderer::Rect bounds; |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 815 | status_t status = renderer->drawRenderNode(renderNode, bounds, flags); |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 816 | if (status != DrawGlInfo::kStatusDone && dirty != NULL) { |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 817 | env->CallVoidMethod(dirty, gRectClassInfo.set, |
| 818 | int(bounds.left), int(bounds.top), int(bounds.right), int(bounds.bottom)); |
| 819 | } |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 820 | return status; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 823 | // ---------------------------------------------------------------------------- |
| 824 | // Layers |
| 825 | // ---------------------------------------------------------------------------- |
| 826 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 827 | static void android_view_GLES20Canvas_drawLayer(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 828 | jlong rendererPtr, jlong layerPtr, jfloat x, jfloat y) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 829 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 830 | Layer* layer = reinterpret_cast<Layer*>(layerPtr); |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 831 | renderer->drawLayer(layer, x, y); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 832 | } |
| 833 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 834 | #endif // USE_OPENGL_RENDERER |
| 835 | |
| 836 | // ---------------------------------------------------------------------------- |
| 837 | // Common |
| 838 | // ---------------------------------------------------------------------------- |
| 839 | |
| 840 | static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz) { |
| 841 | #ifdef USE_OPENGL_RENDERER |
Jesse Hall | 4406345 | 2011-12-01 11:27:45 -0800 | [diff] [blame] | 842 | char prop[PROPERTY_VALUE_MAX]; |
| 843 | if (property_get("ro.kernel.qemu", prop, NULL) == 0) { |
| 844 | // not in the emulator |
| 845 | return JNI_TRUE; |
| 846 | } |
| 847 | // In the emulator this property will be set to 1 when hardware GLES is |
| 848 | // enabled, 0 otherwise. On old emulator versions it will be undefined. |
| 849 | property_get("ro.kernel.qemu.gles", prop, "0"); |
| 850 | return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE; |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 851 | #else |
| 852 | return JNI_FALSE; |
| 853 | #endif |
| 854 | } |
| 855 | |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 856 | // ---------------------------------------------------------------------------- |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 857 | // Logging |
| 858 | // ---------------------------------------------------------------------------- |
| 859 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 860 | static void |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 861 | android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) { |
Chet Haase | 905787a | 2011-04-01 14:33:02 -0700 | [diff] [blame] | 862 | #ifdef USE_OPENGL_RENDERER |
Elliott Hughes | a3804cf | 2011-04-11 16:50:19 -0700 | [diff] [blame] | 863 | int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); |
John Reck | e18264b | 2014-03-12 13:56:30 -0700 | [diff] [blame] | 864 | android::uirenderer::RenderNode::outputLogBuffer(fd); |
Chet Haase | 905787a | 2011-04-01 14:33:02 -0700 | [diff] [blame] | 865 | #endif // USE_OPENGL_RENDERER |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | // ---------------------------------------------------------------------------- |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 869 | // JNI Glue |
| 870 | // ---------------------------------------------------------------------------- |
| 871 | |
| 872 | const char* const kClassPathName = "android/view/GLES20Canvas"; |
| 873 | |
| 874 | static JNINativeMethod gMethods[] = { |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 875 | { "nIsAvailable", "()Z", (void*) android_view_GLES20Canvas_isAvailable }, |
| 876 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 877 | #ifdef USE_OPENGL_RENDERER |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 878 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 879 | { "nDestroyRenderer", "(J)V", (void*) android_view_GLES20Canvas_destroyRenderer }, |
| 880 | { "nSetViewport", "(JII)V", (void*) android_view_GLES20Canvas_setViewport }, |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 881 | { "nSetHighContrastText","(JZ)V", (void*) android_view_GLES20Canvas_setHighContrastText }, |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 882 | { "nInsertReorderBarrier","(JZ)V", (void*) android_view_GLES20Canvas_insertReorderBarrier }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 883 | { "nPrepare", "(JZ)I", (void*) android_view_GLES20Canvas_prepare }, |
| 884 | { "nPrepareDirty", "(JIIIIZ)I", (void*) android_view_GLES20Canvas_prepareDirty }, |
| 885 | { "nFinish", "(J)V", (void*) android_view_GLES20Canvas_finish }, |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 886 | { "nSetProperty", "(Ljava/lang/String;Ljava/lang/String;)V", |
| 887 | (void*) android_view_GLES20Canvas_setProperty }, |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 888 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 889 | { "nCallDrawGLFunction", "(JJ)I", (void*) android_view_GLES20Canvas_callDrawGLFunction }, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 890 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 891 | { "nSave", "(JI)I", (void*) android_view_GLES20Canvas_save }, |
| 892 | { "nRestore", "(J)V", (void*) android_view_GLES20Canvas_restore }, |
| 893 | { "nRestoreToCount", "(JI)V", (void*) android_view_GLES20Canvas_restoreToCount }, |
| 894 | { "nGetSaveCount", "(J)I", (void*) android_view_GLES20Canvas_getSaveCount }, |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 895 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 896 | { "nSaveLayer", "(JFFFFJI)I", (void*) android_view_GLES20Canvas_saveLayer }, |
| 897 | { "nSaveLayer", "(JJI)I", (void*) android_view_GLES20Canvas_saveLayerClip }, |
| 898 | { "nSaveLayerAlpha", "(JFFFFII)I", (void*) android_view_GLES20Canvas_saveLayerAlpha }, |
| 899 | { "nSaveLayerAlpha", "(JII)I", (void*) android_view_GLES20Canvas_saveLayerAlphaClip }, |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 900 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 901 | { "nQuickReject", "(JFFFF)Z", (void*) android_view_GLES20Canvas_quickReject }, |
| 902 | { "nClipRect", "(JFFFFI)Z", (void*) android_view_GLES20Canvas_clipRectF }, |
| 903 | { "nClipRect", "(JIIIII)Z", (void*) android_view_GLES20Canvas_clipRect }, |
| 904 | { "nClipPath", "(JJI)Z", (void*) android_view_GLES20Canvas_clipPath }, |
| 905 | { "nClipRegion", "(JJI)Z", (void*) android_view_GLES20Canvas_clipRegion }, |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 906 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 907 | { "nTranslate", "(JFF)V", (void*) android_view_GLES20Canvas_translate }, |
| 908 | { "nRotate", "(JF)V", (void*) android_view_GLES20Canvas_rotate }, |
| 909 | { "nScale", "(JFF)V", (void*) android_view_GLES20Canvas_scale }, |
| 910 | { "nSkew", "(JFF)V", (void*) android_view_GLES20Canvas_skew }, |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 911 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 912 | { "nSetMatrix", "(JJ)V", (void*) android_view_GLES20Canvas_setMatrix }, |
| 913 | { "nGetMatrix", "(JJ)V", (void*) android_view_GLES20Canvas_getMatrix }, |
| 914 | { "nConcatMatrix", "(JJ)V", (void*) android_view_GLES20Canvas_concatMatrix }, |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 915 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 916 | { "nDrawBitmap", "(JJ[BFFJ)V", (void*) android_view_GLES20Canvas_drawBitmap }, |
| 917 | { "nDrawBitmap", "(JJ[BFFFFFFFFJ)V",(void*) android_view_GLES20Canvas_drawBitmapRect }, |
| 918 | { "nDrawBitmap", "(JJ[BJJ)V", (void*) android_view_GLES20Canvas_drawBitmapMatrix }, |
| 919 | { "nDrawBitmap", "(J[IIIFFIIZJ)V", (void*) android_view_GLES20Canvas_drawBitmapData }, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 920 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 921 | { "nDrawBitmapMesh", "(JJ[BII[FI[IIJ)V",(void*) android_view_GLES20Canvas_drawBitmapMesh }, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 922 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 923 | { "nDrawPatch", "(JJ[BJFFFFJ)V", (void*) android_view_GLES20Canvas_drawPatch }, |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 924 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 925 | { "nDrawColor", "(JII)V", (void*) android_view_GLES20Canvas_drawColor }, |
| 926 | { "nDrawRect", "(JFFFFJ)V", (void*) android_view_GLES20Canvas_drawRect }, |
| 927 | { "nDrawRects", "(JJJ)V", (void*) android_view_GLES20Canvas_drawRegionAsRects }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 928 | { "nDrawRoundRect", "(JFFFFFFJ)V", (void*) android_view_GLES20Canvas_drawRoundRect }, |
Jorim Jaggi | 072707d | 2014-09-15 17:20:08 +0200 | [diff] [blame] | 929 | { "nDrawRoundRect", "(JJJJJJJJ)V", (void*) android_view_GLES20Canvas_drawRoundRectProps }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 930 | { "nDrawCircle", "(JFFFJ)V", (void*) android_view_GLES20Canvas_drawCircle }, |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 931 | { "nDrawCircle", "(JJJJJ)V", (void*) android_view_GLES20Canvas_drawCircleProps }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 932 | { "nDrawOval", "(JFFFFJ)V", (void*) android_view_GLES20Canvas_drawOval }, |
| 933 | { "nDrawArc", "(JFFFFFFZJ)V", (void*) android_view_GLES20Canvas_drawArc }, |
| 934 | { "nDrawPoints", "(J[FIIJ)V", (void*) android_view_GLES20Canvas_drawPoints }, |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 935 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 936 | { "nDrawPath", "(JJJ)V", (void*) android_view_GLES20Canvas_drawPath }, |
| 937 | { "nDrawLines", "(J[FIIJ)V", (void*) android_view_GLES20Canvas_drawLines }, |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 938 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 939 | { "nSetupPaintFilter", "(JII)V", (void*) android_view_GLES20Canvas_setupPaintFilter }, |
| 940 | { "nResetPaintFilter", "(J)V", (void*) android_view_GLES20Canvas_resetPaintFilter }, |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 941 | |
Raph Levien | 1a73f732 | 2014-01-30 16:06:28 -0800 | [diff] [blame] | 942 | { "nDrawText", "(J[CIIFFIJJ)V", (void*) android_view_GLES20Canvas_drawTextArray }, |
| 943 | { "nDrawText", "(JLjava/lang/String;IIFFIJJ)V", |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 944 | (void*) android_view_GLES20Canvas_drawText }, |
| 945 | |
Raph Levien | 9d2b5e1 | 2014-06-15 23:53:57 -0700 | [diff] [blame] | 946 | { "nDrawTextOnPath", "(J[CIIJFFIJJ)V", (void*) android_view_GLES20Canvas_drawTextArrayOnPath }, |
| 947 | { "nDrawTextOnPath", "(JLjava/lang/String;IIJFFIJJ)V", |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 948 | (void*) android_view_GLES20Canvas_drawTextOnPath }, |
| 949 | |
Raph Levien | 051910b | 2014-06-15 18:25:29 -0700 | [diff] [blame] | 950 | { "nDrawTextRun", "(J[CIIIIFFZJJ)V", (void*) android_view_GLES20Canvas_drawTextRunArray }, |
| 951 | { "nDrawTextRun", "(JLjava/lang/String;IIIIFFZJJ)V", |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 952 | (void*) android_view_GLES20Canvas_drawTextRun }, |
| 953 | |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 954 | { "nGetClipBounds", "(JLandroid/graphics/Rect;)Z", (void*) android_view_GLES20Canvas_getClipBounds }, |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 955 | |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 956 | { "nFinishRecording", "(J)J", (void*) android_view_GLES20Canvas_finishRecording }, |
| 957 | { "nDrawRenderNode", "(JJLandroid/graphics/Rect;I)I", (void*) android_view_GLES20Canvas_drawRenderNode }, |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 958 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 959 | { "nCreateDisplayListRenderer", "()J", (void*) android_view_GLES20Canvas_createDisplayListRenderer }, |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 960 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 961 | { "nDrawLayer", "(JJFF)V", (void*) android_view_GLES20Canvas_drawLayer }, |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 962 | |
Romain Guy | f61970fc | 2011-07-07 14:10:06 -0700 | [diff] [blame] | 963 | { "nGetMaximumTextureWidth", "()I", (void*) android_view_GLES20Canvas_getMaxTextureWidth }, |
| 964 | { "nGetMaximumTextureHeight", "()I", (void*) android_view_GLES20Canvas_getMaxTextureHeight }, |
| 965 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 966 | #endif |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 967 | }; |
| 968 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 969 | static JNINativeMethod gActivityThreadMethods[] = { |
| 970 | { "dumpGraphicsInfo", "(Ljava/io/FileDescriptor;)V", |
| 971 | (void*) android_app_ActivityThread_dumpGraphics } |
| 972 | }; |
| 973 | |
| 974 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 975 | #ifdef USE_OPENGL_RENDERER |
| 976 | #define FIND_CLASS(var, className) \ |
| 977 | var = env->FindClass(className); \ |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 978 | LOG_FATAL_IF(! var, "Unable to find class " className); |
| 979 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 980 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \ |
| 981 | var = env->GetMethodID(clazz, methodName, methodDescriptor); \ |
| 982 | LOG_FATAL_IF(! var, "Unable to find method " methodName); |
| 983 | #else |
| 984 | #define FIND_CLASS(var, className) |
| 985 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) |
| 986 | #endif |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 987 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 988 | int register_android_view_GLES20Canvas(JNIEnv* env) { |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 989 | jclass clazz; |
| 990 | FIND_CLASS(clazz, "android/graphics/Rect"); |
| 991 | GET_METHOD_ID(gRectClassInfo.set, clazz, "set", "(IIII)V"); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 992 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 993 | return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); |
| 994 | } |
| 995 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 996 | const char* const kActivityThreadPathName = "android/app/ActivityThread"; |
| 997 | |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 998 | int register_android_app_ActivityThread(JNIEnv* env) { |
| 999 | return AndroidRuntime::registerNativeMethods(env, kActivityThreadPathName, |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1000 | gActivityThreadMethods, NELEM(gActivityThreadMethods)); |
| 1001 | } |
| 1002 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1003 | }; |