diff --git a/api/current.txt b/api/current.txt index 4f39e25b50f5e..da888d7a3c02d 100644 --- a/api/current.txt +++ b/api/current.txt @@ -14861,6 +14861,7 @@ package android.graphics { 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(); @@ -14881,6 +14882,7 @@ package android.graphics { 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 752624b0a0be0..0d75de9ee95f9 100644 --- a/core/jni/android_view_RenderNode.cpp +++ b/core/jni/android_view_RenderNode.cpp @@ -338,6 +338,11 @@ static jboolean android_view_RenderNode_hasOverlappingRendering(jlong renderNode return renderNode->stagingProperties().hasOverlappingRendering(); } +static jboolean android_view_RenderNode_getClipToBounds(jlong renderNodePtr) { + RenderNode* renderNode = reinterpret_cast(renderNodePtr); + return renderNode->stagingProperties().getClipToBounds(); +} + static jboolean android_view_RenderNode_getClipToOutline(jlong renderNodePtr) { RenderNode* renderNode = reinterpret_cast(renderNodePtr); return renderNode->stagingProperties().getOutline().getShouldClip(); @@ -409,6 +414,11 @@ static jboolean android_view_RenderNode_hasIdentityMatrix(jlong renderNodePtr) { return !renderNode->stagingProperties().hasTransformMatrix(); } +static jint android_view_RenderNode_getLayerType(jlong renderNodePtr) { + RenderNode* renderNode = reinterpret_cast(renderNodePtr); + return static_cast(renderNode->stagingProperties().layerProperties().type()); +} + // ---------------------------------------------------------------------------- // RenderProperties - computed getters // ---------------------------------------------------------------------------- @@ -623,10 +633,12 @@ static const JNINativeMethod gMethods[] = { // ---------------------------------------------------------------------------- { "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 d6f08b92a648d..3b1d44b44ed4e 100644 --- a/graphics/java/android/graphics/RenderNode.java +++ b/graphics/java/android/graphics/RenderNode.java @@ -446,7 +446,21 @@ public final class RenderNode { } /** - * 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,15 +474,29 @@ public final class RenderNode { } /** - * 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. @@ -1338,12 +1366,18 @@ public final class RenderNode { @CriticalNative 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 35cf707665cb2..de8777b4e79a9 100644 --- a/libs/hwui/RecordingCanvas.h +++ b/libs/hwui/RecordingCanvas.h @@ -65,6 +65,7 @@ public: 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 04379ae68a0dc..ddb7e4e4ce74d 100644 --- a/libs/hwui/RenderProperties.h +++ b/libs/hwui/RenderProperties.h @@ -98,15 +98,15 @@ public: 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 d7879e722a298..45f3a4c33d846 100644 --- a/libs/hwui/pipeline/skia/SkiaDisplayList.h +++ b/libs/hwui/pipeline/skia/SkiaDisplayList.h @@ -49,7 +49,7 @@ namespace skiapipeline { */ 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