RenderNode


public final class RenderNode
extends Object

java.lang.Object
   ↳ android.graphics.RenderNode


RenderNode is used to build hardware accelerated rendering hierarchies. Each RenderNode contains both a display list as well as a set of properties that affect the rendering of the display list. RenderNodes are used internally for all Views by default and are not typically used directly.

RenderNodes are used to divide up the rendering content of a complex scene into smaller pieces that can then be updated individually more cheaply. Updating part of the scene only needs to update the display list or properties of a small number of RenderNode instead of redrawing everything from scratch. A RenderNode only needs its display list re-recorded when its content alone should be changed. RenderNodes can also be transformed without re-recording the display list through the transform properties.

A text editor might for instance store each paragraph into its own RenderNode. Thus when the user inserts or removes characters, only the display list of the affected paragraph needs to be recorded again.

Hardware acceleration

RenderNodes can be drawn using a RecordingCanvas. They are not supported in software. Always make sure that the Canvas you are using to render a display list is hardware accelerated using Canvas.isHardwareAccelerated().

Creating a RenderNode

     RenderNode renderNode = new RenderNode("myRenderNode");
     renderNode.setPosition(0, 0, 50, 50); // Set the size to 50x50
     RecordingCanvas canvas = renderNode.beginRecording();
     try {
         // Draw with the canvas
         canvas.drawRect(...);
     } finally {
         renderNode.endRecording();
     }

Drawing a RenderNode in a View

     protected void onDraw(Canvas canvas) {
         if (canvas.isHardwareAccelerated()) {
             // Check that the RenderNode has a display list, re-recording it if it does not.
             if (!myRenderNode.hasDisplayList()) {
                 updateDisplayList(myRenderNode);
             }
             // Draw the RenderNode into this canvas.
             canvas.drawRenderNode(myRenderNode);
         }
     }

Releasing resources

This step is not mandatory but recommended if you want to release resources held by a display list as soon as possible. Most significantly any bitmaps it may contain.

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

Properties

In addition, a RenderNode offers several properties, such as setScaleX(float) or setTranslationX(float), that can be used to affect all the drawing commands recorded within. For instance, these properties can be used to move around a large number of images without re-issuing all the individual canvas.drawBitmap() calls.

     private void createDisplayList() {
         mRenderNode = new RenderNode("MyRenderNode");
         mRenderNode.setPosition(0, 0, width, height);
         RecordingCanvas canvas = mRenderNode.beginRecording();
         try {
             for (Bitmap b : mBitmaps) {
                 canvas.drawBitmap(b, 0.0f, 0.0f, null);
                 canvas.translate(0.0f, b.getHeight());
             }
         } finally {
             mRenderNode.endRecording();
         }
     }

     protected void onDraw(Canvas canvas) {
         if (canvas.isHardwareAccelerated())
             canvas.drawRenderNode(mRenderNode);
         }
     }

     private void moveContentBy(int x) {
          // This will move all the bitmaps recorded inside the display list
          // by x pixels to the right and redraw this view. All the commands
          // recorded in createDisplayList() won't be re-issued, only onDraw()
          // will be invoked and will execute very quickly
          mRenderNode.offsetLeftAndRight(x);
          invalidate();
     }

A few of the properties may at first appear redundant, such as setElevation(float) and setTranslationZ(float). The reason for these duplicates are to allow for a separation between static & transient usages. For example consider a button that raises from 2dp to 8dp when pressed. To achieve that an application may decide to setElevation(2dip), and then on press to animate setTranslationZ to 6dip. Combined this achieves the final desired 8dip value, but the animation need only concern itself with animating the lift from press without needing to know the initial starting value. setTranslationX(float) and setTranslationY(float) are similarly provided for animation uses despite the functional overlap with setPosition(android.graphics.Rect).

The RenderNode's transform matrix is computed at render time as follows:

     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);
is equivalent to:
     renderNode.setScaleX(100);
     renderNode.setTranslationX(100);

Threading

RenderNode may be created and used on any thread but they are not thread-safe. Only a single thread may interact with a RenderNode at any given time. It is critical that the RenderNode is only used on the same thread it is drawn with. For example when using RenderNode with a custom View, then that RenderNode must only be used from the UI thread.

