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

Commit 947eabf4 authored by Chris Craik's avatar Chris Craik
Browse files

Early reject drawText calls that will not draw

bug:17114102

Prevents high contrast text from drawing invisible text.

Also fixes stroked text bounds calculation.

Change-Id: Iaeff51ead8b7b8ef2a1a0ca8b89598564e0d443f
parent 49e057d7
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -999,6 +999,8 @@ class DrawStrokableOp : public DrawBoundedOp {
public:
    DrawStrokableOp(float left, float top, float right, float bottom, const SkPaint* paint)
            : DrawBoundedOp(left, top, right, bottom, paint) {};
    DrawStrokableOp(const Rect& localBounds, const SkPaint* paint)
            : DrawBoundedOp(localBounds, paint) {};

    virtual bool getLocalBounds(Rect& localBounds) {
        localBounds.set(mLocalBounds);
@@ -1337,11 +1339,11 @@ private:
    const float* mPositions;
};

class DrawTextOp : public DrawBoundedOp {
class DrawTextOp : public DrawStrokableOp {
public:
    DrawTextOp(const char* text, int bytesCount, int count, float x, float y,
            const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds)
            : DrawBoundedOp(bounds, paint), mText(text), mBytesCount(bytesCount), mCount(count),
            : DrawStrokableOp(bounds, paint), mText(text), mBytesCount(bytesCount), mCount(count),
            mX(x), mY(y), mPositions(positions), mTotalAdvance(totalAdvance) {
        mPrecacheTransform = SkMatrix::InvalidMatrix();
    }
+1 −1
Original line number Diff line number Diff line
@@ -376,7 +376,7 @@ status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int cou
        float x, float y, const float* positions, const SkPaint* paint,
        float totalAdvance, const Rect& bounds, DrawOpMode drawOpMode) {

    if (!text || count <= 0) return DrawGlInfo::kStatusDone;
    if (!text || count <= 0 || paintWillNotDrawText(*paint)) return DrawGlInfo::kStatusDone;

    text = refText(text, bytesCount);
    positions = refBuffer<float>(positions, count * 2);
+15 −11
Original line number Diff line number Diff line
@@ -2518,8 +2518,9 @@ status_t OpenGLRenderer::drawShape(float left, float top, const PathTexture* tex

status_t OpenGLRenderer::drawRoundRect(float left, float top, float right, float bottom,
        float rx, float ry, const SkPaint* p) {
    if (currentSnapshot()->isIgnored() || quickRejectSetupScissor(left, top, right, bottom, p) ||
            (p->getAlpha() == 0 && getXfermode(p->getXfermode()) != SkXfermode::kClear_Mode)) {
    if (currentSnapshot()->isIgnored()
            || quickRejectSetupScissor(left, top, right, bottom, p)
            || paintWillNotDraw(*p)) {
        return DrawGlInfo::kStatusDone;
    }

@@ -2536,9 +2537,9 @@ status_t OpenGLRenderer::drawRoundRect(float left, float top, float right, float
}

status_t OpenGLRenderer::drawCircle(float x, float y, float radius, const SkPaint* p) {
    if (currentSnapshot()->isIgnored() || quickRejectSetupScissor(x - radius, y - radius,
            x + radius, y + radius, p) ||
            (p->getAlpha() == 0 && getXfermode(p->getXfermode()) != SkXfermode::kClear_Mode)) {
    if (currentSnapshot()->isIgnored()
            || quickRejectSetupScissor(x - radius, y - radius, x + radius, y + radius, p)
            || paintWillNotDraw(*p)) {
        return DrawGlInfo::kStatusDone;
    }
    if (p->getPathEffect() != 0) {
@@ -2558,8 +2559,9 @@ status_t OpenGLRenderer::drawCircle(float x, float y, float radius, const SkPain

status_t OpenGLRenderer::drawOval(float left, float top, float right, float bottom,
        const SkPaint* p) {
    if (currentSnapshot()->isIgnored() || quickRejectSetupScissor(left, top, right, bottom, p) ||
            (p->getAlpha() == 0 && getXfermode(p->getXfermode()) != SkXfermode::kClear_Mode)) {
    if (currentSnapshot()->isIgnored()
            || quickRejectSetupScissor(left, top, right, bottom, p)
            || paintWillNotDraw(*p)) {
        return DrawGlInfo::kStatusDone;
    }

@@ -2580,8 +2582,9 @@ status_t OpenGLRenderer::drawOval(float left, float top, float right, float bott

status_t OpenGLRenderer::drawArc(float left, float top, float right, float bottom,
        float startAngle, float sweepAngle, bool useCenter, const SkPaint* p) {
    if (currentSnapshot()->isIgnored() || quickRejectSetupScissor(left, top, right, bottom, p) ||
            (p->getAlpha() == 0 && getXfermode(p->getXfermode()) != SkXfermode::kClear_Mode)) {
    if (currentSnapshot()->isIgnored()
            || quickRejectSetupScissor(left, top, right, bottom, p)
            || paintWillNotDraw(*p)) {
        return DrawGlInfo::kStatusDone;
    }

@@ -2614,8 +2617,9 @@ status_t OpenGLRenderer::drawArc(float left, float top, float right, float botto

status_t OpenGLRenderer::drawRect(float left, float top, float right, float bottom,
        const SkPaint* p) {
    if (currentSnapshot()->isIgnored() || quickRejectSetupScissor(left, top, right, bottom, p) ||
            (p->getAlpha() == 0 && getXfermode(p->getXfermode()) != SkXfermode::kClear_Mode)) {
    if (currentSnapshot()->isIgnored()
            || quickRejectSetupScissor(left, top, right, bottom, p)
            || paintWillNotDraw(*p)) {
        return DrawGlInfo::kStatusDone;
    }

+12 −0
Original line number Diff line number Diff line
@@ -67,6 +67,18 @@ public:
        return resultMode;
    }

    // TODO: move to a method on android:Paint
    static inline bool paintWillNotDraw(const SkPaint& paint) {
        return paint.getAlpha() == 0
                && getXfermode(paint.getXfermode()) != SkXfermode::kClear_Mode;
    }

    // TODO: move to a method on android:Paint
    static inline bool paintWillNotDrawText(const SkPaint& paint) {
        return paint.getAlpha() == 0
                && paint.getLooper() == NULL
                && getXfermode(paint.getXfermode()) == SkXfermode::kSrcOver_Mode;
    }
// ----------------------------------------------------------------------------
// Frame state operations
// ----------------------------------------------------------------------------