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