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

Commit 5341cead authored by Romain Guy's avatar Romain Guy
Browse files

Cleanup 9patch mesh matching code

Bug #7970966

The bug described in #7970966 should normally never happen but just in
case, change the detection code to be more robust.

Change-Id: I7040a6087590e34abe8803cb8f83f051d77f3944
parent 16ad1770
Loading
Loading
Loading
Loading
+22 −23
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ Patch::Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQua
    // 2 triangles per patch, 3 vertices per triangle
    uint32_t maxVertices = ((xCount + 1) * (yCount + 1) - emptyQuads) * 2 * 3;
    mVertices = new TextureVertex[maxVertices];
    mUploaded = false;
    mAllocatedVerticesCount = 0;

    verticesCount = 0;
    hasEmptyQuads = emptyQuads > 0;
@@ -68,38 +68,37 @@ void Patch::copy(const int32_t* xDivs, const int32_t* yDivs) {
    memcpy(mYDivs, yDivs, mYCount * sizeof(int32_t));
}

void Patch::copy(const int32_t* yDivs) {
    memcpy(mYDivs, yDivs, mYCount * sizeof(int32_t));
}

void Patch::updateColorKey(const uint32_t colorKey) {
    mColorKey = colorKey;
}

bool Patch::matches(const int32_t* xDivs, const int32_t* yDivs, const uint32_t colorKey) {
bool Patch::matches(const int32_t* xDivs, const int32_t* yDivs,
        const uint32_t colorKey, const int8_t emptyQuads) {

    bool matches = true;

    if (mEmptyQuads != emptyQuads) {
        mEmptyQuads = emptyQuads;
        hasEmptyQuads = emptyQuads > 0;
        matches = false;
    }

    if (mColorKey != colorKey) {
        updateColorKey(colorKey);
        copy(xDivs, yDivs);
        return false;
        matches = false;
    }

    for (uint32_t i = 0; i < mXCount; i++) {
        if (mXDivs[i] != xDivs[i]) {
            // The Y divs may or may not match, copy everything
            copy(xDivs, yDivs);
            return false;
        }
    if (memcmp(mXDivs, xDivs, mXCount * sizeof(int32_t))) {
        memcpy(mXDivs, xDivs, mXCount * sizeof(int32_t));
        matches = false;
    }

    for (uint32_t i = 0; i < mYCount; i++) {
        if (mYDivs[i] != yDivs[i]) {
            // We know all the X divs match, copy only Y divs
            copy(yDivs);
            return false;
        }
    if (memcmp(mYDivs, yDivs, mYCount * sizeof(int32_t))) {
        memcpy(mYDivs, yDivs, mYCount * sizeof(int32_t));
        matches = false;
    }

    return true;
    return matches;
}

///////////////////////////////////////////////////////////////////////////////
@@ -203,10 +202,10 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
    if (verticesCount > 0) {
        Caches& caches = Caches::getInstance();
        caches.bindMeshBuffer(meshBuffer);
        if (!mUploaded) {
        if (mAllocatedVerticesCount < verticesCount) {
            glBufferData(GL_ARRAY_BUFFER, sizeof(TextureVertex) * verticesCount,
                    mVertices, GL_DYNAMIC_DRAW);
            mUploaded = true;
            mAllocatedVerticesCount = verticesCount;
        } else {
            glBufferSubData(GL_ARRAY_BUFFER, 0,
                    sizeof(TextureVertex) * verticesCount, mVertices);
+4 −5
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ namespace uirenderer {
 * indices to render the vertices.
 */
struct Patch {
    Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads = 0);
    Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads);
    ~Patch();

    void updateVertices(const float bitmapWidth, const float bitmapHeight,
@@ -53,7 +53,8 @@ struct Patch {

    void updateColorKey(const uint32_t colorKey);
    void copy(const int32_t* xDivs, const int32_t* yDivs);
    bool matches(const int32_t* xDivs, const int32_t* yDivs, const uint32_t colorKey);
    bool matches(const int32_t* xDivs, const int32_t* yDivs,
            const uint32_t colorKey, const int8_t emptyQuads);

    GLuint meshBuffer;
    uint32_t verticesCount;
@@ -62,7 +63,7 @@ struct Patch {

private:
    TextureVertex* mVertices;
    bool mUploaded;
    uint32_t mAllocatedVerticesCount;

    int32_t* mXDivs;
    int32_t* mYDivs;
@@ -72,8 +73,6 @@ private:
    uint32_t mYCount;
    int8_t mEmptyQuads;

    void copy(const int32_t* yDivs);

    void generateRow(TextureVertex*& vertex, float y1, float y2,
            float v1, float v2, float stretchX, float rescaleX,
            float width, float bitmapWidth, uint32_t& quadCount);
+1 −1
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ Patch* PatchCache::get(const float bitmapWidth, const float bitmapHeight,
        }

        mCache.add(description, mesh);
    } else if (!mesh->matches(xDivs, yDivs, colorKey)) {
    } else if (!mesh->matches(xDivs, yDivs, colorKey, transparentQuads)) {
        PATCH_LOGD("Patch mesh does not match, refreshing vertices");
        mesh->updateVertices(bitmapWidth, bitmapHeight, 0.0f, 0.0f, pixelWidth, pixelHeight);
    }
−2.8 KiB
Loading image diff...