Add missing getter & improve docs
Also fix SkiaDisplayList::getUsedSize()
Bug: 120865963
Test: atest android.uirendering.cts.testclasses.RenderNodeTests
Change-Id: I3cdbd8d330da9a00367199087c9ae1e0a2cacf46
diff --git a/api/current.txt b/api/current.txt
index 931b9fa..358562c 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -14753,6 +14753,7 @@
method public int getAmbientShadowColor();
method public int getBottom();
method public float getCameraDistance();
+ method public boolean getClipToBounds();
method public boolean getClipToOutline();
method public float getElevation();
method public int getHeight();
@@ -14773,6 +14774,7 @@
method public float getTranslationY();
method public float getTranslationZ();
method public long getUniqueId();
+ method public boolean getUseCompositingLayer();
method public int getWidth();
method public boolean hasDisplayList();
method public boolean hasIdentityMatrix();
diff --git a/core/jni/android_view_RenderNode.cpp b/core/jni/android_view_RenderNode.cpp
index 752624b..0d75de9 100644
--- a/core/jni/android_view_RenderNode.cpp
+++ b/core/jni/android_view_RenderNode.cpp
@@ -338,6 +338,11 @@
return renderNode->stagingProperties().hasOverlappingRendering();
}
+static jboolean android_view_RenderNode_getClipToBounds(jlong renderNodePtr) {
+ RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
+ return renderNode->stagingProperties().getClipToBounds();
+}
+
static jboolean android_view_RenderNode_getClipToOutline(jlong renderNodePtr) {
RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
return renderNode->stagingProperties().getOutline().getShouldClip();
@@ -409,6 +414,11 @@
return !renderNode->stagingProperties().hasTransformMatrix();
}
+static jint android_view_RenderNode_getLayerType(jlong renderNodePtr) {
+ RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
+ return static_cast<int>(renderNode->stagingProperties().layerProperties().type());
+}
+
// ----------------------------------------------------------------------------
// RenderProperties - computed getters
// ----------------------------------------------------------------------------
@@ -623,10 +633,12 @@
// ----------------------------------------------------------------------------
{ "nIsValid", "(J)Z", (void*) android_view_RenderNode_isValid },
{ "nSetLayerType", "(JI)Z", (void*) android_view_RenderNode_setLayerType },
+ { "nGetLayerType", "(J)I", (void*) android_view_RenderNode_getLayerType },
{ "nSetLayerPaint", "(JJ)Z", (void*) android_view_RenderNode_setLayerPaint },
{ "nSetStaticMatrix", "(JJ)Z", (void*) android_view_RenderNode_setStaticMatrix },
{ "nSetAnimationMatrix", "(JJ)Z", (void*) android_view_RenderNode_setAnimationMatrix },
{ "nSetClipToBounds", "(JZ)Z", (void*) android_view_RenderNode_setClipToBounds },
+ { "nGetClipToBounds", "(J)Z", (void*) android_view_RenderNode_getClipToBounds },
{ "nSetClipBounds", "(JIIII)Z", (void*) android_view_RenderNode_setClipBounds },
{ "nSetClipBoundsEmpty", "(J)Z", (void*) android_view_RenderNode_setClipBoundsEmpty },
{ "nSetProjectBackwards", "(JZ)Z", (void*) android_view_RenderNode_setProjectBackwards },
diff --git a/graphics/java/android/graphics/RenderNode.java b/graphics/java/android/graphics/RenderNode.java
index d6f08b9..3b1d44b 100644
--- a/graphics/java/android/graphics/RenderNode.java
+++ b/graphics/java/android/graphics/RenderNode.java
@@ -446,7 +446,21 @@
}
/**
- * Sets the clip bounds of the RenderNode.
+ * 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 {@link #setUseCompositingLayer(boolean, Paint)}.
+ *
+ * @return true if a compositing layer is forced, false otherwise
+ */
+ public boolean getUseCompositingLayer() {
+ return nGetLayerType(mNativeRenderNode) != 0;
+ }
+
+ /**
+ * Sets the clip bounds of the RenderNode. If null, the clip bounds is removed from the
+ * RenderNode. If non-null, the RenderNode will be clipped to this rect. If
+ * {@link #setClipToBounds(boolean)} is true, then the RenderNode will be clipped to the
+ * intersection of this rectangle and the bounds of the render node.
*
* @param rect the bounds to clip to. If null, the clip bounds are reset
* @return True if the clip bounds changed, false otherwise
@@ -460,16 +474,30 @@
}
/**
- * Set whether the Render node should clip itself to its bounds. This property is controlled by
- * the view's parent.
+ * 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 {@link #setClipBounds(Rect)}, which
+ * allows for a different clipping rectangle to be used in addition to or instead of the
+ * {@link #setLeftTopRightBottom(int, int, int, int)} or the RenderNode.
*
- * @param clipToBounds true if the display list should clip to its bounds
+ * @param clipToBounds true if the display list should clip to its bounds, false otherwise.
*/
public boolean setClipToBounds(boolean clipToBounds) {
return nSetClipToBounds(mNativeRenderNode, clipToBounds);
}
/**
+ * Returns whether or not the RenderNode is clipping to its bounds. See
+ * {@link #setClipToBounds(boolean)} and {@link #setLeftTopRightBottom(int, int, int, int)}
+ *
+ * @return true if the render node clips to its bounds, false otherwise.
+ */
+ public boolean getClipToBounds() {
+ return nGetClipToBounds(mNativeRenderNode);
+ }
+
+ /**
* Sets whether the RenderNode should be drawn immediately after the
* closest ancestor RenderNode containing a projection receiver.
*
@@ -1339,12 +1367,18 @@
private static native boolean nSetLayerType(long renderNode, int layerType);
@CriticalNative
+ private static native int nGetLayerType(long renderNode);
+
+ @CriticalNative
private static native boolean nSetLayerPaint(long renderNode, long paint);
@CriticalNative
private static native boolean nSetClipToBounds(long renderNode, boolean clipToBounds);
@CriticalNative
+ private static native boolean nGetClipToBounds(long renderNode);
+
+ @CriticalNative
private static native boolean nSetClipBounds(long renderNode, int left, int top,
int right, int bottom);
diff --git a/libs/hwui/RecordingCanvas.h b/libs/hwui/RecordingCanvas.h
index 35cf707..de8777b 100644
--- a/libs/hwui/RecordingCanvas.h
+++ b/libs/hwui/RecordingCanvas.h
@@ -65,6 +65,7 @@
void applyColorTransform(ColorTransform transform);
bool hasText() const { return mHasText; }
+ size_t usedSize() const { return fUsed; }
private:
friend class RecordingCanvas;
diff --git a/libs/hwui/RenderProperties.h b/libs/hwui/RenderProperties.h
index 04379ae..ddb7e4e 100644
--- a/libs/hwui/RenderProperties.h
+++ b/libs/hwui/RenderProperties.h
@@ -98,15 +98,15 @@
LayerProperties& operator=(const LayerProperties& other);
+ // Strongly recommend using effectiveLayerType instead
+ LayerType type() const { return mType; }
+
private:
LayerProperties();
~LayerProperties();
void reset();
bool setColorFilter(SkColorFilter* filter);
- // Private since external users should go through properties().effectiveLayerType()
- LayerType type() const { return mType; }
-
friend class RenderProperties;
LayerType mType = LayerType::None;
diff --git a/libs/hwui/pipeline/skia/SkiaDisplayList.h b/libs/hwui/pipeline/skia/SkiaDisplayList.h
index d7879e7..45f3a4c 100644
--- a/libs/hwui/pipeline/skia/SkiaDisplayList.h
+++ b/libs/hwui/pipeline/skia/SkiaDisplayList.h
@@ -49,7 +49,7 @@
*/
class SkiaDisplayList {
public:
- size_t getUsedSize() { return allocator.usedSize(); }
+ size_t getUsedSize() { return allocator.usedSize() + mDisplayList.usedSize(); }
~SkiaDisplayList() {
/* Given that we are using a LinearStdAllocator to store some of the