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

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

Merge "Support clipping in Canvas.drawBitmapMesh() Bug #7354162" into jb-mr1-dev

parents dc9e13b3 a92bb4dc
Loading
Loading
Loading
Loading
+25 −24
Original line number Original line Diff line number Diff line
@@ -1730,35 +1730,22 @@ status_t OpenGLRenderer::drawBitmapData(SkBitmap* bitmap, float left, float top,


status_t OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
status_t OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
        float* vertices, int* colors, SkPaint* paint) {
        float* vertices, int* colors, SkPaint* paint) {
    // TODO: Do a quickReject
    if (!vertices || mSnapshot->isIgnored()) {
    if (!vertices || mSnapshot->isIgnored()) {
        return DrawGlInfo::kStatusDone;
        return DrawGlInfo::kStatusDone;
    }
    }


    mCaches.activeTexture(0);
    // TODO: We should compute the bounding box when recording the display list
    Texture* texture = mCaches.textureCache.get(bitmap);
    if (!texture) return DrawGlInfo::kStatusDone;
    const AutoTexture autoCleanup(texture);

    texture->setWrap(GL_CLAMP_TO_EDGE, true);
    texture->setFilter(FILTER(paint), true);

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

    const uint32_t count = meshWidth * meshHeight * 6;

    float left = FLT_MAX;
    float left = FLT_MAX;
    float top = FLT_MAX;
    float top = FLT_MAX;
    float right = FLT_MIN;
    float right = FLT_MIN;
    float bottom = FLT_MIN;
    float bottom = FLT_MIN;


    const bool hasActiveLayer = hasLayer();
    const uint32_t count = meshWidth * meshHeight * 6;


    // TODO: Support the colors array
    // TODO: Support the colors array
    TextureVertex mesh[count];
    TextureVertex mesh[count];
    TextureVertex* vertex = mesh;
    TextureVertex* vertex = mesh;

    for (int32_t y = 0; y < meshHeight; y++) {
    for (int32_t y = 0; y < meshHeight; y++) {
        for (int32_t x = 0; x < meshWidth; x++) {
        for (int32_t x = 0; x < meshWidth; x++) {
            uint32_t i = (y * (meshWidth + 1) + x) * 2;
            uint32_t i = (y * (meshWidth + 1) + x) * 2;
@@ -1785,7 +1772,6 @@ status_t OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int mes
            TextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1);
            TextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1);
            TextureVertex::set(vertex++, vertices[dx], vertices[dy], u2, v2);
            TextureVertex::set(vertex++, vertices[dx], vertices[dy], u2, v2);


            if (hasActiveLayer) {
            // TODO: This could be optimized to avoid unnecessary ops
            // TODO: This could be optimized to avoid unnecessary ops
            left = fminf(left, fminf(vertices[ax], fminf(vertices[bx], vertices[cx])));
            left = fminf(left, fminf(vertices[ax], fminf(vertices[bx], vertices[cx])));
            top = fminf(top, fminf(vertices[ay], fminf(vertices[by], vertices[cy])));
            top = fminf(top, fminf(vertices[ay], fminf(vertices[by], vertices[cy])));
@@ -1793,9 +1779,24 @@ status_t OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int mes
            bottom = fmaxf(bottom, fmaxf(vertices[ay], fmaxf(vertices[by], vertices[cy])));
            bottom = fmaxf(bottom, fmaxf(vertices[ay], fmaxf(vertices[by], vertices[cy])));
        }
        }
    }
    }

    if (quickReject(left, top, right, bottom)) {
        return DrawGlInfo::kStatusDone;
    }
    }


    if (hasActiveLayer) {
    mCaches.activeTexture(0);
    Texture* texture = mCaches.textureCache.get(bitmap);
    if (!texture) return DrawGlInfo::kStatusDone;
    const AutoTexture autoCleanup(texture);

    texture->setWrap(GL_CLAMP_TO_EDGE, true);
    texture->setFilter(FILTER(paint), true);

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

    if (hasLayer()) {
        dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
        dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
    }
    }


+7 −0
Original line number Original line Diff line number Diff line
@@ -68,9 +68,16 @@ public class BitmapMeshActivity extends Activity {
            super.onDraw(canvas);
            super.onDraw(canvas);


            canvas.drawARGB(255, 255, 255, 255);
            canvas.drawARGB(255, 255, 255, 255);

            canvas.translate(100, 100);
            canvas.translate(100, 100);
            canvas.drawBitmapMesh(mBitmap1, 3, 3, mVertices, 0, null, 0, null);
            canvas.drawBitmapMesh(mBitmap1, 3, 3, mVertices, 0, null, 0, null);


            canvas.save();
            canvas.translate(0, 400);
            canvas.clipRect(0.0f, 0.0f, 80.0f, 80.0f);
            canvas.drawBitmapMesh(mBitmap1, 3, 3, mVertices, 0, null, 0, null);
            canvas.restore();

            canvas.translate(400, 0);
            canvas.translate(400, 0);
            canvas.drawBitmapMesh(mBitmap1, 3, 3, mVertices, 0, mColors, 0, null);
            canvas.drawBitmapMesh(mBitmap1, 3, 3, mVertices, 0, mColors, 0, null);
        }
        }