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

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

Merge "(Small) 9patch drawing improvements"

parents d5540fb1 f296dca9
Loading
Loading
Loading
Loading
+18 −19
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ public class Canvas {
    protected int mScreenDensity = Bitmap.DENSITY_NONE;
    
    // Used by native code
    @SuppressWarnings("UnusedDeclaration")
    private int mSurfaceFormat;

    /**
@@ -1079,8 +1080,6 @@ public class Canvas {
    /**
     * Draws the specified bitmap as an N-patch (most often, a 9-patches.)
     *
     * Note: Only supported by hardware accelerated canvas at the moment.
     *
     * @param patch The ninepatch object to render
     * @param dst The destination rectangle.
     * @param paint The paint to draw the bitmap with. may be null
@@ -1088,13 +1087,12 @@ public class Canvas {
     * @hide
     */
    public void drawPatch(NinePatch patch, Rect dst, Paint paint) {
        patch.drawSoftware(this, dst, paint);
    }

    /**
     * Draws the specified bitmap as an N-patch (most often, a 9-patches.)
     *
     * Note: Only supported by hardware accelerated canvas at the moment.
     *
     * @param patch The ninepatch object to render
     * @param dst The destination rectangle.
     * @param paint The paint to draw the bitmap with. may be null
@@ -1102,6 +1100,7 @@ public class Canvas {
     * @hide
     */
    public void drawPatch(NinePatch patch, RectF dst, Paint paint) {
        patch.drawSoftware(this, dst, paint);
    }

    /**
+20 −24
Original line number Diff line number Diff line
@@ -100,14 +100,7 @@ public class NinePatch {
     * @param location  Where to draw the bitmap.
     */
    public void draw(Canvas canvas, RectF location) {
        if (canvas.isHardwareAccelerated()) {
        canvas.drawPatch(this, location, mPaint);
        } else {
            nativeDraw(canvas.mNativeCanvas, location,
                       mBitmap.ni(), mChunk,
                       mPaint != null ? mPaint.mNativePaint : 0,
                       canvas.mDensity, mBitmap.mDensity);
        }
    }

    /** 
@@ -117,14 +110,7 @@ public class NinePatch {
     * @param location  Where to draw the bitmap.
     */
    public void draw(Canvas canvas, Rect location) {
        if (canvas.isHardwareAccelerated()) {
        canvas.drawPatch(this, location, mPaint);
        } else {
            nativeDraw(canvas.mNativeCanvas, location,
                        mBitmap.ni(), mChunk,
                        mPaint != null ? mPaint.mNativePaint : 0,
                        canvas.mDensity, mBitmap.mDensity);
        }
    }

    /** 
@@ -135,13 +121,23 @@ public class NinePatch {
     * @param paint     The Paint to draw through.
     */
    public void draw(Canvas canvas, Rect location, Paint paint) {
        if (canvas.isHardwareAccelerated()) {
        canvas.drawPatch(this, location, paint);
        } else {
            nativeDraw(canvas.mNativeCanvas, location,
                    mBitmap.ni(), mChunk, paint != null ? paint.mNativePaint : 0,
                    canvas.mDensity, mBitmap.mDensity);
    }

    /**
     * @hide
     */
    void drawSoftware(Canvas canvas, RectF location, Paint paint) {
        nativeDraw(canvas.mNativeCanvas, location, mBitmap.ni(), mChunk,
                paint != null ? paint.mNativePaint : 0, canvas.mDensity, mBitmap.mDensity);
    }

    /**
     * @hide
     */
    void drawSoftware(Canvas canvas, Rect location, Paint paint) {
        nativeDraw(canvas.mNativeCanvas, location, mBitmap.ni(), mChunk,
                paint != null ? paint.mNativePaint : 0, canvas.mDensity, mBitmap.mDensity);
    }

    /**
+10 −2
Original line number Diff line number Diff line
@@ -79,8 +79,8 @@ TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeig
    uint32_t maxVertices = ((xCount + 1) * (yCount + 1) - emptyQuads) * 4;
    if (maxVertices == 0) return NULL;

    vertices = new TextureVertex[maxVertices];
    TextureVertex* vertex = vertices;
    TextureVertex* tempVertices = new TextureVertex[maxVertices];
    TextureVertex* vertex = tempVertices;

    const int32_t* xDivs = patch->xDivs;
    const int32_t* yDivs = patch->yDivs;
@@ -159,6 +159,14 @@ TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeig
                width, bitmapWidth, quadCount);
    }

    if (verticesCount == maxVertices) {
        vertices = tempVertices;
    } else {
        vertices = new TextureVertex[verticesCount];
        memcpy(vertices, tempVertices, verticesCount * sizeof(TextureVertex));
        delete[] tempVertices;
    }

    return vertices;
}