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