blob: a45c18d058cbe833328503159f7c9b1adcce8655 [file] [log] [blame]
John Reckf666ad72014-03-14 16:24:57 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view;
18
Chris Craik49e6c732014-03-31 12:34:11 -070019import android.annotation.NonNull;
Chris Craika753f4c2014-07-24 12:39:17 -070020import android.annotation.Nullable;
John Reckf666ad72014-03-14 16:24:57 -070021import android.graphics.Matrix;
Chris Craikb49f4462014-03-20 12:44:20 -070022import android.graphics.Outline;
John Reck25fbb3f2014-06-12 13:46:45 -070023import android.graphics.Paint;
Chris Craika753f4c2014-07-24 12:39:17 -070024import android.graphics.Rect;
Doris Liu766431a2016-02-04 22:17:11 +000025import android.graphics.drawable.AnimatedVectorDrawable;
John Reckf666ad72014-03-14 16:24:57 -070026
27/**
28 * <p>A display list records a series of graphics related operations and can replay
29 * them later. Display lists are usually built by recording operations on a
Chris Craikf6829a02015-03-10 10:28:59 -070030 * {@link DisplayListCanvas}. Replaying the operations from a display list avoids
John Reckf666ad72014-03-14 16:24:57 -070031 * executing application code on every frame, and is thus much more efficient.</p>
32 *
33 * <p>Display lists are used internally for all views by default, and are not
34 * typically used directly. One reason to consider using a display is a custom
35 * {@link View} implementation that needs to issue a large number of drawing commands.
36 * When the view invalidates, all the drawing commands must be reissued, even if
37 * large portions of the drawing command stream stay the same frame to frame, which
38 * can become a performance bottleneck. To solve this issue, a custom View might split
39 * its content into several display lists. A display list is updated only when its
40 * content, and only its content, needs to be updated.</p>
41 *
42 * <p>A text editor might for instance store each paragraph into its own display list.
43 * Thus when the user inserts or removes characters, only the display list of the
44 * affected paragraph needs to be recorded again.</p>
45 *
46 * <h3>Hardware acceleration</h3>
Chris Craikf6829a02015-03-10 10:28:59 -070047 * <p>Display lists can only be replayed using a {@link DisplayListCanvas}. They are not
John Reckf666ad72014-03-14 16:24:57 -070048 * supported in software. Always make sure that the {@link android.graphics.Canvas}
49 * you are using to render a display list is hardware accelerated using
50 * {@link android.graphics.Canvas#isHardwareAccelerated()}.</p>
51 *
52 * <h3>Creating a display list</h3>
53 * <pre class="prettyprint">
54 * HardwareRenderer renderer = myView.getHardwareRenderer();
55 * if (renderer != null) {
56 * DisplayList displayList = renderer.createDisplayList();
Chris Craikf6829a02015-03-10 10:28:59 -070057 * DisplayListCanvas canvas = displayList.start(width, height);
John Reckf666ad72014-03-14 16:24:57 -070058 * try {
59 * // Draw onto the canvas
60 * // For instance: canvas.drawBitmap(...);
61 * } finally {
62 * displayList.end();
63 * }
64 * }
65 * </pre>
66 *
67 * <h3>Rendering a display list on a View</h3>
68 * <pre class="prettyprint">
69 * protected void onDraw(Canvas canvas) {
70 * if (canvas.isHardwareAccelerated()) {
Chris Craikf6829a02015-03-10 10:28:59 -070071 * DisplayListCanvas displayListCanvas = (DisplayListCanvas) canvas;
72 * displayListCanvas.drawDisplayList(mDisplayList);
John Reckf666ad72014-03-14 16:24:57 -070073 * }
74 * }
75 * </pre>
76 *
77 * <h3>Releasing resources</h3>
78 * <p>This step is not mandatory but recommended if you want to release resources
79 * held by a display list as soon as possible.</p>
80 * <pre class="prettyprint">
81 * // Mark this display list invalid, it cannot be used for drawing anymore,
82 * // and release resources held by this display list
83 * displayList.clear();
84 * </pre>
85 *
86 * <h3>Properties</h3>
87 * <p>In addition, a display list offers several properties, such as
88 * {@link #setScaleX(float)} or {@link #setLeft(int)}, that can be used to affect all
89 * the drawing commands recorded within. For instance, these properties can be used
90 * to move around a large number of images without re-issuing all the individual
91 * <code>drawBitmap()</code> calls.</p>
92 *
93 * <pre class="prettyprint">
94 * private void createDisplayList() {
95 * mDisplayList = DisplayList.create("MyDisplayList");
Chris Craikf6829a02015-03-10 10:28:59 -070096 * DisplayListCanvas canvas = mDisplayList.start(width, height);
John Reckf666ad72014-03-14 16:24:57 -070097 * try {
98 * for (Bitmap b : mBitmaps) {
99 * canvas.drawBitmap(b, 0.0f, 0.0f, null);
100 * canvas.translate(0.0f, b.getHeight());
101 * }
102 * } finally {
103 * displayList.end();
104 * }
105 * }
106 *
107 * protected void onDraw(Canvas canvas) {
108 * if (canvas.isHardwareAccelerated()) {
Chris Craikf6829a02015-03-10 10:28:59 -0700109 * DisplayListCanvas displayListCanvas = (DisplayListCanvas) canvas;
110 * displayListCanvas.drawDisplayList(mDisplayList);
John Reckf666ad72014-03-14 16:24:57 -0700111 * }
112 * }
113 *
114 * private void moveContentBy(int x) {
115 * // This will move all the bitmaps recorded inside the display list
116 * // by x pixels to the right and redraw this view. All the commands
117 * // recorded in createDisplayList() won't be re-issued, only onDraw()
118 * // will be invoked and will execute very quickly
119 * mDisplayList.offsetLeftAndRight(x);
120 * invalidate();
121 * }
122 * </pre>
123 *
124 * <h3>Threading</h3>
125 * <p>Display lists must be created on and manipulated from the UI thread only.</p>
126 *
127 * @hide
128 */
129public class RenderNode {
John Reckf666ad72014-03-14 16:24:57 -0700130
131 private boolean mValid;
John Reck119907c2014-08-14 09:02:01 -0700132 // Do not access directly unless you are ThreadedRenderer
133 final long mNativeRenderNode;
134 private final View mOwningView;
John Reckf666ad72014-03-14 16:24:57 -0700135
John Reck119907c2014-08-14 09:02:01 -0700136 private RenderNode(String name, View owningView) {
John Reck8de65a82014-04-09 15:23:38 -0700137 mNativeRenderNode = nCreate(name);
John Reck119907c2014-08-14 09:02:01 -0700138 mOwningView = owningView;
John Reckf6481082016-02-02 15:18:23 -0800139 if (mOwningView instanceof SurfaceView) {
140 nRequestPositionUpdates(mNativeRenderNode, (SurfaceView) mOwningView);
141 }
John Reckf666ad72014-03-14 16:24:57 -0700142 }
143
144 /**
John Recke45b1fd2014-04-15 09:50:16 -0700145 * @see RenderNode#adopt(long)
146 */
147 private RenderNode(long nativePtr) {
148 mNativeRenderNode = nativePtr;
John Reck119907c2014-08-14 09:02:01 -0700149 mOwningView = null;
John Recke45b1fd2014-04-15 09:50:16 -0700150 }
151
152 /**
Chris Craik9a347f12014-06-27 17:23:47 -0700153 * Creates a new RenderNode that can be used to record batches of
154 * drawing operations, and store / apply render properties when drawn.
John Reckf666ad72014-03-14 16:24:57 -0700155 *
Chris Craik9a347f12014-06-27 17:23:47 -0700156 * @param name The name of the RenderNode, used for debugging purpose. May be null.
John Reckf666ad72014-03-14 16:24:57 -0700157 *
Chris Craik9a347f12014-06-27 17:23:47 -0700158 * @return A new RenderNode.
John Reckf666ad72014-03-14 16:24:57 -0700159 */
John Reck119907c2014-08-14 09:02:01 -0700160 public static RenderNode create(String name, @Nullable View owningView) {
161 return new RenderNode(name, owningView);
John Reckf666ad72014-03-14 16:24:57 -0700162 }
163
164 /**
John Recke45b1fd2014-04-15 09:50:16 -0700165 * Adopts an existing native render node.
166 *
167 * Note: This will *NOT* incRef() on the native object, however it will
168 * decRef() when it is destroyed. The caller should have already incRef'd it
169 */
170 public static RenderNode adopt(long nativePtr) {
171 return new RenderNode(nativePtr);
172 }
173
174
175 /**
Chris Craik49e6c732014-03-31 12:34:11 -0700176 * Starts recording a display list for the render node. All
177 * operations performed on the returned canvas are recorded and
178 * stored in this display list.
John Reckf666ad72014-03-14 16:24:57 -0700179 *
Chris Craik49e6c732014-03-31 12:34:11 -0700180 * Calling this method will mark the render node invalid until
Chris Craikf6829a02015-03-10 10:28:59 -0700181 * {@link #end(DisplayListCanvas)} is called.
Chris Craik49e6c732014-03-31 12:34:11 -0700182 * Only valid render nodes can be replayed.
John Reckf666ad72014-03-14 16:24:57 -0700183 *
Chris Craik49e6c732014-03-31 12:34:11 -0700184 * @param width The width of the recording viewport
185 * @param height The height of the recording viewport
John Reckf666ad72014-03-14 16:24:57 -0700186 *
187 * @return A canvas to record drawing operations.
188 *
Chris Craikf6829a02015-03-10 10:28:59 -0700189 * @see #end(DisplayListCanvas)
John Reckf666ad72014-03-14 16:24:57 -0700190 * @see #isValid()
191 */
Chris Craikf6829a02015-03-10 10:28:59 -0700192 public DisplayListCanvas start(int width, int height) {
Derek Sollenbergercc882b62015-07-09 15:51:20 -0400193 return DisplayListCanvas.obtain(this, width, height);
John Reckf666ad72014-03-14 16:24:57 -0700194 }
195
196 /**
197 * Ends the recording for this display list. A display list cannot be
198 * replayed if recording is not finished. Calling this method marks
199 * the display list valid and {@link #isValid()} will return true.
200 *
201 * @see #start(int, int)
202 * @see #isValid()
203 */
Chris Craik3891f3a2015-04-02 15:28:08 -0700204 public void end(DisplayListCanvas canvas) {
Chris Craik003cc3d2015-10-16 10:24:55 -0700205 long displayList = canvas.finishRecording();
206 nSetDisplayList(mNativeRenderNode, displayList);
John Reckf666ad72014-03-14 16:24:57 -0700207 canvas.recycle();
208 mValid = true;
209 }
210
211 /**
212 * Reset native resources. This is called when cleaning up the state of display lists
213 * during destruction of hardware resources, to ensure that we do not hold onto
214 * obsolete resources after related resources are gone.
John Reckf666ad72014-03-14 16:24:57 -0700215 */
Chris Craik003cc3d2015-10-16 10:24:55 -0700216 public void discardDisplayList() {
John Reckf666ad72014-03-14 16:24:57 -0700217 if (!mValid) return;
218
Chris Craik003cc3d2015-10-16 10:24:55 -0700219 nSetDisplayList(mNativeRenderNode, 0);
John Reckf666ad72014-03-14 16:24:57 -0700220 mValid = false;
221 }
222
John Reckf666ad72014-03-14 16:24:57 -0700223 /**
Chris Craikdf0c4312014-03-28 16:55:08 -0700224 * Returns whether the RenderNode's display list content is currently usable.
225 * If this returns false, the display list should be re-recorded prior to replaying it.
John Reckf666ad72014-03-14 16:24:57 -0700226 *
227 * @return boolean true if the display list is able to be replayed, false otherwise.
228 */
229 public boolean isValid() { return mValid; }
230
231 long getNativeDisplayList() {
232 if (!mValid) {
233 throw new IllegalStateException("The display list is not valid.");
234 }
John Reck8de65a82014-04-09 15:23:38 -0700235 return mNativeRenderNode;
John Reckf666ad72014-03-14 16:24:57 -0700236 }
237
238 ///////////////////////////////////////////////////////////////////////////
Chris Craik49e6c732014-03-31 12:34:11 -0700239 // Matrix manipulation
240 ///////////////////////////////////////////////////////////////////////////
241
242 public boolean hasIdentityMatrix() {
John Reck8de65a82014-04-09 15:23:38 -0700243 return nHasIdentityMatrix(mNativeRenderNode);
Chris Craik49e6c732014-03-31 12:34:11 -0700244 }
245
246 public void getMatrix(@NonNull Matrix outMatrix) {
John Reck8de65a82014-04-09 15:23:38 -0700247 nGetTransformMatrix(mNativeRenderNode, outMatrix.native_instance);
Chris Craik49e6c732014-03-31 12:34:11 -0700248 }
249
250 public void getInverseMatrix(@NonNull Matrix outMatrix) {
John Reck8de65a82014-04-09 15:23:38 -0700251 nGetInverseTransformMatrix(mNativeRenderNode, outMatrix.native_instance);
Chris Craik49e6c732014-03-31 12:34:11 -0700252 }
253
254 ///////////////////////////////////////////////////////////////////////////
255 // RenderProperty Setters
John Reckf666ad72014-03-14 16:24:57 -0700256 ///////////////////////////////////////////////////////////////////////////
257
John Reck25fbb3f2014-06-12 13:46:45 -0700258 public boolean setLayerType(int layerType) {
259 return nSetLayerType(mNativeRenderNode, layerType);
260 }
261
262 public boolean setLayerPaint(Paint paint) {
Derek Sollenbergerdfba4d32014-09-02 15:42:54 -0400263 return nSetLayerPaint(mNativeRenderNode, paint != null ? paint.getNativeInstance() : 0);
John Reckf666ad72014-03-14 16:24:57 -0700264 }
265
Chris Craika753f4c2014-07-24 12:39:17 -0700266 public boolean setClipBounds(@Nullable Rect rect) {
267 if (rect == null) {
268 return nSetClipBoundsEmpty(mNativeRenderNode);
269 } else {
270 return nSetClipBounds(mNativeRenderNode, rect.left, rect.top, rect.right, rect.bottom);
271 }
272 }
273
John Reckf666ad72014-03-14 16:24:57 -0700274 /**
Chris Craik49e6c732014-03-31 12:34:11 -0700275 * Set whether the Render node should clip itself to its bounds. This property is controlled by
John Reckf666ad72014-03-14 16:24:57 -0700276 * the view's parent.
277 *
278 * @param clipToBounds true if the display list should clip to its bounds
279 */
John Reck79c7de72014-05-23 10:33:31 -0700280 public boolean setClipToBounds(boolean clipToBounds) {
281 return nSetClipToBounds(mNativeRenderNode, clipToBounds);
John Reckf666ad72014-03-14 16:24:57 -0700282 }
283
284 /**
John Reckf666ad72014-03-14 16:24:57 -0700285 * Sets whether the display list should be drawn immediately after the
Chris Craik49e6c732014-03-31 12:34:11 -0700286 * closest ancestor display list containing a projection receiver.
John Reckf666ad72014-03-14 16:24:57 -0700287 *
288 * @param shouldProject true if the display list should be projected onto a
289 * containing volume.
290 */
John Reck79c7de72014-05-23 10:33:31 -0700291 public boolean setProjectBackwards(boolean shouldProject) {
292 return nSetProjectBackwards(mNativeRenderNode, shouldProject);
John Reckf666ad72014-03-14 16:24:57 -0700293 }
294
295 /**
296 * Sets whether the display list is a projection receiver - that its parent
297 * DisplayList should draw any descendent DisplayLists with
298 * ProjectBackwards=true directly on top of it. Default value is false.
299 */
John Reck79c7de72014-05-23 10:33:31 -0700300 public boolean setProjectionReceiver(boolean shouldRecieve) {
301 return nSetProjectionReceiver(mNativeRenderNode, shouldRecieve);
John Reckf666ad72014-03-14 16:24:57 -0700302 }
303
304 /**
305 * Sets the outline, defining the shape that casts a shadow, and the path to
306 * be clipped if setClipToOutline is set.
307 *
Chris Craikb49f4462014-03-20 12:44:20 -0700308 * Deep copies the data into native to simplify reference ownership.
John Reckf666ad72014-03-14 16:24:57 -0700309 */
John Reck79c7de72014-05-23 10:33:31 -0700310 public boolean setOutline(Outline outline) {
Chris Craik06451282014-07-21 10:25:54 -0700311 if (outline == null) {
312 return nSetOutlineNone(mNativeRenderNode);
313 } else if (outline.isEmpty()) {
John Reck79c7de72014-05-23 10:33:31 -0700314 return nSetOutlineEmpty(mNativeRenderNode);
Chris Craikb49f4462014-03-20 12:44:20 -0700315 } else if (outline.mRect != null) {
John Reck79c7de72014-05-23 10:33:31 -0700316 return nSetOutlineRoundRect(mNativeRenderNode, outline.mRect.left, outline.mRect.top,
Chris Craik77b5cad2014-07-30 18:23:07 -0700317 outline.mRect.right, outline.mRect.bottom, outline.mRadius, outline.mAlpha);
Chris Craikb49f4462014-03-20 12:44:20 -0700318 } else if (outline.mPath != null) {
Chris Craik77b5cad2014-07-30 18:23:07 -0700319 return nSetOutlineConvexPath(mNativeRenderNode, outline.mPath.mNativePath,
320 outline.mAlpha);
Chris Craikb49f4462014-03-20 12:44:20 -0700321 }
John Reck79c7de72014-05-23 10:33:31 -0700322 throw new IllegalArgumentException("Unrecognized outline?");
John Reckf666ad72014-03-14 16:24:57 -0700323 }
324
Chris Craik5c75c522014-09-05 14:08:08 -0700325 public boolean hasShadow() {
326 return nHasShadow(mNativeRenderNode);
327 }
328
John Reckf666ad72014-03-14 16:24:57 -0700329 /**
330 * Enables or disables clipping to the outline.
331 *
332 * @param clipToOutline true if clipping to the outline.
333 */
John Reck79c7de72014-05-23 10:33:31 -0700334 public boolean setClipToOutline(boolean clipToOutline) {
335 return nSetClipToOutline(mNativeRenderNode, clipToOutline);
John Reckf666ad72014-03-14 16:24:57 -0700336 }
337
Chris Craikdeeda3d2014-05-05 19:09:33 -0700338 public boolean getClipToOutline() {
339 return nGetClipToOutline(mNativeRenderNode);
340 }
341
John Reckf666ad72014-03-14 16:24:57 -0700342 /**
Chris Craik8c271ca2014-03-25 10:33:01 -0700343 * Controls the RenderNode's circular reveal clip.
344 */
Chris Craikaf4d04c2014-07-29 12:50:14 -0700345 public boolean setRevealClip(boolean shouldClip,
Chris Craik8c271ca2014-03-25 10:33:01 -0700346 float x, float y, float radius) {
Chris Craikaf4d04c2014-07-29 12:50:14 -0700347 return nSetRevealClip(mNativeRenderNode, shouldClip, x, y, radius);
Chris Craik8c271ca2014-03-25 10:33:01 -0700348 }
349
350 /**
John Reckf666ad72014-03-14 16:24:57 -0700351 * Set the static matrix on the display list. The specified matrix is combined with other
352 * transforms (such as {@link #setScaleX(float)}, {@link #setRotation(float)}, etc.)
353 *
354 * @param matrix A transform matrix to apply to this display list
John Reckf666ad72014-03-14 16:24:57 -0700355 */
John Reck79c7de72014-05-23 10:33:31 -0700356 public boolean setStaticMatrix(Matrix matrix) {
357 return nSetStaticMatrix(mNativeRenderNode, matrix.native_instance);
John Reckf666ad72014-03-14 16:24:57 -0700358 }
359
360 /**
361 * Set the Animation matrix on the display list. This matrix exists if an Animation is
362 * currently playing on a View, and is set on the display list during at draw() time. When
363 * the Animation finishes, the matrix should be cleared by sending <code>null</code>
364 * for the matrix parameter.
365 *
366 * @param matrix The matrix, null indicates that the matrix should be cleared.
John Reckf666ad72014-03-14 16:24:57 -0700367 */
John Reck79c7de72014-05-23 10:33:31 -0700368 public boolean setAnimationMatrix(Matrix matrix) {
369 return nSetAnimationMatrix(mNativeRenderNode,
John Reckf666ad72014-03-14 16:24:57 -0700370 (matrix != null) ? matrix.native_instance : 0);
371 }
372
373 /**
374 * Sets the translucency level for the display list.
375 *
376 * @param alpha The translucency of the display list, must be a value between 0.0f and 1.0f
377 *
378 * @see View#setAlpha(float)
379 * @see #getAlpha()
380 */
John Reck79c7de72014-05-23 10:33:31 -0700381 public boolean setAlpha(float alpha) {
382 return nSetAlpha(mNativeRenderNode, alpha);
John Reckf666ad72014-03-14 16:24:57 -0700383 }
384
385 /**
386 * Returns the translucency level of this display list.
387 *
388 * @return A value between 0.0f and 1.0f
389 *
390 * @see #setAlpha(float)
391 */
392 public float getAlpha() {
John Reck8de65a82014-04-09 15:23:38 -0700393 return nGetAlpha(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700394 }
395
396 /**
397 * Sets whether the display list renders content which overlaps. Non-overlapping rendering
398 * can use a fast path for alpha that avoids rendering to an offscreen buffer. By default
399 * display lists consider they do not have overlapping content.
400 *
401 * @param hasOverlappingRendering False if the content is guaranteed to be non-overlapping,
402 * true otherwise.
403 *
404 * @see android.view.View#hasOverlappingRendering()
405 * @see #hasOverlappingRendering()
406 */
John Reck79c7de72014-05-23 10:33:31 -0700407 public boolean setHasOverlappingRendering(boolean hasOverlappingRendering) {
408 return nSetHasOverlappingRendering(mNativeRenderNode, hasOverlappingRendering);
John Reckf666ad72014-03-14 16:24:57 -0700409 }
410
411 /**
412 * Indicates whether the content of this display list overlaps.
413 *
414 * @return True if this display list renders content which overlaps, false otherwise.
415 *
416 * @see #setHasOverlappingRendering(boolean)
417 */
418 public boolean hasOverlappingRendering() {
419 //noinspection SimplifiableIfStatement
John Reck8de65a82014-04-09 15:23:38 -0700420 return nHasOverlappingRendering(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700421 }
422
John Reck79c7de72014-05-23 10:33:31 -0700423 public boolean setElevation(float lift) {
424 return nSetElevation(mNativeRenderNode, lift);
Chris Craikcc39e162014-04-25 18:34:11 -0700425 }
426
427 public float getElevation() {
428 return nGetElevation(mNativeRenderNode);
429 }
430
John Reckf666ad72014-03-14 16:24:57 -0700431 /**
432 * Sets the translation value for the display list on the X axis.
433 *
434 * @param translationX The X axis translation value of the display list, in pixels
435 *
436 * @see View#setTranslationX(float)
437 * @see #getTranslationX()
438 */
John Reck79c7de72014-05-23 10:33:31 -0700439 public boolean setTranslationX(float translationX) {
440 return nSetTranslationX(mNativeRenderNode, translationX);
John Reckf666ad72014-03-14 16:24:57 -0700441 }
442
443 /**
444 * Returns the translation value for this display list on the X axis, in pixels.
445 *
446 * @see #setTranslationX(float)
447 */
448 public float getTranslationX() {
John Reck8de65a82014-04-09 15:23:38 -0700449 return nGetTranslationX(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700450 }
451
452 /**
453 * Sets the translation value for the display list on the Y axis.
454 *
455 * @param translationY The Y axis translation value of the display list, in pixels
456 *
457 * @see View#setTranslationY(float)
458 * @see #getTranslationY()
459 */
John Reck79c7de72014-05-23 10:33:31 -0700460 public boolean setTranslationY(float translationY) {
461 return nSetTranslationY(mNativeRenderNode, translationY);
John Reckf666ad72014-03-14 16:24:57 -0700462 }
463
464 /**
465 * Returns the translation value for this display list on the Y axis, in pixels.
466 *
467 * @see #setTranslationY(float)
468 */
469 public float getTranslationY() {
John Reck8de65a82014-04-09 15:23:38 -0700470 return nGetTranslationY(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700471 }
472
473 /**
474 * Sets the translation value for the display list on the Z axis.
475 *
476 * @see View#setTranslationZ(float)
477 * @see #getTranslationZ()
478 */
John Reck79c7de72014-05-23 10:33:31 -0700479 public boolean setTranslationZ(float translationZ) {
480 return nSetTranslationZ(mNativeRenderNode, translationZ);
John Reckf666ad72014-03-14 16:24:57 -0700481 }
482
483 /**
484 * Returns the translation value for this display list on the Z axis.
485 *
486 * @see #setTranslationZ(float)
487 */
488 public float getTranslationZ() {
John Reck8de65a82014-04-09 15:23:38 -0700489 return nGetTranslationZ(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700490 }
491
492 /**
493 * Sets the rotation value for the display list around the Z axis.
494 *
495 * @param rotation The rotation value of the display list, in degrees
496 *
497 * @see View#setRotation(float)
498 * @see #getRotation()
499 */
John Reck79c7de72014-05-23 10:33:31 -0700500 public boolean setRotation(float rotation) {
501 return nSetRotation(mNativeRenderNode, rotation);
John Reckf666ad72014-03-14 16:24:57 -0700502 }
503
504 /**
505 * Returns the rotation value for this display list around the Z axis, in degrees.
506 *
507 * @see #setRotation(float)
508 */
509 public float getRotation() {
John Reck8de65a82014-04-09 15:23:38 -0700510 return nGetRotation(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700511 }
512
513 /**
514 * Sets the rotation value for the display list around the X axis.
515 *
516 * @param rotationX The rotation value of the display list, in degrees
517 *
518 * @see View#setRotationX(float)
519 * @see #getRotationX()
520 */
John Reck79c7de72014-05-23 10:33:31 -0700521 public boolean setRotationX(float rotationX) {
522 return nSetRotationX(mNativeRenderNode, rotationX);
John Reckf666ad72014-03-14 16:24:57 -0700523 }
524
525 /**
526 * Returns the rotation value for this display list around the X axis, in degrees.
527 *
528 * @see #setRotationX(float)
529 */
530 public float getRotationX() {
John Reck8de65a82014-04-09 15:23:38 -0700531 return nGetRotationX(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700532 }
533
534 /**
535 * Sets the rotation value for the display list around the Y axis.
536 *
537 * @param rotationY The rotation value of the display list, in degrees
538 *
539 * @see View#setRotationY(float)
540 * @see #getRotationY()
541 */
John Reck79c7de72014-05-23 10:33:31 -0700542 public boolean setRotationY(float rotationY) {
543 return nSetRotationY(mNativeRenderNode, rotationY);
John Reckf666ad72014-03-14 16:24:57 -0700544 }
545
546 /**
547 * Returns the rotation value for this display list around the Y axis, in degrees.
548 *
549 * @see #setRotationY(float)
550 */
551 public float getRotationY() {
John Reck8de65a82014-04-09 15:23:38 -0700552 return nGetRotationY(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700553 }
554
555 /**
556 * Sets the scale value for the display list on the X axis.
557 *
558 * @param scaleX The scale value of the display list
559 *
560 * @see View#setScaleX(float)
561 * @see #getScaleX()
562 */
John Reck79c7de72014-05-23 10:33:31 -0700563 public boolean setScaleX(float scaleX) {
564 return nSetScaleX(mNativeRenderNode, scaleX);
John Reckf666ad72014-03-14 16:24:57 -0700565 }
566
567 /**
568 * Returns the scale value for this display list on the X axis.
569 *
570 * @see #setScaleX(float)
571 */
572 public float getScaleX() {
John Reck8de65a82014-04-09 15:23:38 -0700573 return nGetScaleX(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700574 }
575
576 /**
577 * Sets the scale value for the display list on the Y axis.
578 *
579 * @param scaleY The scale value of the display list
580 *
581 * @see View#setScaleY(float)
582 * @see #getScaleY()
583 */
John Reck79c7de72014-05-23 10:33:31 -0700584 public boolean setScaleY(float scaleY) {
585 return nSetScaleY(mNativeRenderNode, scaleY);
John Reckf666ad72014-03-14 16:24:57 -0700586 }
587
588 /**
589 * Returns the scale value for this display list on the Y axis.
590 *
591 * @see #setScaleY(float)
592 */
593 public float getScaleY() {
John Reck8de65a82014-04-09 15:23:38 -0700594 return nGetScaleY(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700595 }
596
597 /**
John Reckf666ad72014-03-14 16:24:57 -0700598 * Sets the pivot value for the display list on the X axis
599 *
600 * @param pivotX The pivot value of the display list on the X axis, in pixels
601 *
602 * @see View#setPivotX(float)
603 * @see #getPivotX()
604 */
John Reck79c7de72014-05-23 10:33:31 -0700605 public boolean setPivotX(float pivotX) {
606 return nSetPivotX(mNativeRenderNode, pivotX);
John Reckf666ad72014-03-14 16:24:57 -0700607 }
608
609 /**
610 * Returns the pivot value for this display list on the X axis, in pixels.
611 *
612 * @see #setPivotX(float)
613 */
614 public float getPivotX() {
John Reck8de65a82014-04-09 15:23:38 -0700615 return nGetPivotX(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700616 }
617
618 /**
619 * Sets the pivot value for the display list on the Y axis
620 *
621 * @param pivotY The pivot value of the display list on the Y axis, in pixels
622 *
623 * @see View#setPivotY(float)
624 * @see #getPivotY()
625 */
John Reck79c7de72014-05-23 10:33:31 -0700626 public boolean setPivotY(float pivotY) {
627 return nSetPivotY(mNativeRenderNode, pivotY);
John Reckf666ad72014-03-14 16:24:57 -0700628 }
629
630 /**
631 * Returns the pivot value for this display list on the Y axis, in pixels.
632 *
633 * @see #setPivotY(float)
634 */
635 public float getPivotY() {
John Reck8de65a82014-04-09 15:23:38 -0700636 return nGetPivotY(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700637 }
638
Chris Craik49e6c732014-03-31 12:34:11 -0700639 public boolean isPivotExplicitlySet() {
John Reck8de65a82014-04-09 15:23:38 -0700640 return nIsPivotExplicitlySet(mNativeRenderNode);
Chris Craik49e6c732014-03-31 12:34:11 -0700641 }
642
John Reckf666ad72014-03-14 16:24:57 -0700643 /**
644 * Sets the camera distance for the display list. Refer to
645 * {@link View#setCameraDistance(float)} for more information on how to
646 * use this property.
647 *
648 * @param distance The distance in Z of the camera of the display list
649 *
650 * @see View#setCameraDistance(float)
651 * @see #getCameraDistance()
652 */
John Reck79c7de72014-05-23 10:33:31 -0700653 public boolean setCameraDistance(float distance) {
654 return nSetCameraDistance(mNativeRenderNode, distance);
John Reckf666ad72014-03-14 16:24:57 -0700655 }
656
657 /**
658 * Returns the distance in Z of the camera of the display list.
659 *
660 * @see #setCameraDistance(float)
661 */
662 public float getCameraDistance() {
John Reck8de65a82014-04-09 15:23:38 -0700663 return nGetCameraDistance(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700664 }
665
666 /**
667 * Sets the left position for the display list.
668 *
669 * @param left The left position, in pixels, of the display list
670 *
671 * @see View#setLeft(int)
John Reckf666ad72014-03-14 16:24:57 -0700672 */
John Reck79c7de72014-05-23 10:33:31 -0700673 public boolean setLeft(int left) {
674 return nSetLeft(mNativeRenderNode, left);
John Reckf666ad72014-03-14 16:24:57 -0700675 }
676
677 /**
John Reckf666ad72014-03-14 16:24:57 -0700678 * Sets the top position for the display list.
679 *
680 * @param top The top position, in pixels, of the display list
681 *
682 * @see View#setTop(int)
John Reckf666ad72014-03-14 16:24:57 -0700683 */
John Reck79c7de72014-05-23 10:33:31 -0700684 public boolean setTop(int top) {
685 return nSetTop(mNativeRenderNode, top);
John Reckf666ad72014-03-14 16:24:57 -0700686 }
687
688 /**
John Reckf666ad72014-03-14 16:24:57 -0700689 * Sets the right position for the display list.
690 *
691 * @param right The right position, in pixels, of the display list
692 *
693 * @see View#setRight(int)
John Reckf666ad72014-03-14 16:24:57 -0700694 */
John Reck79c7de72014-05-23 10:33:31 -0700695 public boolean setRight(int right) {
696 return nSetRight(mNativeRenderNode, right);
John Reckf666ad72014-03-14 16:24:57 -0700697 }
698
699 /**
John Reckf666ad72014-03-14 16:24:57 -0700700 * Sets the bottom position for the display list.
701 *
702 * @param bottom The bottom position, in pixels, of the display list
703 *
704 * @see View#setBottom(int)
John Reckf666ad72014-03-14 16:24:57 -0700705 */
John Reck79c7de72014-05-23 10:33:31 -0700706 public boolean setBottom(int bottom) {
707 return nSetBottom(mNativeRenderNode, bottom);
John Reckf666ad72014-03-14 16:24:57 -0700708 }
709
710 /**
John Reckf666ad72014-03-14 16:24:57 -0700711 * Sets the left and top positions for the display list
712 *
713 * @param left The left position of the display list, in pixels
714 * @param top The top position of the display list, in pixels
715 * @param right The right position of the display list, in pixels
716 * @param bottom The bottom position of the display list, in pixels
717 *
718 * @see View#setLeft(int)
719 * @see View#setTop(int)
720 * @see View#setRight(int)
721 * @see View#setBottom(int)
722 */
John Reck79c7de72014-05-23 10:33:31 -0700723 public boolean setLeftTopRightBottom(int left, int top, int right, int bottom) {
724 return nSetLeftTopRightBottom(mNativeRenderNode, left, top, right, bottom);
John Reckf666ad72014-03-14 16:24:57 -0700725 }
726
727 /**
728 * Offsets the left and right positions for the display list
729 *
730 * @param offset The amount that the left and right positions of the display
731 * list are offset, in pixels
732 *
733 * @see View#offsetLeftAndRight(int)
734 */
Chris Craika753f4c2014-07-24 12:39:17 -0700735 public boolean offsetLeftAndRight(int offset) {
John Reck79c7de72014-05-23 10:33:31 -0700736 return nOffsetLeftAndRight(mNativeRenderNode, offset);
John Reckf666ad72014-03-14 16:24:57 -0700737 }
738
739 /**
740 * Offsets the top and bottom values for the display list
741 *
742 * @param offset The amount that the top and bottom positions of the display
743 * list are offset, in pixels
744 *
745 * @see View#offsetTopAndBottom(int)
746 */
Chris Craika753f4c2014-07-24 12:39:17 -0700747 public boolean offsetTopAndBottom(int offset) {
John Reck79c7de72014-05-23 10:33:31 -0700748 return nOffsetTopAndBottom(mNativeRenderNode, offset);
John Reckf666ad72014-03-14 16:24:57 -0700749 }
750
751 /**
752 * Outputs the display list to the log. This method exists for use by
753 * tools to output display lists for selected nodes to the log.
John Reckf666ad72014-03-14 16:24:57 -0700754 */
755 public void output() {
John Reck8de65a82014-04-09 15:23:38 -0700756 nOutput(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700757 }
758
John Reckfe5e7b72014-05-23 17:42:28 -0700759 /**
760 * Gets the size of the DisplayList for debug purposes.
761 */
762 public int getDebugSize() {
763 return nGetDebugSize(mNativeRenderNode);
764 }
765
John Reckf666ad72014-03-14 16:24:57 -0700766 ///////////////////////////////////////////////////////////////////////////
John Recke45b1fd2014-04-15 09:50:16 -0700767 // Animations
768 ///////////////////////////////////////////////////////////////////////////
769
770 public void addAnimator(RenderNodeAnimator animator) {
John Reck119907c2014-08-14 09:02:01 -0700771 if (mOwningView == null || mOwningView.mAttachInfo == null) {
772 throw new IllegalStateException("Cannot start this animator on a detached view!");
773 }
John Recke45b1fd2014-04-15 09:50:16 -0700774 nAddAnimator(mNativeRenderNode, animator.getNativeAnimator());
John Reck119907c2014-08-14 09:02:01 -0700775 mOwningView.mAttachInfo.mViewRootImpl.registerAnimatingRenderNode(this);
776 }
777
Doris Liu8b083202016-02-19 21:46:06 +0000778 public boolean isAttached() {
779 return mOwningView != null && mOwningView.mAttachInfo != null;
780 }
781
Doris Liu28cfd202016-02-22 16:51:40 -0800782 public void addAnimator(AnimatedVectorDrawable.VectorDrawableAnimatorRT animatorSet) {
Doris Liu766431a2016-02-04 22:17:11 +0000783 if (mOwningView == null || mOwningView.mAttachInfo == null) {
784 throw new IllegalStateException("Cannot start this animator on a detached view!");
785 }
786 nAddAnimator(mNativeRenderNode, animatorSet.getAnimatorNativePtr());
787 mOwningView.mAttachInfo.mViewRootImpl.registerAnimatingRenderNode(this);
788 }
789
John Reck119907c2014-08-14 09:02:01 -0700790 public void endAllAnimators() {
791 nEndAllAnimators(mNativeRenderNode);
John Recke45b1fd2014-04-15 09:50:16 -0700792 }
793
John Recke45b1fd2014-04-15 09:50:16 -0700794 ///////////////////////////////////////////////////////////////////////////
John Reckf666ad72014-03-14 16:24:57 -0700795 // Native methods
796 ///////////////////////////////////////////////////////////////////////////
797
John Reck8de65a82014-04-09 15:23:38 -0700798 private static native long nCreate(String name);
799 private static native void nDestroyRenderNode(long renderNode);
Chris Craik003cc3d2015-10-16 10:24:55 -0700800 private static native void nSetDisplayList(long renderNode, long newData);
John Reckf666ad72014-03-14 16:24:57 -0700801
Chris Craik49e6c732014-03-31 12:34:11 -0700802 // Matrix
803
John Reck8de65a82014-04-09 15:23:38 -0700804 private static native void nGetTransformMatrix(long renderNode, long nativeMatrix);
805 private static native void nGetInverseTransformMatrix(long renderNode, long nativeMatrix);
806 private static native boolean nHasIdentityMatrix(long renderNode);
Chris Craik49e6c732014-03-31 12:34:11 -0700807
John Reckf666ad72014-03-14 16:24:57 -0700808 // Properties
809
Chris Craika753f4c2014-07-24 12:39:17 -0700810 private static native boolean nOffsetTopAndBottom(long renderNode, int offset);
811 private static native boolean nOffsetLeftAndRight(long renderNode, int offset);
John Reck79c7de72014-05-23 10:33:31 -0700812 private static native boolean nSetLeftTopRightBottom(long renderNode, int left, int top,
John Reckf666ad72014-03-14 16:24:57 -0700813 int right, int bottom);
John Reck79c7de72014-05-23 10:33:31 -0700814 private static native boolean nSetBottom(long renderNode, int bottom);
815 private static native boolean nSetRight(long renderNode, int right);
816 private static native boolean nSetTop(long renderNode, int top);
817 private static native boolean nSetLeft(long renderNode, int left);
818 private static native boolean nSetCameraDistance(long renderNode, float distance);
819 private static native boolean nSetPivotY(long renderNode, float pivotY);
820 private static native boolean nSetPivotX(long renderNode, float pivotX);
John Reck25fbb3f2014-06-12 13:46:45 -0700821 private static native boolean nSetLayerType(long renderNode, int layerType);
822 private static native boolean nSetLayerPaint(long renderNode, long paint);
John Reck79c7de72014-05-23 10:33:31 -0700823 private static native boolean nSetClipToBounds(long renderNode, boolean clipToBounds);
Chris Craika753f4c2014-07-24 12:39:17 -0700824 private static native boolean nSetClipBounds(long renderNode, int left, int top,
825 int right, int bottom);
826 private static native boolean nSetClipBoundsEmpty(long renderNode);
John Reck79c7de72014-05-23 10:33:31 -0700827 private static native boolean nSetProjectBackwards(long renderNode, boolean shouldProject);
828 private static native boolean nSetProjectionReceiver(long renderNode, boolean shouldRecieve);
829 private static native boolean nSetOutlineRoundRect(long renderNode, int left, int top,
Chris Craik77b5cad2014-07-30 18:23:07 -0700830 int right, int bottom, float radius, float alpha);
831 private static native boolean nSetOutlineConvexPath(long renderNode, long nativePath,
832 float alpha);
John Reck79c7de72014-05-23 10:33:31 -0700833 private static native boolean nSetOutlineEmpty(long renderNode);
Chris Craik06451282014-07-21 10:25:54 -0700834 private static native boolean nSetOutlineNone(long renderNode);
Chris Craik5c75c522014-09-05 14:08:08 -0700835 private static native boolean nHasShadow(long renderNode);
John Reck79c7de72014-05-23 10:33:31 -0700836 private static native boolean nSetClipToOutline(long renderNode, boolean clipToOutline);
837 private static native boolean nSetRevealClip(long renderNode,
Chris Craikaf4d04c2014-07-29 12:50:14 -0700838 boolean shouldClip, float x, float y, float radius);
John Reck79c7de72014-05-23 10:33:31 -0700839 private static native boolean nSetAlpha(long renderNode, float alpha);
840 private static native boolean nSetHasOverlappingRendering(long renderNode,
John Reckf666ad72014-03-14 16:24:57 -0700841 boolean hasOverlappingRendering);
John Reck79c7de72014-05-23 10:33:31 -0700842 private static native boolean nSetElevation(long renderNode, float lift);
843 private static native boolean nSetTranslationX(long renderNode, float translationX);
844 private static native boolean nSetTranslationY(long renderNode, float translationY);
845 private static native boolean nSetTranslationZ(long renderNode, float translationZ);
846 private static native boolean nSetRotation(long renderNode, float rotation);
847 private static native boolean nSetRotationX(long renderNode, float rotationX);
848 private static native boolean nSetRotationY(long renderNode, float rotationY);
849 private static native boolean nSetScaleX(long renderNode, float scaleX);
850 private static native boolean nSetScaleY(long renderNode, float scaleY);
851 private static native boolean nSetStaticMatrix(long renderNode, long nativeMatrix);
852 private static native boolean nSetAnimationMatrix(long renderNode, long animationMatrix);
John Reckf666ad72014-03-14 16:24:57 -0700853
John Reck8de65a82014-04-09 15:23:38 -0700854 private static native boolean nHasOverlappingRendering(long renderNode);
Chris Craikdeeda3d2014-05-05 19:09:33 -0700855 private static native boolean nGetClipToOutline(long renderNode);
John Reck8de65a82014-04-09 15:23:38 -0700856 private static native float nGetAlpha(long renderNode);
John Reck8de65a82014-04-09 15:23:38 -0700857 private static native float nGetCameraDistance(long renderNode);
858 private static native float nGetScaleX(long renderNode);
859 private static native float nGetScaleY(long renderNode);
Chris Craikcc39e162014-04-25 18:34:11 -0700860 private static native float nGetElevation(long renderNode);
John Reck8de65a82014-04-09 15:23:38 -0700861 private static native float nGetTranslationX(long renderNode);
862 private static native float nGetTranslationY(long renderNode);
863 private static native float nGetTranslationZ(long renderNode);
864 private static native float nGetRotation(long renderNode);
865 private static native float nGetRotationX(long renderNode);
866 private static native float nGetRotationY(long renderNode);
867 private static native boolean nIsPivotExplicitlySet(long renderNode);
868 private static native float nGetPivotX(long renderNode);
869 private static native float nGetPivotY(long renderNode);
870 private static native void nOutput(long renderNode);
John Reckfe5e7b72014-05-23 17:42:28 -0700871 private static native int nGetDebugSize(long renderNode);
John Reckf666ad72014-03-14 16:24:57 -0700872
John Reckf6481082016-02-02 15:18:23 -0800873 private static native void nRequestPositionUpdates(long renderNode, SurfaceView callback);
874
John Reckf666ad72014-03-14 16:24:57 -0700875 ///////////////////////////////////////////////////////////////////////////
John Recke45b1fd2014-04-15 09:50:16 -0700876 // Animations
877 ///////////////////////////////////////////////////////////////////////////
878
879 private static native void nAddAnimator(long renderNode, long animatorPtr);
John Reck119907c2014-08-14 09:02:01 -0700880 private static native void nEndAllAnimators(long renderNode);
John Recke45b1fd2014-04-15 09:50:16 -0700881
882 ///////////////////////////////////////////////////////////////////////////
John Reckf666ad72014-03-14 16:24:57 -0700883 // Finalization
884 ///////////////////////////////////////////////////////////////////////////
885
886 @Override
887 protected void finalize() throws Throwable {
888 try {
John Reck8de65a82014-04-09 15:23:38 -0700889 nDestroyRenderNode(mNativeRenderNode);
John Reckf666ad72014-03-14 16:24:57 -0700890 } finally {
891 super.finalize();
892 }
893 }
894}