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

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

Merge "Allow 9patches to shrink Bug #7307304" into jb-mr1-dev

parents bcfc1ca8 41d35aef
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -118,7 +118,10 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
    const uint32_t yStretchCount = (mYCount + 1) >> 1;

    float stretchX = 0.0f;
    float stretchY = 0.0;
    float stretchY = 0.0f;

    float rescaleX = 1.0f;
    float rescaleY = 1.0f;

    const float meshWidth = right - left;

@@ -129,8 +132,9 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
        }
        const float xStretchTex = stretchSize;
        const float fixed = bitmapWidth - stretchSize;
        const float xStretch = right - left - fixed;
        const float xStretch = fmaxf(right - left - fixed, 0.0f);
        stretchX = xStretch / xStretchTex;
        rescaleX = fminf(fmaxf(right - left, 0.0f) / fixed, 1.0f);
    }

    if (yStretchCount > 0) {
@@ -140,8 +144,9 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
        }
        const float yStretchTex = stretchSize;
        const float fixed = bitmapHeight - stretchSize;
        const float yStretch = bottom - top - fixed;
        const float yStretch = fmaxf(bottom - top - fixed, 0.0f);
        stretchY = yStretch / yStretchTex;
        rescaleY = fminf(fmaxf(bottom - top, 0.0f) / fixed, 1.0f);
    }

    TextureVertex* vertex = mVertices;
@@ -160,7 +165,7 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
        if (i & 1) {
            y2 = y1 + floorf(segment * stretchY + 0.5f);
        } else {
            y2 = y1 + segment;
            y2 = y1 + segment * rescaleY;
        }

        float vOffset = y1 == y2 ? 0.0f : 0.5 - (0.5 * segment / (y2 - y1));
@@ -172,7 +177,7 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
            y1 += i * EXPLODE_GAP;
            y2 += i * EXPLODE_GAP;
#endif
            generateRow(vertex, y1, y2, v1, v2, stretchX, right - left,
            generateRow(vertex, y1, y2, v1, v2, stretchX, rescaleX, right - left,
                    bitmapWidth, quadCount);
#if DEBUG_EXPLODE_PATCHES
            y2 -= i * EXPLODE_GAP;
@@ -191,7 +196,8 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
        y1 += mYCount * EXPLODE_GAP;
        y2 += mYCount * EXPLODE_GAP;
#endif
        generateRow(vertex, y1, y2, v1, 1.0f, stretchX, right - left, bitmapWidth, quadCount);
        generateRow(vertex, y1, y2, v1, 1.0f, stretchX, rescaleX, right - left,
                bitmapWidth, quadCount);
    }

    if (verticesCount > 0) {
@@ -212,7 +218,7 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
}

void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, float v2,
        float stretchX, float width, float bitmapWidth, uint32_t& quadCount) {
        float stretchX, float rescaleX, float width, float bitmapWidth, uint32_t& quadCount) {
    float previousStepX = 0.0f;

    float x1 = 0.0f;
@@ -227,7 +233,7 @@ void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, fl
        if (i & 1) {
            x2 = x1 + floorf(segment * stretchX + 0.5f);
        } else {
            x2 = x1 + segment;
            x2 = x1 + segment * rescaleX;
        }

        float uOffset = x1 == x2 ? 0.0f : 0.5 - (0.5 * segment / (x2 - x1));
@@ -272,7 +278,7 @@ void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, f
    if (y2 < 0.0f) y2 = 0.0f;

    // Skip degenerate and transparent (empty) quads
    if ((mColorKey >> oldQuadCount) & 0x1) {
    if (((mColorKey >> oldQuadCount) & 0x1) || x1 >= x2 || y1 >= y2) {
#if DEBUG_PATCHES_EMPTY_VERTICES
        PATCH_LOGD("    quad %d (empty)", oldQuadCount);
        PATCH_LOGD("        left,  top    = %.2f, %.2f\t\tu1, v1 = %.4f, %.4f", x1, y1, u1, v1);
+2 −2
Original line number Diff line number Diff line
@@ -75,8 +75,8 @@ private:
    void copy(const int32_t* yDivs);

    void generateRow(TextureVertex*& vertex, float y1, float y2,
            float v1, float v2, float stretchX, float width, float bitmapWidth,
            uint32_t& quadCount);
            float v1, float v2, float stretchX, float rescaleX,
            float width, float bitmapWidth, uint32_t& quadCount);
    void generateQuad(TextureVertex*& vertex,
            float x1, float y1, float x2, float y2,
            float u1, float v1, float u2, float v2,