Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 17 | #define LOG_TAG "OpenGLRenderer" |
| 18 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 19 | #include "jni.h" |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 20 | #include "GraphicsJNI.h" |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 21 | #include <nativehelper/JNIHelp.h> |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 22 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 23 | #include <android_runtime/AndroidRuntime.h> |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 24 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 25 | #include <androidfw/ResourceTypes.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 26 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 27 | #include <cutils/properties.h> |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 28 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 29 | #include <SkBitmap.h> |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 30 | #include <SkRegion.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 31 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 32 | #include <DisplayListCanvas.h> |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 33 | #include <Rect.h> |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 34 | #include <RenderNode.h> |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 35 | #include <CanvasProperty.h> |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 36 | #include <Paint.h> |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 37 | #include <renderthread/RenderProxy.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 38 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 39 | #include "core_jni_helpers.h" |
| 40 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 41 | namespace android { |
| 42 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 43 | using namespace uirenderer; |
| 44 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 45 | static struct { |
| 46 | jmethodID set; |
| 47 | } gRectClassInfo; |
| 48 | |
Romain Guy | 244ada1 | 2012-03-28 16:41:26 -0700 | [diff] [blame] | 49 | // ---------------------------------------------------------------------------- |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 50 | // Setup |
| 51 | // ---------------------------------------------------------------------------- |
| 52 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 53 | static void android_view_DisplayListCanvas_setViewport(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 54 | jlong rendererPtr, jint width, jint height) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 55 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 56 | renderer->setViewport(width, height); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 59 | static void android_view_DisplayListCanvas_setHighContrastText(JNIEnv* env, jobject clazz, |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 60 | jlong rendererPtr, jboolean highContrastText) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 61 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 62 | renderer->setHighContrastText(highContrastText); |
| 63 | } |
| 64 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 65 | static void android_view_DisplayListCanvas_insertReorderBarrier(JNIEnv* env, jobject clazz, |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 66 | jlong rendererPtr, jboolean reorderEnable) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 67 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 68 | renderer->insertReorderBarrier(reorderEnable); |
| 69 | } |
| 70 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 71 | static void android_view_DisplayListCanvas_prepare(JNIEnv* env, jobject clazz, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 72 | jlong rendererPtr) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 73 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 74 | renderer->prepare(); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 77 | static void android_view_DisplayListCanvas_prepareDirty(JNIEnv* env, jobject clazz, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 78 | jlong rendererPtr, jint left, jint top, jint right, jint bottom) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 79 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 80 | renderer->prepareDirty(left, top, right, bottom); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 83 | static void android_view_DisplayListCanvas_finish(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 84 | jlong rendererPtr) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 85 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 86 | renderer->finish(); |
| 87 | } |
| 88 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 89 | static void android_view_DisplayListCanvas_setProperty(JNIEnv* env, |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 90 | jobject clazz, jstring name, jstring value) { |
| 91 | if (!Caches::hasInstance()) { |
| 92 | ALOGW("can't set property, no Caches instance"); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | if (name == NULL || value == NULL) { |
| 97 | ALOGW("can't set prop, null passed"); |
| 98 | } |
| 99 | |
| 100 | const char* nameCharArray = env->GetStringUTFChars(name, NULL); |
| 101 | const char* valueCharArray = env->GetStringUTFChars(value, NULL); |
| 102 | Caches::getInstance().setTempProperty(nameCharArray, valueCharArray); |
| 103 | env->ReleaseStringUTFChars(name, nameCharArray); |
| 104 | env->ReleaseStringUTFChars(name, valueCharArray); |
| 105 | } |
| 106 | |
Romain Guy | 530041d | 2012-01-25 18:56:29 -0800 | [diff] [blame] | 107 | // ---------------------------------------------------------------------------- |
| 108 | // Functor |
| 109 | // ---------------------------------------------------------------------------- |
| 110 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 111 | static void android_view_DisplayListCanvas_callDrawGLFunction(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 112 | jlong rendererPtr, jlong functorPtr) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 113 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 114 | Functor* functor = reinterpret_cast<Functor*>(functorPtr); |
Chris Craik | 956f340 | 2015-04-27 16:41:00 -0700 | [diff] [blame] | 115 | renderer->callDrawGLFunction(functor); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 118 | // ---------------------------------------------------------------------------- |
| 119 | // Misc |
| 120 | // ---------------------------------------------------------------------------- |
| 121 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 122 | static jint android_view_DisplayListCanvas_getMaxTextureWidth(JNIEnv* env, jobject clazz) { |
Romain Guy | f61970fc | 2011-07-07 14:10:06 -0700 | [diff] [blame] | 123 | return Caches::getInstance().maxTextureSize; |
| 124 | } |
| 125 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 126 | static jint android_view_DisplayListCanvas_getMaxTextureHeight(JNIEnv* env, jobject clazz) { |
Romain Guy | f61970fc | 2011-07-07 14:10:06 -0700 | [diff] [blame] | 127 | return Caches::getInstance().maxTextureSize; |
| 128 | } |
| 129 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 130 | // ---------------------------------------------------------------------------- |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 131 | // Drawing |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 132 | // ---------------------------------------------------------------------------- |
| 133 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 134 | static void android_view_DisplayListCanvas_drawPatch(JNIEnv* env, jobject clazz, |
John Reck | 1ff961d | 2015-04-17 20:45:15 +0000 | [diff] [blame] | 135 | jlong rendererPtr, jlong bitmapPtr, jlong patchPtr, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 136 | float left, float top, float right, float bottom, jlong paintPtr) { |
John Reck | 1ff961d | 2015-04-17 20:45:15 +0000 | [diff] [blame] | 137 | SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr); |
| 138 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 139 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 140 | Res_png_9patch* patch = reinterpret_cast<Res_png_9patch*>(patchPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 141 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 142 | renderer->drawPatch(bitmap, patch, left, top, right, bottom, paint); |
Romain Guy | deba785 | 2010-07-07 17:54:48 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 145 | static void android_view_DisplayListCanvas_drawRoundRectProps(JNIEnv* env, jobject clazz, |
Jorim Jaggi | 072707d | 2014-09-15 17:20:08 +0200 | [diff] [blame] | 146 | jlong rendererPtr, jlong leftPropPtr, jlong topPropPtr, jlong rightPropPtr, |
| 147 | jlong bottomPropPtr, jlong rxPropPtr, jlong ryPropPtr, jlong paintPropPtr) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 148 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
Jorim Jaggi | 072707d | 2014-09-15 17:20:08 +0200 | [diff] [blame] | 149 | CanvasPropertyPrimitive* leftProp = reinterpret_cast<CanvasPropertyPrimitive*>(leftPropPtr); |
| 150 | CanvasPropertyPrimitive* topProp = reinterpret_cast<CanvasPropertyPrimitive*>(topPropPtr); |
| 151 | CanvasPropertyPrimitive* rightProp = reinterpret_cast<CanvasPropertyPrimitive*>(rightPropPtr); |
| 152 | CanvasPropertyPrimitive* bottomProp = reinterpret_cast<CanvasPropertyPrimitive*>(bottomPropPtr); |
| 153 | CanvasPropertyPrimitive* rxProp = reinterpret_cast<CanvasPropertyPrimitive*>(rxPropPtr); |
| 154 | CanvasPropertyPrimitive* ryProp = reinterpret_cast<CanvasPropertyPrimitive*>(ryPropPtr); |
| 155 | CanvasPropertyPaint* paintProp = reinterpret_cast<CanvasPropertyPaint*>(paintPropPtr); |
| 156 | renderer->drawRoundRect(leftProp, topProp, rightProp, bottomProp, rxProp, ryProp, paintProp); |
| 157 | } |
| 158 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 159 | static void android_view_DisplayListCanvas_drawCircleProps(JNIEnv* env, jobject clazz, |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 160 | jlong rendererPtr, jlong xPropPtr, jlong yPropPtr, jlong radiusPropPtr, jlong paintPropPtr) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 161 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 162 | CanvasPropertyPrimitive* xProp = reinterpret_cast<CanvasPropertyPrimitive*>(xPropPtr); |
| 163 | CanvasPropertyPrimitive* yProp = reinterpret_cast<CanvasPropertyPrimitive*>(yPropPtr); |
| 164 | CanvasPropertyPrimitive* radiusProp = reinterpret_cast<CanvasPropertyPrimitive*>(radiusPropPtr); |
| 165 | CanvasPropertyPaint* paintProp = reinterpret_cast<CanvasPropertyPaint*>(paintPropPtr); |
| 166 | renderer->drawCircle(xProp, yProp, radiusProp, paintProp); |
| 167 | } |
| 168 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 169 | static void android_view_DisplayListCanvas_drawRegionAsRects(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 170 | jlong rendererPtr, jlong regionPtr, jlong paintPtr) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 171 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
Chris Craik | 9f66ea0 | 2013-12-27 15:15:55 -0800 | [diff] [blame] | 172 | SkRegion* region = reinterpret_cast<SkRegion*>(regionPtr); |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 173 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
| 174 | if (paint->getStyle() != Paint::kFill_Style || |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 175 | (paint->isAntiAlias() && !renderer->isCurrentTransformSimple())) { |
| 176 | SkRegion::Iterator it(*region); |
| 177 | while (!it.done()) { |
| 178 | const SkIRect& r = it.rect(); |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 179 | renderer->drawRect(r.fLeft, r.fTop, r.fRight, r.fBottom, *paint); |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 180 | it.next(); |
| 181 | } |
| 182 | } else { |
| 183 | int count = 0; |
| 184 | Vector<float> rects; |
| 185 | SkRegion::Iterator it(*region); |
| 186 | while (!it.done()) { |
| 187 | const SkIRect& r = it.rect(); |
| 188 | rects.push(r.fLeft); |
| 189 | rects.push(r.fTop); |
| 190 | rects.push(r.fRight); |
| 191 | rects.push(r.fBottom); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 192 | count += 4; |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 193 | it.next(); |
| 194 | } |
| 195 | renderer->drawRects(rects.array(), count, paint); |
Romain Guy | a48a1a8 | 2010-08-10 14:59:15 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 199 | // ---------------------------------------------------------------------------- |
| 200 | // Display lists |
| 201 | // ---------------------------------------------------------------------------- |
| 202 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 203 | static jlong android_view_DisplayListCanvas_finishRecording(JNIEnv* env, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 204 | jobject clazz, jlong rendererPtr) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 205 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 206 | return reinterpret_cast<jlong>(renderer->finishRecording()); |
| 207 | } |
| 208 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 209 | static jlong android_view_DisplayListCanvas_createDisplayListCanvas(JNIEnv* env, jobject clazz) { |
| 210 | return reinterpret_cast<jlong>(new DisplayListCanvas); |
Chet Haase | 5977baa | 2011-01-05 18:01:22 -0800 | [diff] [blame] | 211 | } |
| 212 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 213 | static void android_view_DisplayListCanvas_drawRenderNode(JNIEnv* env, |
Chris Craik | 956f340 | 2015-04-27 16:41:00 -0700 | [diff] [blame] | 214 | jobject clazz, jlong rendererPtr, jlong renderNodePtr) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 215 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 216 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
Chris Craik | 956f340 | 2015-04-27 16:41:00 -0700 | [diff] [blame] | 217 | renderer->drawRenderNode(renderNode); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 220 | // ---------------------------------------------------------------------------- |
| 221 | // Layers |
| 222 | // ---------------------------------------------------------------------------- |
| 223 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 224 | static void android_view_DisplayListCanvas_drawLayer(JNIEnv* env, jobject clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 225 | jlong rendererPtr, jlong layerPtr, jfloat x, jfloat y) { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 226 | DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); |
John Reck | 12f5e34 | 2014-11-07 07:53:43 -0800 | [diff] [blame] | 227 | DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr); |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 228 | renderer->drawLayer(layer, x, y); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 231 | // ---------------------------------------------------------------------------- |
| 232 | // Common |
| 233 | // ---------------------------------------------------------------------------- |
| 234 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 235 | static jboolean android_view_DisplayListCanvas_isAvailable(JNIEnv* env, jobject clazz) { |
John Reck | a2732a2 | 2014-12-18 13:52:33 -0800 | [diff] [blame] | 236 | char prop[PROPERTY_VALUE_MAX]; |
| 237 | if (property_get("ro.kernel.qemu", prop, NULL) == 0) { |
| 238 | // not in the emulator |
| 239 | return JNI_TRUE; |
Jesse Hall | 4406345 | 2011-12-01 11:27:45 -0800 | [diff] [blame] | 240 | } |
John Reck | a2732a2 | 2014-12-18 13:52:33 -0800 | [diff] [blame] | 241 | // In the emulator this property will be set to 1 when hardware GLES is |
| 242 | // enabled, 0 otherwise. On old emulator versions it will be undefined. |
| 243 | property_get("ro.kernel.qemu.gles", prop, "0"); |
| 244 | return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE; |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 247 | // ---------------------------------------------------------------------------- |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 248 | // Logging |
| 249 | // ---------------------------------------------------------------------------- |
| 250 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 251 | static void |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 252 | android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) { |
John Reck | a2732a2 | 2014-12-18 13:52:33 -0800 | [diff] [blame] | 253 | int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 254 | android::uirenderer::renderthread::RenderProxy::dumpGraphicsMemory(fd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | // ---------------------------------------------------------------------------- |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 258 | // JNI Glue |
| 259 | // ---------------------------------------------------------------------------- |
| 260 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 261 | const char* const kClassPathName = "android/view/DisplayListCanvas"; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 262 | |
| 263 | static JNINativeMethod gMethods[] = { |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 264 | { "nIsAvailable", "()Z", (void*) android_view_DisplayListCanvas_isAvailable }, |
| 265 | { "nSetViewport", "(JII)V", (void*) android_view_DisplayListCanvas_setViewport }, |
| 266 | { "nSetHighContrastText","(JZ)V", (void*) android_view_DisplayListCanvas_setHighContrastText }, |
| 267 | { "nInsertReorderBarrier","(JZ)V", (void*) android_view_DisplayListCanvas_insertReorderBarrier }, |
| 268 | { "nPrepare", "(J)V", (void*) android_view_DisplayListCanvas_prepare }, |
| 269 | { "nPrepareDirty", "(JIIII)V", (void*) android_view_DisplayListCanvas_prepareDirty }, |
| 270 | { "nFinish", "(J)V", (void*) android_view_DisplayListCanvas_finish }, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 271 | { "nSetProperty", "(Ljava/lang/String;Ljava/lang/String;)V", |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 272 | (void*) android_view_DisplayListCanvas_setProperty }, |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 273 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 274 | { "nCallDrawGLFunction", "(JJ)V", (void*) android_view_DisplayListCanvas_callDrawGLFunction }, |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 275 | |
John Reck | 1ff961d | 2015-04-17 20:45:15 +0000 | [diff] [blame] | 276 | { "nDrawPatch", "(JJJFFFFJ)V", (void*) android_view_DisplayListCanvas_drawPatch }, |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 277 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 278 | { "nDrawRects", "(JJJ)V", (void*) android_view_DisplayListCanvas_drawRegionAsRects }, |
| 279 | { "nDrawRoundRect", "(JJJJJJJJ)V", (void*) android_view_DisplayListCanvas_drawRoundRectProps }, |
| 280 | { "nDrawCircle", "(JJJJJ)V", (void*) android_view_DisplayListCanvas_drawCircleProps }, |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 281 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 282 | { "nFinishRecording", "(J)J", (void*) android_view_DisplayListCanvas_finishRecording }, |
Chris Craik | 956f340 | 2015-04-27 16:41:00 -0700 | [diff] [blame] | 283 | { "nDrawRenderNode", "(JJ)V", (void*) android_view_DisplayListCanvas_drawRenderNode }, |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 284 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 285 | { "nCreateDisplayListCanvas", "()J", (void*) android_view_DisplayListCanvas_createDisplayListCanvas }, |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 286 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 287 | { "nDrawLayer", "(JJFF)V", (void*) android_view_DisplayListCanvas_drawLayer }, |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 288 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 289 | { "nGetMaximumTextureWidth", "()I", (void*) android_view_DisplayListCanvas_getMaxTextureWidth }, |
| 290 | { "nGetMaximumTextureHeight", "()I", (void*) android_view_DisplayListCanvas_getMaxTextureHeight }, |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 291 | }; |
| 292 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 293 | static JNINativeMethod gActivityThreadMethods[] = { |
| 294 | { "dumpGraphicsInfo", "(Ljava/io/FileDescriptor;)V", |
| 295 | (void*) android_app_ActivityThread_dumpGraphics } |
| 296 | }; |
| 297 | |
Chris Craik | c9070eb | 2015-03-09 18:50:14 -0700 | [diff] [blame] | 298 | int register_android_view_DisplayListCanvas(JNIEnv* env) { |
John Reck | a2732a2 | 2014-12-18 13:52:33 -0800 | [diff] [blame] | 299 | jclass clazz = FindClassOrDie(env, "android/graphics/Rect"); |
| 300 | gRectClassInfo.set = GetMethodIDOrDie(env, clazz, "set", "(IIII)V"); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 301 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 302 | return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Romain Guy | 6be3d55 | 2011-07-14 18:08:37 -0700 | [diff] [blame] | 305 | int register_android_app_ActivityThread(JNIEnv* env) { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 306 | return RegisterMethodsOrDie(env, "android/app/ActivityThread", |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 307 | gActivityThreadMethods, NELEM(gActivityThreadMethods)); |
| 308 | } |
| 309 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 310 | }; |