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 ATRACE_TAG ATRACE_TAG_VIEW
18 #include "GraphicsJNI.h"
19
20 #include <Animator.h>
21 #include <DamageAccumulator.h>
22 #include <Matrix.h>
23 #include <RenderNode.h>
24 #ifdef __ANDROID__ // Layoutlib does not support CanvasContext
25 #include <renderthread/CanvasContext.h>
26 #endif
27 #include <TreeInfo.h>
28 #include <effects/StretchEffect.h>
29 #include <gui/TraceUtils.h>
30 #include <hwui/Paint.h>
31
32 namespace android {
33
34 using namespace uirenderer;
35
36 #define SET_AND_DIRTY(prop, val, dirtyFlag) \
37 (reinterpret_cast<RenderNode*>(renderNodePtr)->mutateStagingProperties().prop(val) \
38 ? (reinterpret_cast<RenderNode*>(renderNodePtr)->setPropertyFieldsDirty(dirtyFlag), true) \
39 : false)
40
41 // ----------------------------------------------------------------------------
42 // DisplayList view properties
43 // ----------------------------------------------------------------------------
44
android_view_RenderNode_output(JNIEnv * env,jobject clazz,jlong renderNodePtr)45 static void android_view_RenderNode_output(JNIEnv* env, jobject clazz, jlong renderNodePtr) {
46 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
47 renderNode->output();
48 }
49
android_view_RenderNode_getUsageSize(JNIEnv * env,jobject clazz,jlong renderNodePtr)50 static jint android_view_RenderNode_getUsageSize(JNIEnv* env, jobject clazz, jlong renderNodePtr) {
51 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
52 return renderNode->getUsageSize();
53 }
54
android_view_RenderNode_getAllocatedSize(JNIEnv * env,jobject clazz,jlong renderNodePtr)55 static jint android_view_RenderNode_getAllocatedSize(JNIEnv* env, jobject clazz, jlong renderNodePtr) {
56 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
57 return renderNode->getAllocatedSize();
58 }
59
android_view_RenderNode_create(JNIEnv * env,jobject,jstring name)60 static jlong android_view_RenderNode_create(JNIEnv* env, jobject, jstring name) {
61 RenderNode* renderNode = new RenderNode();
62 renderNode->incStrong(0);
63 if (name != NULL) {
64 const char* textArray = env->GetStringUTFChars(name, NULL);
65 renderNode->setName(textArray);
66 env->ReleaseStringUTFChars(name, textArray);
67 }
68 return reinterpret_cast<jlong>(renderNode);
69 }
70
releaseRenderNode(RenderNode * renderNode)71 static void releaseRenderNode(RenderNode* renderNode) {
72 renderNode->decStrong(0);
73 }
74
android_view_RenderNode_getNativeFinalizer(JNIEnv * env,jobject clazz)75 static jlong android_view_RenderNode_getNativeFinalizer(JNIEnv* env,
76 jobject clazz) {
77 return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseRenderNode));
78 }
79
android_view_RenderNode_discardDisplayList(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)80 static void android_view_RenderNode_discardDisplayList(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
81 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
82 renderNode->discardStagingDisplayList();
83 }
84
android_view_RenderNode_isValid(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)85 static jboolean android_view_RenderNode_isValid(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
86 return reinterpret_cast<RenderNode*>(renderNodePtr)->isValid();
87 }
88
89 // ----------------------------------------------------------------------------
90 // RenderProperties - setters
91 // ----------------------------------------------------------------------------
92
android_view_RenderNode_setLayerType(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jint jlayerType)93 static jboolean android_view_RenderNode_setLayerType(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, jint jlayerType) {
94 LayerType layerType = static_cast<LayerType>(jlayerType);
95 return SET_AND_DIRTY(mutateLayerProperties().setType, layerType, RenderNode::GENERIC);
96 }
97
android_view_RenderNode_setLayerPaint(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jlong paintPtr)98 static jboolean android_view_RenderNode_setLayerPaint(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, jlong paintPtr) {
99 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
100 return SET_AND_DIRTY(mutateLayerProperties().setFromPaint, paint, RenderNode::GENERIC);
101 }
102
android_view_RenderNode_setStaticMatrix(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jlong matrixPtr)103 static jboolean android_view_RenderNode_setStaticMatrix(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, jlong matrixPtr) {
104 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr);
105 return SET_AND_DIRTY(setStaticMatrix, matrix, RenderNode::GENERIC);
106 }
107
android_view_RenderNode_setAnimationMatrix(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jlong matrixPtr)108 static jboolean android_view_RenderNode_setAnimationMatrix(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, jlong matrixPtr) {
109 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr);
110 return SET_AND_DIRTY(setAnimationMatrix, matrix, RenderNode::GENERIC);
111 }
112
android_view_RenderNode_setClipToBounds(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jboolean clipToBounds)113 static jboolean android_view_RenderNode_setClipToBounds(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
114 jboolean clipToBounds) {
115 return SET_AND_DIRTY(setClipToBounds, clipToBounds, RenderNode::GENERIC);
116 }
117
android_view_RenderNode_setClipBounds(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jint left,jint top,jint right,jint bottom)118 static jboolean android_view_RenderNode_setClipBounds(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
119 jint left, jint top, jint right, jint bottom) {
120 android::uirenderer::Rect clipBounds(left, top, right, bottom);
121 return SET_AND_DIRTY(setClipBounds, clipBounds, RenderNode::GENERIC);
122 }
123
android_view_RenderNode_setClipBoundsEmpty(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)124 static jboolean android_view_RenderNode_setClipBoundsEmpty(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
125 return SET_AND_DIRTY(setClipBoundsEmpty,, RenderNode::GENERIC);
126 }
127
android_view_RenderNode_setProjectBackwards(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jboolean shouldProject)128 static jboolean android_view_RenderNode_setProjectBackwards(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
129 jboolean shouldProject) {
130 return SET_AND_DIRTY(setProjectBackwards, shouldProject, RenderNode::GENERIC);
131 }
132
android_view_RenderNode_setProjectionReceiver(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jboolean shouldRecieve)133 static jboolean android_view_RenderNode_setProjectionReceiver(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
134 jboolean shouldRecieve) {
135 return SET_AND_DIRTY(setProjectionReceiver, shouldRecieve, RenderNode::GENERIC);
136 }
137
android_view_RenderNode_setOutlineRoundRect(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jint left,jint top,jint right,jint bottom,jfloat radius,jfloat alpha)138 static jboolean android_view_RenderNode_setOutlineRoundRect(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
139 jint left, jint top, jint right, jint bottom, jfloat radius, jfloat alpha) {
140 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
141 renderNode->mutateStagingProperties().mutableOutline().setRoundRect(left, top, right, bottom,
142 radius, alpha);
143 renderNode->setPropertyFieldsDirty(RenderNode::GENERIC);
144 return true;
145 }
146
android_view_RenderNode_setOutlinePath(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jlong outlinePathPtr,jfloat alpha)147 static jboolean android_view_RenderNode_setOutlinePath(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
148 jlong outlinePathPtr, jfloat alpha) {
149 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
150 SkPath* outlinePath = reinterpret_cast<SkPath*>(outlinePathPtr);
151 renderNode->mutateStagingProperties().mutableOutline().setPath(outlinePath, alpha);
152 renderNode->setPropertyFieldsDirty(RenderNode::GENERIC);
153 return true;
154 }
155
android_view_RenderNode_setOutlineEmpty(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)156 static jboolean android_view_RenderNode_setOutlineEmpty(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
157 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
158 renderNode->mutateStagingProperties().mutableOutline().setEmpty();
159 renderNode->setPropertyFieldsDirty(RenderNode::GENERIC);
160 return true;
161 }
162
android_view_RenderNode_setOutlineNone(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)163 static jboolean android_view_RenderNode_setOutlineNone(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
164 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
165 renderNode->mutateStagingProperties().mutableOutline().setNone();
166 renderNode->setPropertyFieldsDirty(RenderNode::GENERIC);
167 return true;
168 }
169
android_view_RenderNode_clearStretch(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)170 static jboolean android_view_RenderNode_clearStretch(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
171 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
172 auto& stretch = renderNode->mutateStagingProperties()
173 .mutateLayerProperties().mutableStretchEffect();
174 if (stretch.isEmpty()) {
175 return false;
176 }
177 stretch.setEmpty();
178 renderNode->setPropertyFieldsDirty(RenderNode::GENERIC);
179 return true;
180 }
181
android_view_RenderNode_stretch(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jfloat vX,jfloat vY,jfloat maxX,jfloat maxY)182 static jboolean android_view_RenderNode_stretch(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
183 jfloat vX, jfloat vY, jfloat maxX,
184 jfloat maxY) {
185 auto* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
186 StretchEffect effect = StretchEffect({.fX = vX, .fY = vY}, maxX, maxY);
187 renderNode->mutateStagingProperties().mutateLayerProperties().mutableStretchEffect().mergeWith(
188 effect);
189 renderNode->setPropertyFieldsDirty(RenderNode::GENERIC);
190 return true;
191 }
192
android_view_RenderNode_hasShadow(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)193 static jboolean android_view_RenderNode_hasShadow(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
194 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
195 return renderNode->stagingProperties().hasShadow();
196 }
197
android_view_RenderNode_setSpotShadowColor(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jint shadowColor)198 static jboolean android_view_RenderNode_setSpotShadowColor(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, jint shadowColor) {
199 return SET_AND_DIRTY(setSpotShadowColor,
200 static_cast<SkColor>(shadowColor), RenderNode::GENERIC);
201 }
202
android_view_RenderNode_getSpotShadowColor(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)203 static jint android_view_RenderNode_getSpotShadowColor(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
204 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
205 return renderNode->stagingProperties().getSpotShadowColor();
206 }
207
android_view_RenderNode_setAmbientShadowColor(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jint shadowColor)208 static jboolean android_view_RenderNode_setAmbientShadowColor(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
209 jint shadowColor) {
210 return SET_AND_DIRTY(setAmbientShadowColor,
211 static_cast<SkColor>(shadowColor), RenderNode::GENERIC);
212 }
213
android_view_RenderNode_getAmbientShadowColor(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)214 static jint android_view_RenderNode_getAmbientShadowColor(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
215 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
216 return renderNode->stagingProperties().getAmbientShadowColor();
217 }
218
android_view_RenderNode_setClipToOutline(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jboolean clipToOutline)219 static jboolean android_view_RenderNode_setClipToOutline(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
220 jboolean clipToOutline) {
221 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
222 renderNode->mutateStagingProperties().mutableOutline().setShouldClip(clipToOutline);
223 renderNode->setPropertyFieldsDirty(RenderNode::GENERIC);
224 return true;
225 }
226
android_view_RenderNode_setRevealClip(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jboolean shouldClip,jfloat x,jfloat y,jfloat radius)227 static jboolean android_view_RenderNode_setRevealClip(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, jboolean shouldClip,
228 jfloat x, jfloat y, jfloat radius) {
229 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
230 renderNode->mutateStagingProperties().mutableRevealClip().set(
231 shouldClip, x, y, radius);
232 renderNode->setPropertyFieldsDirty(RenderNode::GENERIC);
233 return true;
234 }
235
android_view_RenderNode_setAlpha(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float alpha)236 static jboolean android_view_RenderNode_setAlpha(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float alpha) {
237 return SET_AND_DIRTY(setAlpha, alpha, RenderNode::ALPHA);
238 }
239
android_view_RenderNode_setRenderEffect(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jlong renderEffectPtr)240 static jboolean android_view_RenderNode_setRenderEffect(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
241 jlong renderEffectPtr) {
242 SkImageFilter* imageFilter = reinterpret_cast<SkImageFilter*>(renderEffectPtr);
243 return SET_AND_DIRTY(mutateLayerProperties().setImageFilter, imageFilter, RenderNode::GENERIC);
244 }
245
android_view_RenderNode_setHasOverlappingRendering(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,bool hasOverlappingRendering)246 static jboolean android_view_RenderNode_setHasOverlappingRendering(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
247 bool hasOverlappingRendering) {
248 return SET_AND_DIRTY(setHasOverlappingRendering, hasOverlappingRendering,
249 RenderNode::GENERIC);
250 }
251
android_view_RenderNode_setUsageHint(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jint usageHint)252 static void android_view_RenderNode_setUsageHint(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, jint usageHint) {
253 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
254 renderNode->setUsageHint(static_cast<UsageHint>(usageHint));
255 }
256
android_view_RenderNode_setElevation(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float elevation)257 static jboolean android_view_RenderNode_setElevation(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float elevation) {
258 return SET_AND_DIRTY(setElevation, elevation, RenderNode::Z);
259 }
260
android_view_RenderNode_setTranslationX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float tx)261 static jboolean android_view_RenderNode_setTranslationX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float tx) {
262 return SET_AND_DIRTY(setTranslationX, tx, RenderNode::TRANSLATION_X | RenderNode::X);
263 }
264
android_view_RenderNode_setTranslationY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float ty)265 static jboolean android_view_RenderNode_setTranslationY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float ty) {
266 return SET_AND_DIRTY(setTranslationY, ty, RenderNode::TRANSLATION_Y | RenderNode::Y);
267 }
268
android_view_RenderNode_setTranslationZ(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float tz)269 static jboolean android_view_RenderNode_setTranslationZ(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float tz) {
270 return SET_AND_DIRTY(setTranslationZ, tz, RenderNode::TRANSLATION_Z | RenderNode::Z);
271 }
272
android_view_RenderNode_setRotation(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float rotation)273 static jboolean android_view_RenderNode_setRotation(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float rotation) {
274 return SET_AND_DIRTY(setRotation, rotation, RenderNode::ROTATION);
275 }
276
android_view_RenderNode_setRotationX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float rx)277 static jboolean android_view_RenderNode_setRotationX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float rx) {
278 return SET_AND_DIRTY(setRotationX, rx, RenderNode::ROTATION_X);
279 }
280
android_view_RenderNode_setRotationY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float ry)281 static jboolean android_view_RenderNode_setRotationY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float ry) {
282 return SET_AND_DIRTY(setRotationY, ry, RenderNode::ROTATION_Y);
283 }
284
android_view_RenderNode_setScaleX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float sx)285 static jboolean android_view_RenderNode_setScaleX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float sx) {
286 return SET_AND_DIRTY(setScaleX, sx, RenderNode::SCALE_X);
287 }
288
android_view_RenderNode_setScaleY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float sy)289 static jboolean android_view_RenderNode_setScaleY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float sy) {
290 return SET_AND_DIRTY(setScaleY, sy, RenderNode::SCALE_Y);
291 }
292
android_view_RenderNode_setPivotX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float px)293 static jboolean android_view_RenderNode_setPivotX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float px) {
294 return SET_AND_DIRTY(setPivotX, px, RenderNode::GENERIC);
295 }
296
android_view_RenderNode_setPivotY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float py)297 static jboolean android_view_RenderNode_setPivotY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float py) {
298 return SET_AND_DIRTY(setPivotY, py, RenderNode::GENERIC);
299 }
300
android_view_RenderNode_resetPivot(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)301 static jboolean android_view_RenderNode_resetPivot(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
302 return SET_AND_DIRTY(resetPivot, /* void */, RenderNode::GENERIC);
303 }
304
android_view_RenderNode_setCameraDistance(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,float distance)305 static jboolean android_view_RenderNode_setCameraDistance(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, float distance) {
306 return SET_AND_DIRTY(setCameraDistance, distance, RenderNode::GENERIC);
307 }
308
android_view_RenderNode_setLeft(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,int left)309 static jboolean android_view_RenderNode_setLeft(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, int left) {
310 return SET_AND_DIRTY(setLeft, left, RenderNode::X);
311 }
312
android_view_RenderNode_setTop(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,int top)313 static jboolean android_view_RenderNode_setTop(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, int top) {
314 return SET_AND_DIRTY(setTop, top, RenderNode::Y);
315 }
316
android_view_RenderNode_setRight(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,int right)317 static jboolean android_view_RenderNode_setRight(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, int right) {
318 return SET_AND_DIRTY(setRight, right, RenderNode::X);
319 }
320
android_view_RenderNode_setBottom(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,int bottom)321 static jboolean android_view_RenderNode_setBottom(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, int bottom) {
322 return SET_AND_DIRTY(setBottom, bottom, RenderNode::Y);
323 }
324
android_view_RenderNode_getLeft(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)325 static jint android_view_RenderNode_getLeft(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
326 return reinterpret_cast<RenderNode*>(renderNodePtr)->stagingProperties().getLeft();
327 }
328
android_view_RenderNode_getTop(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)329 static jint android_view_RenderNode_getTop(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
330 return reinterpret_cast<RenderNode*>(renderNodePtr)->stagingProperties().getTop();
331 }
332
android_view_RenderNode_getRight(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)333 static jint android_view_RenderNode_getRight(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
334 return reinterpret_cast<RenderNode*>(renderNodePtr)->stagingProperties().getRight();
335 }
336
android_view_RenderNode_getBottom(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)337 static jint android_view_RenderNode_getBottom(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
338 return reinterpret_cast<RenderNode*>(renderNodePtr)->stagingProperties().getBottom();
339 }
340
android_view_RenderNode_setLeftTopRightBottom(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,int left,int top,int right,int bottom)341 static jboolean android_view_RenderNode_setLeftTopRightBottom(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
342 int left, int top, int right, int bottom) {
343 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
344 if (renderNode->mutateStagingProperties().setLeftTopRightBottom(left, top, right, bottom)) {
345 renderNode->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y);
346 return true;
347 }
348 return false;
349 }
350
android_view_RenderNode_offsetLeftAndRight(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jint offset)351 static jboolean android_view_RenderNode_offsetLeftAndRight(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, jint offset) {
352 return SET_AND_DIRTY(offsetLeftRight, offset, RenderNode::X);
353 }
354
android_view_RenderNode_offsetTopAndBottom(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jint offset)355 static jboolean android_view_RenderNode_offsetTopAndBottom(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, jint offset) {
356 return SET_AND_DIRTY(offsetTopBottom, offset, RenderNode::Y);
357 }
358
359 // ----------------------------------------------------------------------------
360 // RenderProperties - getters
361 // ----------------------------------------------------------------------------
362
android_view_RenderNode_hasOverlappingRendering(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)363 static jboolean android_view_RenderNode_hasOverlappingRendering(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
364 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
365 return renderNode->stagingProperties().hasOverlappingRendering();
366 }
367
android_view_RenderNode_getAnimationMatrix(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jlong outMatrixPtr)368 static jboolean android_view_RenderNode_getAnimationMatrix(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, jlong outMatrixPtr) {
369 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
370 SkMatrix* outMatrix = reinterpret_cast<SkMatrix*>(outMatrixPtr);
371
372 const SkMatrix* animationMatrix = renderNode->stagingProperties().getAnimationMatrix();
373
374 if (animationMatrix) {
375 *outMatrix = *animationMatrix;
376 return JNI_TRUE;
377 }
378 return JNI_FALSE;
379 }
380
android_view_RenderNode_getClipToBounds(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)381 static jboolean android_view_RenderNode_getClipToBounds(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
382 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
383 return renderNode->stagingProperties().getClipToBounds();
384 }
385
android_view_RenderNode_getClipToOutline(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)386 static jboolean android_view_RenderNode_getClipToOutline(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
387 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
388 return renderNode->stagingProperties().getOutline().getShouldClip();
389 }
390
android_view_RenderNode_getAlpha(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)391 static jfloat android_view_RenderNode_getAlpha(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
392 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
393 return renderNode->stagingProperties().getAlpha();
394 }
395
android_view_RenderNode_getCameraDistance(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)396 static jfloat android_view_RenderNode_getCameraDistance(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
397 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
398 return renderNode->stagingProperties().getCameraDistance();
399 }
400
android_view_RenderNode_getScaleX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)401 static jfloat android_view_RenderNode_getScaleX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
402 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
403 return renderNode->stagingProperties().getScaleX();
404 }
405
android_view_RenderNode_getScaleY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)406 static jfloat android_view_RenderNode_getScaleY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
407 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
408 return renderNode->stagingProperties().getScaleY();
409 }
410
android_view_RenderNode_getElevation(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)411 static jfloat android_view_RenderNode_getElevation(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
412 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
413 return renderNode->stagingProperties().getElevation();
414 }
415
android_view_RenderNode_getTranslationX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)416 static jfloat android_view_RenderNode_getTranslationX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
417 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
418 return renderNode->stagingProperties().getTranslationX();
419 }
420
android_view_RenderNode_getTranslationY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)421 static jfloat android_view_RenderNode_getTranslationY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
422 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
423 return renderNode->stagingProperties().getTranslationY();
424 }
425
android_view_RenderNode_getTranslationZ(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)426 static jfloat android_view_RenderNode_getTranslationZ(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
427 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
428 return renderNode->stagingProperties().getTranslationZ();
429 }
430
android_view_RenderNode_getRotation(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)431 static jfloat android_view_RenderNode_getRotation(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
432 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
433 return renderNode->stagingProperties().getRotation();
434 }
435
android_view_RenderNode_getRotationX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)436 static jfloat android_view_RenderNode_getRotationX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
437 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
438 return renderNode->stagingProperties().getRotationX();
439 }
440
android_view_RenderNode_getRotationY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)441 static jfloat android_view_RenderNode_getRotationY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
442 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
443 return renderNode->stagingProperties().getRotationY();
444 }
445
android_view_RenderNode_isPivotExplicitlySet(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)446 static jboolean android_view_RenderNode_isPivotExplicitlySet(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
447 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
448 return renderNode->stagingProperties().isPivotExplicitlySet();
449 }
450
android_view_RenderNode_hasIdentityMatrix(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)451 static jboolean android_view_RenderNode_hasIdentityMatrix(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
452 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
453 renderNode->mutateStagingProperties().updateMatrix();
454 return !renderNode->stagingProperties().hasTransformMatrix();
455 }
456
android_view_RenderNode_getLayerType(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)457 static jint android_view_RenderNode_getLayerType(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
458 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
459 return static_cast<int>(renderNode->stagingProperties().layerProperties().type());
460 }
461
462 // ----------------------------------------------------------------------------
463 // RenderProperties - computed getters
464 // ----------------------------------------------------------------------------
465
getTransformMatrix(jlong renderNodePtr,jlong outMatrixPtr)466 static void getTransformMatrix(jlong renderNodePtr, jlong outMatrixPtr) {
467 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
468 SkMatrix* outMatrix = reinterpret_cast<SkMatrix*>(outMatrixPtr);
469
470 renderNode->mutateStagingProperties().updateMatrix();
471 const SkMatrix* transformMatrix = renderNode->stagingProperties().getTransformMatrix();
472
473 if (transformMatrix) {
474 *outMatrix = *transformMatrix;
475 } else {
476 outMatrix->setIdentity();
477 }
478 }
479
android_view_RenderNode_getTransformMatrix(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jlong outMatrixPtr)480 static void android_view_RenderNode_getTransformMatrix(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, jlong outMatrixPtr) {
481 getTransformMatrix(renderNodePtr, outMatrixPtr);
482 }
483
android_view_RenderNode_getInverseTransformMatrix(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jlong outMatrixPtr)484 static void android_view_RenderNode_getInverseTransformMatrix(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,
485 jlong outMatrixPtr) {
486 // load transform matrix
487 getTransformMatrix(renderNodePtr, outMatrixPtr);
488 SkMatrix* outMatrix = reinterpret_cast<SkMatrix*>(outMatrixPtr);
489
490 // return it inverted
491 if (!outMatrix->invert(outMatrix)) {
492 // failed to load inverse, pass back identity
493 outMatrix->setIdentity();
494 }
495 }
496
android_view_RenderNode_getPivotX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)497 static jfloat android_view_RenderNode_getPivotX(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
498 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
499 renderNode->mutateStagingProperties().updateMatrix();
500 return renderNode->stagingProperties().getPivotX();
501 }
502
android_view_RenderNode_getPivotY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)503 static jfloat android_view_RenderNode_getPivotY(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
504 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
505 renderNode->mutateStagingProperties().updateMatrix();
506 return renderNode->stagingProperties().getPivotY();
507 }
508
android_view_RenderNode_getWidth(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)509 static jint android_view_RenderNode_getWidth(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
510 return reinterpret_cast<RenderNode*>(renderNodePtr)->stagingProperties().getWidth();
511 }
512
android_view_RenderNode_getHeight(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)513 static jint android_view_RenderNode_getHeight(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
514 return reinterpret_cast<RenderNode*>(renderNodePtr)->stagingProperties().getHeight();
515 }
516
android_view_RenderNode_setAllowForceDark(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr,jboolean allow)517 static jboolean android_view_RenderNode_setAllowForceDark(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr, jboolean allow) {
518 return SET_AND_DIRTY(setAllowForceDark, allow, RenderNode::GENERIC);
519 }
520
android_view_RenderNode_getAllowForceDark(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)521 static jboolean android_view_RenderNode_getAllowForceDark(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
522 return reinterpret_cast<RenderNode*>(renderNodePtr)->stagingProperties().getAllowForceDark();
523 }
524
android_view_RenderNode_getUniqueId(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr)525 static jlong android_view_RenderNode_getUniqueId(CRITICAL_JNI_PARAMS_COMMA jlong renderNodePtr) {
526 return reinterpret_cast<RenderNode*>(renderNodePtr)->uniqueId();
527 }
528
529 // ----------------------------------------------------------------------------
530 // RenderProperties - Animations
531 // ----------------------------------------------------------------------------
532
android_view_RenderNode_addAnimator(JNIEnv * env,jobject clazz,jlong renderNodePtr,jlong animatorPtr)533 static void android_view_RenderNode_addAnimator(JNIEnv* env, jobject clazz, jlong renderNodePtr,
534 jlong animatorPtr) {
535 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
536 RenderPropertyAnimator* animator = reinterpret_cast<RenderPropertyAnimator*>(animatorPtr);
537 renderNode->addAnimator(animator);
538 }
539
android_view_RenderNode_endAllAnimators(JNIEnv * env,jobject clazz,jlong renderNodePtr)540 static void android_view_RenderNode_endAllAnimators(JNIEnv* env, jobject clazz,
541 jlong renderNodePtr) {
542 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
543 renderNode->animators().endAllStagingAnimators();
544 }
545
android_view_RenderNode_forceEndAnimators(JNIEnv * env,jobject clazz,jlong renderNodePtr)546 static void android_view_RenderNode_forceEndAnimators(JNIEnv* env, jobject clazz,
547 jlong renderNodePtr) {
548 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
549 renderNode->animators().forceEndAnimators();
550 }
551
552 // ----------------------------------------------------------------------------
553 // SurfaceView position callback
554 // ----------------------------------------------------------------------------
555
556 struct {
557 jclass clazz;
558 jmethodID callPositionChanged;
559 jmethodID callApplyStretch;
560 jmethodID callPositionLost;
561 } gPositionListener;
562
android_view_RenderNode_requestPositionUpdates(JNIEnv * env,jobject,jlong renderNodePtr,jobject listener)563 static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,
564 jlong renderNodePtr, jobject listener) {
565 class PositionListenerTrampoline : public RenderNode::PositionListener {
566 public:
567 PositionListenerTrampoline(JNIEnv* env, jobject listener) {
568 env->GetJavaVM(&mVm);
569 mListener = env->NewGlobalRef(listener);
570 }
571
572 virtual ~PositionListenerTrampoline() {
573 jnienv()->DeleteGlobalRef(mListener);
574 mListener = nullptr;
575 }
576
577 virtual void onPositionUpdated(RenderNode& node, const TreeInfo& info) override {
578 if (CC_UNLIKELY(!mListener || !info.updateWindowPositions)) return;
579
580 Matrix4 transform;
581 info.damageAccumulator->computeCurrentTransform(&transform);
582 const RenderProperties& props = node.properties();
583
584 uirenderer::Rect bounds(props.getWidth(), props.getHeight());
585 bool useStretchShader =
586 Properties::getStretchEffectBehavior() != StretchEffectBehavior::UniformScale;
587 if (useStretchShader && info.stretchEffectCount) {
588 handleStretchEffect(info, bounds);
589 }
590
591 transform.mapRect(bounds);
592
593 if (CC_LIKELY(transform.isPureTranslate())) {
594 // snap/round the computed bounds, so they match the rounding behavior
595 // of the clear done in SurfaceView#draw().
596 bounds.snapGeometryToPixelBoundaries(false);
597 } else {
598 // Conservatively round out so the punched hole (in the ZOrderOnTop = true case)
599 // doesn't extend beyond the other window
600 bounds.roundOut();
601 }
602
603 if (mPreviousPosition == bounds) {
604 return;
605 }
606 mPreviousPosition = bounds;
607
608 #ifdef __ANDROID__ // Layoutlib does not support CanvasContext
609 incStrong(0);
610 auto functor = std::bind(
611 std::mem_fn(&PositionListenerTrampoline::doUpdatePositionAsync), this,
612 (jlong) info.canvasContext.getFrameNumber(),
613 (jint) bounds.left, (jint) bounds.top,
614 (jint) bounds.right, (jint) bounds.bottom);
615
616 info.canvasContext.enqueueFrameWork(std::move(functor));
617 #endif
618 }
619
620 virtual void onPositionLost(RenderNode& node, const TreeInfo* info) override {
621 if (CC_UNLIKELY(!mListener || (info && !info->updateWindowPositions))) return;
622
623 if (mPreviousPosition.isEmpty()) {
624 return;
625 }
626 mPreviousPosition.setEmpty();
627
628 ATRACE_NAME("SurfaceView position lost");
629 JNIEnv* env = jnienv();
630 #ifdef __ANDROID__ // Layoutlib does not support CanvasContext
631 // TODO: Remember why this is synchronous and then make a comment
632 jboolean keepListening = env->CallStaticBooleanMethod(
633 gPositionListener.clazz, gPositionListener.callPositionLost, mListener,
634 info ? info->canvasContext.getFrameNumber() : 0);
635 if (!keepListening) {
636 env->DeleteGlobalRef(mListener);
637 mListener = nullptr;
638 }
639 #endif
640 }
641
642 private:
643 JNIEnv* jnienv() {
644 JNIEnv* env;
645 if (mVm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
646 LOG_ALWAYS_FATAL("Failed to get JNIEnv for JavaVM: %p", mVm);
647 }
648 return env;
649 }
650
651 void stretchTargetBounds(const StretchEffect& stretchEffect,
652 float width, float height,
653 const SkRect& childRelativeBounds,
654 uirenderer::Rect& bounds) {
655 float normalizedLeft = childRelativeBounds.left() / width;
656 float normalizedTop = childRelativeBounds.top() / height;
657 float normalizedRight = childRelativeBounds.right() / width;
658 float normalizedBottom = childRelativeBounds.bottom() / height;
659 float reverseLeft = width *
660 (stretchEffect.computeStretchedPositionX(normalizedLeft) -
661 normalizedLeft);
662 float reverseTop = height *
663 (stretchEffect.computeStretchedPositionY(normalizedTop) -
664 normalizedTop);
665 float reverseRight = width *
666 (stretchEffect.computeStretchedPositionX(normalizedRight) -
667 normalizedLeft);
668 float reverseBottom = height *
669 (stretchEffect.computeStretchedPositionY(normalizedBottom) -
670 normalizedTop);
671 bounds.left = reverseLeft;
672 bounds.top = reverseTop;
673 bounds.right = reverseRight;
674 bounds.bottom = reverseBottom;
675 }
676
677 void handleStretchEffect(const TreeInfo& info, uirenderer::Rect& targetBounds) {
678 // Search up to find the nearest stretcheffect parent
679 const DamageAccumulator::StretchResult result =
680 info.damageAccumulator->findNearestStretchEffect();
681 const StretchEffect* effect = result.stretchEffect;
682 if (!effect) {
683 return;
684 }
685
686 const auto& childRelativeBounds = result.childRelativeBounds;
687 stretchTargetBounds(*effect, result.width, result.height,
688 childRelativeBounds,targetBounds);
689
690 if (Properties::getStretchEffectBehavior() ==
691 StretchEffectBehavior::Shader) {
692 JNIEnv* env = jnienv();
693
694 #ifdef __ANDROID__ // Layoutlib does not support CanvasContext
695 SkVector stretchDirection = effect->getStretchDirection();
696 jboolean keepListening = env->CallStaticBooleanMethod(
697 gPositionListener.clazz, gPositionListener.callApplyStretch, mListener,
698 info.canvasContext.getFrameNumber(), result.width, result.height,
699 stretchDirection.fX, stretchDirection.fY, effect->maxStretchAmountX,
700 effect->maxStretchAmountY, childRelativeBounds.left(),
701 childRelativeBounds.top(), childRelativeBounds.right(),
702 childRelativeBounds.bottom());
703 if (!keepListening) {
704 env->DeleteGlobalRef(mListener);
705 mListener = nullptr;
706 }
707 #endif
708 }
709 }
710
711 void doUpdatePositionAsync(jlong frameNumber, jint left, jint top,
712 jint right, jint bottom) {
713 ATRACE_NAME("Update SurfaceView position");
714
715 JNIEnv* env = jnienv();
716 jboolean keepListening = env->CallStaticBooleanMethod(
717 gPositionListener.clazz, gPositionListener.callPositionChanged, mListener,
718 frameNumber, left, top, right, bottom);
719 if (!keepListening) {
720 env->DeleteGlobalRef(mListener);
721 mListener = nullptr;
722 }
723
724 // We need to release ourselves here
725 decStrong(0);
726 }
727
728 JavaVM* mVm;
729 jobject mListener;
730 uirenderer::Rect mPreviousPosition;
731 };
732
733 RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
734 renderNode->setPositionListener(new PositionListenerTrampoline(env, listener));
735 }
736
737 // ----------------------------------------------------------------------------
738 // JNI Glue
739 // ----------------------------------------------------------------------------
740
741 const char* const kClassPathName = "android/graphics/RenderNode";
742
743 static const JNINativeMethod gMethods[] = {
744 // ----------------------------------------------------------------------------
745 // Regular JNI
746 // ----------------------------------------------------------------------------
747 {"nCreate", "(Ljava/lang/String;)J", (void*)android_view_RenderNode_create},
748 {"nGetNativeFinalizer", "()J", (void*)android_view_RenderNode_getNativeFinalizer},
749 {"nOutput", "(J)V", (void*)android_view_RenderNode_output},
750 {"nGetUsageSize", "(J)I", (void*)android_view_RenderNode_getUsageSize},
751 {"nGetAllocatedSize", "(J)I", (void*)android_view_RenderNode_getAllocatedSize},
752 {"nAddAnimator", "(JJ)V", (void*)android_view_RenderNode_addAnimator},
753 {"nEndAllAnimators", "(J)V", (void*)android_view_RenderNode_endAllAnimators},
754 {"nForceEndAnimators", "(J)V", (void*)android_view_RenderNode_forceEndAnimators},
755 {"nRequestPositionUpdates", "(JLjava/lang/ref/WeakReference;)V",
756 (void*)android_view_RenderNode_requestPositionUpdates},
757
758 // ----------------------------------------------------------------------------
759 // Critical JNI via @CriticalNative annotation in RenderNode.java
760 // ----------------------------------------------------------------------------
761 {"nDiscardDisplayList", "(J)V", (void*)android_view_RenderNode_discardDisplayList},
762 {"nIsValid", "(J)Z", (void*)android_view_RenderNode_isValid},
763 {"nSetLayerType", "(JI)Z", (void*)android_view_RenderNode_setLayerType},
764 {"nGetLayerType", "(J)I", (void*)android_view_RenderNode_getLayerType},
765 {"nSetLayerPaint", "(JJ)Z", (void*)android_view_RenderNode_setLayerPaint},
766 {"nSetStaticMatrix", "(JJ)Z", (void*)android_view_RenderNode_setStaticMatrix},
767 {"nSetAnimationMatrix", "(JJ)Z", (void*)android_view_RenderNode_setAnimationMatrix},
768 {"nGetAnimationMatrix", "(JJ)Z", (void*)android_view_RenderNode_getAnimationMatrix},
769 {"nSetClipToBounds", "(JZ)Z", (void*)android_view_RenderNode_setClipToBounds},
770 {"nGetClipToBounds", "(J)Z", (void*)android_view_RenderNode_getClipToBounds},
771 {"nSetClipBounds", "(JIIII)Z", (void*)android_view_RenderNode_setClipBounds},
772 {"nSetClipBoundsEmpty", "(J)Z", (void*)android_view_RenderNode_setClipBoundsEmpty},
773 {"nSetProjectBackwards", "(JZ)Z", (void*)android_view_RenderNode_setProjectBackwards},
774 {"nSetProjectionReceiver", "(JZ)Z", (void*)android_view_RenderNode_setProjectionReceiver},
775
776 {"nSetOutlineRoundRect", "(JIIIIFF)Z", (void*)android_view_RenderNode_setOutlineRoundRect},
777 {"nSetOutlinePath", "(JJF)Z", (void*)android_view_RenderNode_setOutlinePath},
778 {"nSetOutlineEmpty", "(J)Z", (void*)android_view_RenderNode_setOutlineEmpty},
779 {"nSetOutlineNone", "(J)Z", (void*)android_view_RenderNode_setOutlineNone},
780 {"nClearStretch", "(J)Z", (void*)android_view_RenderNode_clearStretch},
781 {"nStretch", "(JFFFF)Z", (void*)android_view_RenderNode_stretch},
782 {"nHasShadow", "(J)Z", (void*)android_view_RenderNode_hasShadow},
783 {"nSetSpotShadowColor", "(JI)Z", (void*)android_view_RenderNode_setSpotShadowColor},
784 {"nGetSpotShadowColor", "(J)I", (void*)android_view_RenderNode_getSpotShadowColor},
785 {"nSetAmbientShadowColor", "(JI)Z", (void*)android_view_RenderNode_setAmbientShadowColor},
786 {"nGetAmbientShadowColor", "(J)I", (void*)android_view_RenderNode_getAmbientShadowColor},
787 {"nSetClipToOutline", "(JZ)Z", (void*)android_view_RenderNode_setClipToOutline},
788 {"nSetRevealClip", "(JZFFF)Z", (void*)android_view_RenderNode_setRevealClip},
789
790 {"nSetAlpha", "(JF)Z", (void*)android_view_RenderNode_setAlpha},
791 {"nSetRenderEffect", "(JJ)Z", (void*)android_view_RenderNode_setRenderEffect},
792 {"nSetHasOverlappingRendering", "(JZ)Z",
793 (void*)android_view_RenderNode_setHasOverlappingRendering},
794 {"nSetUsageHint", "(JI)V", (void*)android_view_RenderNode_setUsageHint},
795 {"nSetElevation", "(JF)Z", (void*)android_view_RenderNode_setElevation},
796 {"nSetTranslationX", "(JF)Z", (void*)android_view_RenderNode_setTranslationX},
797 {"nSetTranslationY", "(JF)Z", (void*)android_view_RenderNode_setTranslationY},
798 {"nSetTranslationZ", "(JF)Z", (void*)android_view_RenderNode_setTranslationZ},
799 {"nSetRotation", "(JF)Z", (void*)android_view_RenderNode_setRotation},
800 {"nSetRotationX", "(JF)Z", (void*)android_view_RenderNode_setRotationX},
801 {"nSetRotationY", "(JF)Z", (void*)android_view_RenderNode_setRotationY},
802 {"nSetScaleX", "(JF)Z", (void*)android_view_RenderNode_setScaleX},
803 {"nSetScaleY", "(JF)Z", (void*)android_view_RenderNode_setScaleY},
804 {"nSetPivotX", "(JF)Z", (void*)android_view_RenderNode_setPivotX},
805 {"nSetPivotY", "(JF)Z", (void*)android_view_RenderNode_setPivotY},
806 {"nResetPivot", "(J)Z", (void*)android_view_RenderNode_resetPivot},
807 {"nSetCameraDistance", "(JF)Z", (void*)android_view_RenderNode_setCameraDistance},
808 {"nSetLeft", "(JI)Z", (void*)android_view_RenderNode_setLeft},
809 {"nSetTop", "(JI)Z", (void*)android_view_RenderNode_setTop},
810 {"nSetRight", "(JI)Z", (void*)android_view_RenderNode_setRight},
811 {"nSetBottom", "(JI)Z", (void*)android_view_RenderNode_setBottom},
812 {"nGetLeft", "(J)I", (void*)android_view_RenderNode_getLeft},
813 {"nGetTop", "(J)I", (void*)android_view_RenderNode_getTop},
814 {"nGetRight", "(J)I", (void*)android_view_RenderNode_getRight},
815 {"nGetBottom", "(J)I", (void*)android_view_RenderNode_getBottom},
816 {"nSetLeftTopRightBottom", "(JIIII)Z",
817 (void*)android_view_RenderNode_setLeftTopRightBottom},
818 {"nOffsetLeftAndRight", "(JI)Z", (void*)android_view_RenderNode_offsetLeftAndRight},
819 {"nOffsetTopAndBottom", "(JI)Z", (void*)android_view_RenderNode_offsetTopAndBottom},
820
821 {"nHasOverlappingRendering", "(J)Z",
822 (void*)android_view_RenderNode_hasOverlappingRendering},
823 {"nGetClipToOutline", "(J)Z", (void*)android_view_RenderNode_getClipToOutline},
824 {"nGetAlpha", "(J)F", (void*)android_view_RenderNode_getAlpha},
825 {"nGetCameraDistance", "(J)F", (void*)android_view_RenderNode_getCameraDistance},
826 {"nGetScaleX", "(J)F", (void*)android_view_RenderNode_getScaleX},
827 {"nGetScaleY", "(J)F", (void*)android_view_RenderNode_getScaleY},
828 {"nGetElevation", "(J)F", (void*)android_view_RenderNode_getElevation},
829 {"nGetTranslationX", "(J)F", (void*)android_view_RenderNode_getTranslationX},
830 {"nGetTranslationY", "(J)F", (void*)android_view_RenderNode_getTranslationY},
831 {"nGetTranslationZ", "(J)F", (void*)android_view_RenderNode_getTranslationZ},
832 {"nGetRotation", "(J)F", (void*)android_view_RenderNode_getRotation},
833 {"nGetRotationX", "(J)F", (void*)android_view_RenderNode_getRotationX},
834 {"nGetRotationY", "(J)F", (void*)android_view_RenderNode_getRotationY},
835 {"nIsPivotExplicitlySet", "(J)Z", (void*)android_view_RenderNode_isPivotExplicitlySet},
836 {"nHasIdentityMatrix", "(J)Z", (void*)android_view_RenderNode_hasIdentityMatrix},
837
838 {"nGetTransformMatrix", "(JJ)V", (void*)android_view_RenderNode_getTransformMatrix},
839 {"nGetInverseTransformMatrix", "(JJ)V",
840 (void*)android_view_RenderNode_getInverseTransformMatrix},
841
842 {"nGetPivotX", "(J)F", (void*)android_view_RenderNode_getPivotX},
843 {"nGetPivotY", "(J)F", (void*)android_view_RenderNode_getPivotY},
844 {"nGetWidth", "(J)I", (void*)android_view_RenderNode_getWidth},
845 {"nGetHeight", "(J)I", (void*)android_view_RenderNode_getHeight},
846 {"nSetAllowForceDark", "(JZ)Z", (void*)android_view_RenderNode_setAllowForceDark},
847 {"nGetAllowForceDark", "(J)Z", (void*)android_view_RenderNode_getAllowForceDark},
848 {"nGetUniqueId", "(J)J", (void*)android_view_RenderNode_getUniqueId},
849 };
850
register_android_view_RenderNode(JNIEnv * env)851 int register_android_view_RenderNode(JNIEnv* env) {
852 jclass clazz = FindClassOrDie(env, "android/graphics/RenderNode$PositionUpdateListener");
853 gPositionListener.clazz = MakeGlobalRefOrDie(env, clazz);
854 gPositionListener.callPositionChanged = GetStaticMethodIDOrDie(
855 env, clazz, "callPositionChanged", "(Ljava/lang/ref/WeakReference;JIIII)Z");
856 gPositionListener.callApplyStretch = GetStaticMethodIDOrDie(
857 env, clazz, "callApplyStretch", "(Ljava/lang/ref/WeakReference;JFFFFFFFFFF)Z");
858 gPositionListener.callPositionLost = GetStaticMethodIDOrDie(
859 env, clazz, "callPositionLost", "(Ljava/lang/ref/WeakReference;J)Z");
860 return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
861 }
862
863 };
864
865