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

Commit be6f9dc1 authored by Romain Guy's avatar Romain Guy
Browse files

Don't copy paints for 9patches

Change-Id: I863100a0dc53fec1a3a1b2acbdeb76e6049ffe58
parent ef863701
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -486,7 +486,8 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
                float top = getFloat();
                float right = getFloat();
                float bottom = getFloat();
                SkPaint* paint = getPaint(renderer);
                int alpha = getInt();
                SkXfermode::Mode mode = (SkXfermode::Mode) getInt();
                ALOGD("%s%s %.2f, %.2f, %.2f, %.2f", (char*) indent, OP_NAMES[op],
                        left, top, right, bottom);
            }
@@ -1089,11 +1090,14 @@ status_t DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flag
                float top = getFloat();
                float right = getFloat();
                float bottom = getFloat();
                SkPaint* paint = getPaint(renderer);

                int alpha = getInt();
                SkXfermode::Mode mode = (SkXfermode::Mode) getInt();

                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
                drawGlStatus |= renderer.drawPatch(bitmap, xDivs, yDivs, colors,
                        xDivsCount, yDivsCount, numColors, left, top, right, bottom, paint);
                        xDivsCount, yDivsCount, numColors, left, top, right, bottom,
                        alpha, mode);
            }
            break;
            case DrawColor: {
@@ -1570,6 +1574,10 @@ status_t DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, in
status_t DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs,
        const int32_t* yDivs, const uint32_t* colors, uint32_t width, uint32_t height,
        int8_t numColors, float left, float top, float right, float bottom, SkPaint* paint) {
    int alpha;
    SkXfermode::Mode mode;
    OpenGLRenderer::getAlphaAndModeDirect(paint, &alpha, &mode);

    const bool reject = quickReject(left, top, right, bottom);
    uint32_t* location = addOp(DisplayList::DrawPatch, reject);
    addBitmap(bitmap);
@@ -1577,7 +1585,8 @@ status_t DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs,
    addInts(yDivs, height);
    addUInts(colors, numColors);
    addBounds(left, top, right, bottom);
    addPaint(paint);
    addInt(alpha);
    addInt(mode);
    addSkip(location);
    return DrawGlInfo::kStatusDone;
}
+14 −26
Original line number Diff line number Diff line
@@ -1677,10 +1677,23 @@ status_t OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
status_t OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
        const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
        float left, float top, float right, float bottom, SkPaint* paint) {
    int alpha;
    SkXfermode::Mode mode;
    getAlphaAndModeDirect(paint, &alpha, &mode);

    return drawPatch(bitmap, xDivs, yDivs, colors, width, height, numColors,
            left, top, right, bottom, alpha, mode);
}

status_t OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
        const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
        float left, float top, float right, float bottom, int alpha, SkXfermode::Mode mode) {
    if (quickReject(left, top, right, bottom)) {
        return DrawGlInfo::kStatusDone;
    }

    alpha *= mSnapshot->alpha;

    mCaches.activeTexture(0);
    Texture* texture = mCaches.textureCache.get(bitmap);
    if (!texture) return DrawGlInfo::kStatusDone;
@@ -1688,10 +1701,6 @@ status_t OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const
    texture->setWrap(GL_CLAMP_TO_EDGE, true);
    texture->setFilter(GL_LINEAR, true);

    int alpha;
    SkXfermode::Mode mode;
    getAlphaAndMode(paint, &alpha, &mode);

    const Patch* mesh = mCaches.patchCache.get(bitmap->width(), bitmap->height(),
            right - left, bottom - top, xDivs, yDivs, colors, width, height, numColors);

@@ -2921,30 +2930,9 @@ void OpenGLRenderer::resetDrawTextureTexCoords(float u1, float v1, float u2, flo
}

void OpenGLRenderer::getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
    if (paint) {
        *mode = getXfermode(paint->getXfermode());

        // Skia draws using the color's alpha channel if < 255
        // Otherwise, it uses the paint's alpha
        int color = paint->getColor();
        *alpha = (color >> 24) & 0xFF;
        if (*alpha == 255) {
            *alpha = paint->getAlpha();
        }
    } else {
        *mode = SkXfermode::kSrcOver_Mode;
        *alpha = 255;
    }
    getAlphaAndModeDirect(paint, alpha,  mode);
    *alpha *= mSnapshot->alpha;
}

