blob: 6080f2a21b160416cb6cdc509773de70773af1e4 [file] [log] [blame]
Romain Guye4d01122010-06-16 18:44:05 -07001/*
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 Guya1db5742010-07-20 13:09:13 -070017#define LOG_TAG "OpenGLRenderer"
18
Romain Guye4d01122010-06-16 18:44:05 -070019#include "jni.h"
Patrick Dubroye4ac2d62010-12-01 11:23:13 -080020#include "GraphicsJNI.h"
Romain Guye4d01122010-06-16 18:44:05 -070021#include <nativehelper/JNIHelp.h>
Romain Guy65549432012-03-26 16:45:05 -070022
Romain Guye4d01122010-06-16 18:44:05 -070023#include <android_runtime/AndroidRuntime.h>
Romain Guy65549432012-03-26 16:45:05 -070024
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080025#include <androidfw/ResourceTypes.h>
Romain Guye4d01122010-06-16 18:44:05 -070026
Romain Guy65549432012-03-26 16:45:05 -070027#include <private/hwui/DrawGlInfo.h>
28
29#include <cutils/properties.h>
Romain Guy8f0095c2011-05-02 17:24:22 -070030
Romain Guyce0537b2010-06-29 21:05:21 -070031#include <SkBitmap.h>
Romain Guyc7d53492010-06-25 13:41:57 -070032#include <SkCanvas.h>
Leon Scroggins III57ee6202014-06-04 18:51:07 -040033#include <SkImageInfo.h>
Romain Guyf6a11b82010-06-23 17:47:49 -070034#include <SkMatrix.h>
Chris Craik2ce93282014-06-23 17:48:09 -070035#include <SkPorterDuff.h>
Romain Guy079ba2c2010-07-16 14:12:24 -070036#include <SkRegion.h>
Romain Guya1db5742010-07-20 13:09:13 -070037#include <SkScalerContext.h>
Romain Guy61c8c9c2010-08-09 20:48:09 -070038#include <SkTemplates.h>
Romain Guy85bf02f2010-06-22 13:11:24 -070039#include <SkXfermode.h>
Romain Guye4d01122010-06-16 18:44:05 -070040
Romain Guyb051e892010-09-28 19:09:36 -070041#include <DisplayListRenderer.h>
Romain Guy9d5316e2010-06-24 19:30:36 -070042#include <Rect.h>
John Reck113e0822014-03-18 09:22:59 -070043#include <RenderNode.h>
John Reck52244ff2014-05-01 21:27:37 -070044#include <CanvasProperty.h>
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040045#include <Paint.h>
Romain Guy85bf02f2010-06-22 13:11:24 -070046
Raph Levien1a73f7322014-01-30 16:06:28 -080047#include "MinikinUtils.h"
Romain Guye8e62a42010-07-23 18:55:21 -070048
Romain Guye4d01122010-06-16 18:44:05 -070049namespace android {
50
Romain Guy9d5316e2010-06-24 19:30:36 -070051using namespace uirenderer;
52
Romain Guy16393512010-08-08 00:14:31 -070053/**
John Reck3b202512014-06-23 13:13:08 -070054 * Note: DisplayListRenderer JNI layer is generated and compiled only on supported
Romain Guy16393512010-08-08 00:14:31 -070055 * devices. This means all the logic must be compiled only when the
56 * preprocessor variable USE_OPENGL_RENDERER is defined.
57 */
58#ifdef USE_OPENGL_RENDERER
59
Romain Guy244ada12012-03-28 16:41:26 -070060// ----------------------------------------------------------------------------
Romain Guybdb801ca2010-10-04 17:22:29 -070061// Defines
Romain Guy244ada12012-03-28 16:41:26 -070062// ----------------------------------------------------------------------------
Romain Guybdb801ca2010-10-04 17:22:29 -070063
64// Debug
Romain Guye2d345e2010-09-24 18:39:22 -070065#define DEBUG_RENDERER 0
Romain Guybdb801ca2010-10-04 17:22:29 -070066
67// Debug
68#if DEBUG_RENDERER
Steve Block5baa3a62011-12-20 16:23:08 +000069 #define RENDERER_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guybdb801ca2010-10-04 17:22:29 -070070#else
71 #define RENDERER_LOGD(...)
72#endif
Romain Guye2d345e2010-09-24 18:39:22 -070073
Romain Guy9d5316e2010-06-24 19:30:36 -070074// ----------------------------------------------------------------------------
Romain Guy9d5316e2010-06-24 19:30:36 -070075
76static struct {
Romain Guy7ae7ac42010-06-25 13:46:18 -070077 jmethodID set;
Romain Guy9d5316e2010-06-24 19:30:36 -070078} gRectClassInfo;
79
Romain Guye4d01122010-06-16 18:44:05 -070080// ----------------------------------------------------------------------------
81// Constructors
82// ----------------------------------------------------------------------------
83
Chet Haase5c13d892010-10-08 08:37:55 -070084static void android_view_GLES20Canvas_destroyRenderer(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +000085 jlong rendererPtr) {
John Reck3b202512014-06-23 13:13:08 -070086 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
87 RENDERER_LOGD("Destroy DisplayListRenderer");
Romain Guyf6a11b82010-06-23 17:47:49 -070088 delete renderer;
Romain Guye4d01122010-06-16 18:44:05 -070089}
90
91// ----------------------------------------------------------------------------
92// Setup
93// ----------------------------------------------------------------------------
94
Romain Guy7d7b5492011-01-24 16:33:45 -080095static void android_view_GLES20Canvas_setViewport(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +000096 jlong rendererPtr, jint width, jint height) {
John Reck3b202512014-06-23 13:13:08 -070097 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guyf6a11b82010-06-23 17:47:49 -070098 renderer->setViewport(width, height);
Romain Guye4d01122010-06-16 18:44:05 -070099}
100
Chris Craikcce47eb2014-07-16 15:12:15 -0700101static void android_view_GLES20Canvas_setHighContrastText(JNIEnv* env, jobject clazz,
102 jlong rendererPtr, jboolean highContrastText) {
103 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
104 renderer->setHighContrastText(highContrastText);
105}
106
Chris Craik8afd0f22014-08-21 17:41:57 -0700107static void android_view_GLES20Canvas_insertReorderBarrier(JNIEnv* env, jobject clazz,
108 jlong rendererPtr, jboolean reorderEnable) {
109 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
110 renderer->insertReorderBarrier(reorderEnable);
111}
112
Chet Haase44b2fe32012-06-06 19:03:58 -0700113static int android_view_GLES20Canvas_prepare(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000114 jlong rendererPtr, jboolean opaque) {
John Reck3b202512014-06-23 13:13:08 -0700115 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chet Haase44b2fe32012-06-06 19:03:58 -0700116 return renderer->prepare(opaque);
Romain Guye4d01122010-06-16 18:44:05 -0700117}
118
Chet Haase44b2fe32012-06-06 19:03:58 -0700119static int android_view_GLES20Canvas_prepareDirty(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000120 jlong rendererPtr, jint left, jint top, jint right, jint bottom,
Romain Guy7d7b5492011-01-24 16:33:45 -0800121 jboolean opaque) {
John Reck3b202512014-06-23 13:13:08 -0700122 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chet Haase44b2fe32012-06-06 19:03:58 -0700123 return renderer->prepareDirty(left, top, right, bottom, opaque);
Romain Guy7d7b5492011-01-24 16:33:45 -0800124}
125
126static void android_view_GLES20Canvas_finish(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000127 jlong rendererPtr) {
John Reck3b202512014-06-23 13:13:08 -0700128 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guyb025b9c2010-09-16 14:16:48 -0700129 renderer->finish();
130}
131
Chris Craikba9b6132013-12-15 17:10:19 -0800132static void android_view_GLES20Canvas_setProperty(JNIEnv* env,
133 jobject clazz, jstring name, jstring value) {
134 if (!Caches::hasInstance()) {
135 ALOGW("can't set property, no Caches instance");
136 return;
137 }
138
139 if (name == NULL || value == NULL) {
140 ALOGW("can't set prop, null passed");
141 }
142
143 const char* nameCharArray = env->GetStringUTFChars(name, NULL);
144 const char* valueCharArray = env->GetStringUTFChars(value, NULL);
145 Caches::getInstance().setTempProperty(nameCharArray, valueCharArray);
146 env->ReleaseStringUTFChars(name, nameCharArray);
147 env->ReleaseStringUTFChars(name, valueCharArray);
148}
149
Romain Guy530041d2012-01-25 18:56:29 -0800150// ----------------------------------------------------------------------------
151// Functor
152// ----------------------------------------------------------------------------
153
Romain Guy65549432012-03-26 16:45:05 -0700154static jint android_view_GLES20Canvas_callDrawGLFunction(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000155 jlong rendererPtr, jlong functorPtr) {
John Reck3b202512014-06-23 13:13:08 -0700156 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800157 Functor* functor = reinterpret_cast<Functor*>(functorPtr);
Romain Guycabfcc12011-03-07 18:06:46 -0800158 android::uirenderer::Rect dirty;
159 return renderer->callDrawGLFunction(functor, dirty);
Chet Haasedaf98e92011-01-10 14:10:36 -0800160}
161
Romain Guy8f3b8e32012-03-27 16:33:45 -0700162// ----------------------------------------------------------------------------
163// Misc
164// ----------------------------------------------------------------------------
165
Romain Guyf61970fc2011-07-07 14:10:06 -0700166static jint android_view_GLES20Canvas_getMaxTextureWidth(JNIEnv* env, jobject clazz) {
167 return Caches::getInstance().maxTextureSize;
168}
169
170static jint android_view_GLES20Canvas_getMaxTextureHeight(JNIEnv* env, jobject clazz) {
171 return Caches::getInstance().maxTextureSize;
172}
173
Romain Guye4d01122010-06-16 18:44:05 -0700174// ----------------------------------------------------------------------------
Romain Guybb9524b2010-06-22 18:56:38 -0700175// State
176// ----------------------------------------------------------------------------
177
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000178static jint android_view_GLES20Canvas_save(JNIEnv* env, jobject clazz, jlong rendererPtr,
Romain Guybb9524b2010-06-22 18:56:38 -0700179 jint flags) {
John Reck3b202512014-06-23 13:13:08 -0700180 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guyf6a11b82010-06-23 17:47:49 -0700181 return renderer->save(flags);
Romain Guybb9524b2010-06-22 18:56:38 -0700182}
183
Romain Guy7d7b5492011-01-24 16:33:45 -0800184static jint android_view_GLES20Canvas_getSaveCount(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000185 jlong rendererPtr) {
John Reck3b202512014-06-23 13:13:08 -0700186 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guyf6a11b82010-06-23 17:47:49 -0700187 return renderer->getSaveCount();
Romain Guybb9524b2010-06-22 18:56:38 -0700188}
189
Romain Guy7d7b5492011-01-24 16:33:45 -0800190static void android_view_GLES20Canvas_restore(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000191 jlong rendererPtr) {
John Reck3b202512014-06-23 13:13:08 -0700192 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guyf6a11b82010-06-23 17:47:49 -0700193 renderer->restore();
Romain Guybb9524b2010-06-22 18:56:38 -0700194}
195
Romain Guy7d7b5492011-01-24 16:33:45 -0800196static void android_view_GLES20Canvas_restoreToCount(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000197 jlong rendererPtr, jint saveCount) {
John Reck3b202512014-06-23 13:13:08 -0700198 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guyf6a11b82010-06-23 17:47:49 -0700199 renderer->restoreToCount(saveCount);
Romain Guybb9524b2010-06-22 18:56:38 -0700200}
201
202// ----------------------------------------------------------------------------
Romain Guybd6b79b2010-06-26 00:13:53 -0700203// Layers
204// ----------------------------------------------------------------------------
205
Romain Guy7d7b5492011-01-24 16:33:45 -0800206static jint android_view_GLES20Canvas_saveLayer(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000207 jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom,
208 jlong paintPtr, jint saveFlags) {
John Reck3b202512014-06-23 13:13:08 -0700209 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400210 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Romain Guybd6b79b2010-06-26 00:13:53 -0700211 return renderer->saveLayer(left, top, right, bottom, paint, saveFlags);
212}
213
Romain Guy189887e2011-08-25 11:45:13 -0700214static jint android_view_GLES20Canvas_saveLayerClip(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000215 jlong rendererPtr, jlong paintPtr, jint saveFlags) {
John Reck3b202512014-06-23 13:13:08 -0700216 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400217 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Chris Craik3f0854292014-04-15 16:18:08 -0700218 const android::uirenderer::Rect& bounds(renderer->getLocalClipBounds());
Romain Guy189887e2011-08-25 11:45:13 -0700219 return renderer->saveLayer(bounds.left, bounds.top, bounds.right, bounds.bottom,
220 paint, saveFlags);
221}
222
Romain Guy7d7b5492011-01-24 16:33:45 -0800223static jint android_view_GLES20Canvas_saveLayerAlpha(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000224 jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom,
Romain Guybd6b79b2010-06-26 00:13:53 -0700225 jint alpha, jint saveFlags) {
John Reck3b202512014-06-23 13:13:08 -0700226 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guybd6b79b2010-06-26 00:13:53 -0700227 return renderer->saveLayerAlpha(left, top, right, bottom, alpha, saveFlags);
228}
229
Romain Guy189887e2011-08-25 11:45:13 -0700230static jint android_view_GLES20Canvas_saveLayerAlphaClip(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000231 jlong rendererPtr, jint alpha, jint saveFlags) {
John Reck3b202512014-06-23 13:13:08 -0700232 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik3f0854292014-04-15 16:18:08 -0700233 const android::uirenderer::Rect& bounds(renderer->getLocalClipBounds());
Romain Guy189887e2011-08-25 11:45:13 -0700234 return renderer->saveLayerAlpha(bounds.left, bounds.top, bounds.right, bounds.bottom,
235 alpha, saveFlags);
236}
237
Romain Guybd6b79b2010-06-26 00:13:53 -0700238// ----------------------------------------------------------------------------
Romain Guybb9524b2010-06-22 18:56:38 -0700239// Clipping
240// ----------------------------------------------------------------------------
241
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000242static jboolean android_view_GLES20Canvas_quickReject(JNIEnv* env, jobject clazz,
243 jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom) {
John Reck3b202512014-06-23 13:13:08 -0700244 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000245 const bool result = renderer->quickRejectConservative(left, top, right, bottom);
246 return result ? JNI_TRUE : JNI_FALSE;
Romain Guyc7d53492010-06-25 13:41:57 -0700247}
248
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000249static jboolean android_view_GLES20Canvas_clipRectF(JNIEnv* env, jobject clazz,
250 jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom,
251 jint op) {
John Reck3b202512014-06-23 13:13:08 -0700252 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000253 const bool result = renderer->clipRect(left, top, right, bottom,
254 static_cast<SkRegion::Op>(op));
255 return result ? JNI_TRUE : JNI_FALSE;
Romain Guybb9524b2010-06-22 18:56:38 -0700256}
257
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000258static jboolean android_view_GLES20Canvas_clipRect(JNIEnv* env, jobject clazz,
259 jlong rendererPtr, jint left, jint top, jint right, jint bottom,
260 jint op) {
John Reck3b202512014-06-23 13:13:08 -0700261 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000262 const bool result = renderer->clipRect(float(left), float(top), float(right),
263 float(bottom),
264 static_cast<SkRegion::Op>(op));
265 return result ? JNI_TRUE : JNI_FALSE;
Romain Guyf6a11b82010-06-23 17:47:49 -0700266}
Romain Guybb9524b2010-06-22 18:56:38 -0700267
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000268static jboolean android_view_GLES20Canvas_clipPath(JNIEnv* env, jobject clazz,
269 jlong rendererPtr, jlong pathPtr, jint op) {
John Reck3b202512014-06-23 13:13:08 -0700270 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800271 SkPath* path = reinterpret_cast<SkPath*>(pathPtr);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000272 const bool result = renderer->clipPath(path, static_cast<SkRegion::Op>(op));
273 return result ? JNI_TRUE : JNI_FALSE;
Romain Guy735738c2012-12-03 12:34:51 -0800274}
275
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000276static jboolean android_view_GLES20Canvas_clipRegion(JNIEnv* env, jobject clazz,
277 jlong rendererPtr, jlong regionPtr, jint op) {
John Reck3b202512014-06-23 13:13:08 -0700278 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800279 SkRegion* region = reinterpret_cast<SkRegion*>(regionPtr);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000280 const bool result = renderer->clipRegion(region, static_cast<SkRegion::Op>(op));
281 return result ? JNI_TRUE : JNI_FALSE;
Romain Guy735738c2012-12-03 12:34:51 -0800282}
283
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000284static jboolean android_view_GLES20Canvas_getClipBounds(JNIEnv* env, jobject clazz,
285 jlong rendererPtr, jobject rect) {
John Reck3b202512014-06-23 13:13:08 -0700286 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik3f0854292014-04-15 16:18:08 -0700287 const android::uirenderer::Rect& bounds(renderer->getLocalClipBounds());
Romain Guy9d5316e2010-06-24 19:30:36 -0700288
Romain Guy7ae7ac42010-06-25 13:46:18 -0700289 env->CallVoidMethod(rect, gRectClassInfo.set,
290 int(bounds.left), int(bounds.top), int(bounds.right), int(bounds.bottom));
Romain Guy9d5316e2010-06-24 19:30:36 -0700291
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000292 return !bounds.isEmpty() ? JNI_TRUE : JNI_FALSE;
Romain Guy9d5316e2010-06-24 19:30:36 -0700293}
294
Romain Guyf6a11b82010-06-23 17:47:49 -0700295// ----------------------------------------------------------------------------
296// Transforms
297// ----------------------------------------------------------------------------
298
Romain Guy7d7b5492011-01-24 16:33:45 -0800299static void android_view_GLES20Canvas_translate(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000300 jlong rendererPtr, jfloat dx, jfloat dy) {
John Reck3b202512014-06-23 13:13:08 -0700301 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guy7ae7ac42010-06-25 13:46:18 -0700302 renderer->translate(dx, dy);
Romain Guyf6a11b82010-06-23 17:47:49 -0700303}
304
Romain Guy7d7b5492011-01-24 16:33:45 -0800305static void android_view_GLES20Canvas_rotate(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000306 jlong rendererPtr, jfloat degrees) {
John Reck3b202512014-06-23 13:13:08 -0700307 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guy7ae7ac42010-06-25 13:46:18 -0700308 renderer->rotate(degrees);
Romain Guyf6a11b82010-06-23 17:47:49 -0700309}
310
Romain Guy7d7b5492011-01-24 16:33:45 -0800311static void android_view_GLES20Canvas_scale(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000312 jlong rendererPtr, jfloat sx, jfloat sy) {
John Reck3b202512014-06-23 13:13:08 -0700313 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guy7ae7ac42010-06-25 13:46:18 -0700314 renderer->scale(sx, sy);
Romain Guyf6a11b82010-06-23 17:47:49 -0700315}
316
Romain Guy7d7b5492011-01-24 16:33:45 -0800317static void android_view_GLES20Canvas_skew(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000318 jlong rendererPtr, jfloat sx, jfloat sy) {
John Reck3b202512014-06-23 13:13:08 -0700319 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guy807daf72011-01-18 11:19:19 -0800320 renderer->skew(sx, sy);
321}
322
Romain Guy7d7b5492011-01-24 16:33:45 -0800323static void android_view_GLES20Canvas_setMatrix(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000324 jlong rendererPtr, jlong matrixPtr) {
John Reck3b202512014-06-23 13:13:08 -0700325 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800326 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr);
Derek Sollenberger13908822013-12-10 12:28:58 -0500327 renderer->setMatrix(matrix ? *matrix : SkMatrix::I());
Romain Guyf6a11b82010-06-23 17:47:49 -0700328}
329
Romain Guy7d7b5492011-01-24 16:33:45 -0800330static void android_view_GLES20Canvas_getMatrix(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000331 jlong rendererPtr, jlong matrixPtr) {
John Reck3b202512014-06-23 13:13:08 -0700332 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800333 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr);
Romain Guy7ae7ac42010-06-25 13:46:18 -0700334 renderer->getMatrix(matrix);
Romain Guyf6a11b82010-06-23 17:47:49 -0700335}
336
Romain Guy7d7b5492011-01-24 16:33:45 -0800337static void android_view_GLES20Canvas_concatMatrix(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000338 jlong rendererPtr, jlong matrixPtr) {
John Reck3b202512014-06-23 13:13:08 -0700339 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800340 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr);
Derek Sollenberger13908822013-12-10 12:28:58 -0500341 renderer->concatMatrix(*matrix);
Romain Guybb9524b2010-06-22 18:56:38 -0700342}
343
344// ----------------------------------------------------------------------------
345// Drawing
Romain Guy85bf02f2010-06-22 13:11:24 -0700346// ----------------------------------------------------------------------------
347
Romain Guy7d7b5492011-01-24 16:33:45 -0800348static void android_view_GLES20Canvas_drawBitmap(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000349 jlong rendererPtr, jlong bitmapPtr, jbyteArray buffer,
350 jfloat left, jfloat top, jlong paintPtr) {
Chris Craik9f66ea02013-12-27 15:15:55 -0800351 SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr);
Chris Craik0c20c382013-07-02 10:48:54 -0700352 // This object allows the renderer to allocate a global JNI ref to the buffer object.
353 JavaHeapBitmapRef bitmapRef(env, bitmap, buffer);
354
John Reck3b202512014-06-23 13:13:08 -0700355 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400356 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Chris Craik79647502014-08-06 13:42:24 -0700357
358 // apply transform directly to canvas, so it affects shaders correctly
359 renderer->save(SkCanvas::kMatrix_SaveFlag);
360 renderer->translate(left, top);
361 renderer->drawBitmap(bitmap, paint);
362 renderer->restore();
Romain Guy85bf02f2010-06-22 13:11:24 -0700363}
364
Romain Guy7d7b5492011-01-24 16:33:45 -0800365static void android_view_GLES20Canvas_drawBitmapRect(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000366 jlong rendererPtr, jlong bitmapPtr, jbyteArray buffer,
Romain Guyce0537b2010-06-29 21:05:21 -0700367 float srcLeft, float srcTop, float srcRight, float srcBottom,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000368 float dstLeft, float dstTop, float dstRight, float dstBottom, jlong paintPtr) {
Chris Craik9f66ea02013-12-27 15:15:55 -0800369 SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr);
Chris Craik0c20c382013-07-02 10:48:54 -0700370 // This object allows the renderer to allocate a global JNI ref to the buffer object.
371 JavaHeapBitmapRef bitmapRef(env, bitmap, buffer);
372
John Reck3b202512014-06-23 13:13:08 -0700373 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400374 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Romain Guydbd77cd2010-07-09 10:36:05 -0700375 renderer->drawBitmap(bitmap, srcLeft, srcTop, srcRight, srcBottom,
376 dstLeft, dstTop, dstRight, dstBottom, paint);
Romain Guyf86ef572010-07-01 11:05:42 -0700377}
Romain Guy8ba548f2010-06-30 19:21:21 -0700378
Romain Guy7d7b5492011-01-24 16:33:45 -0800379static void android_view_GLES20Canvas_drawBitmapMatrix(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000380 jlong rendererPtr, jlong bitmapPtr, jbyteArray buffer,
381 jlong matrixPtr, jlong paintPtr) {
Chris Craik9f66ea02013-12-27 15:15:55 -0800382 SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr);
Chris Craik0c20c382013-07-02 10:48:54 -0700383 // This object allows the renderer to allocate a global JNI ref to the buffer object.
384 JavaHeapBitmapRef bitmapRef(env, bitmap, buffer);
385
John Reck3b202512014-06-23 13:13:08 -0700386 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800387 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400388 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Chris Craik79647502014-08-06 13:42:24 -0700389
390 // apply transform directly to canvas, so it affects shaders correctly
391 renderer->save(SkCanvas::kMatrix_SaveFlag);
392 renderer->concatMatrix(*matrix);
393 renderer->drawBitmap(bitmap, paint);
394 renderer->restore();
Romain Guyce0537b2010-06-29 21:05:21 -0700395}
396
Romain Guye651cc62012-05-14 19:44:40 -0700397static void android_view_GLES20Canvas_drawBitmapData(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000398 jlong rendererPtr, jintArray colors, jint offset, jint stride,
399 jfloat left, jfloat top, jint width, jint height, jboolean hasAlpha, jlong paintPtr) {
Leon Scroggins III57ee6202014-06-04 18:51:07 -0400400 // Note: If hasAlpha is false, kRGB_565_SkColorType will be used, which will
401 // correct the alphaType to kOpaque_SkAlphaType.
Mike Reedb9330552014-06-16 17:31:48 -0400402 const SkImageInfo info = SkImageInfo::Make(width, height,
403 hasAlpha ? kN32_SkColorType : kRGB_565_SkColorType,
404 kPremul_SkAlphaType);
Romain Guy49c5fc02012-05-15 11:10:01 -0700405 SkBitmap* bitmap = new SkBitmap;
Mike Reedb9330552014-06-16 17:31:48 -0400406 if (!bitmap->allocPixels(info)) {
Romain Guy49c5fc02012-05-15 11:10:01 -0700407 delete bitmap;
Romain Guye651cc62012-05-14 19:44:40 -0700408 return;
409 }
410
Leon Scroggins III57ee6202014-06-04 18:51:07 -0400411 if (!GraphicsJNI::SetPixels(env, colors, offset, stride, 0, 0, width, height, *bitmap)) {
Romain Guy49c5fc02012-05-15 11:10:01 -0700412 delete bitmap;
Romain Guye651cc62012-05-14 19:44:40 -0700413 return;
414 }
415
John Reck3b202512014-06-23 13:13:08 -0700416 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400417 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Chris Craik79647502014-08-06 13:42:24 -0700418
419 // apply transform directly to canvas, so it affects shaders correctly
420 renderer->save(SkCanvas::kMatrix_SaveFlag);
421 renderer->translate(left, top);
422 renderer->drawBitmapData(bitmap, paint);
423 renderer->restore();
Romain Guy49c5fc02012-05-15 11:10:01 -0700424
Chris Craikf23b25a2014-06-26 15:46:20 -0700425 // Note - bitmap isn't deleted as DisplayListRenderer owns it now
Romain Guye651cc62012-05-14 19:44:40 -0700426}
427
Romain Guy7d7b5492011-01-24 16:33:45 -0800428static void android_view_GLES20Canvas_drawBitmapMesh(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000429 jlong rendererPtr, jlong bitmapPtr, jbyteArray buffer,
Chris Craik0c20c382013-07-02 10:48:54 -0700430 jint meshWidth, jint meshHeight, jfloatArray vertices, jint offset, jintArray colors,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000431 jint colorOffset, jlong paintPtr) {
Chris Craik9f66ea02013-12-27 15:15:55 -0800432 SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr);
Chris Craik0c20c382013-07-02 10:48:54 -0700433 // This object allows the renderer to allocate a global JNI ref to the buffer object.
434 JavaHeapBitmapRef bitmapRef(env, bitmap, buffer);
435
Romain Guy5a7b4662011-01-20 19:09:30 -0800436 jfloat* verticesArray = vertices ? env->GetFloatArrayElements(vertices, NULL) + offset : NULL;
437 jint* colorsArray = colors ? env->GetIntArrayElements(colors, NULL) + colorOffset : NULL;
438
John Reck3b202512014-06-23 13:13:08 -0700439 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400440 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Romain Guy5a7b4662011-01-20 19:09:30 -0800441 renderer->drawBitmapMesh(bitmap, meshWidth, meshHeight, verticesArray, colorsArray, paint);
442
443 if (vertices) env->ReleaseFloatArrayElements(vertices, verticesArray, 0);
444 if (colors) env->ReleaseIntArrayElements(colors, colorsArray, 0);
445}
446
Romain Guy7d7b5492011-01-24 16:33:45 -0800447static void android_view_GLES20Canvas_drawPatch(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000448 jlong rendererPtr, jlong bitmapPtr, jbyteArray buffer, jlong patchPtr,
449 float left, float top, float right, float bottom, jlong paintPtr) {
Chris Craik9f66ea02013-12-27 15:15:55 -0800450 SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr);
Chris Craik0c20c382013-07-02 10:48:54 -0700451 // This object allows the renderer to allocate a global JNI ref to the buffer object.
452 JavaHeapBitmapRef bitmapRef(env, bitmap, buffer);
453
John Reck3b202512014-06-23 13:13:08 -0700454 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800455 Res_png_9patch* patch = reinterpret_cast<Res_png_9patch*>(patchPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400456 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Romain Guy3b748a42013-04-17 18:54:38 -0700457 renderer->drawPatch(bitmap, patch, left, top, right, bottom, paint);
Romain Guydeba7852010-07-07 17:54:48 -0700458}
459
Romain Guy7d7b5492011-01-24 16:33:45 -0800460static void android_view_GLES20Canvas_drawColor(JNIEnv* env, jobject clazz,
Chris Craik2ce93282014-06-23 17:48:09 -0700461 jlong rendererPtr, jint color, jint modeHandle) {
John Reck3b202512014-06-23 13:13:08 -0700462 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik2ce93282014-06-23 17:48:09 -0700463 SkPorterDuff::Mode mode = static_cast<SkPorterDuff::Mode>(modeHandle);
464 renderer->drawColor(color, SkPorterDuff::ToXfermodeMode(mode));
Romain Guyce0537b2010-06-29 21:05:21 -0700465}
466
Romain Guy7d7b5492011-01-24 16:33:45 -0800467static void android_view_GLES20Canvas_drawRect(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000468 jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom,
469 jlong paintPtr) {
John Reck3b202512014-06-23 13:13:08 -0700470 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400471 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Romain Guyc7d53492010-06-25 13:41:57 -0700472 renderer->drawRect(left, top, right, bottom, paint);
473}
474
Romain Guy7d7b5492011-01-24 16:33:45 -0800475static void android_view_GLES20Canvas_drawRoundRect(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000476 jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom,
477 jfloat rx, jfloat ry, jlong paintPtr) {
John Reck3b202512014-06-23 13:13:08 -0700478 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400479 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Romain Guy01d58e42011-01-19 21:54:02 -0800480 renderer->drawRoundRect(left, top, right, bottom, rx, ry, paint);
481}
482
Romain Guy7d7b5492011-01-24 16:33:45 -0800483static void android_view_GLES20Canvas_drawCircle(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000484 jlong rendererPtr, jfloat x, jfloat y, jfloat radius, jlong paintPtr) {
John Reck3b202512014-06-23 13:13:08 -0700485 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400486 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Romain Guy01d58e42011-01-19 21:54:02 -0800487 renderer->drawCircle(x, y, radius, paint);
488}
489
John Reck52244ff2014-05-01 21:27:37 -0700490static void android_view_GLES20Canvas_drawCircleProps(JNIEnv* env, jobject clazz,
491 jlong rendererPtr, jlong xPropPtr, jlong yPropPtr, jlong radiusPropPtr, jlong paintPropPtr) {
John Reck3b202512014-06-23 13:13:08 -0700492 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
John Reck52244ff2014-05-01 21:27:37 -0700493 CanvasPropertyPrimitive* xProp = reinterpret_cast<CanvasPropertyPrimitive*>(xPropPtr);
494 CanvasPropertyPrimitive* yProp = reinterpret_cast<CanvasPropertyPrimitive*>(yPropPtr);
495 CanvasPropertyPrimitive* radiusProp = reinterpret_cast<CanvasPropertyPrimitive*>(radiusPropPtr);
496 CanvasPropertyPaint* paintProp = reinterpret_cast<CanvasPropertyPaint*>(paintPropPtr);
497 renderer->drawCircle(xProp, yProp, radiusProp, paintProp);
498}
499
Romain Guy7d7b5492011-01-24 16:33:45 -0800500static void android_view_GLES20Canvas_drawOval(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000501 jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom,
502 jlong paintPtr) {
John Reck3b202512014-06-23 13:13:08 -0700503 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400504 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800505 renderer->drawOval(left, top, right, bottom, paint);
506}
507
Romain Guy7d7b5492011-01-24 16:33:45 -0800508static void android_view_GLES20Canvas_drawArc(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000509 jlong rendererPtr, jfloat left, jfloat top, jfloat right, jfloat bottom,
510 jfloat startAngle, jfloat sweepAngle, jboolean useCenter, jlong paintPtr) {
John Reck3b202512014-06-23 13:13:08 -0700511 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400512 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Romain Guy8b2f5262011-01-23 16:15:02 -0800513 renderer->drawArc(left, top, right, bottom, startAngle, sweepAngle, useCenter, paint);
514}
515
Romain Guy672433d2013-01-04 19:05:13 -0800516static void android_view_GLES20Canvas_drawRegionAsRects(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000517 jlong rendererPtr, jlong regionPtr, jlong paintPtr) {
John Reck3b202512014-06-23 13:13:08 -0700518 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800519 SkRegion* region = reinterpret_cast<SkRegion*>(regionPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400520 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
521 if (paint->getStyle() != Paint::kFill_Style ||
Romain Guy672433d2013-01-04 19:05:13 -0800522 (paint->isAntiAlias() && !renderer->isCurrentTransformSimple())) {
523 SkRegion::Iterator it(*region);
524 while (!it.done()) {
525 const SkIRect& r = it.rect();
526 renderer->drawRect(r.fLeft, r.fTop, r.fRight, r.fBottom, paint);
527 it.next();
528 }
529 } else {
530 int count = 0;
531 Vector<float> rects;
532 SkRegion::Iterator it(*region);
533 while (!it.done()) {
534 const SkIRect& r = it.rect();
535 rects.push(r.fLeft);
536 rects.push(r.fTop);
537 rects.push(r.fRight);
538 rects.push(r.fBottom);
Chris Craik2af46352012-11-26 18:30:17 -0800539 count += 4;
Romain Guy672433d2013-01-04 19:05:13 -0800540 it.next();
541 }
542 renderer->drawRects(rects.array(), count, paint);
Romain Guya48a1a82010-08-10 14:59:15 -0700543 }
544}
545
Romain Guyed6fcb02011-03-21 13:11:28 -0700546static void android_view_GLES20Canvas_drawPoints(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000547 jlong rendererPtr, jfloatArray points, jint offset, jint count, jlong paintPtr) {
John Reck3b202512014-06-23 13:13:08 -0700548 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guyed6fcb02011-03-21 13:11:28 -0700549 jfloat* storage = env->GetFloatArrayElements(points, NULL);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400550 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Romain Guyed6fcb02011-03-21 13:11:28 -0700551 renderer->drawPoints(storage + offset, count, paint);
552 env->ReleaseFloatArrayElements(points, storage, 0);
553}
554
Romain Guy7d7b5492011-01-24 16:33:45 -0800555static void android_view_GLES20Canvas_drawPath(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000556 jlong rendererPtr, jlong pathPtr, jlong paintPtr) {
John Reck3b202512014-06-23 13:13:08 -0700557 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800558 SkPath* path = reinterpret_cast<SkPath*>(pathPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400559 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Romain Guy7fbcc042010-08-04 15:40:07 -0700560 renderer->drawPath(path, paint);
561}
562
Romain Guy7d7b5492011-01-24 16:33:45 -0800563static void android_view_GLES20Canvas_drawLines(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000564 jlong rendererPtr, jfloatArray points, jint offset, jint count, jlong paintPtr) {
John Reck3b202512014-06-23 13:13:08 -0700565 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guy759ea802010-09-16 20:49:46 -0700566 jfloat* storage = env->GetFloatArrayElements(points, NULL);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400567 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Romain Guy759ea802010-09-16 20:49:46 -0700568 renderer->drawLines(storage + offset, count, paint);
Romain Guy759ea802010-09-16 20:49:46 -0700569 env->ReleaseFloatArrayElements(points, storage, 0);
570}
571
Romain Guy85bf02f2010-06-22 13:11:24 -0700572// ----------------------------------------------------------------------------
Romain Guy5ff9df62012-01-23 17:09:05 -0800573// Draw filters
574// ----------------------------------------------------------------------------
575
576static void android_view_GLES20Canvas_setupPaintFilter(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000577 jlong rendererPtr, jint clearBits, jint setBits) {
John Reck3b202512014-06-23 13:13:08 -0700578 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guy5ff9df62012-01-23 17:09:05 -0800579 renderer->setupPaintFilter(clearBits, setBits);
580}
581
582static void android_view_GLES20Canvas_resetPaintFilter(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000583 jlong rendererPtr) {
John Reck3b202512014-06-23 13:13:08 -0700584 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guy5ff9df62012-01-23 17:09:05 -0800585 renderer->resetPaintFilter();
586}
587
588// ----------------------------------------------------------------------------
Romain Guya1db5742010-07-20 13:09:13 -0700589// Text
590// ----------------------------------------------------------------------------
591
Raph Levienf2114d52014-06-01 15:54:47 -0700592class RenderTextFunctor {
593public:
John Reck3b202512014-06-23 13:13:08 -0700594 RenderTextFunctor(const Layout& layout, DisplayListRenderer* renderer, jfloat x, jfloat y,
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400595 Paint* paint, uint16_t* glyphs, float* pos, float totalAdvance,
Raph Levienf2114d52014-06-01 15:54:47 -0700596 uirenderer::Rect& bounds)
597 : layout(layout), renderer(renderer), x(x), y(y), paint(paint), glyphs(glyphs),
598 pos(pos), totalAdvance(totalAdvance), bounds(bounds) { }
Raph Levien1fc0fa82014-06-06 18:05:22 -0700599 void operator()(size_t start, size_t end) {
Raph Levienf2114d52014-06-01 15:54:47 -0700600 for (size_t i = start; i < end; i++) {
601 glyphs[i] = layout.getGlyphId(i);
602 pos[2 * i] = layout.getX(i);
603 pos[2 * i + 1] = layout.getY(i);
604 }
Raph Levienf2114d52014-06-01 15:54:47 -0700605 size_t glyphsCount = end - start;
606 int bytesCount = glyphsCount * sizeof(jchar);
607 renderer->drawText((const char*) (glyphs + start), bytesCount, glyphsCount,
608 x, y, pos + 2 * start, paint, totalAdvance, bounds);
609 }
610private:
611 const Layout& layout;
John Reck3b202512014-06-23 13:13:08 -0700612 DisplayListRenderer* renderer;
Raph Levienf2114d52014-06-01 15:54:47 -0700613 jfloat x;
614 jfloat y;
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400615 Paint* paint;
Raph Levienf2114d52014-06-01 15:54:47 -0700616 uint16_t* glyphs;
617 float* pos;
618 float totalAdvance;
619 uirenderer::Rect& bounds;
620};
621
John Reck3b202512014-06-23 13:13:08 -0700622static void renderTextLayout(DisplayListRenderer* renderer, Layout* layout,
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400623 jfloat x, jfloat y, Paint* paint) {
Raph Levien1a73f7322014-01-30 16:06:28 -0800624 size_t nGlyphs = layout->nGlyphs();
625 float* pos = new float[nGlyphs * 2];
626 uint16_t* glyphs = new uint16_t[nGlyphs];
Raph Levien1a73f7322014-01-30 16:06:28 -0800627 MinikinRect b;
628 layout->getBounds(&b);
629 android::uirenderer::Rect bounds(b.mLeft, b.mTop, b.mRight, b.mBottom);
630 bounds.translate(x, y);
631 float totalAdvance = layout->getAdvance();
632
Raph Levienf2114d52014-06-01 15:54:47 -0700633 RenderTextFunctor f(*layout, renderer, x, y, paint, glyphs, pos, totalAdvance, bounds);
Raph Levien1fc0fa82014-06-06 18:05:22 -0700634 MinikinUtils::forFontRun(*layout, paint, f);
Raph Levien1a73f7322014-01-30 16:06:28 -0800635 delete[] glyphs;
636 delete[] pos;
637}
Raph Levien1a73f7322014-01-30 16:06:28 -0800638
John Reck3b202512014-06-23 13:13:08 -0700639static void renderText(DisplayListRenderer* renderer, const jchar* text, int count,
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400640 jfloat x, jfloat y, int bidiFlags, Paint* paint, TypefaceImpl* typeface) {
Raph Levien1a73f7322014-01-30 16:06:28 -0800641 Layout layout;
Behdad Esfahbod63c5c782014-07-25 14:54:46 -0400642 MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count);
Raph Levien36607892014-06-25 16:32:13 -0700643 x += MinikinUtils::xOffsetForTextAlign(paint, layout);
Raph Levien1a73f7322014-01-30 16:06:28 -0800644 renderTextLayout(renderer, &layout, x, y, paint);
Romain Guye8e62a42010-07-23 18:55:21 -0700645}
646
Raph Levien9d2b5e12014-06-15 23:53:57 -0700647class RenderTextOnPathFunctor {
648public:
John Reck3b202512014-06-23 13:13:08 -0700649 RenderTextOnPathFunctor(const Layout& layout, DisplayListRenderer* renderer, float hOffset,
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400650 float vOffset, Paint* paint, SkPath* path)
Raph Levien9d2b5e12014-06-15 23:53:57 -0700651 : layout(layout), renderer(renderer), hOffset(hOffset), vOffset(vOffset),
652 paint(paint), path(path) {
653 }
654 void operator()(size_t start, size_t end) {
655 uint16_t glyphs[1];
656 for (size_t i = start; i < end; i++) {
657 glyphs[0] = layout.getGlyphId(i);
658 float x = hOffset + layout.getX(i);
659 float y = vOffset + layout.getY(i);
660 renderer->drawTextOnPath((const char*) glyphs, sizeof(glyphs), 1, path, x, y, paint);
661 }
662 }
663private:
664 const Layout& layout;
John Reck3b202512014-06-23 13:13:08 -0700665 DisplayListRenderer* renderer;
Raph Levien9d2b5e12014-06-15 23:53:57 -0700666 float hOffset;
667 float vOffset;
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400668 Paint* paint;
Raph Levien9d2b5e12014-06-15 23:53:57 -0700669 SkPath* path;
670};
Raph Levien9d2b5e12014-06-15 23:53:57 -0700671
John Reck3b202512014-06-23 13:13:08 -0700672static void renderTextOnPath(DisplayListRenderer* renderer, const jchar* text, int count,
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400673 SkPath* path, jfloat hOffset, jfloat vOffset, int bidiFlags, Paint* paint,
Raph Levien9d2b5e12014-06-15 23:53:57 -0700674 TypefaceImpl* typeface) {
Raph Levien9d2b5e12014-06-15 23:53:57 -0700675 Layout layout;
Behdad Esfahbod63c5c782014-07-25 14:54:46 -0400676 MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count);
Raph Levien9d2b5e12014-06-15 23:53:57 -0700677 hOffset += MinikinUtils::hOffsetForTextAlign(paint, layout, *path);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400678 Paint::Align align = paint->getTextAlign();
679 paint->setTextAlign(Paint::kLeft_Align);
Raph Levien9d2b5e12014-06-15 23:53:57 -0700680
681 RenderTextOnPathFunctor f(layout, renderer, hOffset, vOffset, paint, path);
682 MinikinUtils::forFontRun(layout, paint, f);
683 paint->setTextAlign(align);
Romain Guy325740f2012-02-24 16:48:34 -0800684}
685
John Reck3b202512014-06-23 13:13:08 -0700686static void renderTextRun(DisplayListRenderer* renderer, const jchar* text,
Romain Guy61c8c9c2010-08-09 20:48:09 -0700687 jint start, jint count, jint contextCount, jfloat x, jfloat y,
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400688 int bidiFlags, Paint* paint, TypefaceImpl* typeface) {
Raph Levien1a73f7322014-01-30 16:06:28 -0800689 Layout layout;
Behdad Esfahbod63c5c782014-07-25 14:54:46 -0400690 MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, start, count, contextCount);
Raph Levien36607892014-06-25 16:32:13 -0700691 x += MinikinUtils::xOffsetForTextAlign(paint, layout);
Raph Levien1a73f7322014-01-30 16:06:28 -0800692 renderTextLayout(renderer, &layout, x, y, paint);
Romain Guy61c8c9c2010-08-09 20:48:09 -0700693}
694
Romain Guy7d7b5492011-01-24 16:33:45 -0800695static void android_view_GLES20Canvas_drawTextArray(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000696 jlong rendererPtr, jcharArray text, jint index, jint count,
Raph Levien051910b2014-06-15 18:25:29 -0700697 jfloat x, jfloat y, jint bidiFlags, jlong paintPtr, jlong typefacePtr) {
John Reck3b202512014-06-23 13:13:08 -0700698 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guya1db5742010-07-20 13:09:13 -0700699 jchar* textArray = env->GetCharArrayElements(text, NULL);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400700 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Raph Levien1a73f7322014-01-30 16:06:28 -0800701 TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefacePtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800702
Raph Levien051910b2014-06-15 18:25:29 -0700703 renderText(renderer, textArray + index, count, x, y, bidiFlags, paint, typeface);
Romain Guya1db5742010-07-20 13:09:13 -0700704 env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
705}
706
Romain Guy7d7b5492011-01-24 16:33:45 -0800707static void android_view_GLES20Canvas_drawText(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000708 jlong rendererPtr, jstring text, jint start, jint end,
Raph Levien051910b2014-06-15 18:25:29 -0700709 jfloat x, jfloat y, jint bidiFlags, jlong paintPtr, jlong typefacePtr) {
John Reck3b202512014-06-23 13:13:08 -0700710 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guya1db5742010-07-20 13:09:13 -0700711 const jchar* textArray = env->GetStringChars(text, NULL);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400712 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Raph Levien1a73f7322014-01-30 16:06:28 -0800713 TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefacePtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800714
Raph Levien051910b2014-06-15 18:25:29 -0700715 renderText(renderer, textArray + start, end - start, x, y, bidiFlags, paint, typeface);
Romain Guya1db5742010-07-20 13:09:13 -0700716 env->ReleaseStringChars(text, textArray);
717}
718
Romain Guy325740f2012-02-24 16:48:34 -0800719static void android_view_GLES20Canvas_drawTextArrayOnPath(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000720 jlong rendererPtr, jcharArray text, jint index, jint count,
Raph Levien9d2b5e12014-06-15 23:53:57 -0700721 jlong pathPtr, jfloat hOffset, jfloat vOffset, jint bidiFlags, jlong paintPtr,
722 jlong typefacePtr) {
John Reck3b202512014-06-23 13:13:08 -0700723 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guy325740f2012-02-24 16:48:34 -0800724 jchar* textArray = env->GetCharArrayElements(text, NULL);
Chris Craik9f66ea02013-12-27 15:15:55 -0800725 SkPath* path = reinterpret_cast<SkPath*>(pathPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400726 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Raph Levien9d2b5e12014-06-15 23:53:57 -0700727 TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefacePtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800728
Romain Guy325740f2012-02-24 16:48:34 -0800729 renderTextOnPath(renderer, textArray + index, count, path,
Raph Levien9d2b5e12014-06-15 23:53:57 -0700730 hOffset, vOffset, bidiFlags, paint, typeface);
Romain Guy325740f2012-02-24 16:48:34 -0800731 env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
732}
733
734static void android_view_GLES20Canvas_drawTextOnPath(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000735 jlong rendererPtr, jstring text, jint start, jint end,
Raph Levien9d2b5e12014-06-15 23:53:57 -0700736 jlong pathPtr, jfloat hOffset, jfloat vOffset, jint bidiFlags, jlong paintPtr,
737 jlong typefacePtr) {
John Reck3b202512014-06-23 13:13:08 -0700738 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guy325740f2012-02-24 16:48:34 -0800739 const jchar* textArray = env->GetStringChars(text, NULL);
Chris Craik9f66ea02013-12-27 15:15:55 -0800740 SkPath* path = reinterpret_cast<SkPath*>(pathPtr);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400741 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Raph Levien9d2b5e12014-06-15 23:53:57 -0700742 TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefacePtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800743
Romain Guy325740f2012-02-24 16:48:34 -0800744 renderTextOnPath(renderer, textArray + start, end - start, path,
Raph Levien9d2b5e12014-06-15 23:53:57 -0700745 hOffset, vOffset, bidiFlags, paint, typeface);
Romain Guy325740f2012-02-24 16:48:34 -0800746 env->ReleaseStringChars(text, textArray);
747}
748
Romain Guy7d7b5492011-01-24 16:33:45 -0800749static void android_view_GLES20Canvas_drawTextRunArray(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000750 jlong rendererPtr, jcharArray text, jint index, jint count,
Raph Levien051910b2014-06-15 18:25:29 -0700751 jint contextIndex, jint contextCount, jfloat x, jfloat y, jboolean isRtl,
Raph Levien1a73f7322014-01-30 16:06:28 -0800752 jlong paintPtr, jlong typefacePtr) {
John Reck3b202512014-06-23 13:13:08 -0700753 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guy61c8c9c2010-08-09 20:48:09 -0700754 jchar* textArray = env->GetCharArrayElements(text, NULL);
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400755 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Raph Levien1a73f7322014-01-30 16:06:28 -0800756 TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefacePtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800757
Raph Levien051910b2014-06-15 18:25:29 -0700758 int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR;
Romain Guy61c8c9c2010-08-09 20:48:09 -0700759 renderTextRun(renderer, textArray + contextIndex, index - contextIndex,
Raph Levien051910b2014-06-15 18:25:29 -0700760 count, contextCount, x, y, bidiFlags, paint, typeface);
Romain Guy61c8c9c2010-08-09 20:48:09 -0700761 env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
762 }
763
Romain Guy7d7b5492011-01-24 16:33:45 -0800764static void android_view_GLES20Canvas_drawTextRun(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000765 jlong rendererPtr, jstring text, jint start, jint end,
Raph Levien051910b2014-06-15 18:25:29 -0700766 jint contextStart, int contextEnd, jfloat x, jfloat y, jboolean isRtl,
Raph Levien1a73f7322014-01-30 16:06:28 -0800767 jlong paintPtr, jlong typefacePtr) {
John Reck3b202512014-06-23 13:13:08 -0700768 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Romain Guy61c8c9c2010-08-09 20:48:09 -0700769 const jchar* textArray = env->GetStringChars(text, NULL);
770 jint count = end - start;
771 jint contextCount = contextEnd - contextStart;
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -0400772 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
Raph Levien1a73f7322014-01-30 16:06:28 -0800773 TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefacePtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800774
Raph Levien051910b2014-06-15 18:25:29 -0700775 int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR;
Romain Guy61c8c9c2010-08-09 20:48:09 -0700776 renderTextRun(renderer, textArray + contextStart, start - contextStart,
Raph Levien051910b2014-06-15 18:25:29 -0700777 count, contextCount, x, y, bidiFlags, paint, typeface);
Romain Guy61c8c9c2010-08-09 20:48:09 -0700778 env->ReleaseStringChars(text, textArray);
779}
780
Romain Guyb051e892010-09-28 19:09:36 -0700781// ----------------------------------------------------------------------------
782// Display lists
783// ----------------------------------------------------------------------------
784
John Reck44fd8d22014-02-26 11:00:11 -0800785static jlong android_view_GLES20Canvas_finishRecording(JNIEnv* env,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000786 jobject clazz, jlong rendererPtr) {
Chris Craik9f66ea02013-12-27 15:15:55 -0800787 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
John Reck44fd8d22014-02-26 11:00:11 -0800788 return reinterpret_cast<jlong>(renderer->finishRecording());
789}
790
Chris Craik3f0854292014-04-15 16:18:08 -0700791static jlong android_view_GLES20Canvas_createDisplayListRenderer(JNIEnv* env, jobject clazz) {
John Reck44fd8d22014-02-26 11:00:11 -0800792 return reinterpret_cast<jlong>(new DisplayListRenderer);
Chet Haase5977baa2011-01-05 18:01:22 -0800793}
794
Chris Craika7090e02014-06-20 16:01:00 -0700795static jint android_view_GLES20Canvas_drawRenderNode(JNIEnv* env,
796 jobject clazz, jlong rendererPtr, jlong renderNodePtr,
Chet Haase1271e2c2012-04-20 09:54:27 -0700797 jobject dirty, jint flags) {
John Reck3b202512014-06-23 13:13:08 -0700798 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craika7090e02014-06-20 16:01:00 -0700799 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
Romain Guycabfcc12011-03-07 18:06:46 -0800800 android::uirenderer::Rect bounds;
Chris Craika7090e02014-06-20 16:01:00 -0700801 status_t status = renderer->drawRenderNode(renderNode, bounds, flags);
Romain Guy65549432012-03-26 16:45:05 -0700802 if (status != DrawGlInfo::kStatusDone && dirty != NULL) {
Romain Guycabfcc12011-03-07 18:06:46 -0800803 env->CallVoidMethod(dirty, gRectClassInfo.set,
804 int(bounds.left), int(bounds.top), int(bounds.right), int(bounds.bottom));
805 }
Romain Guy65549432012-03-26 16:45:05 -0700806 return status;
Romain Guyb051e892010-09-28 19:09:36 -0700807}
808
Romain Guy6c319ca2011-01-11 14:29:25 -0800809// ----------------------------------------------------------------------------
810// Layers
811// ----------------------------------------------------------------------------
812
Romain Guy7d7b5492011-01-24 16:33:45 -0800813static void android_view_GLES20Canvas_drawLayer(JNIEnv* env, jobject clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000814 jlong rendererPtr, jlong layerPtr, jfloat x, jfloat y) {
John Reck3b202512014-06-23 13:13:08 -0700815 DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
Chris Craik9f66ea02013-12-27 15:15:55 -0800816 Layer* layer = reinterpret_cast<Layer*>(layerPtr);
Chris Craika08f95c2013-03-15 17:24:33 -0700817 renderer->drawLayer(layer, x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -0800818}
819
Romain Guy16393512010-08-08 00:14:31 -0700820#endif // USE_OPENGL_RENDERER
821
822// ----------------------------------------------------------------------------
823// Common
824// ----------------------------------------------------------------------------
825
826static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz) {
827#ifdef USE_OPENGL_RENDERER
Jesse Hall44063452011-12-01 11:27:45 -0800828 char prop[PROPERTY_VALUE_MAX];
829 if (property_get("ro.kernel.qemu", prop, NULL) == 0) {
830 // not in the emulator
831 return JNI_TRUE;
832 }
833 // In the emulator this property will be set to 1 when hardware GLES is
834 // enabled, 0 otherwise. On old emulator versions it will be undefined.
835 property_get("ro.kernel.qemu.gles", prop, "0");
836 return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE;
Romain Guy16393512010-08-08 00:14:31 -0700837#else
838 return JNI_FALSE;
839#endif
840}
841
Romain Guya1db5742010-07-20 13:09:13 -0700842// ----------------------------------------------------------------------------
Chet Haase9c1e23b2011-03-24 10:51:31 -0700843// Logging
844// ----------------------------------------------------------------------------
845
Chet Haase9c1e23b2011-03-24 10:51:31 -0700846static void
Romain Guy65b345f2011-07-27 18:51:50 -0700847android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) {
Chet Haase905787a2011-04-01 14:33:02 -0700848#ifdef USE_OPENGL_RENDERER
Elliott Hughesa3804cf2011-04-11 16:50:19 -0700849 int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor);
John Recke18264b2014-03-12 13:56:30 -0700850 android::uirenderer::RenderNode::outputLogBuffer(fd);
Chet Haase905787a2011-04-01 14:33:02 -0700851#endif // USE_OPENGL_RENDERER
Chet Haase9c1e23b2011-03-24 10:51:31 -0700852}
853
854// ----------------------------------------------------------------------------
Romain Guye4d01122010-06-16 18:44:05 -0700855// JNI Glue
856// ----------------------------------------------------------------------------
857
858const char* const kClassPathName = "android/view/GLES20Canvas";
859
860static JNINativeMethod gMethods[] = {
Romain Guy61c8c9c2010-08-09 20:48:09 -0700861 { "nIsAvailable", "()Z", (void*) android_view_GLES20Canvas_isAvailable },
862
Romain Guy16393512010-08-08 00:14:31 -0700863#ifdef USE_OPENGL_RENDERER
Romain Guy7d7b5492011-01-24 16:33:45 -0800864
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000865 { "nDestroyRenderer", "(J)V", (void*) android_view_GLES20Canvas_destroyRenderer },
866 { "nSetViewport", "(JII)V", (void*) android_view_GLES20Canvas_setViewport },
Chris Craikcce47eb2014-07-16 15:12:15 -0700867 { "nSetHighContrastText","(JZ)V", (void*) android_view_GLES20Canvas_setHighContrastText },
Chris Craik8afd0f22014-08-21 17:41:57 -0700868 { "nInsertReorderBarrier","(JZ)V", (void*) android_view_GLES20Canvas_insertReorderBarrier },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000869 { "nPrepare", "(JZ)I", (void*) android_view_GLES20Canvas_prepare },
870 { "nPrepareDirty", "(JIIIIZ)I", (void*) android_view_GLES20Canvas_prepareDirty },
871 { "nFinish", "(J)V", (void*) android_view_GLES20Canvas_finish },
Chris Craikba9b6132013-12-15 17:10:19 -0800872 { "nSetProperty", "(Ljava/lang/String;Ljava/lang/String;)V",
873 (void*) android_view_GLES20Canvas_setProperty },
Romain Guy16393512010-08-08 00:14:31 -0700874
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000875 { "nCallDrawGLFunction", "(JJ)I", (void*) android_view_GLES20Canvas_callDrawGLFunction },
Romain Guy7d7b5492011-01-24 16:33:45 -0800876
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000877 { "nSave", "(JI)I", (void*) android_view_GLES20Canvas_save },
878 { "nRestore", "(J)V", (void*) android_view_GLES20Canvas_restore },
879 { "nRestoreToCount", "(JI)V", (void*) android_view_GLES20Canvas_restoreToCount },
880 { "nGetSaveCount", "(J)I", (void*) android_view_GLES20Canvas_getSaveCount },
Romain Guy85bf02f2010-06-22 13:11:24 -0700881
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000882 { "nSaveLayer", "(JFFFFJI)I", (void*) android_view_GLES20Canvas_saveLayer },
883 { "nSaveLayer", "(JJI)I", (void*) android_view_GLES20Canvas_saveLayerClip },
884 { "nSaveLayerAlpha", "(JFFFFII)I", (void*) android_view_GLES20Canvas_saveLayerAlpha },
885 { "nSaveLayerAlpha", "(JII)I", (void*) android_view_GLES20Canvas_saveLayerAlphaClip },
Romain Guybb9524b2010-06-22 18:56:38 -0700886
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000887 { "nQuickReject", "(JFFFF)Z", (void*) android_view_GLES20Canvas_quickReject },
888 { "nClipRect", "(JFFFFI)Z", (void*) android_view_GLES20Canvas_clipRectF },
889 { "nClipRect", "(JIIIII)Z", (void*) android_view_GLES20Canvas_clipRect },
890 { "nClipPath", "(JJI)Z", (void*) android_view_GLES20Canvas_clipPath },
891 { "nClipRegion", "(JJI)Z", (void*) android_view_GLES20Canvas_clipRegion },
Romain Guyc7d53492010-06-25 13:41:57 -0700892
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000893 { "nTranslate", "(JFF)V", (void*) android_view_GLES20Canvas_translate },
894 { "nRotate", "(JF)V", (void*) android_view_GLES20Canvas_rotate },
895 { "nScale", "(JFF)V", (void*) android_view_GLES20Canvas_scale },
896 { "nSkew", "(JFF)V", (void*) android_view_GLES20Canvas_skew },
Romain Guyc7d53492010-06-25 13:41:57 -0700897
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000898 { "nSetMatrix", "(JJ)V", (void*) android_view_GLES20Canvas_setMatrix },
899 { "nGetMatrix", "(JJ)V", (void*) android_view_GLES20Canvas_getMatrix },
900 { "nConcatMatrix", "(JJ)V", (void*) android_view_GLES20Canvas_concatMatrix },
Romain Guyc7d53492010-06-25 13:41:57 -0700901
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000902 { "nDrawBitmap", "(JJ[BFFJ)V", (void*) android_view_GLES20Canvas_drawBitmap },
903 { "nDrawBitmap", "(JJ[BFFFFFFFFJ)V",(void*) android_view_GLES20Canvas_drawBitmapRect },
904 { "nDrawBitmap", "(JJ[BJJ)V", (void*) android_view_GLES20Canvas_drawBitmapMatrix },
905 { "nDrawBitmap", "(J[IIIFFIIZJ)V", (void*) android_view_GLES20Canvas_drawBitmapData },
Romain Guy5a7b4662011-01-20 19:09:30 -0800906
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000907 { "nDrawBitmapMesh", "(JJ[BII[FI[IIJ)V",(void*) android_view_GLES20Canvas_drawBitmapMesh },
Romain Guy5a7b4662011-01-20 19:09:30 -0800908
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000909 { "nDrawPatch", "(JJ[BJFFFFJ)V", (void*) android_view_GLES20Canvas_drawPatch },
Patrick Dubroye4ac2d62010-12-01 11:23:13 -0800910
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000911 { "nDrawColor", "(JII)V", (void*) android_view_GLES20Canvas_drawColor },
912 { "nDrawRect", "(JFFFFJ)V", (void*) android_view_GLES20Canvas_drawRect },
913 { "nDrawRects", "(JJJ)V", (void*) android_view_GLES20Canvas_drawRegionAsRects },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000914 { "nDrawRoundRect", "(JFFFFFFJ)V", (void*) android_view_GLES20Canvas_drawRoundRect },
915 { "nDrawCircle", "(JFFFJ)V", (void*) android_view_GLES20Canvas_drawCircle },
John Reck52244ff2014-05-01 21:27:37 -0700916 { "nDrawCircle", "(JJJJJ)V", (void*) android_view_GLES20Canvas_drawCircleProps },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000917 { "nDrawOval", "(JFFFFJ)V", (void*) android_view_GLES20Canvas_drawOval },
918 { "nDrawArc", "(JFFFFFFZJ)V", (void*) android_view_GLES20Canvas_drawArc },
919 { "nDrawPoints", "(J[FIIJ)V", (void*) android_view_GLES20Canvas_drawPoints },
Romain Guy8b2f5262011-01-23 16:15:02 -0800920
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000921 { "nDrawPath", "(JJJ)V", (void*) android_view_GLES20Canvas_drawPath },
922 { "nDrawLines", "(J[FIIJ)V", (void*) android_view_GLES20Canvas_drawLines },
Romain Guybd6b79b2010-06-26 00:13:53 -0700923
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000924 { "nSetupPaintFilter", "(JII)V", (void*) android_view_GLES20Canvas_setupPaintFilter },
925 { "nResetPaintFilter", "(J)V", (void*) android_view_GLES20Canvas_resetPaintFilter },
Romain Guy5ff9df62012-01-23 17:09:05 -0800926
Raph Levien1a73f7322014-01-30 16:06:28 -0800927 { "nDrawText", "(J[CIIFFIJJ)V", (void*) android_view_GLES20Canvas_drawTextArray },
928 { "nDrawText", "(JLjava/lang/String;IIFFIJJ)V",
Romain Guya1db5742010-07-20 13:09:13 -0700929 (void*) android_view_GLES20Canvas_drawText },
930
Raph Levien9d2b5e12014-06-15 23:53:57 -0700931 { "nDrawTextOnPath", "(J[CIIJFFIJJ)V", (void*) android_view_GLES20Canvas_drawTextArrayOnPath },
932 { "nDrawTextOnPath", "(JLjava/lang/String;IIJFFIJJ)V",
Romain Guy325740f2012-02-24 16:48:34 -0800933 (void*) android_view_GLES20Canvas_drawTextOnPath },
934
Raph Levien051910b2014-06-15 18:25:29 -0700935 { "nDrawTextRun", "(J[CIIIIFFZJJ)V", (void*) android_view_GLES20Canvas_drawTextRunArray },
936 { "nDrawTextRun", "(JLjava/lang/String;IIIIFFZJJ)V",
Romain Guy61c8c9c2010-08-09 20:48:09 -0700937 (void*) android_view_GLES20Canvas_drawTextRun },
938
Chris Craika7090e02014-06-20 16:01:00 -0700939 { "nGetClipBounds", "(JLandroid/graphics/Rect;)Z", (void*) android_view_GLES20Canvas_getClipBounds },
Romain Guyb051e892010-09-28 19:09:36 -0700940
Chris Craika7090e02014-06-20 16:01:00 -0700941 { "nFinishRecording", "(J)J", (void*) android_view_GLES20Canvas_finishRecording },
942 { "nDrawRenderNode", "(JJLandroid/graphics/Rect;I)I", (void*) android_view_GLES20Canvas_drawRenderNode },
Romain Guy13631f32012-01-30 17:41:55 -0800943
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000944 { "nCreateDisplayListRenderer", "()J", (void*) android_view_GLES20Canvas_createDisplayListRenderer },
Romain Guy13631f32012-01-30 17:41:55 -0800945
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000946 { "nDrawLayer", "(JJFF)V", (void*) android_view_GLES20Canvas_drawLayer },
Romain Guyb051e892010-09-28 19:09:36 -0700947
Romain Guyf61970fc2011-07-07 14:10:06 -0700948 { "nGetMaximumTextureWidth", "()I", (void*) android_view_GLES20Canvas_getMaxTextureWidth },
949 { "nGetMaximumTextureHeight", "()I", (void*) android_view_GLES20Canvas_getMaxTextureHeight },
950
Romain Guy16393512010-08-08 00:14:31 -0700951#endif
Romain Guye4d01122010-06-16 18:44:05 -0700952};
953
Chet Haase9c1e23b2011-03-24 10:51:31 -0700954static JNINativeMethod gActivityThreadMethods[] = {
955 { "dumpGraphicsInfo", "(Ljava/io/FileDescriptor;)V",
956 (void*) android_app_ActivityThread_dumpGraphics }
957};
958
959
Romain Guy16393512010-08-08 00:14:31 -0700960#ifdef USE_OPENGL_RENDERER
961 #define FIND_CLASS(var, className) \
962 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800963 LOG_FATAL_IF(! var, "Unable to find class " className);
964
Romain Guy16393512010-08-08 00:14:31 -0700965 #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
966 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
967 LOG_FATAL_IF(! var, "Unable to find method " methodName);
968#else
969 #define FIND_CLASS(var, className)
970 #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor)
971#endif
Romain Guy9d5316e2010-06-24 19:30:36 -0700972
Romain Guye4d01122010-06-16 18:44:05 -0700973int register_android_view_GLES20Canvas(JNIEnv* env) {
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800974 jclass clazz;
975 FIND_CLASS(clazz, "android/graphics/Rect");
976 GET_METHOD_ID(gRectClassInfo.set, clazz, "set", "(IIII)V");
Romain Guy9d5316e2010-06-24 19:30:36 -0700977
Romain Guye4d01122010-06-16 18:44:05 -0700978 return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
979}
980
Chet Haase9c1e23b2011-03-24 10:51:31 -0700981const char* const kActivityThreadPathName = "android/app/ActivityThread";
982
Romain Guy6be3d552011-07-14 18:08:37 -0700983int register_android_app_ActivityThread(JNIEnv* env) {
984 return AndroidRuntime::registerNativeMethods(env, kActivityThreadPathName,
Chet Haase9c1e23b2011-03-24 10:51:31 -0700985 gActivityThreadMethods, NELEM(gActivityThreadMethods));
986}
987
Romain Guye4d01122010-06-16 18:44:05 -0700988};