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 | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 23 | #include "android_view_GraphicBuffer.h" |
| 24 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 25 | #include <android_runtime/AndroidRuntime.h> |
Romain Guy | e5e0c50 | 2011-06-15 15:18:31 -0700 | [diff] [blame] | 26 | #include <android_runtime/android_graphics_SurfaceTexture.h> |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 27 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 28 | #include <androidfw/ResourceTypes.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 29 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 30 | #include <gui/GLConsumer.h> |
| 31 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 32 | #include <private/hwui/DrawGlInfo.h> |
| 33 | |
| 34 | #include <cutils/properties.h> |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 35 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 36 | #include <SkBitmap.h> |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 37 | #include <SkCanvas.h> |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 38 | #include <SkMatrix.h> |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 39 | #include <SkPaint.h> |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 40 | #include <SkRegion.h> |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 41 | #include <SkScalerContext.h> |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 42 | #include <SkTemplates.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 43 | #include <SkXfermode.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 44 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 45 | #include <DisplayList.h> |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 46 | #include <DisplayListRenderer.h> |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 47 | #include <LayerRenderer.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 48 | #include <OpenGLRenderer.h> |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 49 | #include <SkiaShader.h> |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 50 | #include <SkiaColorFilter.h> |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 51 | #include <Stencil.h> |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 52 | #include <Rect.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 53 | |
Romain Guy | d1d4bb7 | 2012-01-17 17:31:27 -0800 | [diff] [blame] | 54 | #include <TextLayout.h> |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 55 | #include <TextLayoutCache.h> |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 56 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 57 | namespace android { |
| 58 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 59 | using namespace uirenderer; |
| 60 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 61 | /** |
| 62 | * Note: OpenGLRenderer JNI layer is generated and compiled only on supported |
| 63 | * devices. This means all the logic must be compiled only when the |
| 64 | * preprocessor variable USE_OPENGL_RENDERER is defined. |
| 65 | */ |
| 66 | #ifdef USE_OPENGL_RENDERER |
| 67 | |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 68 | // ---------------------------------------------------------------------------- |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 69 | // Defines |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 70 | // ---------------------------------------------------------------------------- |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 71 | |
| 72 | // Debug |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 73 | #define DEBUG_RENDERER 0 |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 74 | |
| 75 | // Debug |
| 76 | #if DEBUG_RENDERER |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 77 | #define RENDERER_LOGD(...) ALOGD(__VA_ARGS__) |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 78 | #else |
| 79 | #define RENDERER_LOGD(...) |
| 80 | #endif |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 81 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 82 | #define MODIFIER_SHADOW 1 |
| 83 | #define MODIFIER_SHADER 2 |
| 84 | #define MODIFIER_COLOR_FILTER 4 |
| 85 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 86 | // ---------------------------------------------------------------------------- |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 87 | |
| 88 | static struct { |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 89 | jmethodID set; |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 90 | } gRectClassInfo; |
| 91 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 92 | // ---------------------------------------------------------------------------- |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 93 | // Caching |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 94 | // ---------------------------------------------------------------------------- |
| 95 | |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 96 | static void android_view_GLES20Canvas_flushCaches(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 97 | jint mode) { |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 98 | if (Caches::hasInstance()) { |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 99 | Caches::getInstance().flush(static_cast<Caches::FlushMode>(mode)); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 103 | static jboolean android_view_GLES20Canvas_initCaches(JNIEnv* env, jobject clazz) { |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 104 | if (Caches::hasInstance()) { |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 105 | return Caches::getInstance().init() ? JNI_TRUE : JNI_FALSE; |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 106 | } |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 107 | return JNI_FALSE; |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static void android_view_GLES20Canvas_terminateCaches(JNIEnv* env, jobject clazz) { |
| 111 | if (Caches::hasInstance()) { |
| 112 | Caches::getInstance().terminate(); |
| 113 | } |
| 114 | } |
| 115 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 116 | // ---------------------------------------------------------------------------- |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 117 | // Caching |
| 118 | // ---------------------------------------------------------------------------- |
| 119 | |
| 120 | static void android_view_GLES20Canvas_initAtlas(JNIEnv* env, jobject clazz, |
| 121 | jobject graphicBuffer, jintArray atlasMapArray, jint count) { |
| 122 | |
| 123 | sp<GraphicBuffer> buffer = graphicBufferForJavaObject(env, graphicBuffer); |
| 124 | jint* atlasMap = env->GetIntArrayElements(atlasMapArray, NULL); |
| 125 | |
| 126 | Caches::getInstance().assetAtlas.init(buffer, atlasMap, count); |
| 127 | |
| 128 | env->ReleaseIntArrayElements(atlasMapArray, atlasMap, 0); |
| 129 | } |
| 130 | |
| 131 | // ---------------------------------------------------------------------------- |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 132 | // Constructors |
| 133 | // ---------------------------------------------------------------------------- |
| 134 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 135 | static jlong android_view_GLES20Canvas_createRenderer(JNIEnv* env, jobject clazz) { |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 136 | RENDERER_LOGD("Create OpenGLRenderer"); |
Romain Guy | 87e2f757 | 2012-09-24 11:37:12 -0700 | [diff] [blame] | 137 | OpenGLRenderer* renderer = new OpenGLRenderer(); |
| 138 | renderer->initProperties(); |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 139 | return reinterpret_cast<jlong>(renderer); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 142 | static void android_view_GLES20Canvas_destroyRenderer(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 143 | jlong rendererHandle) { |
| 144 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | bdb801ca | 2010-10-04 17:22:29 -0700 | [diff] [blame] | 145 | RENDERER_LOGD("Destroy OpenGLRenderer"); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 146 | delete renderer; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | // ---------------------------------------------------------------------------- |
| 150 | // Setup |
| 151 | // ---------------------------------------------------------------------------- |
| 152 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 153 | static void android_view_GLES20Canvas_setViewport(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 154 | jlong rendererHandle, jint width, jint height) { |
| 155 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 156 | renderer->setViewport(width, height); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 159 | static jint android_view_GLES20Canvas_prepare(JNIEnv* env, jobject clazz, |
| 160 | jlong rendererHandle, jboolean opaque) { |
| 161 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 162 | return renderer->prepare(opaque); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 165 | static jint android_view_GLES20Canvas_prepareDirty(JNIEnv* env, jobject clazz, |
| 166 | jlong rendererHandle, jint left, jint top, jint right, jint bottom, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 167 | jboolean opaque) { |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 168 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 169 | return renderer->prepareDirty(left, top, right, bottom, opaque); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static void android_view_GLES20Canvas_finish(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 173 | jlong rendererHandle) { |
| 174 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 175 | renderer->finish(); |
| 176 | } |
| 177 | |
Romain Guy | 530041d | 2012-01-25 18:56:29 -0800 | [diff] [blame] | 178 | static jint android_view_GLES20Canvas_getStencilSize(JNIEnv* env, jobject clazz) { |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 179 | return Stencil::getStencilSize(); |
Romain Guy | 530041d | 2012-01-25 18:56:29 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Romain Guy | ef35927 | 2013-01-31 19:07:29 -0800 | [diff] [blame] | 182 | static void android_view_GLES20Canvas_setName(JNIEnv* env, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 183 | jobject clazz, jlong rendererHandle, jstring name) { |
| 184 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | ef35927 | 2013-01-31 19:07:29 -0800 | [diff] [blame] | 185 | if (name != NULL) { |
| 186 | const char* textArray = env->GetStringUTFChars(name, NULL); |
| 187 | renderer->setName(textArray); |
| 188 | env->ReleaseStringUTFChars(name, textArray); |
| 189 | } else { |
| 190 | renderer->setName(NULL); |
| 191 | } |
| 192 | } |
| 193 | |
Romain Guy | 78dd96d | 2013-05-03 14:24:16 -0700 | [diff] [blame] | 194 | static void android_view_GLES20Canvas_setCountOverdrawEnabled(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 195 | jlong rendererHandle, jboolean enabled) { |
| 196 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 78dd96d | 2013-05-03 14:24:16 -0700 | [diff] [blame] | 197 | renderer->setCountOverdrawEnabled(enabled); |
| 198 | } |
| 199 | |
| 200 | static jfloat android_view_GLES20Canvas_getOverdraw(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 201 | jlong rendererHandle) { |
| 202 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 78dd96d | 2013-05-03 14:24:16 -0700 | [diff] [blame] | 203 | return renderer->getOverdraw(); |
| 204 | } |
| 205 | |
Romain Guy | 530041d | 2012-01-25 18:56:29 -0800 | [diff] [blame] | 206 | // ---------------------------------------------------------------------------- |
| 207 | // Functor |
| 208 | // ---------------------------------------------------------------------------- |
| 209 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 210 | static jint android_view_GLES20Canvas_callDrawGLFunction(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 211 | jlong rendererHandle, jlong functorHandle) { |
| 212 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 213 | Functor* functor = reinterpret_cast<Functor*>(functorHandle); |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 214 | android::uirenderer::Rect dirty; |
| 215 | return renderer->callDrawGLFunction(functor, dirty); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 218 | static void android_view_GLES20Canvas_detachFunctor(JNIEnv* env, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 219 | jobject clazz, jlong rendererHandle, jlong functorHandle) { |
| 220 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 221 | Functor* functor = reinterpret_cast<Functor*>(functorHandle); |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 222 | renderer->detachFunctor(functor); |
| 223 | } |
| 224 | |
| 225 | static void android_view_GLES20Canvas_attachFunctor(JNIEnv* env, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 226 | jobject clazz, jlong rendererHandle, jlong functorHandle) { |
| 227 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 228 | Functor* functor = reinterpret_cast<Functor*>(functorHandle); |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 229 | renderer->attachFunctor(functor); |
| 230 | } |
| 231 | |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 232 | static jint android_view_GLES20Canvas_invokeFunctors(JNIEnv* env, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 233 | jobject clazz, jlong rendererHandle, jobject dirty) { |
| 234 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 235 | android::uirenderer::Rect bounds; |
| 236 | status_t status = renderer->invokeFunctors(bounds); |
| 237 | if (status != DrawGlInfo::kStatusDone && dirty != NULL) { |
| 238 | env->CallVoidMethod(dirty, gRectClassInfo.set, |
| 239 | int(bounds.left), int(bounds.top), int(bounds.right), int(bounds.bottom)); |
| 240 | } |
| 241 | return status; |
| 242 | } |
| 243 | |
| 244 | // ---------------------------------------------------------------------------- |
| 245 | // Misc |
| 246 | // ---------------------------------------------------------------------------- |
| 247 | |
Romain Guy | f61970fc | 2011-07-07 14:10:06 -0700 | [diff] [blame] | 248 | static jint android_view_GLES20Canvas_getMaxTextureWidth(JNIEnv* env, jobject clazz) { |
| 249 | return Caches::getInstance().maxTextureSize; |
| 250 | } |
| 251 | |
| 252 | static jint android_view_GLES20Canvas_getMaxTextureHeight(JNIEnv* env, jobject clazz) { |
| 253 | return Caches::getInstance().maxTextureSize; |
| 254 | } |
| 255 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 256 | // ---------------------------------------------------------------------------- |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 257 | // State |
| 258 | // ---------------------------------------------------------------------------- |
| 259 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 260 | static jint android_view_GLES20Canvas_save(JNIEnv* env, jobject clazz, jlong rendererHandle, |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 261 | jint flags) { |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 262 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 263 | return renderer->save(flags); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 266 | static jint android_view_GLES20Canvas_getSaveCount(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 267 | jlong rendererHandle) { |
| 268 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 269 | return renderer->getSaveCount(); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 272 | static void android_view_GLES20Canvas_restore(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 273 | jlong rendererHandle) { |
| 274 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 275 | renderer->restore(); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 278 | static void android_view_GLES20Canvas_restoreToCount(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 279 | jlong rendererHandle, jint saveCount) { |
| 280 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 281 | renderer->restoreToCount(saveCount); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | // ---------------------------------------------------------------------------- |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 285 | // Layers |
| 286 | // ---------------------------------------------------------------------------- |
| 287 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 288 | static jint android_view_GLES20Canvas_saveLayer(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 289 | jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 290 | jlong paintHandle, jint saveFlags) { |
| 291 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 292 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 293 | return renderer->saveLayer(left, top, right, bottom, paint, saveFlags); |
| 294 | } |
| 295 | |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 296 | static jint android_view_GLES20Canvas_saveLayerClip(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 297 | jlong rendererHandle, jlong paintHandle, jint saveFlags) { |
| 298 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 299 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 300 | const android::uirenderer::Rect& bounds(renderer->getClipBounds()); |
| 301 | return renderer->saveLayer(bounds.left, bounds.top, bounds.right, bounds.bottom, |
| 302 | paint, saveFlags); |
| 303 | } |
| 304 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 305 | static jint android_view_GLES20Canvas_saveLayerAlpha(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 306 | jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom, |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 307 | jint alpha, jint saveFlags) { |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 308 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 309 | return renderer->saveLayerAlpha(left, top, right, bottom, alpha, saveFlags); |
| 310 | } |
| 311 | |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 312 | static jint android_view_GLES20Canvas_saveLayerAlphaClip(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 313 | jlong rendererHandle, jint alpha, jint saveFlags) { |
| 314 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 189887e | 2011-08-25 11:45:13 -0700 | [diff] [blame] | 315 | const android::uirenderer::Rect& bounds(renderer->getClipBounds()); |
| 316 | return renderer->saveLayerAlpha(bounds.left, bounds.top, bounds.right, bounds.bottom, |
| 317 | alpha, saveFlags); |
| 318 | } |
| 319 | |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 320 | // ---------------------------------------------------------------------------- |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 321 | // Clipping |
| 322 | // ---------------------------------------------------------------------------- |
| 323 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 324 | static jboolean android_view_GLES20Canvas_quickReject(JNIEnv* env, jobject clazz, |
| 325 | jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom) { |
| 326 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 327 | bool result = renderer->quickRejectNoScissor(left, top, right, bottom); |
| 328 | return result ? JNI_TRUE : JNI_FALSE; |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 331 | static jboolean android_view_GLES20Canvas_clipRectF(JNIEnv* env, jobject clazz, |
| 332 | jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 333 | jint opHandle) { |
| 334 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 335 | SkRegion::Op op = static_cast<SkRegion::Op>(opHandle); |
| 336 | bool result; |
| 337 | result = renderer->clipRect(left, top, right, bottom, op); |
| 338 | return result ? JNI_TRUE : JNI_FALSE; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 341 | static jboolean android_view_GLES20Canvas_clipRect(JNIEnv* env, jobject clazz, |
| 342 | jlong rendererHandle, jint left, jint top, jint right, jint bottom, |
| 343 | jint opHandle) { |
| 344 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 345 | SkRegion::Op op = static_cast<SkRegion::Op>(opHandle); |
| 346 | bool result = renderer->clipRect(float(left), float(top), float(right), float(bottom), op); |
| 347 | return result ? JNI_TRUE : JNI_FALSE; |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 348 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 349 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 350 | static jboolean android_view_GLES20Canvas_clipPath(JNIEnv* env, jobject clazz, |
| 351 | jlong rendererHandle, jlong pathHandle, jint opHandle) { |
| 352 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 353 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
| 354 | SkRegion::Op op = static_cast<SkRegion::Op>(opHandle); |
| 355 | return renderer->clipPath(path, op) ? JNI_TRUE : JNI_FALSE; |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 358 | static jboolean android_view_GLES20Canvas_clipRegion(JNIEnv* env, jobject clazz, |
| 359 | jlong rendererHandle, jlong regionHandle, jint opHandle) { |
| 360 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 361 | SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle); |
| 362 | SkRegion::Op op = static_cast<SkRegion::Op>(opHandle); |
| 363 | return renderer->clipRegion(region, op) ? JNI_TRUE : JNI_FALSE; |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 364 | } |
| 365 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 366 | static jboolean android_view_GLES20Canvas_getClipBounds(JNIEnv* env, jobject clazz, |
| 367 | jlong rendererHandle, jobject rect) { |
| 368 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 369 | const android::uirenderer::Rect& bounds(renderer->getClipBounds()); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 370 | |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 371 | env->CallVoidMethod(rect, gRectClassInfo.set, |
| 372 | int(bounds.left), int(bounds.top), int(bounds.right), int(bounds.bottom)); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 373 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 374 | return !bounds.isEmpty() ? JNI_TRUE : JNI_FALSE; |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 377 | // ---------------------------------------------------------------------------- |
| 378 | // Transforms |
| 379 | // ---------------------------------------------------------------------------- |
| 380 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 381 | static void android_view_GLES20Canvas_translate(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 382 | jlong rendererHandle, jfloat dx, jfloat dy) { |
| 383 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 384 | renderer->translate(dx, dy); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 387 | static void android_view_GLES20Canvas_rotate(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 388 | jlong rendererHandle, jfloat degrees) { |
| 389 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 390 | renderer->rotate(degrees); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 393 | static void android_view_GLES20Canvas_scale(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 394 | jlong rendererHandle, jfloat sx, jfloat sy) { |
| 395 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 396 | renderer->scale(sx, sy); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 399 | static void android_view_GLES20Canvas_skew(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 400 | jlong rendererHandle, jfloat sx, jfloat sy) { |
| 401 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 402 | renderer->skew(sx, sy); |
| 403 | } |
| 404 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 405 | static void android_view_GLES20Canvas_setMatrix(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 406 | jlong rendererHandle, jlong matrixHandle) { |
| 407 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 408 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 409 | renderer->setMatrix(matrix); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 412 | static void android_view_GLES20Canvas_getMatrix(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 413 | jlong rendererHandle, jlong matrixHandle) { |
| 414 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 415 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 416 | renderer->getMatrix(matrix); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 419 | static void android_view_GLES20Canvas_concatMatrix(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 420 | jlong rendererHandle, jlong matrixHandle) { |
| 421 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 422 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 423 | renderer->concatMatrix(matrix); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | // ---------------------------------------------------------------------------- |
| 427 | // Drawing |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 428 | // ---------------------------------------------------------------------------- |
| 429 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 430 | static void android_view_GLES20Canvas_drawBitmap(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 431 | jlong rendererHandle, jlong bitmapHandle, jbyteArray buffer, |
| 432 | jfloat left, jfloat top, jlong paintHandle) { |
| 433 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 434 | SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); |
| 435 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 436 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 437 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 438 | |
Romain Guy | dbd77cd | 2010-07-09 10:36:05 -0700 | [diff] [blame] | 439 | renderer->drawBitmap(bitmap, left, top, paint); |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 442 | static void android_view_GLES20Canvas_drawBitmapRect(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 443 | jlong rendererHandle, jlong bitmapHandle, jbyteArray buffer, |
| 444 | jfloat srcLeft, jfloat srcTop, jfloat srcRight, jfloat srcBottom, |
| 445 | jfloat dstLeft, jfloat dstTop, jfloat dstRight, jfloat dstBottom, jlong paintHandle) { |
| 446 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 447 | SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); |
| 448 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 449 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 450 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 451 | |
Romain Guy | dbd77cd | 2010-07-09 10:36:05 -0700 | [diff] [blame] | 452 | renderer->drawBitmap(bitmap, srcLeft, srcTop, srcRight, srcBottom, |
| 453 | dstLeft, dstTop, dstRight, dstBottom, paint); |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 454 | } |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 455 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 456 | static void android_view_GLES20Canvas_drawBitmapMatrix(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 457 | jlong rendererHandle, jlong bitmapHandle, jbyteArray buffer, |
| 458 | jlong matrixHandle, jlong paintHandle) { |
| 459 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 460 | SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); |
| 461 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); |
| 462 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 463 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 464 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 465 | |
Romain Guy | dbd77cd | 2010-07-09 10:36:05 -0700 | [diff] [blame] | 466 | renderer->drawBitmap(bitmap, matrix, paint); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 469 | static void android_view_GLES20Canvas_drawBitmapData(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 470 | jlong rendererHandle, jintArray colors, jint offset, jint stride, |
| 471 | jfloat left, jfloat top, jint width, jint height, jboolean hasAlpha, jlong paintHandle) { |
| 472 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 473 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 474 | SkBitmap* bitmap = new SkBitmap; |
| 475 | bitmap->setConfig(hasAlpha ? SkBitmap::kARGB_8888_Config : SkBitmap::kRGB_565_Config, |
| 476 | width, height); |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 477 | |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 478 | if (!bitmap->allocPixels()) { |
| 479 | delete bitmap; |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 480 | return; |
| 481 | } |
| 482 | |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 483 | if (!GraphicsJNI::SetPixels(env, colors, offset, stride, 0, 0, width, height, *bitmap, true)) { |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 484 | delete bitmap; |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 485 | return; |
| 486 | } |
| 487 | |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 488 | renderer->drawBitmapData(bitmap, left, top, paint); |
| 489 | |
| 490 | // If the renderer is a deferred renderer it will own the bitmap |
| 491 | if (!renderer->isDeferred()) { |
| 492 | delete bitmap; |
| 493 | } |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 496 | static void android_view_GLES20Canvas_drawBitmapMesh(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 497 | jlong rendererHandle, jlong bitmapHandle, jbyteArray buffer, |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 498 | jint meshWidth, jint meshHeight, jfloatArray vertices, jint offset, jintArray colors, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 499 | jint colorOffset, jlong paintHandle) { |
| 500 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 501 | SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); |
| 502 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 503 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 504 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 505 | |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 506 | jfloat* verticesArray = vertices ? env->GetFloatArrayElements(vertices, NULL) + offset : NULL; |
| 507 | jint* colorsArray = colors ? env->GetIntArrayElements(colors, NULL) + colorOffset : NULL; |
| 508 | |
| 509 | renderer->drawBitmapMesh(bitmap, meshWidth, meshHeight, verticesArray, colorsArray, paint); |
| 510 | |
| 511 | if (vertices) env->ReleaseFloatArrayElements(vertices, verticesArray, 0); |
| 512 | if (colors) env->ReleaseIntArrayElements(colors, colorsArray, 0); |
| 513 | } |
| 514 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 515 | static void android_view_GLES20Canvas_drawPatch(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 516 | jlong rendererHandle, jlong bitmapHandle, jbyteArray buffer, jlong patchHandle, |
| 517 | jfloat left, jfloat top, jfloat right, jfloat bottom, jlong paintHandle) { |
| 518 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 519 | SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); |
| 520 | Res_png_9patch* patch = reinterpret_cast<Res_png_9patch*>(patchHandle); |
| 521 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
| 522 | |
Chris Craik | 0c20c38 | 2013-07-02 10:48:54 -0700 | [diff] [blame] | 523 | // This object allows the renderer to allocate a global JNI ref to the buffer object. |
| 524 | JavaHeapBitmapRef bitmapRef(env, bitmap, buffer); |
| 525 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 526 | renderer->drawPatch(bitmap, patch, left, top, right, bottom, paint); |
Romain Guy | deba785 | 2010-07-07 17:54:48 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 529 | static void android_view_GLES20Canvas_drawColor(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 530 | jlong rendererHandle, jint color, SkXfermode::Mode mode) { |
| 531 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 532 | renderer->drawColor(color, mode); |
| 533 | } |
| 534 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 535 | static void android_view_GLES20Canvas_drawRect(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 536 | jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 537 | jlong paintHandle) { |
| 538 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 539 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 540 | renderer->drawRect(left, top, right, bottom, paint); |
| 541 | } |
| 542 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 543 | static void android_view_GLES20Canvas_drawRoundRect(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 544 | jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 545 | jfloat rx, jfloat ry, jlong paintHandle) { |
| 546 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 547 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 548 | renderer->drawRoundRect(left, top, right, bottom, rx, ry, paint); |
| 549 | } |
| 550 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 551 | static void android_view_GLES20Canvas_drawCircle(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 552 | jlong rendererHandle, jfloat x, jfloat y, jfloat radius, jlong paintHandle) { |
| 553 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 554 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 555 | renderer->drawCircle(x, y, radius, paint); |
| 556 | } |
| 557 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 558 | static void android_view_GLES20Canvas_drawOval(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 559 | jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 560 | jlong paintHandle) { |
| 561 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 562 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 563 | renderer->drawOval(left, top, right, bottom, paint); |
| 564 | } |
| 565 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 566 | static void android_view_GLES20Canvas_drawArc(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 567 | jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom, |
| 568 | jfloat startAngle, jfloat sweepAngle, jboolean useCenter, jlong paintHandle) { |
| 569 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 570 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 571 | renderer->drawArc(left, top, right, bottom, startAngle, sweepAngle, useCenter, paint); |
| 572 | } |
| 573 | |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 574 | static void android_view_GLES20Canvas_drawRegionAsRects(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 575 | jlong rendererHandle, jlong regionHandle, jlong paintHandle) { |
| 576 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 577 | SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle); |
| 578 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
| 579 | |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 580 | if (paint->getStyle() != SkPaint::kFill_Style || |
| 581 | (paint->isAntiAlias() && !renderer->isCurrentTransformSimple())) { |
| 582 | SkRegion::Iterator it(*region); |
| 583 | while (!it.done()) { |
| 584 | const SkIRect& r = it.rect(); |
| 585 | renderer->drawRect(r.fLeft, r.fTop, r.fRight, r.fBottom, paint); |
| 586 | it.next(); |
| 587 | } |
| 588 | } else { |
| 589 | int count = 0; |
| 590 | Vector<float> rects; |
| 591 | SkRegion::Iterator it(*region); |
| 592 | while (!it.done()) { |
| 593 | const SkIRect& r = it.rect(); |
| 594 | rects.push(r.fLeft); |
| 595 | rects.push(r.fTop); |
| 596 | rects.push(r.fRight); |
| 597 | rects.push(r.fBottom); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 598 | count += 4; |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 599 | it.next(); |
| 600 | } |
| 601 | renderer->drawRects(rects.array(), count, paint); |
Romain Guy | a48a1a8 | 2010-08-10 14:59:15 -0700 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 605 | static void android_view_GLES20Canvas_drawRects(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 606 | jlong rendererHandle, jfloatArray rects, jint count, jlong paintHandle) { |
| 607 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 608 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 609 | jfloat* storage = env->GetFloatArrayElements(rects, NULL); |
| 610 | renderer->drawRects(storage, count, paint); |
| 611 | env->ReleaseFloatArrayElements(rects, storage, 0); |
| 612 | } |
| 613 | |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 614 | static void android_view_GLES20Canvas_drawPoints(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 615 | jlong rendererHandle, jfloatArray points, jint offset, jint count, jlong paintHandle) { |
| 616 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 617 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 618 | jfloat* storage = env->GetFloatArrayElements(points, NULL); |
| 619 | renderer->drawPoints(storage + offset, count, paint); |
| 620 | env->ReleaseFloatArrayElements(points, storage, 0); |
| 621 | } |
| 622 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 623 | static void android_view_GLES20Canvas_drawPath(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 624 | jlong rendererHandle, jlong pathHandle, jlong paintHandle) { |
| 625 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 626 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
| 627 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 628 | renderer->drawPath(path, paint); |
| 629 | } |
| 630 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 631 | static void android_view_GLES20Canvas_drawLines(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 632 | jlong rendererHandle, jfloatArray points, jint offset, jint count, jlong paintHandle) { |
| 633 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 634 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 635 | jfloat* storage = env->GetFloatArrayElements(points, NULL); |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 636 | renderer->drawLines(storage + offset, count, paint); |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 637 | env->ReleaseFloatArrayElements(points, storage, 0); |
| 638 | } |
| 639 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 640 | // ---------------------------------------------------------------------------- |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 641 | // Shaders and color filters |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 642 | // ---------------------------------------------------------------------------- |
| 643 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 644 | static void android_view_GLES20Canvas_resetModifiers(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 645 | jlong rendererHandle, jint modifiers) { |
| 646 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 647 | if (modifiers & MODIFIER_SHADOW) renderer->resetShadow(); |
| 648 | if (modifiers & MODIFIER_SHADER) renderer->resetShader(); |
| 649 | if (modifiers & MODIFIER_COLOR_FILTER) renderer->resetColorFilter(); |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 652 | static void android_view_GLES20Canvas_setupShader(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 653 | jlong rendererHandle, jlong shaderHandle) { |
| 654 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 655 | SkiaShader* shader = reinterpret_cast<SkiaShader*>(shaderHandle); |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 656 | renderer->setupShader(shader); |
Romain Guy | 7fac2e1 | 2010-07-16 17:10:13 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 659 | static void android_view_GLES20Canvas_setupColorFilter(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 660 | jlong rendererHandle, jlong filterHandle) { |
| 661 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 662 | SkiaColorFilter* filter = reinterpret_cast<SkiaColorFilter*>(filterHandle); |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 663 | renderer->setupColorFilter(filter); |
| 664 | } |
| 665 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 666 | static void android_view_GLES20Canvas_setupShadow(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 667 | jlong rendererHandle, jfloat radius, jfloat dx, jfloat dy, jint color) { |
| 668 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 669 | renderer->setupShadow(radius, dx, dy, color); |
| 670 | } |
| 671 | |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 672 | // ---------------------------------------------------------------------------- |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 673 | // Draw filters |
| 674 | // ---------------------------------------------------------------------------- |
| 675 | |
| 676 | static void android_view_GLES20Canvas_setupPaintFilter(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 677 | jlong rendererHandle, jint clearBits, jint setBits) { |
| 678 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 679 | renderer->setupPaintFilter(clearBits, setBits); |
| 680 | } |
| 681 | |
| 682 | static void android_view_GLES20Canvas_resetPaintFilter(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 683 | jlong rendererHandle) { |
| 684 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 685 | renderer->resetPaintFilter(); |
| 686 | } |
| 687 | |
| 688 | // ---------------------------------------------------------------------------- |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 689 | // Text |
| 690 | // ---------------------------------------------------------------------------- |
| 691 | |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 692 | static float xOffsetForTextAlign(SkPaint* paint, float totalAdvance) { |
| 693 | switch (paint->getTextAlign()) { |
| 694 | case SkPaint::kCenter_Align: |
| 695 | return -totalAdvance / 2.0f; |
| 696 | break; |
| 697 | case SkPaint::kRight_Align: |
| 698 | return -totalAdvance; |
| 699 | break; |
| 700 | default: |
| 701 | break; |
| 702 | } |
| 703 | return 0; |
| 704 | } |
| 705 | |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 706 | static void renderText(OpenGLRenderer* renderer, const jchar* text, int count, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 707 | jfloat x, jfloat y, int flags, SkPaint* paint) { |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 708 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 709 | text, 0, count, count, flags); |
Fabrice Di Meglio | 2ea75880 | 2011-05-12 17:42:06 -0700 | [diff] [blame] | 710 | if (value == NULL) { |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 711 | return; |
Fabrice Di Meglio | 2ea75880 | 2011-05-12 17:42:06 -0700 | [diff] [blame] | 712 | } |
Fabrice Di Meglio | 5c863f7 | 2011-10-05 18:11:59 -0700 | [diff] [blame] | 713 | const jchar* glyphs = value->getGlyphs(); |
| 714 | size_t glyphsCount = value->getGlyphsCount(); |
Raph Levien | 996e57c | 2012-07-23 15:22:52 -0700 | [diff] [blame] | 715 | jfloat totalAdvance = value->getTotalAdvance(); |
Romain Guy | b15b446 | 2013-08-12 13:25:29 -0700 | [diff] [blame] | 716 | x += xOffsetForTextAlign(paint, totalAdvance); |
Raph Levien | 996e57c | 2012-07-23 15:22:52 -0700 | [diff] [blame] | 717 | const float* positions = value->getPos(); |
Fabrice Di Meglio | 79df532 | 2011-09-19 15:17:56 -0700 | [diff] [blame] | 718 | int bytesCount = glyphsCount * sizeof(jchar); |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 719 | const SkRect& r = value->getBounds(); |
| 720 | android::uirenderer::Rect bounds(r.fLeft, r.fTop, r.fRight, r.fBottom); |
Chris Craik | f09b746 | 2013-06-17 15:17:11 -0700 | [diff] [blame] | 721 | bounds.translate(x, y); |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 722 | |
| 723 | renderer->drawText((const char*) glyphs, bytesCount, glyphsCount, |
Romain Guy | b15b446 | 2013-08-12 13:25:29 -0700 | [diff] [blame] | 724 | x, y, positions, paint, totalAdvance, bounds); |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 727 | static void renderTextOnPath(OpenGLRenderer* renderer, const jchar* text, int count, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 728 | SkPath* path, jfloat hOffset, jfloat vOffset, int flags, SkPaint* paint) { |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 729 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 730 | text, 0, count, count, flags); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 731 | if (value == NULL) { |
| 732 | return; |
| 733 | } |
| 734 | const jchar* glyphs = value->getGlyphs(); |
| 735 | size_t glyphsCount = value->getGlyphsCount(); |
| 736 | int bytesCount = glyphsCount * sizeof(jchar); |
| 737 | renderer->drawTextOnPath((const char*) glyphs, bytesCount, glyphsCount, path, |
| 738 | hOffset, vOffset, paint); |
| 739 | } |
| 740 | |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 741 | static void renderTextRun(OpenGLRenderer* renderer, const jchar* text, |
| 742 | jint start, jint count, jint contextCount, jfloat x, jfloat y, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 743 | int flags, SkPaint* paint) { |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 744 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 745 | text, start, count, contextCount, flags); |
Fabrice Di Meglio | 2ea75880 | 2011-05-12 17:42:06 -0700 | [diff] [blame] | 746 | if (value == NULL) { |
Fabrice Di Meglio | b02d0ca | 2011-12-08 14:05:44 -0800 | [diff] [blame] | 747 | return; |
Fabrice Di Meglio | 2ea75880 | 2011-05-12 17:42:06 -0700 | [diff] [blame] | 748 | } |
Fabrice Di Meglio | 5c863f7 | 2011-10-05 18:11:59 -0700 | [diff] [blame] | 749 | const jchar* glyphs = value->getGlyphs(); |
| 750 | size_t glyphsCount = value->getGlyphsCount(); |
Raph Levien | 996e57c | 2012-07-23 15:22:52 -0700 | [diff] [blame] | 751 | jfloat totalAdvance = value->getTotalAdvance(); |
Romain Guy | b15b446 | 2013-08-12 13:25:29 -0700 | [diff] [blame] | 752 | x += xOffsetForTextAlign(paint, totalAdvance); |
Raph Levien | 996e57c | 2012-07-23 15:22:52 -0700 | [diff] [blame] | 753 | const float* positions = value->getPos(); |
Fabrice Di Meglio | 79df532 | 2011-09-19 15:17:56 -0700 | [diff] [blame] | 754 | int bytesCount = glyphsCount * sizeof(jchar); |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 755 | const SkRect& r = value->getBounds(); |
| 756 | android::uirenderer::Rect bounds(r.fLeft, r.fTop, r.fRight, r.fBottom); |
Chris Craik | f09b746 | 2013-06-17 15:17:11 -0700 | [diff] [blame] | 757 | bounds.translate(x, y); |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 758 | |
| 759 | renderer->drawText((const char*) glyphs, bytesCount, glyphsCount, |
Romain Guy | b15b446 | 2013-08-12 13:25:29 -0700 | [diff] [blame] | 760 | x, y, positions, paint, totalAdvance, bounds); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 763 | static void android_view_GLES20Canvas_drawTextArray(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 764 | jlong rendererHandle, jcharArray text, jint index, jint count, |
| 765 | jfloat x, jfloat y, jint flags, jlong paintHandle) { |
| 766 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 767 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 768 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 769 | renderText(renderer, textArray + index, count, x, y, flags, paint); |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 770 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 771 | } |
| 772 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 773 | static void android_view_GLES20Canvas_drawText(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 774 | jlong rendererHandle, jstring text, jint start, jint end, |
| 775 | jfloat x, jfloat y, jint flags, jlong paintHandle) { |
| 776 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 777 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 778 | const jchar* textArray = env->GetStringChars(text, NULL); |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 779 | renderText(renderer, textArray + start, end - start, x, y, flags, paint); |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 780 | env->ReleaseStringChars(text, textArray); |
| 781 | } |
| 782 | |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 783 | static void android_view_GLES20Canvas_drawTextArrayOnPath(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 784 | jlong rendererHandle, jcharArray text, jint index, jint count, |
| 785 | jlong pathHandle, jfloat hOffset, jfloat vOffset, jint flags, jlong paintHandle) { |
| 786 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 787 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
| 788 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 789 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 790 | renderTextOnPath(renderer, textArray + index, count, path, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 791 | hOffset, vOffset, flags, paint); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 792 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 793 | } |
| 794 | |
| 795 | static void android_view_GLES20Canvas_drawTextOnPath(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 796 | jlong rendererHandle, jstring text, jint start, jint end, |
| 797 | jlong pathHandle, jfloat hOffset, jfloat vOffset, jint flags, jlong paintHandle) { |
| 798 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 799 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
| 800 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 801 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 802 | renderTextOnPath(renderer, textArray + start, end - start, path, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 803 | hOffset, vOffset, flags, paint); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 804 | env->ReleaseStringChars(text, textArray); |
| 805 | } |
| 806 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 807 | static void android_view_GLES20Canvas_drawTextRunArray(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 808 | jlong rendererHandle, jcharArray text, jint index, jint count, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 809 | jint contextIndex, jint contextCount, jfloat x, jfloat y, jint dirFlags, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 810 | jlong paintHandle) { |
| 811 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 812 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 813 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 814 | renderTextRun(renderer, textArray + contextIndex, index - contextIndex, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 815 | count, contextCount, x, y, dirFlags, paint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 816 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 817 | } |
| 818 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 819 | static void android_view_GLES20Canvas_drawTextRun(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 820 | jlong rendererHandle, jstring text, jint start, jint end, |
| 821 | jint contextStart, jint contextEnd, jfloat x, jfloat y, jint dirFlags, |
| 822 | jlong paintHandle) { |
| 823 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 824 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 825 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 826 | jint count = end - start; |
| 827 | jint contextCount = contextEnd - contextStart; |
| 828 | renderTextRun(renderer, textArray + contextStart, start - contextStart, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 829 | count, contextCount, x, y, dirFlags, paint); |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 830 | env->ReleaseStringChars(text, textArray); |
| 831 | } |
| 832 | |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 833 | static void renderPosText(OpenGLRenderer* renderer, const jchar* text, int count, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 834 | const jfloat* positions, jint dirFlags, SkPaint* paint) { |
Fabrice Di Meglio | a731b08 | 2012-01-23 18:18:45 -0800 | [diff] [blame] | 835 | sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint, |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 836 | text, 0, count, count, dirFlags); |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 837 | if (value == NULL) { |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 838 | return; |
| 839 | } |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 840 | const jchar* glyphs = value->getGlyphs(); |
| 841 | size_t glyphsCount = value->getGlyphsCount(); |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 842 | if (count < int(glyphsCount)) glyphsCount = count; |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 843 | int bytesCount = glyphsCount * sizeof(jchar); |
| 844 | |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 845 | renderer->drawPosText((const char*) glyphs, bytesCount, glyphsCount, positions, paint); |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | static void android_view_GLES20Canvas_drawPosTextArray(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 849 | jlong rendererHandle, jcharArray text, jint index, jint count, |
| 850 | jfloatArray pos, jlong paintHandle) { |
| 851 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 852 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 853 | jchar* textArray = env->GetCharArrayElements(text, NULL); |
| 854 | jfloat* positions = env->GetFloatArrayElements(pos, NULL); |
| 855 | |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 856 | renderPosText(renderer, textArray + index, count, positions, kBidi_LTR, paint); |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 857 | |
| 858 | env->ReleaseFloatArrayElements(pos, positions, JNI_ABORT); |
| 859 | env->ReleaseCharArrayElements(text, textArray, JNI_ABORT); |
| 860 | } |
| 861 | |
| 862 | static void android_view_GLES20Canvas_drawPosText(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 863 | jlong rendererHandle, jstring text, jint start, jint end, |
| 864 | jfloatArray pos, jlong paintHandle) { |
| 865 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 866 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 867 | const jchar* textArray = env->GetStringChars(text, NULL); |
| 868 | jfloat* positions = env->GetFloatArrayElements(pos, NULL); |
| 869 | |
Fabrice Di Meglio | da12f38 | 2013-03-15 11:26:56 -0700 | [diff] [blame] | 870 | renderPosText(renderer, textArray + start, end - start, positions, kBidi_LTR, paint); |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 871 | |
| 872 | env->ReleaseFloatArrayElements(pos, positions, JNI_ABORT); |
| 873 | env->ReleaseStringChars(text, textArray); |
| 874 | } |
| 875 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 876 | // ---------------------------------------------------------------------------- |
| 877 | // Display lists |
| 878 | // ---------------------------------------------------------------------------- |
| 879 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 880 | static jlong android_view_GLES20Canvas_getDisplayList(JNIEnv* env, |
| 881 | jobject clazz, jlong rendererHandle, jlong displayListHandle) { |
| 882 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererHandle); |
| 883 | DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle); |
| 884 | DisplayList* list = renderer->getDisplayList(displayList); |
| 885 | return reinterpret_cast<jlong>(list); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 888 | static jlong android_view_GLES20Canvas_createDisplayListRenderer(JNIEnv* env, |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 889 | jobject clazz) { |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 890 | OpenGLRenderer* renderer = new DisplayListRenderer; |
| 891 | return reinterpret_cast<jlong>(renderer); |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | static void android_view_GLES20Canvas_resetDisplayListRenderer(JNIEnv* env, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 895 | jobject clazz, jlong rendererHandle) { |
| 896 | DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererHandle); |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 897 | renderer->reset(); |
Chet Haase | 5977baa | 2011-01-05 18:01:22 -0800 | [diff] [blame] | 898 | } |
| 899 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 900 | static jint android_view_GLES20Canvas_drawDisplayList(JNIEnv* env, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 901 | jobject clazz, jlong rendererHandle, jlong displayListHandle, |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 902 | jobject dirty, jint flags) { |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 903 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 904 | DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle); |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 905 | android::uirenderer::Rect bounds; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 906 | status_t status = renderer->drawDisplayList(displayList, bounds, flags); |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 907 | if (status != DrawGlInfo::kStatusDone && dirty != NULL) { |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 908 | env->CallVoidMethod(dirty, gRectClassInfo.set, |
| 909 | int(bounds.left), int(bounds.top), int(bounds.right), int(bounds.bottom)); |
| 910 | } |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 911 | return status; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 914 | static void android_view_GLES20Canvas_outputDisplayList(JNIEnv* env, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 915 | jobject clazz, jlong rendererHandle, jlong displayListHandle) { |
| 916 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 917 | DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle); |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 918 | renderer->outputDisplayList(displayList); |
| 919 | } |
| 920 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 921 | // ---------------------------------------------------------------------------- |
| 922 | // Layers |
| 923 | // ---------------------------------------------------------------------------- |
| 924 | |
Romain Guy | c89b14b | 2012-08-08 14:53:48 -0700 | [diff] [blame] | 925 | static void android_view_GLES20Canvas_interrupt(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 926 | jlong rendererHandle) { |
| 927 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | c89b14b | 2012-08-08 14:53:48 -0700 | [diff] [blame] | 928 | renderer->interrupt(); |
| 929 | } |
| 930 | |
| 931 | static void android_view_GLES20Canvas_resume(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 932 | jlong rendererHandle) { |
| 933 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | c89b14b | 2012-08-08 14:53:48 -0700 | [diff] [blame] | 934 | renderer->resume(); |
| 935 | } |
| 936 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 937 | static jlong android_view_GLES20Canvas_createLayerRenderer(JNIEnv* env, |
| 938 | jobject clazz, jlong layerHandle) { |
| 939 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 940 | if (layer) { |
Romain Guy | 87e2f757 | 2012-09-24 11:37:12 -0700 | [diff] [blame] | 941 | OpenGLRenderer* renderer = new LayerRenderer(layer); |
| 942 | renderer->initProperties(); |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 943 | return reinterpret_cast<jlong>(renderer); |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 944 | } |
| 945 | return NULL; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 946 | } |
| 947 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 948 | static jlong android_view_GLES20Canvas_createTextureLayer(JNIEnv* env, jobject clazz, |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 949 | jboolean isOpaque, jintArray layerInfo) { |
| 950 | Layer* layer = LayerRenderer::createTextureLayer(isOpaque); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 951 | |
| 952 | if (layer) { |
| 953 | jint* storage = env->GetIntArrayElements(layerInfo, NULL); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 954 | storage[0] = layer->getTexture(); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 955 | env->ReleaseIntArrayElements(layerInfo, storage, 0); |
| 956 | } |
| 957 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 958 | return reinterpret_cast<jlong>(layer); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 959 | } |
| 960 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 961 | static jlong android_view_GLES20Canvas_createLayer(JNIEnv* env, jobject clazz, |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 962 | jint width, jint height, jboolean isOpaque, jintArray layerInfo) { |
| 963 | Layer* layer = LayerRenderer::createLayer(width, height, isOpaque); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 964 | |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 965 | if (layer) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 966 | jint* storage = env->GetIntArrayElements(layerInfo, NULL); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 967 | storage[0] = layer->getWidth(); |
| 968 | storage[1] = layer->getHeight(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 969 | env->ReleaseIntArrayElements(layerInfo, storage, 0); |
| 970 | } |
| 971 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 972 | return reinterpret_cast<jlong>(layer); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 973 | } |
| 974 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 975 | static jboolean android_view_GLES20Canvas_resizeLayer(JNIEnv* env, jobject clazz, |
| 976 | jlong layerHandle, jint width, jint height, jintArray layerInfo) { |
| 977 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 978 | if (LayerRenderer::resizeLayer(layer, width, height)) { |
| 979 | jint* storage = env->GetIntArrayElements(layerInfo, NULL); |
| 980 | storage[0] = layer->getWidth(); |
| 981 | storage[1] = layer->getHeight(); |
| 982 | env->ReleaseIntArrayElements(layerInfo, storage, 0); |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 983 | return JNI_TRUE; |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 984 | } |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 985 | return JNI_FALSE; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 986 | } |
| 987 | |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 988 | static void android_view_GLES20Canvas_setLayerPaint(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 989 | jlong layerHandle, jlong paintHandle) { |
| 990 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
| 991 | SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle); |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 992 | if (layer) { |
| 993 | layer->setPaint(paint); |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | static void android_view_GLES20Canvas_setLayerColorFilter(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 998 | jlong layerHandle, jlong colorFilterHandle) { |
| 999 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
| 1000 | SkiaColorFilter* colorFilter = reinterpret_cast<SkiaColorFilter*>(colorFilterHandle); |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 1001 | if (layer) { |
| 1002 | layer->setColorFilter(colorFilter); |
| 1003 | } |
| 1004 | } |
| 1005 | |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 1006 | static void android_view_GLES20Canvas_setOpaqueLayer(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1007 | jlong layerHandle, jboolean isOpaque) { |
| 1008 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 1009 | if (layer) { |
| 1010 | layer->setBlend(!isOpaque); |
| 1011 | } |
| 1012 | } |
| 1013 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1014 | static void android_view_GLES20Canvas_updateTextureLayer(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1015 | jlong layerHandle, jint width, jint height, jboolean isOpaque, jobject surface) { |
| 1016 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 1017 | float transform[16]; |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 1018 | sp<GLConsumer> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, surface)); |
Romain Guy | e5e0c50 | 2011-06-15 15:18:31 -0700 | [diff] [blame] | 1019 | |
Mathias Agopian | df07148 | 2012-05-18 16:58:00 -0700 | [diff] [blame] | 1020 | if (surfaceTexture->updateTexImage() == NO_ERROR) { |
Eino-Ville Talvala | a3402c3 | 2013-09-19 12:49:13 -0700 | [diff] [blame] | 1021 | int64_t frameNumber = surfaceTexture->getFrameNumber(); |
| 1022 | // If the GLConsumer queue is in synchronous mode, need to discard all |
| 1023 | // but latest frame, using the frame number to tell when we no longer |
| 1024 | // have newer frames to target. Since we can't tell which mode it is in, |
| 1025 | // do this unconditionally. |
| 1026 | int dropCounter = 0; |
| 1027 | while (surfaceTexture->updateTexImage() == NO_ERROR) { |
| 1028 | int64_t newFrameNumber = surfaceTexture->getFrameNumber(); |
| 1029 | if (newFrameNumber == frameNumber) break; |
| 1030 | frameNumber = newFrameNumber; |
| 1031 | dropCounter++; |
| 1032 | } |
| 1033 | #if DEBUG_RENDERER |
| 1034 | if (dropCounter > 0) { |
| 1035 | RENDERER_LOGD("Dropped %d frames on texture layer update", dropCounter); |
| 1036 | } |
| 1037 | #endif |
Mathias Agopian | df07148 | 2012-05-18 16:58:00 -0700 | [diff] [blame] | 1038 | surfaceTexture->getTransformMatrix(transform); |
| 1039 | GLenum renderTarget = surfaceTexture->getCurrentTextureTarget(); |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 1040 | |
Mathias Agopian | df07148 | 2012-05-18 16:58:00 -0700 | [diff] [blame] | 1041 | LayerRenderer::updateTextureLayer(layer, width, height, isOpaque, renderTarget, transform); |
| 1042 | } |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 1045 | static void android_view_GLES20Canvas_updateRenderLayer(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1046 | jlong layerHandle, jlong rendererHandle, jlong displayListHandle, |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 1047 | jint left, jint top, jint right, jint bottom) { |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1048 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
| 1049 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 1050 | DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle); |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 1051 | layer->updateDeferred(renderer, displayList, left, top, right, bottom); |
| 1052 | } |
| 1053 | |
Romain Guy | ef09a21 | 2012-09-25 12:17:14 -0700 | [diff] [blame] | 1054 | static void android_view_GLES20Canvas_clearLayerTexture(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1055 | jlong layerHandle) { |
| 1056 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
Romain Guy | ef09a21 | 2012-09-25 12:17:14 -0700 | [diff] [blame] | 1057 | layer->clearTexture(); |
| 1058 | } |
| 1059 | |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 1060 | static void android_view_GLES20Canvas_setTextureLayerTransform(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1061 | jlong layerHandle, jlong matrixHandle) { |
| 1062 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
| 1063 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 1064 | layer->getTransform().load(*matrix); |
| 1065 | } |
| 1066 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1067 | static void android_view_GLES20Canvas_destroyLayer(JNIEnv* env, jobject clazz, jlong layerHandle) { |
| 1068 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 1069 | LayerRenderer::destroyLayer(layer); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 1070 | } |
| 1071 | |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 1072 | static void android_view_GLES20Canvas_destroyLayerDeferred(JNIEnv* env, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1073 | jobject clazz, jlong layerHandle) { |
| 1074 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 1075 | LayerRenderer::destroyLayerDeferred(layer); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 1076 | } |
| 1077 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 1078 | static void android_view_GLES20Canvas_drawLayer(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1079 | jlong rendererHandle, jlong layerHandle, jfloat x, jfloat y) { |
| 1080 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 1081 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 1082 | renderer->drawLayer(layer, x, y); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 1083 | } |
| 1084 | |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 1085 | static jboolean android_view_GLES20Canvas_copyLayer(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1086 | jlong layerHandle, jlong bitmapHandle) { |
| 1087 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
| 1088 | SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); |
Romain Guy | 77a8116 | 2011-06-14 16:45:55 -0700 | [diff] [blame] | 1089 | return LayerRenderer::copyLayer(layer, bitmap); |
| 1090 | } |
| 1091 | |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 1092 | static void android_view_GLES20Canvas_pushLayerUpdate(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1093 | jlong rendererHandle, jlong layerHandle) { |
| 1094 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 1095 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 1096 | renderer->pushLayerUpdate(layer); |
| 1097 | } |
| 1098 | |
Romain Guy | e93482f | 2013-06-17 13:14:51 -0700 | [diff] [blame] | 1099 | static void android_view_GLES20Canvas_cancelLayerUpdate(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1100 | jlong rendererHandle, jlong layerHandle) { |
| 1101 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
| 1102 | Layer* layer = reinterpret_cast<Layer*>(layerHandle); |
Romain Guy | e93482f | 2013-06-17 13:14:51 -0700 | [diff] [blame] | 1103 | renderer->cancelLayerUpdate(layer); |
| 1104 | } |
| 1105 | |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 1106 | static void android_view_GLES20Canvas_clearLayerUpdates(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1107 | jlong rendererHandle) { |
| 1108 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 1109 | renderer->clearLayerUpdates(); |
| 1110 | } |
| 1111 | |
Romain Guy | 4054360 | 2013-06-12 15:31:28 -0700 | [diff] [blame] | 1112 | static void android_view_GLES20Canvas_flushLayerUpdates(JNIEnv* env, jobject clazz, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1113 | jlong rendererHandle) { |
| 1114 | OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle); |
Romain Guy | 4054360 | 2013-06-12 15:31:28 -0700 | [diff] [blame] | 1115 | renderer->flushLayerUpdates(); |
| 1116 | } |
| 1117 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 1118 | #endif // USE_OPENGL_RENDERER |
| 1119 | |
| 1120 | // ---------------------------------------------------------------------------- |
| 1121 | // Common |
| 1122 | // ---------------------------------------------------------------------------- |
| 1123 | |
| 1124 | static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz) { |
| 1125 | #ifdef USE_OPENGL_RENDERER |
Jesse Hall | 4406345 | 2011-12-01 11:27:45 -0800 | [diff] [blame] | 1126 | char prop[PROPERTY_VALUE_MAX]; |
| 1127 | if (property_get("ro.kernel.qemu", prop, NULL) == 0) { |
| 1128 | // not in the emulator |
| 1129 | return JNI_TRUE; |
| 1130 | } |
| 1131 | // In the emulator this property will be set to 1 when hardware GLES is |
| 1132 | // enabled, 0 otherwise. On old emulator versions it will be undefined. |
| 1133 | property_get("ro.kernel.qemu.gles", prop, "0"); |
| 1134 | return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE; |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 1135 | #else |
| 1136 | return JNI_FALSE; |
| 1137 | #endif |
| 1138 | } |
| 1139 | |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 1140 | // ---------------------------------------------------------------------------- |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1141 | // Logging |
| 1142 | // ---------------------------------------------------------------------------- |
| 1143 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1144 | static void |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1145 | android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) { |
Chet Haase | 905787a | 2011-04-01 14:33:02 -0700 | [diff] [blame] | 1146 | #ifdef USE_OPENGL_RENDERER |
Elliott Hughes | a3804cf | 2011-04-11 16:50:19 -0700 | [diff] [blame] | 1147 | int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); |
Chet Haase | 0865d33 | 2011-04-01 14:33:02 -0700 | [diff] [blame] | 1148 | android::uirenderer::DisplayList::outputLogBuffer(fd); |
Chet Haase | 905787a | 2011-04-01 14:33:02 -0700 | [diff] [blame] | 1149 | #endif // USE_OPENGL_RENDERER |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | // ---------------------------------------------------------------------------- |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1153 | // JNI Glue |
| 1154 | // ---------------------------------------------------------------------------- |
| 1155 | |
| 1156 | const char* const kClassPathName = "android/view/GLES20Canvas"; |
| 1157 | |
| 1158 | static JNINativeMethod gMethods[] = { |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1159 | { "nIsAvailable", "()Z", (void*) android_view_GLES20Canvas_isAvailable }, |
| 1160 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 1161 | #ifdef USE_OPENGL_RENDERER |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 1162 | { "nFlushCaches", "(I)V", (void*) android_view_GLES20Canvas_flushCaches }, |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 1163 | { "nInitCaches", "()Z", (void*) android_view_GLES20Canvas_initCaches }, |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 1164 | { "nTerminateCaches", "()V", (void*) android_view_GLES20Canvas_terminateCaches }, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 1165 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 1166 | { "nInitAtlas", "(Landroid/view/GraphicBuffer;[II)V", |
| 1167 | (void*) android_view_GLES20Canvas_initAtlas }, |
| 1168 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1169 | { "nCreateRenderer", "()J", (void*) android_view_GLES20Canvas_createRenderer }, |
| 1170 | { "nDestroyRenderer", "(J)V", (void*) android_view_GLES20Canvas_destroyRenderer }, |
| 1171 | { "nSetViewport", "(JII)V", (void*) android_view_GLES20Canvas_setViewport }, |
| 1172 | { "nPrepare", "(JZ)I", (void*) android_view_GLES20Canvas_prepare }, |
| 1173 | { "nPrepareDirty", "(JIIIIZ)I", (void*) android_view_GLES20Canvas_prepareDirty }, |
| 1174 | { "nFinish", "(J)V", (void*) android_view_GLES20Canvas_finish }, |
| 1175 | { "nSetName", "(JLjava/lang/String;)V", |
Romain Guy | ef35927 | 2013-01-31 19:07:29 -0800 | [diff] [blame] | 1176 | (void*) android_view_GLES20Canvas_setName }, |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 1177 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1178 | { "nSetCountOverdrawEnabled", "(JZ)V", (void*) android_view_GLES20Canvas_setCountOverdrawEnabled }, |
| 1179 | { "nGetOverdraw", "(J)F", (void*) android_view_GLES20Canvas_getOverdraw }, |
Romain Guy | 78dd96d | 2013-05-03 14:24:16 -0700 | [diff] [blame] | 1180 | |
Romain Guy | 530041d | 2012-01-25 18:56:29 -0800 | [diff] [blame] | 1181 | { "nGetStencilSize", "()I", (void*) android_view_GLES20Canvas_getStencilSize }, |
| 1182 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1183 | { "nCallDrawGLFunction", "(JJ)I", (void*) android_view_GLES20Canvas_callDrawGLFunction }, |
| 1184 | { "nDetachFunctor", "(JJ)V", (void*) android_view_GLES20Canvas_detachFunctor }, |
| 1185 | { "nAttachFunctor", "(JJ)V", (void*) android_view_GLES20Canvas_attachFunctor }, |
| 1186 | { "nInvokeFunctors", "(JLandroid/graphics/Rect;)I", |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 1187 | (void*) android_view_GLES20Canvas_invokeFunctors }, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 1188 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1189 | { "nSave", "(JI)I", (void*) android_view_GLES20Canvas_save }, |
| 1190 | { "nRestore", "(J)V", (void*) android_view_GLES20Canvas_restore }, |
| 1191 | { "nRestoreToCount", "(JI)V", (void*) android_view_GLES20Canvas_restoreToCount }, |
| 1192 | { "nGetSaveCount", "(J)I", (void*) android_view_GLES20Canvas_getSaveCount }, |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 1193 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1194 | { "nSaveLayer", "(JFFFFJI)I", (void*) android_view_GLES20Canvas_saveLayer }, |
| 1195 | { "nSaveLayer", "(JJI)I", (void*) android_view_GLES20Canvas_saveLayerClip }, |
| 1196 | { "nSaveLayerAlpha", "(JFFFFII)I", (void*) android_view_GLES20Canvas_saveLayerAlpha }, |
| 1197 | { "nSaveLayerAlpha", "(JII)I", (void*) android_view_GLES20Canvas_saveLayerAlphaClip }, |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 1198 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1199 | { "nQuickReject", "(JFFFF)Z", (void*) android_view_GLES20Canvas_quickReject }, |
| 1200 | { "nClipRect", "(JFFFFI)Z", (void*) android_view_GLES20Canvas_clipRectF }, |
| 1201 | { "nClipRect", "(JIIIII)Z", (void*) android_view_GLES20Canvas_clipRect }, |
| 1202 | { "nClipPath", "(JJI)Z", (void*) android_view_GLES20Canvas_clipPath }, |
| 1203 | { "nClipRegion", "(JJI)Z", (void*) android_view_GLES20Canvas_clipRegion }, |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 1204 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1205 | { "nTranslate", "(JFF)V", (void*) android_view_GLES20Canvas_translate }, |
| 1206 | { "nRotate", "(JF)V", (void*) android_view_GLES20Canvas_rotate }, |
| 1207 | { "nScale", "(JFF)V", (void*) android_view_GLES20Canvas_scale }, |
| 1208 | { "nSkew", "(JFF)V", (void*) android_view_GLES20Canvas_skew }, |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 1209 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1210 | { "nSetMatrix", "(JJ)V", (void*) android_view_GLES20Canvas_setMatrix }, |
| 1211 | { "nGetMatrix", "(JJ)V", (void*) android_view_GLES20Canvas_getMatrix }, |
| 1212 | { "nConcatMatrix", "(JJ)V", (void*) android_view_GLES20Canvas_concatMatrix }, |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 1213 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1214 | { "nDrawBitmap", "(JJ[BFFJ)V", (void*) android_view_GLES20Canvas_drawBitmap }, |
| 1215 | { "nDrawBitmap", "(JJ[BFFFFFFFFJ)V",(void*) android_view_GLES20Canvas_drawBitmapRect }, |
| 1216 | { "nDrawBitmap", "(JJ[BJJ)V", (void*) android_view_GLES20Canvas_drawBitmapMatrix }, |
| 1217 | { "nDrawBitmap", "(J[IIIFFIIZJ)V", (void*) android_view_GLES20Canvas_drawBitmapData }, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 1218 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1219 | { "nDrawBitmapMesh", "(JJ[BII[FI[IIJ)V",(void*) android_view_GLES20Canvas_drawBitmapMesh }, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 1220 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1221 | { "nDrawPatch", "(JJ[BJFFFFJ)V", (void*) android_view_GLES20Canvas_drawPatch }, |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 1222 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1223 | { "nDrawColor", "(JII)V", (void*) android_view_GLES20Canvas_drawColor }, |
| 1224 | { "nDrawRect", "(JFFFFJ)V", (void*) android_view_GLES20Canvas_drawRect }, |
| 1225 | { "nDrawRects", "(JJJ)V", (void*) android_view_GLES20Canvas_drawRegionAsRects }, |
| 1226 | { "nDrawRects", "(J[FIJ)V", (void*) android_view_GLES20Canvas_drawRects }, |
| 1227 | { "nDrawRoundRect", "(JFFFFFFJ)V", (void*) android_view_GLES20Canvas_drawRoundRect }, |
| 1228 | { "nDrawCircle", "(JFFFJ)V", (void*) android_view_GLES20Canvas_drawCircle }, |
| 1229 | { "nDrawOval", "(JFFFFJ)V", (void*) android_view_GLES20Canvas_drawOval }, |
| 1230 | { "nDrawArc", "(JFFFFFFZJ)V", (void*) android_view_GLES20Canvas_drawArc }, |
| 1231 | { "nDrawPoints", "(J[FIIJ)V", (void*) android_view_GLES20Canvas_drawPoints }, |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 1232 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1233 | { "nDrawPath", "(JJJ)V", (void*) android_view_GLES20Canvas_drawPath }, |
| 1234 | { "nDrawLines", "(J[FIIJ)V", (void*) android_view_GLES20Canvas_drawLines }, |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 1235 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1236 | { "nResetModifiers", "(JI)V", (void*) android_view_GLES20Canvas_resetModifiers }, |
| 1237 | { "nSetupShader", "(JJ)V", (void*) android_view_GLES20Canvas_setupShader }, |
| 1238 | { "nSetupColorFilter", "(JJ)V", (void*) android_view_GLES20Canvas_setupColorFilter }, |
| 1239 | { "nSetupShadow", "(JFFFI)V", (void*) android_view_GLES20Canvas_setupShadow }, |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 1240 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1241 | { "nSetupPaintFilter", "(JII)V", (void*) android_view_GLES20Canvas_setupPaintFilter }, |
| 1242 | { "nResetPaintFilter", "(J)V", (void*) android_view_GLES20Canvas_resetPaintFilter }, |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 1243 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1244 | { "nDrawText", "(J[CIIFFIJ)V", (void*) android_view_GLES20Canvas_drawTextArray }, |
| 1245 | { "nDrawText", "(JLjava/lang/String;IIFFIJ)V", |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 1246 | (void*) android_view_GLES20Canvas_drawText }, |
| 1247 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1248 | { "nDrawTextOnPath", "(J[CIIJFFIJ)V", (void*) android_view_GLES20Canvas_drawTextArrayOnPath }, |
| 1249 | { "nDrawTextOnPath", "(JLjava/lang/String;IIJFFIJ)V", |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 1250 | (void*) android_view_GLES20Canvas_drawTextOnPath }, |
| 1251 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1252 | { "nDrawTextRun", "(J[CIIIIFFIJ)V", (void*) android_view_GLES20Canvas_drawTextRunArray }, |
| 1253 | { "nDrawTextRun", "(JLjava/lang/String;IIIIFFIJ)V", |
Romain Guy | 61c8c9c | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 1254 | (void*) android_view_GLES20Canvas_drawTextRun }, |
| 1255 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1256 | { "nDrawPosText", "(J[CII[FJ)V", (void*) android_view_GLES20Canvas_drawPosTextArray }, |
| 1257 | { "nDrawPosText", "(JLjava/lang/String;II[FJ)V", |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 1258 | (void*) android_view_GLES20Canvas_drawPosText }, |
| 1259 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1260 | { "nGetClipBounds", "(JLandroid/graphics/Rect;)Z", |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 1261 | (void*) android_view_GLES20Canvas_getClipBounds }, |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1262 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1263 | { "nGetDisplayList", "(JJ)J", (void*) android_view_GLES20Canvas_getDisplayList }, |
| 1264 | { "nOutputDisplayList", "(JJ)V", (void*) android_view_GLES20Canvas_outputDisplayList }, |
| 1265 | { "nDrawDisplayList", "(JJLandroid/graphics/Rect;I)I", |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 1266 | (void*) android_view_GLES20Canvas_drawDisplayList }, |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 1267 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1268 | { "nCreateDisplayListRenderer", "()J", (void*) android_view_GLES20Canvas_createDisplayListRenderer }, |
| 1269 | { "nResetDisplayListRenderer", "(J)V", (void*) android_view_GLES20Canvas_resetDisplayListRenderer }, |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 1270 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1271 | { "nInterrupt", "(J)V", (void*) android_view_GLES20Canvas_interrupt }, |
| 1272 | { "nResume", "(J)V", (void*) android_view_GLES20Canvas_resume }, |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 1273 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1274 | { "nCreateLayerRenderer", "(J)J", (void*) android_view_GLES20Canvas_createLayerRenderer }, |
| 1275 | { "nCreateLayer", "(IIZ[I)J", (void*) android_view_GLES20Canvas_createLayer }, |
| 1276 | { "nResizeLayer", "(JII[I)Z" , (void*) android_view_GLES20Canvas_resizeLayer }, |
| 1277 | { "nSetLayerPaint", "(JJ)V", (void*) android_view_GLES20Canvas_setLayerPaint }, |
| 1278 | { "nSetLayerColorFilter", "(JJ)V", (void*) android_view_GLES20Canvas_setLayerColorFilter }, |
| 1279 | { "nSetOpaqueLayer", "(JZ)V", (void*) android_view_GLES20Canvas_setOpaqueLayer }, |
| 1280 | { "nCreateTextureLayer", "(Z[I)J", (void*) android_view_GLES20Canvas_createTextureLayer }, |
| 1281 | { "nUpdateTextureLayer", "(JIIZLandroid/graphics/SurfaceTexture;)V", |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 1282 | (void*) android_view_GLES20Canvas_updateTextureLayer }, |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1283 | { "nUpdateRenderLayer", "(JJJIIII)V", (void*) android_view_GLES20Canvas_updateRenderLayer }, |
| 1284 | { "nClearLayerTexture", "(J)V", (void*) android_view_GLES20Canvas_clearLayerTexture }, |
| 1285 | { "nDestroyLayer", "(J)V", (void*) android_view_GLES20Canvas_destroyLayer }, |
| 1286 | { "nDestroyLayerDeferred", "(J)V", (void*) android_view_GLES20Canvas_destroyLayerDeferred }, |
| 1287 | { "nDrawLayer", "(JJFF)V", (void*) android_view_GLES20Canvas_drawLayer }, |
| 1288 | { "nCopyLayer", "(JJ)Z", (void*) android_view_GLES20Canvas_copyLayer }, |
| 1289 | { "nClearLayerUpdates", "(J)V", (void*) android_view_GLES20Canvas_clearLayerUpdates }, |
| 1290 | { "nFlushLayerUpdates", "(J)V", (void*) android_view_GLES20Canvas_flushLayerUpdates }, |
| 1291 | { "nPushLayerUpdate", "(JJ)V", (void*) android_view_GLES20Canvas_pushLayerUpdate }, |
| 1292 | { "nCancelLayerUpdate", "(JJ)V", (void*) android_view_GLES20Canvas_cancelLayerUpdate }, |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1293 | |
Ashok Bhat | a039843 | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 1294 | { "nSetTextureLayerTransform", "(JJ)V", (void*) android_view_GLES20Canvas_setTextureLayerTransform }, |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 1295 | |
Romain Guy | f61970fc | 2011-07-07 14:10:06 -0700 | [diff] [blame] | 1296 | { "nGetMaximumTextureWidth", "()I", (void*) android_view_GLES20Canvas_getMaxTextureWidth }, |
| 1297 | { "nGetMaximumTextureHeight", "()I", (void*) android_view_GLES20Canvas_getMaxTextureHeight }, |
| 1298 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 1299 | #endif |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1300 | }; |
| 1301 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1302 | static JNINativeMethod gActivityThreadMethods[] = { |
| 1303 | { "dumpGraphicsInfo", "(Ljava/io/FileDescriptor;)V", |
| 1304 | (void*) android_app_ActivityThread_dumpGraphics } |
| 1305 | }; |
| 1306 | |
| 1307 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 1308 | #ifdef USE_OPENGL_RENDERER |
| 1309 | #define FIND_CLASS(var, className) \ |
| 1310 | var = env->FindClass(className); \ |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 1311 | LOG_FATAL_IF(! var, "Unable to find class " className); |
| 1312 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 1313 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \ |
| 1314 | var = env->GetMethodID(clazz, methodName, methodDescriptor); \ |
| 1315 | LOG_FATAL_IF(! var, "Unable to find method " methodName); |
| 1316 | #else |
| 1317 | #define FIND_CLASS(var, className) |
| 1318 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) |
| 1319 | #endif |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 1320 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1321 | int register_android_view_GLES20Canvas(JNIEnv* env) { |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 1322 | jclass clazz; |
| 1323 | FIND_CLASS(clazz, "android/graphics/Rect"); |
| 1324 | GET_METHOD_ID(gRectClassInfo.set, clazz, "set", "(IIII)V"); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 1325 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1326 | return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); |
| 1327 | } |
| 1328 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1329 | const char* const kActivityThreadPathName = "android/app/ActivityThread"; |
| 1330 | |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 1331 | int register_android_app_ActivityThread(JNIEnv* env) { |
| 1332 | return AndroidRuntime::registerNativeMethods(env, kActivityThreadPathName, |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 1333 | gActivityThreadMethods, NELEM(gActivityThreadMethods)); |
| 1334 | } |
| 1335 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1336 | }; |