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

Commit 8820fd1d authored by Chris Craik's avatar Chris Craik
Browse files

Patch cleanup, reenable Patch Glops

bug:19597454

Change-Id: If12b95e83588b81a553210cd8c2437c6c771073a
parent a9761e69
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ GlopBuilder& GlopBuilder::setMeshPatchQuads(const Patch& patch) {
    mOutGlop->mesh.vertices = {
            mCaches.patchCache.getMeshBuffer(),
            VertexAttribFlags::kTextureCoord,
            (void*)patch.offset, (void*)patch.textureOffset, nullptr,
            (void*)patch.positionOffset, (void*)patch.textureOffset, nullptr,
            kTextureVertexStride };
    mOutGlop->mesh.elementCount = patch.indexCount;
    return *this;
@@ -518,6 +518,7 @@ GlopBuilder& GlopBuilder::setModelViewOffsetRectSnap(float offsetX, float offset
    }

    mOutGlop->transform.modelView.loadTranslate(offsetX, offsetY, 0.0f);
    mOutGlop->bounds = source;
    mOutGlop->bounds.translate(offsetX, offsetY);
    return *this;
}
+2 −2
Original line number Diff line number Diff line
@@ -2329,7 +2329,7 @@ void OpenGLRenderer::drawPatch(const SkBitmap* bitmap, const Patch* mesh,
    Texture* texture = entry ? entry->texture : mCaches.textureCache.get(bitmap);
    if (!texture) return;

    if (false) {
    if (USE_GLOPS) {
        // 9 patches are built for stretching - always filter
        int textureFillFlags = static_cast<int>(TextureFillFlags::kForceFilter);
        if (bitmap->colorType() == kAlpha_8_SkColorType) {
@@ -2384,7 +2384,7 @@ void OpenGLRenderer::drawPatch(const SkBitmap* bitmap, const Patch* mesh,
        ignoreTransform = true;
    }
    drawIndexedTextureMesh(left, top, right, bottom, texture->id, paint,
            texture->blend, (GLvoid*) mesh->offset, (GLvoid*) mesh->textureOffset,
            texture->blend, (GLvoid*) mesh->positionOffset, (GLvoid*) mesh->textureOffset,
            GL_TRIANGLES, mesh->indexCount, false, ignoreTransform,
            mCaches.patchCache.getMeshBuffer(), kModelViewMode_Translate, !mesh->hasEmptyQuads);

+9 −18
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include "Patch.h"
#include "Properties.h"
#include "UvMapper.h"
#include "utils/MathUtils.h"

namespace android {
namespace uirenderer {
@@ -36,19 +37,11 @@ uint32_t Patch::getSize() const {
    return verticesCount * sizeof(TextureVertex);
}

TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeight,
        float width, float height, const Res_png_9patch* patch) {
    UvMapper mapper;
    return createMesh(bitmapWidth, bitmapHeight, width, height, mapper, patch);
}

TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeight,
        float width, float height, const UvMapper& mapper, const Res_png_9patch* patch) {
    if (vertices) return vertices.get();
Patch::Patch(const float bitmapWidth, const float bitmapHeight,
        float width, float height, const UvMapper& mapper, const Res_png_9patch* patch)
        : mColors(patch->getColors()) {

    int8_t emptyQuads = 0;
    mColors = patch->getColors();

    const int8_t numColors = patch->numColors;
    if (uint8_t(numColors) < sizeof(uint32_t) * 4) {
        for (int8_t i = 0; i < numColors; i++) {
@@ -64,7 +57,7 @@ TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeig
    uint32_t yCount = patch->numYDivs;

    uint32_t maxVertices = ((xCount + 1) * (yCount + 1) - emptyQuads) * 4;
    if (maxVertices == 0) return nullptr;
    if (maxVertices == 0) return;

    vertices.reset(new TextureVertex[maxVertices]);
    TextureVertex* vertex = vertices.get();
@@ -151,8 +144,6 @@ TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeig
        memcpy(reducedVertices.get(), vertices.get(), verticesCount * sizeof(TextureVertex));
        vertices = std::move(reducedVertices);
    }

    return vertices.get();
}

void Patch::generateRow(const int32_t* xDivs, uint32_t xCount, TextureVertex*& vertex,
@@ -200,10 +191,10 @@ void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, f
    const uint32_t oldQuadCount = quadCount;
    quadCount++;

    if (x1 < 0.0f) x1 = 0.0f;
    if (x2 < 0.0f) x2 = 0.0f;
    if (y1 < 0.0f) y1 = 0.0f;
    if (y2 < 0.0f) y2 = 0.0f;
    x1 = MathUtils::max(x1, 0.0f);
    x2 = MathUtils::max(x2, 0.0f);
    y1 = MathUtils::max(y1, 0.0f);
    y2 = MathUtils::max(y2, 0.0f);

    // Skip degenerate and transparent (empty) quads
    if ((mColors[oldQuadCount] == 0) || x1 >= x2 || y1 >= y2) {
+5 −9
Original line number Diff line number Diff line
@@ -39,7 +39,9 @@ struct TextureVertex;

class Patch {
public:
    Patch() {}
    Patch(const float bitmapWidth, const float bitmapHeight,
            float width, float height,
            const UvMapper& mapper, const Res_png_9patch* patch);

    /**
     * Returns the size of this patch's mesh in bytes.
@@ -52,15 +54,9 @@ public:
    bool hasEmptyQuads = false;
    Vector<Rect> quads;

    Rect bounds;
    GLintptr offset = 0;
    GLintptr positionOffset = 0;
    GLintptr textureOffset = 0;

    TextureVertex* createMesh(const float bitmapWidth, const float bitmapHeight,
            float width, float height, const Res_png_9patch* patch);
    TextureVertex* createMesh(const float bitmapWidth, const float bitmapHeight,
            float width, float height, const UvMapper& mapper, const Res_png_9patch* patch);

private:
    void generateRow(const int32_t* xDivs, uint32_t xCount, TextureVertex*& vertex,
            float y1, float y2, float v1, float v2, float stretchX, float rescaleX,
@@ -68,7 +64,7 @@ private:
    void generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, float y2,
            float u1, float v1, float u2, float v2, uint32_t& quadCount);

    const uint32_t* mColors = nullptr;
    const uint32_t* mColors;
    UvMapper mUvMapper;
}; // struct Patch

+13 −19
Original line number Diff line number Diff line
@@ -162,7 +162,7 @@ void PatchCache::clearGarbage() {

        // Release the patch and mark the space in the free list
        Patch* patch = pair.getSecond();
        BufferBlock* block = new BufferBlock(patch->offset, patch->getSize());
        BufferBlock* block = new BufferBlock(patch->positionOffset, patch->getSize());
        block->next = mFreeBlocks;
        mFreeBlocks = block;

@@ -190,7 +190,7 @@ void PatchCache::createVertexBuffer() {
 * Sets the mesh's offsets and copies its associated vertices into
 * the mesh buffer (VBO).
 */
void PatchCache::setupMesh(Patch* newMesh, TextureVertex* vertices) {
void PatchCache::setupMesh(Patch* newMesh) {
    // This call ensures the VBO exists and that it is bound
    init();

@@ -223,9 +223,9 @@ void PatchCache::setupMesh(Patch* newMesh, TextureVertex* vertices) {
    }

    // Copy the 9patch mesh in the VBO
    newMesh->offset = (GLintptr) (block->offset);
    newMesh->textureOffset = newMesh->offset + kMeshTextureOffset;
    glBufferSubData(GL_ARRAY_BUFFER, newMesh->offset, size, vertices);
    newMesh->positionOffset = (GLintptr) (block->offset);
    newMesh->textureOffset = newMesh->positionOffset + kMeshTextureOffset;
    glBufferSubData(GL_ARRAY_BUFFER, newMesh->positionOffset, size, newMesh->vertices.get());

    // Remove the block since we've used it entirely
    if (block->size == size) {
@@ -244,6 +244,8 @@ void PatchCache::setupMesh(Patch* newMesh, TextureVertex* vertices) {
    mSize += size;
}

static const UvMapper sIdentity;

const Patch* PatchCache::get(const AssetAtlas::Entry* entry,
        const uint32_t bitmapWidth, const uint32_t bitmapHeight,
        const float pixelWidth, const float pixelHeight, const Res_png_9patch* patch) {
@@ -252,20 +254,12 @@ const Patch* PatchCache::get(const AssetAtlas::Entry* entry,
    const Patch* mesh = mCache.get(description);

    if (!mesh) {
        Patch* newMesh = new Patch();
        TextureVertex* vertices;

        if (entry) {
            // An atlas entry has a UV mapper
            vertices = newMesh->createMesh(bitmapWidth, bitmapHeight,
                    pixelWidth, pixelHeight, entry->uvMapper, patch);
        } else {
            vertices = newMesh->createMesh(bitmapWidth, bitmapHeight,
                    pixelWidth, pixelHeight, patch);
        }
        const UvMapper& mapper = entry ? entry->uvMapper : sIdentity;
        Patch* newMesh = new Patch(bitmapWidth, bitmapHeight,
                pixelWidth, pixelHeight, mapper, patch);

        if (vertices) {
            setupMesh(newMesh, vertices);
        if (newMesh->vertices) {
            setupMesh(newMesh);
        }

#if DEBUG_PATCHES
@@ -284,7 +278,7 @@ void PatchCache::dumpFreeBlocks(const char* prefix) {
    String8 dump;
    BufferBlock* block = mFreeBlocks;
    while (block) {
        dump.appendFormat("->(%d, %d)", block->offset, block->size);
        dump.appendFormat("->(%d, %d)", block->positionOffset, block->size);
        block = block->next;
    }
    ALOGD("%s: Free blocks%s", prefix, dump.string());
Loading