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

Commit 3bb02a34 authored by Romain Guy's avatar Romain Guy Committed by Android Git Automerger
Browse files

am 38a64240: Merge "Allow 9patches to shrink Bug #7307304" into jb-mr1-dev

* commit '38a64240':
  Allow 9patches to shrink Bug #7307304
parents 7e466e89 38a64240
Loading
Loading
Loading
Loading
+15 −9
Original line number Original line 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;
    const uint32_t yStretchCount = (mYCount + 1) >> 1;


    float stretchX = 0.0f;
    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;
    const float meshWidth = right - left;


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


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


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


        float vOffset = y1 == y2 ? 0.0f : 0.5 - (0.5 * segment / (y2 - y1));
        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;
            y1 += i * EXPLODE_GAP;
            y2 += i * EXPLODE_GAP;
            y2 += i * EXPLODE_GAP;
#endif
#endif
            generateRow(vertex, y1, y2, v1, v2, stretchX, right - left,
            generateRow(vertex, y1, y2, v1, v2, stretchX, rescaleX, right - left,
                    bitmapWidth, quadCount);
                    bitmapWidth, quadCount);
#if DEBUG_EXPLODE_PATCHES
#if DEBUG_EXPLODE_PATCHES
            y2 -= i * EXPLODE_GAP;
            y2 -= i * EXPLODE_GAP;
@@ -191,7 +196,8 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
        y1 += mYCount * EXPLODE_GAP;
        y1 += mYCount * EXPLODE_GAP;
        y2 += mYCount * EXPLODE_GAP;
        y2 += mYCount * EXPLODE_GAP;
#endif
#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) {
    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,
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 previousStepX = 0.0f;


    float x1 = 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) {
        if (i & 1) {
            x2 = x1 + floorf(segment * stretchX + 0.5f);
            x2 = x1 + floorf(segment * stretchX + 0.5f);
        } else {
        } else {
            x2 = x1 + segment;
            x2 = x1 + segment * rescaleX;
        }
        }


        float uOffset = x1 == x2 ? 0.0f : 0.5 - (0.5 * segment / (x2 - x1));
        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;
    if (y2 < 0.0f) y2 = 0.0f;


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


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