From 08a68d59487c2922ae5954d40c41605816189d60 Mon Sep 17 00:00:00 2001 From: John Reck Date: Wed, 13 Mar 2019 10:16:10 -0700 Subject: Tweak RenderNode's docs Bug: 125026642 Test: looked at offline-sdk-docs Change-Id: I1e03ac2291c31e79489b9cf545d2b7760fb4252d --- graphics/java/android/graphics/RenderNode.java | 39 ++++++++++++-------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'graphics/java/android') diff --git a/graphics/java/android/graphics/RenderNode.java b/graphics/java/android/graphics/RenderNode.java index 5e48ea1c98d8..f2c6aefa101d 100644 --- a/graphics/java/android/graphics/RenderNode.java +++ b/graphics/java/android/graphics/RenderNode.java @@ -70,8 +70,7 @@ import java.lang.annotation.RetentionPolicy; * canvas.drawRect(...); * } finally { * renderNode.endRecording(); - * } - * + * } * *

Drawing a RenderNode in a View

*
@@ -84,8 +83,7 @@ import java.lang.annotation.RetentionPolicy;
  *             // Draw the RenderNode into this canvas.
  *             canvas.drawRenderNode(myRenderNode);
  *         }
- *     }
- * 
+ * } * *

Releasing resources

*

This step is not mandatory but recommended if you want to release resources @@ -93,8 +91,7 @@ import java.lang.annotation.RetentionPolicy; *

  *     // Discards the display list content allowing for any held resources to be released.
  *     // After calling this
- *     renderNode.discardDisplayList();
- * 
+ * renderNode.discardDisplayList(); * * *

Properties

@@ -132,8 +129,7 @@ import java.lang.annotation.RetentionPolicy; * // will be invoked and will execute very quickly * mRenderNode.offsetLeftAndRight(x); * invalidate(); - * } - * + * } * *

A few of the properties may at first appear redundant, such as {@link #setElevation(float)} * and {@link #setTranslationZ(float)}. The reason for these duplicates are to allow for a @@ -146,24 +142,26 @@ import java.lang.annotation.RetentionPolicy; * overlap with {@link #setPosition(Rect)}. * *

The RenderNode's transform matrix is computed at render time as follows: - * First a setTranslate(getTranslationX(), getTranslationY()) is applied to a {@link Matrix}. - * Second a preRotate(getRotationZ(), getPivotX(), getPivotY()) is applied to the matrix. And - * finally a preScale(getScaleX(), getScaleY(), getPivotX(), getPivotY()) is applied. The current - * canvas transform matrix, which is translated to the RenderNode's position, - * is then multiplied by the RenderNode's transform matrix. Therefore there is no implicit - * ordering in setting various RenderNode properties. That is to say that: + *

+ *     Matrix transform = new Matrix();
+ *     transform.setTranslate(renderNode.getTranslationX(), renderNode.getTranslationY());
+ *     transform.preRotate(renderNode.getRotationZ(),
+ *             renderNode.getPivotX(), renderNode.getPivotY());
+ *     transform.preScale(renderNode.getScaleX(), renderNode.getScaleY(),
+ *             renderNode.getPivotX(), renderNode.getPivotY());
+ * The current canvas transform matrix, which is translated to the RenderNode's position, + * is then multiplied by the RenderNode's transform matrix. Therefore the ordering of calling + * property setters does not affect the result. That is to say that: * *
  *     renderNode.setTranslationX(100);
- *     renderNode.setScaleX(100);
- * 
+ * renderNode.setScaleX(100); * - * is equivalent to + * is equivalent to: * *
  *     renderNode.setScaleX(100);
- *     renderNode.setTranslationX(100);
- * 
+ * renderNode.setTranslationX(100); * *

Threading

*

RenderNode may be created and used on any thread but they are not thread-safe. Only @@ -182,8 +180,7 @@ import java.lang.annotation.RetentionPolicy; * if (needsUpdate) { * myOwningView.invalidate(); * } - * } - * + * } * This is marginally faster than doing a more explicit up-front check if the value changed by * comparing the desired value against {@link #getTranslationX()} as it minimizes JNI transitions. * The actual mechanism of requesting a new frame to be rendered will depend on how this -- cgit v1.2.3-59-g8ed1b