When to re-render

Many of the RenderNode mutation methods, such as setTranslationX(float), return a boolean indicating if the value actually changed or not. This is useful in detecting if a new frame should be rendered or not. A typical usage would look like:

     public void translateTo(int x, int y) {
         boolean needsUpdate = myRenderNode.setTranslationX(x);
         needsUpdate |= myRenderNode.setTranslationY(y);
         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 getTranslationX() as it minimizes JNI transitions. The actual mechanism of requesting a new frame to be rendered will depend on how this RenderNode is being drawn. If it's drawn to a containing View, as in the above snippet, then simply invalidating that View works. If instead the RenderNode is being drawn to a Canvas directly such as with Surface#lockHardwareCanvas() then a new frame needs to be drawn by calling Surface#lockHardwareCanvas(), re-drawing the root RenderNode or whatever top-level content is desired, and finally calling Surface#unlockCanvasAndPost(Canvas).

Summary

Public constructors

RenderNode(String name)

Creates a new RenderNode that can be used to record batches of drawing operations, and store / apply render properties when drawn.

Public methods

RecordingCanvas beginRecording(int width, int height)

Starts recording a display list for the render node.

RecordingCanvas beginRecording()

Same as beginRecording(int, int) with the width & height set to the RenderNode's own width & height.

long computeApproximateMemoryUsage()

Gets the approximate memory usage of the RenderNode for debug purposes.

void discardDisplayList()

Reset native resources.

void endRecording()

` Ends the recording for this display list.

float getAlpha()

Returns the translucency level of this display list.

int getAmbientShadowColor()
int getBottom()

Gets the bottom position for the RenderNode.

float getCameraDistance()

Returns the distance in Z of the camera for this RenderNode

boolean getClipToBounds()

Returns whether or not the RenderNode is clipping to its bounds.

boolean getClipToOutline()

See setClipToOutline(boolean)

float getElevation()

See setElevation(float)

int getHeight()

Gets the height of the RenderNode, which is the bottom - top.

void getInverseMatrix(Matrix outMatrix)

Gets the current transform inverted.

int getLeft()

Gets the left position for the RenderNode.

void getMatrix(Matrix outMatrix)

Gets the current transform matrix

float getPivotX()

Returns the pivot value for this display list on the X axis, in pixels.

float getPivotY()

Returns the pivot value for this display list on the Y axis, in pixels.

int getRight()

Gets the right position for the RenderNode.

float getRotationX()

Returns the rotation value for this display list around the X axis, in degrees.

float getRotationY()

Returns the rotation value for this display list around the Y axis, in degrees.

float getRotationZ()

Returns the rotation value for this display list around the Z axis, in degrees.

float getScaleX()

Returns the scale value for this display list on the X axis.

float getScaleY()

Returns the scale value for this display list on the Y axis.

int getSpotShadowColor()
int getTop()

Gets the top position for the RenderNode.

float getTranslationX()

Returns the translation value for this display list on the X axis, in pixels.

float getTranslationY()

Returns the translation value for this display list on the Y axis, in pixels.

float getTranslationZ()

Returns the translation value for this display list on the Z axis.

long getUniqueId()

Returns the unique ID that identifies this RenderNode.

boolean getUseCompositingLayer()

Gets whether or not a compositing layer is forced to be used.

int getWidth()

Gets the width of the RenderNode, which is the right - left.

boolean hasDisplayList()

Returns whether the RenderNode has a display list.

boolean hasIdentityMatrix()

Whether or not the RenderNode has an identity transform.

boolean hasOverlappingRendering()

Indicates whether the content of this display list overlaps.

boolean hasShadow()

Checks if the RenderNode has a shadow.

boolean isForceDarkAllowed()

See setForceDarkAllowed(boolean)

boolean isPivotExplicitlySet()
boolean offsetLeftAndRight(int offset)

Offsets the left and right positions for the RenderNode

boolean offsetTopAndBottom(int offset)

Offsets the top and bottom values for the RenderNode

boolean resetPivot()

Clears any pivot previously set by a call to setPivotX(float) or setPivotY(float).

boolean setAlpha(float alpha)

Sets the translucency level for the display list.

boolean setAmbientShadowColor(int color)

Sets the color of the ambient shadow that is drawn when the RenderNode has a positive Z or elevation value and is drawn inside of a Canvas#enableZ() section.

boolean setCameraDistance(float distance)

Sets the distance along the Z axis (orthogonal to the X/Y plane on which RenderNodes are drawn) from the camera to this RenderNode.

boolean setClipRect(Rect rect)

Sets an additional clip on the RenderNode.

boolean setClipToBounds(boolean clipToBounds)

Set whether the Render node should clip itself to its bounds.

boolean setClipToOutline(boolean clipToOutline)

Enables or disables clipping to the outline.

boolean setElevation(float lift)

Sets the base elevation of this RenderNode in pixels

boolean setForceDarkAllowed(boolean allow)

Sets whether or not to allow force dark to apply to this RenderNode.

boolean setHasOverlappingRendering(boolean hasOverlappingRendering)

Sets whether the display list renders content which overlaps.

boolean setOutline(Outline outline)

Sets the outline, defining the shape that casts a shadow, and the path to be clipped if setClipToOutline is set.

boolean setPivotX(float pivotX)

Sets the pivot value for the display list on the X axis

boolean setPivotY(float pivotY)

Sets the pivot value for the display list on the Y axis

boolean setPosition(int left, int top, int right, int bottom)

Sets the position of the RenderNode.

boolean setPosition(Rect position)

Sets the position of the RenderNode.

boolean setProjectBackwards(boolean shouldProject)

Sets whether the RenderNode should be drawn immediately after the closest ancestor RenderNode containing a projection receiver.

boolean setProjectionReceiver(boolean shouldReceive)

Sets whether the RenderNode is a projection receiver.

boolean setRenderEffect(RenderEffect renderEffect)

Configure the RenderEffect to apply to this RenderNode.

boolean setRotationX(float rotationX)

Sets the rotation value for the display list around the X axis.

boolean setRotationY(float rotationY)

Sets the rotation value for the display list around the Y axis.

boolean setRotationZ(float rotation)

Sets the rotation value for the display list around the Z axis.

boolean setScaleX(float scaleX)

Sets the scale value for the display list on the X axis.

boolean setScaleY(float scaleY)

Sets the scale value for the display list on the Y axis.

boolean setSpotShadowColor(int color)

Sets the color of the spot shadow that is drawn when the RenderNode has a positive Z or elevation value and is drawn inside of a Canvas#enableZ() section.

boolean setTranslationX(float translationX)

Sets the translation value for the display list on the X axis.

boolean setTranslationY(float translationY)

Sets the translation value for the display list on the Y axis.

boolean setTranslationZ(float translationZ)

Sets the translation value for the display list on the Z axis.

boolean setUseCompositingLayer(boolean forceToLayer, Paint paint)

Controls whether or not to force this RenderNode to render to an intermediate buffer.

Inherited methods

Public constructors

RenderNode

Added in API level 29
public RenderNode (String name)

Creates a new RenderNode that can be used to record batches of drawing operations, and store / apply render properties when drawn.

Parameters
name String: The name of the RenderNode, used for debugging purpose. May be null.

Public methods

beginRecording

Added in API level 29
public RecordingCanvas beginRecording (int width, 
                int height)

Starts recording a display list for the render node. All operations performed on the returned canvas are recorded and stored in this display list. endRecording() must be called when the recording is finished in order to apply the updated display list. Failing to call endRecording() will result in an IllegalStateException if beginRecording(int, int) is called again.

Parameters
width int: The width of the recording viewport. This will not alter the width of the RenderNode itself, that must be set with setPosition(android.graphics.Rect).

height int: The height of the recording viewport. This will not alter the height of the RenderNode itself, that must be set with setPosition(android.graphics.Rect).

Returns
RecordingCanvas A canvas to record drawing operations. This value cannot be null.

Throws
IllegalStateException If a recording is already in progress. That is, the previous call to beginRecording(int, int) did not call endRecording().

beginRecording

Added in API level 29
public RecordingCanvas beginRecording ()

Same as beginRecording(int, int) with the width & height set to the RenderNode's own width & height. The RenderNode's width & height may be set with setPosition(int, int, int, int).

Returns
RecordingCanvas A canvas to record drawing operations. This value cannot be null.

Throws
IllegalStateException If a recording is already in progress. That is, the previous call to beginRecording(int, int) did not call endRecording().

computeApproximateMemoryUsage

Added in API level 29
public long computeApproximateMemoryUsage ()

Gets the approximate memory usage of the RenderNode for debug purposes. Does not include the memory usage of any child RenderNodes nor any bitmaps, only the memory usage of this RenderNode and any data it owns.
Value is a non-negative number of bytes.

Returns
long Approximate memory usage in bytes. Value is a non-negative number of bytes.

discardDisplayList

Added in API level 29
public void discardDisplayList ()

Reset native resources. This is called when cleaning up the state of display lists during destruction of hardware resources, to ensure that we do not hold onto obsolete resources after related resources are gone.

endRecording

Added in API level 29
public void endRecording ()

` Ends the recording for this display list. Calling this method marks the display list valid and hasDisplayList() will return true.

getAlpha

Added in API level 29
public float getAlpha ()

Returns the translucency level of this display list.

Returns
float A value between 0.0f and 1.0f

See also:

getAmbientShadowColor

Added in API level 29
public int getAmbientShadowColor ()

Returns
int The shadow color set by setAmbientShadowColor(int), or black if nothing was set

getBottom

Added in API level 29
public int getBottom ()

Gets the bottom position for the RenderNode.

Returns
int the bottom position in pixels

getCameraDistance

Added in API level 29
public float getCameraDistance ()

Returns the distance in Z of the camera for this RenderNode

Returns
float the distance along the Z axis in pixels. Value is between 0.0f and Float.MAX_VALUE inclusive

getClipToBounds

Added in API level 29
public boolean getClipToBounds ()

Returns whether or not the RenderNode is clipping to its bounds. See setClipToBounds(boolean) and setPosition(int, int, int, int)

Returns
boolean true if the render node clips to its bounds, false otherwise.

getClipToOutline

Added in API level 29
public boolean getClipToOutline ()

See setClipToOutline(boolean)

Returns
boolean True if this RenderNode clips to its outline, false otherwise

getElevation

Added in API level 29
public float getElevation ()

See setElevation(float)

Returns
float The RenderNode's current elevation

getHeight

Added in API level 29
public int getHeight ()

Gets the height of the RenderNode, which is the bottom - top.

Returns
int the height of the RenderNode

getInverseMatrix

Added in API level 29
public void getInverseMatrix (Matrix outMatrix)

Gets the current transform inverted. This is a faster way to do the otherwise equivalent getMatrix(android.graphics.Matrix) followed by Matrix#invert(Matrix)

Parameters
outMatrix Matrix: The matrix to store the inverse transform of the RenderNode This value cannot be null.

getLeft

Added in API level 29
public int getLeft ()

Gets the left position for the RenderNode.

Returns
int the left position in pixels

getMatrix

Added in API level 29
public void getMatrix (Matrix outMatrix)

Gets the current transform matrix

Parameters
outMatrix Matrix: The matrix to store the transform of the RenderNode This value cannot be null.

getPivotX

Added in API level 29
public float getPivotX ()

Returns the pivot value for this display list on the X axis, in pixels.

Returns
float

See also:

getPivotY

Added in API level 29
public float getPivotY ()

Returns the pivot value for this display list on the Y axis, in pixels.

Returns
float

See also:

getRight

Added in API level 29
public int getRight ()

Gets the right position for the RenderNode.

Returns
int the right position in pixels

getRotationX

Added in API level 29
public float getRotationX ()

Returns the rotation value for this display list around the X axis, in degrees.

Returns
float

getRotationY

Added in API level 29
public float getRotationY ()

Returns the rotation value for this display list around the Y axis, in degrees.

Returns
float

getRotationZ

Added in API level 29
public float getRotationZ ()

Returns the rotation value for this display list around the Z axis, in degrees.

Returns
float

getScaleX

Added in API level 29
public float getScaleX ()

Returns the scale value for this display list on the X axis.

Returns
float

See also:

getScaleY

Added in API level 29
public float getScaleY ()

Returns the scale value for this display list on the Y axis.

Returns
float

See also:

getSpotShadowColor

Added in API level 29
public int getSpotShadowColor ()

Returns
int The shadow color set by setSpotShadowColor(int), or black if nothing was set

getTop

Added in API level 29
public int getTop ()

Gets the top position for the RenderNode.

Returns
int the top position in pixels

getTranslationX

Added in API level 29
public float getTranslationX ()

Returns the translation value for this display list on the X axis, in pixels.

Returns
float

getTranslationY

Added in API level 29
public float getTranslationY ()

Returns the translation value for this display list on the Y axis, in pixels.

Returns
float

getTranslationZ

Added in API level 29
public float getTranslationZ ()

Returns the translation value for this display list on the Z axis.

Returns
float

getUniqueId

Added in API level 29
public long getUniqueId ()

Returns the unique ID that identifies this RenderNode. This ID is unique for the lifetime of the process. IDs are reset on process death, and are unique only within the process. This ID is intended to be used with debugging tools to associate a particular RenderNode across different debug dumping & inspection tools. For example a View layout inspector should include the unique ID for any RenderNodes that it owns to associate the drawing content with the layout content.

Returns
long the unique ID for this RenderNode

getUseCompositingLayer

Added in API level 29
public boolean getUseCompositingLayer ()

Gets whether or not a compositing layer is forced to be used. The default & recommended is false, as it is typically faster to avoid using compositing layers. See setUseCompositingLayer(boolean, android.graphics.Paint).

Returns
boolean true if a compositing layer is forced, false otherwise

getWidth

Added in API level 29
public int getWidth ()

Gets the width of the RenderNode, which is the right - left.

Returns
int the width of the RenderNode

hasDisplayList

Added in API level 29
public boolean hasDisplayList ()

Returns whether the RenderNode has a display list. If this returns false, the RenderNode should be re-recorded with beginRecording() and endRecording(). A RenderNode without a display list may still be drawn, however it will have no impact on the rendering content until its display list is updated. When a RenderNode is no longer drawn by anything the system may automatically invoke discardDisplayList(). It is therefore important to ensure that hasDisplayList() is true on a RenderNode prior to drawing it. See discardDisplayList()

Returns
boolean boolean true if this RenderNode has a display list, false otherwise.

hasIdentityMatrix

Added in API level 29
public boolean hasIdentityMatrix ()

Whether or not the RenderNode has an identity transform. This is a faster way to do the otherwise equivalent getMatrix(android.graphics.Matrix) Matrix#isIdentity() as it doesn't require copying the Matrix first, thus minimizing overhead.

Returns
boolean true if the RenderNode has an identity transform, false otherwise

hasOverlappingRendering

Added in API level 29
public boolean hasOverlappingRendering ()

Indicates whether the content of this display list overlaps.

Returns
boolean True if this display list renders content which overlaps, false otherwise.

hasShadow

Added in API level 29
public boolean hasShadow ()

Checks if the RenderNode has a shadow. That is, if the combination of getElevation() and getTranslationZ() is greater than zero, there is an Outline set with a valid shadow caster path, and the provided outline has a non-zero Outline#getAlpha().

Returns
boolean True if this RenderNode has a shadow, false otherwise

isForceDarkAllowed

Added in API level 29
public boolean isForceDarkAllowed ()

See setForceDarkAllowed(boolean)

Returns
boolean true if force dark is allowed (default), false if it is disabled

isPivotExplicitlySet

Added in API level 29
public boolean isPivotExplicitlySet ()

Returns
boolean Whether or not a pivot was explicitly set with setPivotX(float) or setPivotY(float). If no pivot has been set then the pivot will be the center of the RenderNode.

offsetLeftAndRight

Added in API level 29
public boolean offsetLeftAndRight (int offset)

Offsets the left and right positions for the RenderNode

Parameters
offset int: The amount that the left and right positions are offset in pixels

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

offsetTopAndBottom

Added in API level 29
public boolean offsetTopAndBottom (int offset)

Offsets the top and bottom values for the RenderNode

Parameters
offset int: The amount that the left and right positions are offset in pixels

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

resetPivot

Added in API level 29
public boolean resetPivot ()

Clears any pivot previously set by a call to setPivotX(float) or setPivotY(float). After calling this isPivotExplicitlySet() will be false and the pivot used for rotation will return to default of being centered on the view.

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setAlpha

Added in API level 29
public boolean setAlpha (float alpha)

Sets the translucency level for the display list.

Parameters
alpha float: The translucency of the display list, must be a value between 0.0f and 1.0f

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setAmbientShadowColor

Added in API level 29
public boolean setAmbientShadowColor (int color)

Sets the color of the ambient shadow that is drawn when the RenderNode has a positive Z or elevation value and is drawn inside of a Canvas#enableZ() section.

By default the shadow color is black. Generally, this color will be opaque so the intensity of the shadow is consistent between different RenderNodes with different colors.

The opacity of the final ambient shadow is a function of the shadow caster height, the alpha channel of the outlineAmbientShadowColor (typically opaque), and the R.attr.ambientShadowAlpha theme attribute.

Parameters
color int: The color this RenderNode will cast for its elevation shadow.

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setCameraDistance

Added in API level 29
public boolean setCameraDistance (float distance)

Sets the distance along the Z axis (orthogonal to the X/Y plane on which RenderNodes are drawn) from the camera to this RenderNode. The camera's distance affects 3D transformations, for instance rotations around the X and Y axis. If the rotationX or rotationY properties are changed and this view is large (more than half the size of the screen), it is recommended to always use a camera distance that's greater than the height (X axis rotation) or the width (Y axis rotation) of this view.

The distance of the camera from the drawing plane can have an affect on the perspective distortion of the RenderNode when it is rotated around the x or y axis. For example, a large distance will result in a large viewing angle, and there will not be much perspective distortion of the view as it rotates. A short distance may cause much more perspective distortion upon rotation, and can also result in some drawing artifacts if the rotated view ends up partially behind the camera (which is why the recommendation is to use a distance at least as far as the size of the view, if the view is to be rotated.)

The distance is expressed in pixels and must always be positive

Parameters
distance float: The distance in pixels, must always be positive Value is between 0.0f and Float.MAX_VALUE inclusive

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setClipRect

Added in API level 29
public boolean setClipRect (Rect rect)

Sets an additional clip on the RenderNode. If null, the extra clip is removed from the RenderNode. If non-null, the RenderNode will be clipped to this rect. In addition if setClipToBounds(boolean) is true, then the RenderNode will be clipped to the intersection of this rectangle and the bounds of the render node, which is set with setPosition(android.graphics.Rect).

This is equivalent to do a Canvas#clipRect(Rect) at the start of this RenderNode's display list. However, as this is a property of the RenderNode instead of part of the display list it can be more easily animated for transient additional clipping. An example usage of this would be the ChangeBounds transition animation with the resizeClip=true option.

Parameters
rect Rect: the bounds to clip to. If null, the additional clip is removed.

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setClipToBounds

Added in API level 29
public boolean setClipToBounds (boolean clipToBounds)

Set whether the Render node should clip itself to its bounds. This defaults to true, and is useful to the renderer in enable quick-rejection of chunks of the tree as well as better partial invalidation support. Clipping can be further restricted or controlled through the combination of this property as well as setClipRect(android.graphics.Rect), which allows for a different clipping rectangle to be used in addition to or instead of the setPosition(int, int, int, int) or the RenderNode.

Parameters
clipToBounds boolean: true if the display list should clip to its bounds, false otherwise.

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setClipToOutline

Added in API level 29
public boolean setClipToOutline (boolean clipToOutline)

Enables or disables clipping to the outline.

Parameters
clipToOutline boolean: true if clipping to the outline.

Returns
boolean True if the clipToOutline value changed, false if previous value matched the new value.

setElevation

Added in API level 29
public boolean setElevation (float lift)

Sets the base elevation of this RenderNode in pixels

Parameters
lift float: the elevation in pixels

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setForceDarkAllowed

Added in API level 29
public boolean setForceDarkAllowed (boolean allow)

Sets whether or not to allow force dark to apply to this RenderNode. Setting this to false will disable the auto-dark feature on everything this RenderNode draws, including any descendants. Setting this to true will allow this RenderNode to be automatically made dark, however a value of 'true' will not override any 'false' value in its parent chain nor will it prevent any 'false' in any of its children.

Parameters
allow boolean: Whether or not to allow force dark.

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setHasOverlappingRendering

Added in API level 29
public boolean setHasOverlappingRendering (boolean hasOverlappingRendering)

Sets whether the display list renders content which overlaps. Non-overlapping rendering can use a fast path for alpha that avoids rendering to an offscreen buffer. By default display lists consider they do not have overlapping content.

Parameters
hasOverlappingRendering boolean: False if the content is guaranteed to be non-overlapping, true otherwise.

Returns
boolean

setOutline

Added in API level 29
public boolean setOutline (Outline outline)

Sets the outline, defining the shape that casts a shadow, and the path to be clipped if setClipToOutline is set. This will make a copy of the provided Outline, so any future modifications to the outline will need to call setOutline(android.graphics.Outline) with the modified outline for those changes to be applied.

Parameters
outline Outline: The outline to use for this RenderNode. This value may be null.

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setPivotX

Added in API level 29
public boolean setPivotX (float pivotX)

Sets the pivot value for the display list on the X axis

Parameters
pivotX float: The pivot value of the display list on the X axis, in pixels

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setPivotY

Added in API level 29
public boolean setPivotY (float pivotY)

Sets the pivot value for the display list on the Y axis

Parameters
pivotY float: The pivot value of the display list on the Y axis, in pixels

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setPosition

Added in API level 29
public boolean setPosition (int left, 
                int top, 
                int right, 
                int bottom)

Sets the position of the RenderNode.

Parameters
left int: The left position of the RenderNode, in pixels

top int: The top position of the RenderNode, in pixels

right int: The right position of the RenderNode, in pixels

bottom int: The bottom position of the RenderNode, in pixels

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setPosition

Added in API level 29
public boolean setPosition (Rect position)

Sets the position of the RenderNode.

Parameters
position Rect: The position rectangle in pixels This value cannot be null.

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setProjectBackwards

Added in API level 29
public boolean setProjectBackwards (boolean shouldProject)

Sets whether the RenderNode should be drawn immediately after the closest ancestor RenderNode containing a projection receiver.

The default is false, and the rendering of this node happens in the typical draw order.

If true, then at rendering time this rendernode will not be drawn in order with the Canvas#drawRenderNode(RenderNode) command that drew this RenderNode, but instead it will be re-positioned in the RenderNode tree to be drawn on the closet ancestor with a child rendernode that has setProjectionReceiver(boolean) as true.

The typical usage of this is to allow a child RenderNode to draw on a parent's background, such as the platform's usage with RippleDrawable. Consider the following structure, built out of which RenderNode called drawRenderNode on a different RenderNode:

        +-------------+
        |RenderNode: P|
        +-+----------++
          |          |
          v          v
  +-------+-----+  +-+--------------+
  |RenderNode: C|  |RenderNode: P'BG|
  +-------+-----+  +----------------+
          |
          |
 +--------+-------+
 |RenderNode: C'BG|
 +----------------+
 
If P'BG is a projection receiver, and C'BG is set to project backwards then C'BG will behave as if it was drawn directly by P'BG instead of by C. This includes inheriting P'BG's clip instead of C's clip.

Parameters
shouldProject boolean: true if the display list should be projected onto a containing volume. Default is false.

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setProjectionReceiver

Added in API level 29
public boolean setProjectionReceiver (boolean shouldReceive)

Sets whether the RenderNode is a projection receiver. If true then this RenderNode's parent should draw any descendant RenderNodes with ProjectBackwards=true directly on top of it. Default value is false. See setProjectBackwards(boolean) for a description of what this entails.

Parameters
shouldReceive boolean: True if this RenderNode is a projection receiver, false otherwise. Default is false.

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setRenderEffect

Added in API level 31
public boolean setRenderEffect (RenderEffect renderEffect)

Configure the RenderEffect to apply to this RenderNode. This will apply a visual effect to the end result of the contents of this RenderNode before it is drawn into the destination. For example if RenderEffect#createBlurEffect(float, float, RenderEffect, Shader.TileMode) is provided, the contents will be drawn in a separate layer, then this layer will be blurred when this RenderNode is drawn into the destination.

Parameters
renderEffect RenderEffect: to be applied to the RenderNode. Passing null clears all previously configured RenderEffects

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setRotationX

Added in API level 29
public boolean setRotationX (float rotationX)

Sets the rotation value for the display list around the X axis.

Parameters
rotationX float: The rotation value of the display list, in degrees

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setRotationY

Added in API level 29
public boolean setRotationY (float rotationY)

Sets the rotation value for the display list around the Y axis.

Parameters
rotationY float: The rotation value of the display list, in degrees

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setRotationZ

Added in API level 29
public boolean setRotationZ (float rotation)

Sets the rotation value for the display list around the Z axis.

Parameters
rotation float: The rotation value of the display list, in degrees

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setScaleX

Added in API level 29
public boolean setScaleX (float scaleX)

Sets the scale value for the display list on the X axis.

Parameters
scaleX float: The scale value of the display list

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setScaleY

Added in API level 29
public boolean setScaleY (float scaleY)

Sets the scale value for the display list on the Y axis.

Parameters
scaleY float: The scale value of the display list

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setSpotShadowColor

Added in API level 29
public boolean setSpotShadowColor (int color)

Sets the color of the spot shadow that is drawn when the RenderNode has a positive Z or elevation value and is drawn inside of a Canvas#enableZ() section.

By default the shadow color is black. Generally, this color will be opaque so the intensity of the shadow is consistent between different RenderNodes with different colors.

The opacity of the final spot shadow is a function of the shadow caster height, the alpha channel of the outlineSpotShadowColor (typically opaque), and the R.attr.spotShadowAlpha theme attribute

Parameters
color int: The color this RenderNode will cast for its elevation spot shadow.

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setTranslationX

Added in API level 29
public boolean setTranslationX (float translationX)

Sets the translation value for the display list on the X axis.

Parameters
translationX float: The X axis translation value of the display list, in pixels

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setTranslationY

Added in API level 29
public boolean setTranslationY (float translationY)

Sets the translation value for the display list on the Y axis.

Parameters
translationY float: The Y axis translation value of the display list, in pixels

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setTranslationZ

Added in API level 29
public boolean setTranslationZ (float translationZ)

Sets the translation value for the display list on the Z axis.

Parameters
translationZ float

Returns
boolean True if the value changed, false if the new value was the same as the previous value.

setUseCompositingLayer

Added in API level 29
public boolean setUseCompositingLayer (boolean forceToLayer, 
                Paint paint)

Controls whether or not to force this RenderNode to render to an intermediate buffer. Internally RenderNode will already promote itself to a composition layer if it's useful for performance or required for the current combination of setAlpha(float) and setHasOverlappingRendering(boolean).

The usage of this is instead to allow for either overriding of the internal behavior if it's measured to be necessary for the particular rendering content in question or, more usefully, to add a composition effect to the RenderNode via the optional paint parameter.

Note: When a RenderNode is using a compositing layer it will also result in clipToBounds=true behavior.

Parameters
forceToLayer boolean: if true this forces the RenderNode to use an intermediate buffer. Default & generally recommended value is false.

paint Paint: The blend mode, alpha, and ColorFilter to apply to the compositing layer. Only applies if forceToLayer is true. The paint's alpha is multiplied with getAlpha() to resolve the final alpha of the RenderNode. If null then no additional composition effects are applied on top of the composition layer.

Returns
boolean True if the value changed, false if the new value was the same as the previous value.