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

Commit d5d2b738 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Don't draw fully transparent views/primitives."

parents 02241ab2 dbc26d2b
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -24,6 +24,20 @@ import android.util.SparseArray;
 * Contains methods to standard constants used in the UI for timeouts, sizes, and distances.
 */
public class ViewConfiguration {
    /**
     * Expected bit depth of the display panel.
     * 
     * @hide
     */
    public static final float PANEL_BIT_DEPTH = 24;

    /**
     * Minimum alpha required for a view to draw.
     * 
     * @hide
     */
    public static final float ALPHA_THRESHOLD = 0.5f / PANEL_BIT_DEPTH;
    
    /**
     * Defines the width of the horizontal scrollbar and the height of the vertical scrollbar in
     * pixels
+6 −4
Original line number Diff line number Diff line
@@ -2186,6 +2186,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            return more;
        }
        
        float alpha = child.getAlpha();
        // Bail out early if the view does not need to be drawn
        if (alpha <= ViewConfiguration.ALPHA_THRESHOLD) return more;

        child.computeScroll();

        final int sx = child.mScrollX;
@@ -2217,8 +2221,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            }
        }

        float alpha = child.getAlpha();

        if (transformToApply != null || alpha < 1.0f || !child.hasIdentityMatrix()) {
            int transX = 0;
            int transY = 0;
+24 −2
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@ namespace uirenderer {
#define RAD_TO_DEG (180.0f / 3.14159265f)
#define MIN_ANGLE 0.001f

// TODO: This should be set in properties
#define ALPHA_THRESHOLD (0x7f / PANEL_BIT_DEPTH)

///////////////////////////////////////////////////////////////////////////////
// Globals
///////////////////////////////////////////////////////////////////////////////
@@ -294,7 +297,9 @@ int OpenGLRenderer::saveLayer(float left, float top, float right, float bottom,
        mode = SkXfermode::kSrcOver_Mode;
    }

    if (!mSnapshot->previous->invisible) {
        createLayer(mSnapshot, left, top, right, bottom, alpha, mode, flags, previousFbo);
    }

    return count;
}
@@ -380,6 +385,14 @@ bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,

    if (bounds.isEmpty() || bounds.getWidth() > mMaxTextureSize ||
            bounds.getHeight() > mMaxTextureSize) {
        snapshot->invisible = true;
    } else {
        // TODO: Should take the mode into account
        snapshot->invisible = snapshot->previous->invisible || alpha <= ALPHA_THRESHOLD;
    }

    // Bail out if we won't draw in this snapshot
    if (snapshot->invisible) {
        return false;
    }

@@ -536,7 +549,7 @@ void OpenGLRenderer::composeLayer(sp<Snapshot> current, sp<Snapshot> previous) {
}

void OpenGLRenderer::clearLayerRegions() {
    if (mLayers.size() == 0) return;
    if (mLayers.size() == 0 || mSnapshot->invisible) return;

    for (uint32_t i = 0; i < mLayers.size(); i++) {
        Rect* bounds = mLayers.itemAt(i);
@@ -598,6 +611,10 @@ const Rect& OpenGLRenderer::getClipBounds() {
}

bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) {
    if (mSnapshot->invisible) {
        return true;
    }

    Rect r(left, top, right, bottom);
    mSnapshot->transform->mapRect(r);
    return !mSnapshot->clipRect->intersects(r);
@@ -703,6 +720,8 @@ void OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int
}

void OpenGLRenderer::drawLines(float* points, int count, const SkPaint* paint) {
    if (mSnapshot->invisible) return;

    int alpha;
    SkXfermode::Mode mode;
    getAlphaAndMode(paint, &alpha, &mode);
@@ -802,6 +821,7 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
    if (text == NULL || count == 0 || (paint->getAlpha() == 0 && paint->getXfermode() == NULL)) {
        return;
    }
    if (mSnapshot->invisible) return;

    paint->setAntiAlias(true);

@@ -866,6 +886,8 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
}

void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
    if (mSnapshot->invisible) return;

    GLuint textureUnit = 0;
    glActiveTexture(gTextureUnits[textureUnit]);

+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ namespace uirenderer {
#endif

// TODO: This should be set in properties
#define PANEL_BIT_DEPTH 18
#define PANEL_BIT_DEPTH 20
#define COLOR_COMPONENT_THRESHOLD (1.0f - (0.5f / PANEL_BIT_DEPTH))
#define COLOR_COMPONENT_INV_THRESHOLD (0.5f / PANEL_BIT_DEPTH)

+9 −3
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ namespace uirenderer {
 */
class Snapshot: public LightRefBase<Snapshot> {
public:
    Snapshot(): flags(0), previous(NULL), layer(NULL), fbo(0) {
    Snapshot(): flags(0), previous(NULL), layer(NULL), fbo(0), invisible(false) {
        transform = &mTransformRoot;
        clipRect = &mClipRectRoot;
    }
@@ -53,8 +53,8 @@ public:
     * the previous snapshot.
     */
    Snapshot(const sp<Snapshot>& s, int saveFlags):
            flags(0), previous(s), layer(NULL),
            fbo(s->fbo), viewport(s->viewport), height(s->height) {
            flags(0), previous(s), layer(NULL), fbo(s->fbo),
            invisible(s->invisible), viewport(s->viewport), height(s->height) {
        if (saveFlags & SkCanvas::kMatrix_SaveFlag) {
            mTransformRoot.load(*s->transform);
            transform = &mTransformRoot;
@@ -211,6 +211,12 @@ public:
     */
    GLuint fbo;

    /**
     * Indicates that this snapshot is invisible and nothing should be drawn
     * inside it.
     */
    bool invisible;

    /**
     * Current viewport.
     */