SkXfermode::Mode OpenGLRenderer::getXfermode(SkXfermode* mode) {
    SkXfermode::Mode resultMode;
    if (!SkXfermode::AsMode(mode, &resultMode)) {
        resultMode = SkXfermode::kSrcOver_Mode;
    }
    return resultMode;
}

}; // namespace uirenderer
}; // namespace android
+51 −16
Original line number Diff line number Diff line
@@ -123,6 +123,9 @@ public:
    virtual status_t drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
            const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
            float left, float top, float right, float bottom, SkPaint* paint);
    status_t drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
            const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
            float left, float top, float right, float bottom, int alpha, SkXfermode::Mode mode);
    virtual status_t drawColor(int color, SkXfermode::Mode mode);
    virtual status_t drawRect(float left, float top, float right, float bottom, SkPaint* paint);
    virtual status_t drawRoundRect(float left, float top, float right, float bottom,
@@ -213,6 +216,54 @@ protected:
     */
    void drawTextureLayer(Layer* layer, const Rect& rect);

    /**
     * Gets the alpha and xfermode out of a paint object. If the paint is null
     * alpha will be 255 and the xfermode will be SRC_OVER.
     *
     * @param paint The paint to extract values from
     * @param alpha Where to store the resulting alpha
     * @param mode Where to store the resulting xfermode
     */
    inline void getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode);

    /**
     * Gets the alpha and xfermode out of a paint object. If the paint is null
     * alpha will be 255 and the xfermode will be SRC_OVER. This method does
     * not multiply the paint's alpha by the current snapshot's alpha.
     *
     * @param paint The paint to extract values from
     * @param alpha Where to store the resulting alpha
     * @param mode Where to store the resulting xfermode
     */
    static inline void getAlphaAndModeDirect(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
        if (paint) {
            *mode = getXfermode(paint->getXfermode());

            // Skia draws using the color's alpha channel if < 255
            // Otherwise, it uses the paint's alpha
            int color = paint->getColor();
            *alpha = (color >> 24) & 0xFF;
            if (*alpha == 255) {
                *alpha = paint->getAlpha();
            }
        } else {
            *mode = SkXfermode::kSrcOver_Mode;
            *alpha = 255;
        }
    }

    /**
     * Safely retrieves the mode from the specified xfermode. If the specified
     * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode.
     */
    static inline SkXfermode::Mode getXfermode(SkXfermode* mode) {
        SkXfermode::Mode resultMode;
        if (!SkXfermode::AsMode(mode, &resultMode)) {
            resultMode = SkXfermode::kSrcOver_Mode;
        }
        return resultMode;
    }

private:
    /**
     * Ensures the state of the renderer is the same as the state of
@@ -470,16 +521,6 @@ private:
     */
    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);

    /**
     * Gets the alpha and xfermode out of a paint object. If the paint is null
     * alpha will be 255 and the xfermode will be SRC_OVER.
     *
     * @param paint The paint to extract values from
     * @param alpha Where to store the resulting alpha
     * @param mode Where to store the resulting xfermode
     */
    inline void getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode);

    /**
     * Binds the specified texture. The texture unit must have been selected
     * prior to calling this method.
@@ -503,12 +544,6 @@ private:
    inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description,
            bool swapSrcDst = false);

    /**
     * Safely retrieves the mode from the specified xfermode. If the specified
     * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode.
     */
    inline SkXfermode::Mode getXfermode(SkXfermode* mode);

    /**
     * Use the specified program with the current GL context. If the program is already
     * in use, it will not be bound again. If it is not in use, the current program is