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

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

Merge "Optimize 9patch rendering."

parents b8203e97 4bb94208
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -257,8 +257,9 @@ static void android_view_GLES20Canvas_drawPatch(JNIEnv* env, jobject canvas,
    Res_png_9patch* patch = reinterpret_cast<Res_png_9patch*>(storage);
    Res_png_9patch::deserialize(patch);

    renderer->drawPatch(bitmap, &patch->xDivs[0], &patch->yDivs[0],
            patch->numXDivs, patch->numYDivs, left, top, right, bottom, paint);
    renderer->drawPatch(bitmap, &patch->xDivs[0], &patch->yDivs[0], &patch->colors[0],
            patch->numXDivs, patch->numYDivs, patch->numColors,
            left, top, right, bottom, paint);

    env->ReleaseByteArrayElements(chunks, storage, 0);
}
+2 −2
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ public class NinePatch {
                       mPaint != null ? mPaint.mNativePaint : 0,
                       canvas.mDensity, mBitmap.mDensity);
        } else {
            canvas.drawPatch(mBitmap, mChunk, location, null);
            canvas.drawPatch(mBitmap, mChunk, location, mPaint);
        }
    }
    
@@ -104,7 +104,7 @@ public class NinePatch {
                        canvas.mDensity, mBitmap.mDensity);
        } else {
            mRect.set(location);
            canvas.drawPatch(mBitmap, mChunk, mRect, null);
            canvas.drawPatch(mBitmap, mChunk, mRect, mPaint);
        }
    }

+8 −4
Original line number Diff line number Diff line
@@ -236,16 +236,19 @@ void DisplayList::replay(OpenGLRenderer& renderer) {
            case DrawPatch: {
                int32_t* xDivs = NULL;
                int32_t* yDivs = NULL;
                uint32_t* colors = NULL;
                uint32_t xDivsCount = 0;
                uint32_t yDivsCount = 0;
                int8_t numColors = 0;

                SkBitmap* bitmap = getBitmap();

                xDivs = getInts(xDivsCount);
                yDivs = getInts(yDivsCount);
                colors = getUInts(numColors);

                renderer.drawPatch(bitmap, xDivs, yDivs, xDivsCount, yDivsCount,
                        getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
                renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount,
                        numColors, getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
            }
            break;
            case DrawColor: {
@@ -450,12 +453,13 @@ void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcT
}

void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
        uint32_t width, uint32_t height, float left, float top, float right, float bottom,
        const SkPaint* paint) {
        const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
        float left, float top, float right, float bottom, const SkPaint* paint) {
    addOp(DisplayList::DrawPatch);
    addBitmap(bitmap);
    addInts(xDivs, width);
    addInts(yDivs, height);
    addUInts(colors, numColors);
    addBounds(left, top, right, bottom);
    addPaint(paint);
}
+14 −2
Original line number Diff line number Diff line
@@ -169,6 +169,11 @@ private:
        return (int32_t*) mReader.skip(count * sizeof(int32_t));
    }

    uint32_t* getUInts(int8_t& count) {
        count = getInt();
        return (uint32_t*) mReader.skip(count * sizeof(uint32_t));
    }

    float* getFloats(int& count) {
        count = getInt();
        return (float*) mReader.skip(count * sizeof(float));
@@ -236,8 +241,8 @@ public:
            float srcRight, float srcBottom, float dstLeft, float dstTop,
            float dstRight, float dstBottom, const SkPaint* paint);
    void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
            uint32_t width, uint32_t height, float left, float top, float right, float bottom,
            const SkPaint* paint);
            const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
            float left, float top, float right, float bottom, const SkPaint* paint);
    void drawColor(int color, SkXfermode::Mode mode);
    void drawRect(float left, float top, float right, float bottom, const SkPaint* paint);
    void drawPath(SkPath* path, SkPaint* paint);
@@ -291,6 +296,13 @@ private:
        }
    }

    void addUInts(const uint32_t* values, int8_t count) {
        mWriter.writeInt(count);
        for (int8_t i = 0; i < count; i++) {
            mWriter.writeInt(values[i]);
        }
    }

    inline void addFloat(float value) {
        mWriter.writeScalar(value);
    }
+1 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@

#include <SkMatrix.h>

#include "utils/Compare.h"
#include "Matrix.h"

namespace android {
@@ -53,9 +54,6 @@ void Matrix4::loadIdentity() {
    mSimpleMatrix = true;
}

#define EPSILON 0.00001f
#define almost(u, v) (fabs((u) - (v)) < EPSILON)

bool Matrix4::changesBounds() {
    return !(almost(data[0], 1.0f) && almost(data[1], 0.0f) && almost(data[2], 0.0f) &&
             almost(data[4], 0.0f) && almost(data[5], 1.0f) && almost(data[6], 0.0f) &&
Loading