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

Commit 15b6ba58 authored by Chet Haase's avatar Chet Haase
Browse files

Add setHasOverlappingRendering() method

View.hasOverlappingRendering() is an important performance tweak that
subclasses can override to do the right thing return false when appropriate
to avoid expensive operations when view is translucent).
But this requires subclassing View to get this behavior.

This new API allows the property to be set from outside, enabling
standard views to have this behavior set. When the new method is called,
the behavior will derive from whatever it was set to. Otherwise, it
will default to the old/overriden behavior.

Issue #16561361  Make hasOverlappingRendering settable from outside/XML

Change-Id: If0fbc8667cdb82b1d85e795e782716a07196f3c0
parent f54aede6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -576,6 +576,7 @@ package android {
    field public static final int fontFamily = 16843692; // 0x10103ac
    field public static final int fontFeatureSettings = 16843959; // 0x10104b7
    field public static final int footerDividersEnabled = 16843311; // 0x101022f
    field public static final int forceHasOverlappingRendering = 16844068; // 0x1010524
    field public static final int foreground = 16843017; // 0x1010109
    field public static final int foregroundGravity = 16843264; // 0x1010200
    field public static final int foregroundTint = 16843885; // 0x101046d
@@ -42345,6 +42346,7 @@ package android.view {
    method public void findViewsWithText(java.util.ArrayList<android.view.View>, java.lang.CharSequence, int);
    method protected deprecated boolean fitSystemWindows(android.graphics.Rect);
    method public android.view.View focusSearch(int);
    method public void forceHasOverlappingRendering(boolean);
    method public void forceLayout();
    method public static int generateViewId();
    method public java.lang.CharSequence getAccessibilityClassName();
@@ -42390,6 +42392,7 @@ package android.view {
    method public boolean getGlobalVisibleRect(android.graphics.Rect, android.graphics.Point);
    method public final boolean getGlobalVisibleRect(android.graphics.Rect);
    method public android.os.Handler getHandler();
    method public final boolean getHasOverlappingRendering();
    method public final int getHeight();
    method public void getHitRect(android.graphics.Rect);
    method public int getHorizontalFadingEdgeLength();
@@ -66433,3 +66436,4 @@ package org.xmlpull.v1.sax2 {
  }
}
+4 −0
Original line number Diff line number Diff line
@@ -671,6 +671,7 @@ package android {
    field public static final int fontFamily = 16843692; // 0x10103ac
    field public static final int fontFeatureSettings = 16843959; // 0x10104b7
    field public static final int footerDividersEnabled = 16843311; // 0x101022f
    field public static final int forceHasOverlappingRendering = 16844068; // 0x1010524
    field public static final int foreground = 16843017; // 0x1010109
    field public static final int foregroundGravity = 16843264; // 0x1010200
    field public static final int foregroundTint = 16843885; // 0x101046d
@@ -45071,6 +45072,7 @@ package android.view {
    method public void findViewsWithText(java.util.ArrayList<android.view.View>, java.lang.CharSequence, int);
    method protected deprecated boolean fitSystemWindows(android.graphics.Rect);
    method public android.view.View focusSearch(int);
    method public void forceHasOverlappingRendering(boolean);
    method public void forceLayout();
    method public static int generateViewId();
    method public java.lang.CharSequence getAccessibilityClassName();
@@ -45116,6 +45118,7 @@ package android.view {
    method public boolean getGlobalVisibleRect(android.graphics.Rect, android.graphics.Point);
    method public final boolean getGlobalVisibleRect(android.graphics.Rect);
    method public android.os.Handler getHandler();
    method public final boolean getHasOverlappingRendering();
    method public final int getHeight();
    method public void getHitRect(android.graphics.Rect);
    method public int getHorizontalFadingEdgeLength();
@@ -69498,3 +69501,4 @@ package org.xmlpull.v1.sax2 {
  }
}
+4 −0
Original line number Diff line number Diff line
@@ -576,6 +576,7 @@ package android {
    field public static final int fontFamily = 16843692; // 0x10103ac
    field public static final int fontFeatureSettings = 16843959; // 0x10104b7
    field public static final int footerDividersEnabled = 16843311; // 0x101022f
    field public static final int forceHasOverlappingRendering = 16844068; // 0x1010524
    field public static final int foreground = 16843017; // 0x1010109
    field public static final int foregroundGravity = 16843264; // 0x1010200
    field public static final int foregroundTint = 16843885; // 0x101046d
@@ -42419,6 +42420,7 @@ package android.view {
    method public void findViewsWithText(java.util.ArrayList<android.view.View>, java.lang.CharSequence, int);
    method protected deprecated boolean fitSystemWindows(android.graphics.Rect);
    method public android.view.View focusSearch(int);
    method public void forceHasOverlappingRendering(boolean);
    method public void forceLayout();
    method public static int generateViewId();
    method public java.lang.CharSequence getAccessibilityClassName();
@@ -42464,6 +42466,7 @@ package android.view {
    method public boolean getGlobalVisibleRect(android.graphics.Rect, android.graphics.Point);
    method public final boolean getGlobalVisibleRect(android.graphics.Rect);
    method public android.os.Handler getHandler();
    method public final boolean getHasOverlappingRendering();
    method public final int getHeight();
    method public void getHitRect(android.graphics.Rect);
    method public int getHorizontalFadingEdgeLength();
@@ -66507,3 +66510,4 @@ package org.xmlpull.v1.sax2 {
  }
}
+68 −4
Original line number Diff line number Diff line
@@ -2429,7 +2429,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     *                     1             PFLAG3_SCROLL_INDICATOR_START
     *                    1              PFLAG3_SCROLL_INDICATOR_END
     *                   1               PFLAG3_ASSIST_BLOCKED
     *            1111111                PFLAG3_POINTER_ICON_MASK
     *                  1                PFLAG3_POINTER_ICON_NULL
     *                 1                 PFLAG3_POINTER_ICON_VALUE_START
     *           11111111                PFLAG3_POINTER_ICON_MASK
     *          1                        PFLAG3_OVERLAPPING_RENDERING_FORCED_VALUE
     *         1                         PFLAG3_HAS_OVERLAPPING_RENDERING_FORCED
     * |-------|-------|-------|-------|
     */
@@ -2518,8 +2522,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    static final int PFLAG3_SCROLL_INDICATOR_END = 0x2000;
    /* End of masks for mPrivateFlags3 */
    static final int DRAG_MASK = PFLAG2_DRAG_CAN_ACCEPT | PFLAG2_DRAG_HOVERED;
    static final int SCROLL_INDICATORS_NONE = 0x0000;
@@ -2650,6 +2652,23 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    private static final int PFLAG3_POINTER_ICON_VALUE_START = 2 << PFLAG3_POINTER_ICON_LSHIFT;
    /**
     * Whether this view has rendered elements that overlap (see {@link
     * #hasOverlappingRendering()}, {@link #forceHasOverlappingRendering(boolean)}, and
     * {@link #getHasOverlappingRendering()} ). The value in this bit is only valid when
     * PFLAG3_HAS_OVERLAPPING_RENDERING_FORCED has been set. Otherwise, the value is
     * determined by whatever {@link #hasOverlappingRendering()} returns.
     */
    private static final int PFLAG3_OVERLAPPING_RENDERING_FORCED_VALUE = 0x800000;
    /**
     * Whether {@link #forceHasOverlappingRendering(boolean)} has been called. When true, value
     * in PFLAG3_OVERLAPPING_RENDERING_FORCED_VALUE is valid.
     */
    private static final int PFLAG3_HAS_OVERLAPPING_RENDERING_FORCED = 0x1000000;
    /* End of masks for mPrivateFlags3 */
    /**
     * Always allow a user to over-scroll this view, provided it is a
     * view that can scroll.
@@ -4516,6 +4535,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                        }
                    }
                    break;
                case R.styleable.View_forceHasOverlappingRendering:
                    if (a.peekValue(attr) != null) {
                        forceHasOverlappingRendering(a.getBoolean(attr, true));
                    }
                    break;
            }
        }
@@ -12115,6 +12140,42 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1;
    }
    /**
     * Sets the behavior for overlapping rendering for this view (see {@link
     * #hasOverlappingRendering()} for more details on this behavior). Calling this method
     * is an alternative to overriding {@link #hasOverlappingRendering()} in a subclass,
     * providing the value which is then used internally. That is, when {@link
     * #forceHasOverlappingRendering(boolean)} is called, the value of {@link
     * #hasOverlappingRendering()} is ignored and the value passed into this method is used
     * instead.
     *
     * @param hasOverlappingRendering The value for overlapping rendering to be used internally
     * instead of that returned by {@link #hasOverlappingRendering()}.
     *
     * @attr ref android.R.styleable#View_forceHasOverlappingRendering
     */
    public void forceHasOverlappingRendering(boolean hasOverlappingRendering) {
        mPrivateFlags3 |= PFLAG3_HAS_OVERLAPPING_RENDERING_FORCED;
        if (hasOverlappingRendering) {
            mPrivateFlags3 |= PFLAG3_OVERLAPPING_RENDERING_FORCED_VALUE;
        } else {
            mPrivateFlags3 &= ~PFLAG3_OVERLAPPING_RENDERING_FORCED_VALUE;
        }
    }
    /**
     * Returns the value for overlapping rendering that is used internally. This is either
     * the value passed into {@link #forceHasOverlappingRendering(boolean)}, if called, or
     * the return value of {@link #hasOverlappingRendering()}, otherwise.
     *
     * @return The value for overlapping rendering being used internally.
     */
    public final boolean getHasOverlappingRendering() {
        return (mPrivateFlags3 & PFLAG3_HAS_OVERLAPPING_RENDERING_FORCED) != 0 ?
                (mPrivateFlags3 & PFLAG3_OVERLAPPING_RENDERING_FORCED_VALUE) != 0 :
                hasOverlappingRendering();
    }
    /**
     * Returns whether this View has content which overlaps.
     *
@@ -12131,6 +12192,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * necessitates that a View return true if it uses the methods internally without passing the
     * {@link Canvas#CLIP_TO_LAYER_SAVE_FLAG}.</p>
     *
     * <p><strong>Note:</strong> The return value of this method is ignored if {@link
     * #forceHasOverlappingRendering(boolean)} has been called on this view.</p>
     *
     * @return true if the content in this view might overlap, false otherwise.
     */
    @ViewDebug.ExportedProperty(category = "drawing")
@@ -16566,7 +16630,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    void setDisplayListProperties(RenderNode renderNode) {
        if (renderNode != null) {
            renderNode.setHasOverlappingRendering(hasOverlappingRendering());
            renderNode.setHasOverlappingRendering(getHasOverlappingRendering());
            renderNode.setClipToBounds(mParent instanceof ViewGroup
                    && ((ViewGroup) mParent).getClipChildren());
+5 −0
Original line number Diff line number Diff line
@@ -2846,6 +2846,11 @@ i
            <!-- Pointer icon of a hand sign while grabbing something. -->
            <enum name="grabbing" value="1021" />
        </attr>

        <!-- Whether this view has elements that may overlap when drawn. See
             {@link android.view.View#forceHasOverlappingRendering(boolean)}. -->
        <attr name="forceHasOverlappingRendering" format="boolean" />

    </declare-styleable>

    <!-- Attributes that can be assigned to a tag for a particular View. -->
Loading