Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
| 17 | #define LOG_TAG "OpenGLRenderer" |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_VIEW |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 19 | |
| 20 | #include <EGL/egl.h> |
| 21 | |
| 22 | #include "jni.h" |
| 23 | #include "GraphicsJNI.h" |
| 24 | #include <nativehelper/JNIHelp.h> |
| 25 | #include <android_runtime/AndroidRuntime.h> |
| 26 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 27 | #include <Animator.h> |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 28 | #include <DamageAccumulator.h> |
| 29 | #include <Matrix.h> |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 30 | #include <RenderNode.h> |
John Reck | 38f6c03 | 2016-03-17 10:23:49 -0700 | [diff] [blame] | 31 | #include <renderthread/CanvasContext.h> |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 32 | #include <TreeInfo.h> |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 33 | #include <Paint.h> |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 34 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 35 | #include "core_jni_helpers.h" |
| 36 | |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 37 | namespace android { |
| 38 | |
| 39 | using namespace uirenderer; |
| 40 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 41 | #define SET_AND_DIRTY(prop, val, dirtyFlag) \ |
| 42 | (reinterpret_cast<RenderNode*>(renderNodePtr)->mutateStagingProperties().prop(val) \ |
| 43 | ? (reinterpret_cast<RenderNode*>(renderNodePtr)->setPropertyFieldsDirty(dirtyFlag), true) \ |
| 44 | : false) |
| 45 | |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 46 | // ---------------------------------------------------------------------------- |
| 47 | // DisplayList view properties |
| 48 | // ---------------------------------------------------------------------------- |
| 49 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 50 | static void android_view_RenderNode_output(JNIEnv* env, |
| 51 | jobject clazz, jlong renderNodePtr) { |
| 52 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 53 | renderNode->output(); |
| 54 | } |
| 55 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 56 | static jint android_view_RenderNode_getDebugSize(JNIEnv* env, |
| 57 | jobject clazz, jlong renderNodePtr) { |
| 58 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 59 | return renderNode->getDebugSize(); |
| 60 | } |
| 61 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 62 | static jlong android_view_RenderNode_create(JNIEnv* env, jobject clazz, jstring name) { |
| 63 | RenderNode* renderNode = new RenderNode(); |
| 64 | renderNode->incStrong(0); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 65 | if (name != NULL) { |
| 66 | const char* textArray = env->GetStringUTFChars(name, NULL); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 67 | renderNode->setName(textArray); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 68 | env->ReleaseStringUTFChars(name, textArray); |
| 69 | } |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 70 | return reinterpret_cast<jlong>(renderNode); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 71 | } |
| 72 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 73 | static void android_view_RenderNode_destroyRenderNode(JNIEnv* env, |
| 74 | jobject clazz, jlong renderNodePtr) { |
| 75 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 76 | renderNode->decStrong(0); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 79 | static void android_view_RenderNode_setDisplayList(JNIEnv* env, |
| 80 | jobject clazz, jlong renderNodePtr, jlong displayListPtr) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 81 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 82 | DisplayList* newData = reinterpret_cast<DisplayList*>(displayListPtr); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 83 | renderNode->setStagingDisplayList(newData); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | // ---------------------------------------------------------------------------- |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 87 | // RenderProperties - setters |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 88 | // ---------------------------------------------------------------------------- |
| 89 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 90 | static jboolean android_view_RenderNode_setLayerType(JNIEnv* env, |
| 91 | jobject clazz, jlong renderNodePtr, jint jlayerType) { |
| 92 | LayerType layerType = static_cast<LayerType>(jlayerType); |
| 93 | return SET_AND_DIRTY(mutateLayerProperties().setType, layerType, RenderNode::GENERIC); |
| 94 | } |
| 95 | |
| 96 | static jboolean android_view_RenderNode_setLayerPaint(JNIEnv* env, |
| 97 | jobject clazz, jlong renderNodePtr, jlong paintPtr) { |
Behdad Esfahbod | 6ba30b8 | 2014-07-15 16:22:32 -0400 | [diff] [blame] | 98 | Paint* paint = reinterpret_cast<Paint*>(paintPtr); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 99 | return SET_AND_DIRTY(mutateLayerProperties().setFromPaint, paint, RenderNode::GENERIC); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 100 | } |
| 101 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 102 | static jboolean android_view_RenderNode_setStaticMatrix(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 103 | jobject clazz, jlong renderNodePtr, jlong matrixPtr) { |
Chris Craik | 7a02ea3 | 2013-12-27 16:43:22 -0800 | [diff] [blame] | 104 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 105 | return SET_AND_DIRTY(setStaticMatrix, matrix, RenderNode::GENERIC); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 106 | } |
| 107 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 108 | static jboolean android_view_RenderNode_setAnimationMatrix(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 109 | jobject clazz, jlong renderNodePtr, jlong matrixPtr) { |
Chris Craik | 7a02ea3 | 2013-12-27 16:43:22 -0800 | [diff] [blame] | 110 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 111 | return SET_AND_DIRTY(setAnimationMatrix, matrix, RenderNode::GENERIC); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 112 | } |
| 113 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 114 | static jboolean android_view_RenderNode_setClipToBounds(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 115 | jobject clazz, jlong renderNodePtr, jboolean clipToBounds) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 116 | return SET_AND_DIRTY(setClipToBounds, clipToBounds, RenderNode::GENERIC); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 119 | static jboolean android_view_RenderNode_setClipBounds(JNIEnv* env, |
| 120 | jobject clazz, jlong renderNodePtr, jint left, jint top, jint right, jint bottom) { |
| 121 | android::uirenderer::Rect clipBounds(left, top, right, bottom); |
| 122 | return SET_AND_DIRTY(setClipBounds, clipBounds, RenderNode::GENERIC); |
| 123 | } |
| 124 | |
| 125 | static jboolean android_view_RenderNode_setClipBoundsEmpty(JNIEnv* env, |
| 126 | jobject clazz, jlong renderNodePtr) { |
| 127 | return SET_AND_DIRTY(setClipBoundsEmpty,, RenderNode::GENERIC); |
| 128 | } |
| 129 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 130 | static jboolean android_view_RenderNode_setProjectBackwards(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 131 | jobject clazz, jlong renderNodePtr, jboolean shouldProject) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 132 | return SET_AND_DIRTY(setProjectBackwards, shouldProject, RenderNode::GENERIC); |
Alan Viverette | 58f09b3 | 2014-01-08 17:18:19 -0800 | [diff] [blame] | 133 | } |
| 134 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 135 | static jboolean android_view_RenderNode_setProjectionReceiver(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 136 | jobject clazz, jlong renderNodePtr, jboolean shouldRecieve) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 137 | return SET_AND_DIRTY(setProjectionReceiver, shouldRecieve, RenderNode::GENERIC); |
Chris Craik | 1df2644 | 2014-02-05 16:50:41 -0800 | [diff] [blame] | 138 | } |
| 139 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 140 | static jboolean android_view_RenderNode_setOutlineRoundRect(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 141 | jobject clazz, jlong renderNodePtr, jint left, jint top, |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 142 | jint right, jint bottom, jfloat radius, jfloat alpha) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 143 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 144 | renderNode->mutateStagingProperties().mutableOutline().setRoundRect(left, top, right, bottom, |
| 145 | radius, alpha); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 146 | renderNode->setPropertyFieldsDirty(RenderNode::GENERIC); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 147 | return true; |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 148 | } |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 149 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 150 | static jboolean android_view_RenderNode_setOutlineConvexPath(JNIEnv* env, |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 151 | jobject clazz, jlong renderNodePtr, jlong outlinePathPtr, jfloat alpha) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 152 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 153 | SkPath* outlinePath = reinterpret_cast<SkPath*>(outlinePathPtr); |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 154 | renderNode->mutateStagingProperties().mutableOutline().setConvexPath(outlinePath, alpha); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 155 | renderNode->setPropertyFieldsDirty(RenderNode::GENERIC); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 156 | return true; |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 157 | } |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 158 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 159 | static jboolean android_view_RenderNode_setOutlineEmpty(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 160 | jobject clazz, jlong renderNodePtr) { |
| 161 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 162 | renderNode->mutateStagingProperties().mutableOutline().setEmpty(); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 163 | renderNode->setPropertyFieldsDirty(RenderNode::GENERIC); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 164 | return true; |
Chris Craik | a2fe7af | 2014-01-28 17:25:06 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Chris Craik | 0645128 | 2014-07-21 10:25:54 -0700 | [diff] [blame] | 167 | static jboolean android_view_RenderNode_setOutlineNone(JNIEnv* env, |
| 168 | jobject clazz, jlong renderNodePtr) { |
| 169 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 170 | renderNode->mutateStagingProperties().mutableOutline().setNone(); |
| 171 | renderNode->setPropertyFieldsDirty(RenderNode::GENERIC); |
| 172 | return true; |
| 173 | } |
| 174 | |
Chris Craik | 5c75c52 | 2014-09-05 14:08:08 -0700 | [diff] [blame] | 175 | static jboolean android_view_RenderNode_hasShadow(JNIEnv* env, |
| 176 | jobject clazz, jlong renderNodePtr) { |
| 177 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 178 | return renderNode->stagingProperties().hasShadow(); |
| 179 | } |
| 180 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 181 | static jboolean android_view_RenderNode_setClipToOutline(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 182 | jobject clazz, jlong renderNodePtr, jboolean clipToOutline) { |
| 183 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 184 | renderNode->mutateStagingProperties().mutableOutline().setShouldClip(clipToOutline); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 185 | renderNode->setPropertyFieldsDirty(RenderNode::GENERIC); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 186 | return true; |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 187 | } |
| 188 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 189 | static jboolean android_view_RenderNode_setRevealClip(JNIEnv* env, |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 190 | jobject clazz, jlong renderNodePtr, jboolean shouldClip, |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 191 | jfloat x, jfloat y, jfloat radius) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 192 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 193 | renderNode->mutateStagingProperties().mutableRevealClip().set( |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 194 | shouldClip, x, y, radius); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 195 | renderNode->setPropertyFieldsDirty(RenderNode::GENERIC); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 196 | return true; |
ztenghui | fad4593 | 2014-02-06 10:33:58 -0800 | [diff] [blame] | 197 | } |
| 198 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 199 | static jboolean android_view_RenderNode_setAlpha(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 200 | jobject clazz, jlong renderNodePtr, float alpha) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 201 | return SET_AND_DIRTY(setAlpha, alpha, RenderNode::ALPHA); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 202 | } |
| 203 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 204 | static jboolean android_view_RenderNode_setHasOverlappingRendering(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 205 | jobject clazz, jlong renderNodePtr, bool hasOverlappingRendering) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 206 | return SET_AND_DIRTY(setHasOverlappingRendering, hasOverlappingRendering, |
| 207 | RenderNode::GENERIC); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 208 | } |
| 209 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 210 | static jboolean android_view_RenderNode_setElevation(JNIEnv* env, |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 211 | jobject clazz, jlong renderNodePtr, float elevation) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 212 | return SET_AND_DIRTY(setElevation, elevation, RenderNode::Z); |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 213 | } |
| 214 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 215 | static jboolean android_view_RenderNode_setTranslationX(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 216 | jobject clazz, jlong renderNodePtr, float tx) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 217 | return SET_AND_DIRTY(setTranslationX, tx, RenderNode::TRANSLATION_X | RenderNode::X); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 218 | } |
| 219 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 220 | static jboolean android_view_RenderNode_setTranslationY(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 221 | jobject clazz, jlong renderNodePtr, float ty) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 222 | return SET_AND_DIRTY(setTranslationY, ty, RenderNode::TRANSLATION_Y | RenderNode::Y); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 223 | } |
| 224 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 225 | static jboolean android_view_RenderNode_setTranslationZ(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 226 | jobject clazz, jlong renderNodePtr, float tz) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 227 | return SET_AND_DIRTY(setTranslationZ, tz, RenderNode::TRANSLATION_Z | RenderNode::Z); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 228 | } |
| 229 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 230 | static jboolean android_view_RenderNode_setRotation(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 231 | jobject clazz, jlong renderNodePtr, float rotation) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 232 | return SET_AND_DIRTY(setRotation, rotation, RenderNode::ROTATION); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 233 | } |
| 234 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 235 | static jboolean android_view_RenderNode_setRotationX(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 236 | jobject clazz, jlong renderNodePtr, float rx) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 237 | return SET_AND_DIRTY(setRotationX, rx, RenderNode::ROTATION_X); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 238 | } |
| 239 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 240 | static jboolean android_view_RenderNode_setRotationY(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 241 | jobject clazz, jlong renderNodePtr, float ry) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 242 | return SET_AND_DIRTY(setRotationY, ry, RenderNode::ROTATION_Y); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 243 | } |
| 244 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 245 | static jboolean android_view_RenderNode_setScaleX(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 246 | jobject clazz, jlong renderNodePtr, float sx) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 247 | return SET_AND_DIRTY(setScaleX, sx, RenderNode::SCALE_X); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 248 | } |
| 249 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 250 | static jboolean android_view_RenderNode_setScaleY(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 251 | jobject clazz, jlong renderNodePtr, float sy) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 252 | return SET_AND_DIRTY(setScaleY, sy, RenderNode::SCALE_Y); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 253 | } |
| 254 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 255 | static jboolean android_view_RenderNode_setPivotX(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 256 | jobject clazz, jlong renderNodePtr, float px) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 257 | return SET_AND_DIRTY(setPivotX, px, RenderNode::GENERIC); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 258 | } |
| 259 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 260 | static jboolean android_view_RenderNode_setPivotY(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 261 | jobject clazz, jlong renderNodePtr, float py) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 262 | return SET_AND_DIRTY(setPivotY, py, RenderNode::GENERIC); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 263 | } |
| 264 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 265 | static jboolean android_view_RenderNode_setCameraDistance(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 266 | jobject clazz, jlong renderNodePtr, float distance) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 267 | return SET_AND_DIRTY(setCameraDistance, distance, RenderNode::GENERIC); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 268 | } |
| 269 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 270 | static jboolean android_view_RenderNode_setLeft(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 271 | jobject clazz, jlong renderNodePtr, int left) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 272 | return SET_AND_DIRTY(setLeft, left, RenderNode::X); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 273 | } |
| 274 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 275 | static jboolean android_view_RenderNode_setTop(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 276 | jobject clazz, jlong renderNodePtr, int top) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 277 | return SET_AND_DIRTY(setTop, top, RenderNode::Y); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 278 | } |
| 279 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 280 | static jboolean android_view_RenderNode_setRight(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 281 | jobject clazz, jlong renderNodePtr, int right) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 282 | return SET_AND_DIRTY(setRight, right, RenderNode::X); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 283 | } |
| 284 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 285 | static jboolean android_view_RenderNode_setBottom(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 286 | jobject clazz, jlong renderNodePtr, int bottom) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 287 | return SET_AND_DIRTY(setBottom, bottom, RenderNode::Y); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 288 | } |
| 289 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 290 | static jboolean android_view_RenderNode_setLeftTopRightBottom(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 291 | jobject clazz, jlong renderNodePtr, int left, int top, |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 292 | int right, int bottom) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 293 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 294 | if (renderNode->mutateStagingProperties().setLeftTopRightBottom(left, top, right, bottom)) { |
| 295 | renderNode->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); |
| 296 | return true; |
| 297 | } |
| 298 | return false; |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 299 | } |
| 300 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 301 | static jboolean android_view_RenderNode_offsetLeftAndRight(JNIEnv* env, |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 302 | jobject clazz, jlong renderNodePtr, jint offset) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 303 | return SET_AND_DIRTY(offsetLeftRight, offset, RenderNode::X); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 304 | } |
| 305 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 306 | static jboolean android_view_RenderNode_offsetTopAndBottom(JNIEnv* env, |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 307 | jobject clazz, jlong renderNodePtr, jint offset) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 308 | return SET_AND_DIRTY(offsetTopBottom, offset, RenderNode::Y); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 311 | // ---------------------------------------------------------------------------- |
| 312 | // RenderProperties - getters |
| 313 | // ---------------------------------------------------------------------------- |
| 314 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 315 | static jboolean android_view_RenderNode_hasOverlappingRendering(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 316 | jobject clazz, jlong renderNodePtr) { |
| 317 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 318 | return renderNode->stagingProperties().hasOverlappingRendering(); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 319 | } |
| 320 | |
Chris Craik | deeda3d | 2014-05-05 19:09:33 -0700 | [diff] [blame] | 321 | static jboolean android_view_RenderNode_getClipToOutline(JNIEnv* env, |
| 322 | jobject clazz, jlong renderNodePtr) { |
| 323 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 324 | return renderNode->stagingProperties().getOutline().getShouldClip(); |
| 325 | } |
| 326 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 327 | static jfloat android_view_RenderNode_getAlpha(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 328 | jobject clazz, jlong renderNodePtr) { |
| 329 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 330 | return renderNode->stagingProperties().getAlpha(); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 331 | } |
| 332 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 333 | static jfloat android_view_RenderNode_getCameraDistance(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 334 | jobject clazz, jlong renderNodePtr) { |
| 335 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 336 | return renderNode->stagingProperties().getCameraDistance(); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 337 | } |
| 338 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 339 | static jfloat android_view_RenderNode_getScaleX(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 340 | jobject clazz, jlong renderNodePtr) { |
| 341 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 342 | return renderNode->stagingProperties().getScaleX(); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 343 | } |
| 344 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 345 | static jfloat android_view_RenderNode_getScaleY(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 346 | jobject clazz, jlong renderNodePtr) { |
| 347 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 348 | return renderNode->stagingProperties().getScaleY(); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 349 | } |
| 350 | |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 351 | static jfloat android_view_RenderNode_getElevation(JNIEnv* env, |
| 352 | jobject clazz, jlong renderNodePtr) { |
| 353 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 354 | return renderNode->stagingProperties().getElevation(); |
| 355 | } |
| 356 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 357 | static jfloat android_view_RenderNode_getTranslationX(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 358 | jobject clazz, jlong renderNodePtr) { |
| 359 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 360 | return renderNode->stagingProperties().getTranslationX(); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 361 | } |
| 362 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 363 | static jfloat android_view_RenderNode_getTranslationY(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 364 | jobject clazz, jlong renderNodePtr) { |
| 365 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 366 | return renderNode->stagingProperties().getTranslationY(); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 369 | static jfloat android_view_RenderNode_getTranslationZ(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 370 | jobject clazz, jlong renderNodePtr) { |
| 371 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 372 | return renderNode->stagingProperties().getTranslationZ(); |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 373 | } |
| 374 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 375 | static jfloat android_view_RenderNode_getRotation(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 376 | jobject clazz, jlong renderNodePtr) { |
| 377 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 378 | return renderNode->stagingProperties().getRotation(); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 379 | } |
| 380 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 381 | static jfloat android_view_RenderNode_getRotationX(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 382 | jobject clazz, jlong renderNodePtr) { |
| 383 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 384 | return renderNode->stagingProperties().getRotationX(); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 385 | } |
| 386 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 387 | static jfloat android_view_RenderNode_getRotationY(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 388 | jobject clazz, jlong renderNodePtr) { |
| 389 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 390 | return renderNode->stagingProperties().getRotationY(); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 391 | } |
| 392 | |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 393 | static jboolean android_view_RenderNode_isPivotExplicitlySet(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 394 | jobject clazz, jlong renderNodePtr) { |
| 395 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 396 | return renderNode->stagingProperties().isPivotExplicitlySet(); |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static jboolean android_view_RenderNode_hasIdentityMatrix(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 400 | jobject clazz, jlong renderNodePtr) { |
| 401 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 402 | renderNode->mutateStagingProperties().updateMatrix(); |
| 403 | return !renderNode->stagingProperties().hasTransformMatrix(); |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | // ---------------------------------------------------------------------------- |
| 407 | // RenderProperties - computed getters |
| 408 | // ---------------------------------------------------------------------------- |
| 409 | |
| 410 | static void android_view_RenderNode_getTransformMatrix(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 411 | jobject clazz, jlong renderNodePtr, jlong outMatrixPtr) { |
| 412 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 413 | SkMatrix* outMatrix = reinterpret_cast<SkMatrix*>(outMatrixPtr); |
| 414 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 415 | renderNode->mutateStagingProperties().updateMatrix(); |
| 416 | const SkMatrix* transformMatrix = renderNode->stagingProperties().getTransformMatrix(); |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 417 | |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 418 | if (transformMatrix) { |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 419 | *outMatrix = *transformMatrix; |
| 420 | } else { |
| 421 | outMatrix->setIdentity(); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | static void android_view_RenderNode_getInverseTransformMatrix(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 426 | jobject clazz, jlong renderNodePtr, jlong outMatrixPtr) { |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 427 | // load transform matrix |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 428 | android_view_RenderNode_getTransformMatrix(env, clazz, renderNodePtr, outMatrixPtr); |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 429 | SkMatrix* outMatrix = reinterpret_cast<SkMatrix*>(outMatrixPtr); |
| 430 | |
| 431 | // return it inverted |
| 432 | if (!outMatrix->invert(outMatrix)) { |
| 433 | // failed to load inverse, pass back identity |
| 434 | outMatrix->setIdentity(); |
| 435 | } |
| 436 | } |
| 437 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 438 | static jfloat android_view_RenderNode_getPivotX(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 439 | jobject clazz, jlong renderNodePtr) { |
| 440 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 441 | renderNode->mutateStagingProperties().updateMatrix(); |
| 442 | return renderNode->stagingProperties().getPivotX(); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 443 | } |
| 444 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 445 | static jfloat android_view_RenderNode_getPivotY(JNIEnv* env, |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 446 | jobject clazz, jlong renderNodePtr) { |
| 447 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 448 | renderNode->mutateStagingProperties().updateMatrix(); |
| 449 | return renderNode->stagingProperties().getPivotY(); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 450 | } |
| 451 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 452 | // ---------------------------------------------------------------------------- |
| 453 | // RenderProperties - Animations |
| 454 | // ---------------------------------------------------------------------------- |
| 455 | |
| 456 | static void android_view_RenderNode_addAnimator(JNIEnv* env, jobject clazz, |
| 457 | jlong renderNodePtr, jlong animatorPtr) { |
| 458 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 459 | RenderPropertyAnimator* animator = reinterpret_cast<RenderPropertyAnimator*>(animatorPtr); |
| 460 | renderNode->addAnimator(animator); |
| 461 | } |
| 462 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 463 | static void android_view_RenderNode_endAllAnimators(JNIEnv* env, jobject clazz, |
| 464 | jlong renderNodePtr) { |
| 465 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 466 | renderNode->animators().endAllStagingAnimators(); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 469 | // ---------------------------------------------------------------------------- |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 470 | // SurfaceView position callback |
| 471 | // ---------------------------------------------------------------------------- |
| 472 | |
| 473 | jmethodID gSurfaceViewPositionUpdateMethod; |
| 474 | |
| 475 | static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject, |
| 476 | jlong renderNodePtr, jobject surfaceview) { |
| 477 | class SurfaceViewPositionUpdater : public RenderNode::PositionListener { |
| 478 | public: |
| 479 | SurfaceViewPositionUpdater(JNIEnv* env, jobject surfaceview) { |
| 480 | env->GetJavaVM(&mVm); |
| 481 | mWeakRef = env->NewWeakGlobalRef(surfaceview); |
| 482 | } |
| 483 | |
| 484 | virtual ~SurfaceViewPositionUpdater() { |
| 485 | jnienv()->DeleteWeakGlobalRef(mWeakRef); |
| 486 | mWeakRef = nullptr; |
| 487 | } |
| 488 | |
| 489 | virtual void onPositionUpdated(RenderNode& node, const TreeInfo& info) override { |
| 490 | if (CC_UNLIKELY(!mWeakRef || !info.updateWindowPositions)) return; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 491 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 492 | Matrix4 transform; |
| 493 | info.damageAccumulator->computeCurrentTransform(&transform); |
| 494 | const RenderProperties& props = node.properties(); |
| 495 | uirenderer::Rect bounds(props.getWidth(), props.getHeight()); |
| 496 | transform.mapRect(bounds); |
| 497 | bounds.left -= info.windowInsetLeft; |
| 498 | bounds.right -= info.windowInsetLeft; |
| 499 | bounds.top -= info.windowInsetTop; |
| 500 | bounds.bottom -= info.windowInsetTop; |
John Reck | 38f6c03 | 2016-03-17 10:23:49 -0700 | [diff] [blame] | 501 | |
| 502 | auto functor = std::bind( |
| 503 | std::mem_fn(&SurfaceViewPositionUpdater::doUpdatePosition), this, |
| 504 | (jlong) info.frameNumber, (jint) bounds.left, (jint) bounds.top, |
| 505 | (jint) bounds.right, (jint) bounds.bottom); |
| 506 | |
| 507 | info.canvasContext.enqueueFrameWork(std::move(functor)); |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | private: |
| 511 | JNIEnv* jnienv() { |
| 512 | JNIEnv* env; |
| 513 | if (mVm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { |
| 514 | LOG_ALWAYS_FATAL("Failed to get JNIEnv for JavaVM: %p", mVm); |
| 515 | } |
| 516 | return env; |
| 517 | } |
| 518 | |
John Reck | 38f6c03 | 2016-03-17 10:23:49 -0700 | [diff] [blame] | 519 | void doUpdatePosition(jlong frameNumber, jint left, jint top, |
| 520 | jint right, jint bottom) { |
| 521 | ATRACE_NAME("Update SurfaceView position"); |
| 522 | |
| 523 | JNIEnv* env = jnienv(); |
| 524 | jobject localref = env->NewLocalRef(mWeakRef); |
| 525 | if (CC_UNLIKELY(!localref)) { |
| 526 | jnienv()->DeleteWeakGlobalRef(mWeakRef); |
| 527 | mWeakRef = nullptr; |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | env->CallVoidMethod(localref, gSurfaceViewPositionUpdateMethod, |
| 532 | frameNumber, left, top, right, bottom); |
| 533 | env->DeleteLocalRef(localref); |
| 534 | } |
| 535 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 536 | JavaVM* mVm; |
| 537 | jobject mWeakRef; |
| 538 | }; |
| 539 | |
| 540 | RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr); |
| 541 | renderNode->setPositionListener(new SurfaceViewPositionUpdater(env, surfaceview)); |
| 542 | } |
| 543 | |
| 544 | // ---------------------------------------------------------------------------- |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 545 | // JNI Glue |
| 546 | // ---------------------------------------------------------------------------- |
| 547 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 548 | const char* const kClassPathName = "android/view/RenderNode"; |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 549 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 550 | static const JNINativeMethod gMethods[] = { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 551 | { "nCreate", "(Ljava/lang/String;)J", (void*) android_view_RenderNode_create }, |
| 552 | { "nDestroyRenderNode", "(J)V", (void*) android_view_RenderNode_destroyRenderNode }, |
| 553 | { "nSetDisplayList", "(JJ)V", (void*) android_view_RenderNode_setDisplayList }, |
| 554 | { "nOutput", "(J)V", (void*) android_view_RenderNode_output }, |
| 555 | { "nGetDebugSize", "(J)I", (void*) android_view_RenderNode_getDebugSize }, |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 556 | |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 557 | { "nSetLayerType", "!(JI)Z", (void*) android_view_RenderNode_setLayerType }, |
| 558 | { "nSetLayerPaint", "!(JJ)Z", (void*) android_view_RenderNode_setLayerPaint }, |
| 559 | { "nSetStaticMatrix", "!(JJ)Z", (void*) android_view_RenderNode_setStaticMatrix }, |
| 560 | { "nSetAnimationMatrix", "!(JJ)Z", (void*) android_view_RenderNode_setAnimationMatrix }, |
| 561 | { "nSetClipToBounds", "!(JZ)Z", (void*) android_view_RenderNode_setClipToBounds }, |
| 562 | { "nSetClipBounds", "!(JIIII)Z", (void*) android_view_RenderNode_setClipBounds }, |
| 563 | { "nSetClipBoundsEmpty", "!(J)Z", (void*) android_view_RenderNode_setClipBoundsEmpty }, |
| 564 | { "nSetProjectBackwards", "!(JZ)Z", (void*) android_view_RenderNode_setProjectBackwards }, |
| 565 | { "nSetProjectionReceiver","!(JZ)Z", (void*) android_view_RenderNode_setProjectionReceiver }, |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 566 | |
Chris Craik | 40de9f2 | 2015-07-29 12:51:41 -0700 | [diff] [blame] | 567 | { "nSetOutlineRoundRect", "!(JIIIIFF)Z", (void*) android_view_RenderNode_setOutlineRoundRect }, |
| 568 | { "nSetOutlineConvexPath", "!(JJF)Z", (void*) android_view_RenderNode_setOutlineConvexPath }, |
| 569 | { "nSetOutlineEmpty", "!(J)Z", (void*) android_view_RenderNode_setOutlineEmpty }, |
| 570 | { "nSetOutlineNone", "!(J)Z", (void*) android_view_RenderNode_setOutlineNone }, |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 571 | { "nHasShadow", "!(J)Z", (void*) android_view_RenderNode_hasShadow }, |
| 572 | { "nSetClipToOutline", "!(JZ)Z", (void*) android_view_RenderNode_setClipToOutline }, |
Chris Craik | 40de9f2 | 2015-07-29 12:51:41 -0700 | [diff] [blame] | 573 | { "nSetRevealClip", "!(JZFFF)Z", (void*) android_view_RenderNode_setRevealClip }, |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 574 | |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 575 | { "nSetAlpha", "!(JF)Z", (void*) android_view_RenderNode_setAlpha }, |
| 576 | { "nSetHasOverlappingRendering", "!(JZ)Z", |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 577 | (void*) android_view_RenderNode_setHasOverlappingRendering }, |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 578 | { "nSetElevation", "!(JF)Z", (void*) android_view_RenderNode_setElevation }, |
| 579 | { "nSetTranslationX", "!(JF)Z", (void*) android_view_RenderNode_setTranslationX }, |
| 580 | { "nSetTranslationY", "!(JF)Z", (void*) android_view_RenderNode_setTranslationY }, |
| 581 | { "nSetTranslationZ", "!(JF)Z", (void*) android_view_RenderNode_setTranslationZ }, |
| 582 | { "nSetRotation", "!(JF)Z", (void*) android_view_RenderNode_setRotation }, |
| 583 | { "nSetRotationX", "!(JF)Z", (void*) android_view_RenderNode_setRotationX }, |
| 584 | { "nSetRotationY", "!(JF)Z", (void*) android_view_RenderNode_setRotationY }, |
| 585 | { "nSetScaleX", "!(JF)Z", (void*) android_view_RenderNode_setScaleX }, |
| 586 | { "nSetScaleY", "!(JF)Z", (void*) android_view_RenderNode_setScaleY }, |
| 587 | { "nSetPivotX", "!(JF)Z", (void*) android_view_RenderNode_setPivotX }, |
| 588 | { "nSetPivotY", "!(JF)Z", (void*) android_view_RenderNode_setPivotY }, |
| 589 | { "nSetCameraDistance", "!(JF)Z", (void*) android_view_RenderNode_setCameraDistance }, |
| 590 | { "nSetLeft", "!(JI)Z", (void*) android_view_RenderNode_setLeft }, |
| 591 | { "nSetTop", "!(JI)Z", (void*) android_view_RenderNode_setTop }, |
| 592 | { "nSetRight", "!(JI)Z", (void*) android_view_RenderNode_setRight }, |
| 593 | { "nSetBottom", "!(JI)Z", (void*) android_view_RenderNode_setBottom }, |
| 594 | { "nSetLeftTopRightBottom","!(JIIII)Z", (void*) android_view_RenderNode_setLeftTopRightBottom }, |
| 595 | { "nOffsetLeftAndRight", "!(JI)Z", (void*) android_view_RenderNode_offsetLeftAndRight }, |
| 596 | { "nOffsetTopAndBottom", "!(JI)Z", (void*) android_view_RenderNode_offsetTopAndBottom }, |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 597 | |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 598 | { "nHasOverlappingRendering", "!(J)Z", (void*) android_view_RenderNode_hasOverlappingRendering }, |
| 599 | { "nGetClipToOutline", "!(J)Z", (void*) android_view_RenderNode_getClipToOutline }, |
| 600 | { "nGetAlpha", "!(J)F", (void*) android_view_RenderNode_getAlpha }, |
| 601 | { "nGetCameraDistance", "!(J)F", (void*) android_view_RenderNode_getCameraDistance }, |
| 602 | { "nGetScaleX", "!(J)F", (void*) android_view_RenderNode_getScaleX }, |
| 603 | { "nGetScaleY", "!(J)F", (void*) android_view_RenderNode_getScaleY }, |
| 604 | { "nGetElevation", "!(J)F", (void*) android_view_RenderNode_getElevation }, |
| 605 | { "nGetTranslationX", "!(J)F", (void*) android_view_RenderNode_getTranslationX }, |
| 606 | { "nGetTranslationY", "!(J)F", (void*) android_view_RenderNode_getTranslationY }, |
| 607 | { "nGetTranslationZ", "!(J)F", (void*) android_view_RenderNode_getTranslationZ }, |
| 608 | { "nGetRotation", "!(J)F", (void*) android_view_RenderNode_getRotation }, |
| 609 | { "nGetRotationX", "!(J)F", (void*) android_view_RenderNode_getRotationX }, |
| 610 | { "nGetRotationY", "!(J)F", (void*) android_view_RenderNode_getRotationY }, |
| 611 | { "nIsPivotExplicitlySet", "!(J)Z", (void*) android_view_RenderNode_isPivotExplicitlySet }, |
| 612 | { "nHasIdentityMatrix", "!(J)Z", (void*) android_view_RenderNode_hasIdentityMatrix }, |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 613 | |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 614 | { "nGetTransformMatrix", "!(JJ)V", (void*) android_view_RenderNode_getTransformMatrix }, |
| 615 | { "nGetInverseTransformMatrix","!(JJ)V", (void*) android_view_RenderNode_getInverseTransformMatrix }, |
Chris Craik | 49e6c73 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 616 | |
Chris Craik | 4136a0a | 2014-10-07 15:09:46 -0700 | [diff] [blame] | 617 | { "nGetPivotX", "!(J)F", (void*) android_view_RenderNode_getPivotX }, |
| 618 | { "nGetPivotY", "!(J)F", (void*) android_view_RenderNode_getPivotY }, |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 619 | |
| 620 | { "nAddAnimator", "(JJ)V", (void*) android_view_RenderNode_addAnimator }, |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 621 | { "nEndAllAnimators", "(J)V", (void*) android_view_RenderNode_endAllAnimators }, |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 622 | |
| 623 | { "nRequestPositionUpdates", "(JLandroid/view/SurfaceView;)V", (void*) android_view_RenderNode_requestPositionUpdates }, |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 624 | }; |
| 625 | |
John Reck | f666ad7 | 2014-03-14 16:24:57 -0700 | [diff] [blame] | 626 | int register_android_view_RenderNode(JNIEnv* env) { |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 627 | jclass clazz = FindClassOrDie(env, "android/view/SurfaceView"); |
| 628 | gSurfaceViewPositionUpdateMethod = GetMethodIDOrDie(env, clazz, |
| 629 | "updateWindowPositionRT", "(JIIII)V"); |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 630 | return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); |
Chris Craik | 5438979 | 2013-12-20 13:28:11 -0800 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | }; |
| 634 | |