Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9ee304c authored by Chris Craik's avatar Chris Craik Committed by Android (Google) Code Review
Browse files

Merge "Round rect outline clipping"

parents 6c536eac deeda3d3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10214,7 +10214,9 @@ package android.graphics {
  public final class Outline {
    ctor public Outline();
    ctor public Outline(android.graphics.Outline);
    method public boolean canClip();
    method public boolean isValid();
    method public void reset();
    method public void set(android.graphics.Outline);
    method public void setConvexPath(android.graphics.Path);
    method public void setOval(int, int, int, int);
+5 −0
Original line number Diff line number Diff line
@@ -387,6 +387,10 @@ public class RenderNode {
        nSetClipToOutline(mNativeRenderNode, clipToOutline);
    }

    public boolean getClipToOutline() {
        return nGetClipToOutline(mNativeRenderNode);
    }

    /**
     * Controls the RenderNode's circular reveal clip.
     */
@@ -919,6 +923,7 @@ public class RenderNode {
    private static native void nSetAnimationMatrix(long renderNode, long animationMatrix);

    private static native boolean nHasOverlappingRendering(long renderNode);
    private static native boolean nGetClipToOutline(long renderNode);
    private static native float nGetAlpha(long renderNode);
    private static native float nGetLeft(long renderNode);
    private static native float nGetTop(long renderNode);
+11 −4
Original line number Diff line number Diff line
@@ -10706,9 +10706,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        mRenderNode.setOutline(mOutline);
    }
    // TODO: remove
    public final boolean getClipToOutline() { return false; }
    public void setClipToOutline(boolean clipToOutline) {}
    public final boolean getClipToOutline() {
        return mRenderNode.getClipToOutline();
    }
    public void setClipToOutline(boolean clipToOutline) {
        // TODO: add a fast invalidation here
        if (getClipToOutline() != clipToOutline) {
            mRenderNode.setClipToOutline(clipToOutline);
        }
    }
    private void queryOutlineFromBackgroundIfUndefined() {
        if ((mPrivateFlags3 & PFLAG3_OUTLINE_DEFINED) == 0) {
@@ -10717,7 +10724,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                mOutline = new Outline();
            } else {
                //invalidate outline, to ensure background calculates it
                mOutline.set(null);
                mOutline.reset();
            }
            if (mBackground.getOutline(mOutline)) {
                if (!mOutline.isValid()) {
+7 −0
Original line number Diff line number Diff line
@@ -317,6 +317,12 @@ static jboolean android_view_RenderNode_hasOverlappingRendering(JNIEnv* env,
    return renderNode->stagingProperties().hasOverlappingRendering();
}

static jboolean android_view_RenderNode_getClipToOutline(JNIEnv* env,
        jobject clazz, jlong renderNodePtr) {
    RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
    return renderNode->stagingProperties().getOutline().getShouldClip();
}

static jfloat android_view_RenderNode_getAlpha(JNIEnv* env,
        jobject clazz, jlong renderNodePtr) {
    RenderNode* renderNode = reinterpret_cast<RenderNode*>(renderNodePtr);
@@ -537,6 +543,7 @@ static JNINativeMethod gMethods[] = {
    { "nOffsetTopAndBottom",   "(JF)V",  (void*) android_view_RenderNode_offsetTopAndBottom },

    { "nHasOverlappingRendering", "(J)Z",  (void*) android_view_RenderNode_hasOverlappingRendering },
    { "nGetClipToOutline",        "(J)Z",  (void*) android_view_RenderNode_getClipToOutline },
    { "nGetAlpha",                "(J)F",  (void*) android_view_RenderNode_getAlpha },
    { "nGetLeft",                 "(J)F",  (void*) android_view_RenderNode_getLeft },
    { "nGetTop",                  "(J)F",  (void*) android_view_RenderNode_getTop },
+30 −20
Original line number Diff line number Diff line
@@ -53,8 +53,7 @@ public final class Outline {
        set(src);
    }

    /** @hide */
    public void markInvalid() {
    public void reset() {
        mRadius = 0;
        mRect = null;
        mPath = null;
@@ -74,12 +73,7 @@ public final class Outline {
     *
     * @param src Source outline to copy from.
     */
    public void set(@Nullable Outline src) {
        if (src == null) {
            mRadius = 0;
            mRect = null;
            mPath = null;
        } else {
    public void set(@NonNull Outline src) {
        if (src.mPath != null) {
            if (mPath == null) {
                mPath = new Path();
@@ -95,7 +89,6 @@ public final class Outline {
        }
        mRadius = src.mRadius;
    }
    }

    /**
     * Sets the Outline to the rounded rect defined by the input rect, and corner radius.
@@ -134,6 +127,11 @@ public final class Outline {
     * Sets the outline to the oval defined by input rect.
     */
    public void setOval(int left, int top, int right, int bottom) {
        if ((bottom - top) == (right - left)) {
            // represent circle as round rect, for efficiency, and to enable clipping
            setRoundRect(left, top, right, bottom, (bottom - top) / 2.0f);
            return;
        }
        mRect = null;
        if (mPath == null) mPath = new Path();
        mPath.reset();
@@ -160,4 +158,16 @@ public final class Outline {
        mRadius = -1.0f;
        mPath.set(convexPath);
    }

    /**
     * Returns whether the outline can be used to clip a View.
     *
     * Currently, only outlines that can be represented as a rectangle, circle, or round rect
     * support clipping.
     *
     * @see {@link View#setClipToOutline(boolean)}
     */
    public boolean canClip() {
        return mRect != null;
    }
}
Loading