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

Commit adfe1d99 authored by Nader Jawad's avatar Nader Jawad
Browse files

Added support for Canvas#drawDoubleRoundRect in application Canvas API

Exposed Skia's underlying drawDRRect method used to draw a double
rounded rectangle

Bug: 117181396
Test: Added test case to verify Canvas#drawDRRect and re-ran CanvasTests
Change-Id: I4e1954c8ffc82811dc541488d1df9b37309faf51
parent 2616b08d
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -13394,6 +13394,8 @@ package android.graphics {
    method public void drawCircle(float, float, float, android.graphics.Paint);
    method public void drawCircle(float, float, float, android.graphics.Paint);
    method public void drawColor(int);
    method public void drawColor(int);
    method public void drawColor(int, android.graphics.PorterDuff.Mode);
    method public void drawColor(int, android.graphics.PorterDuff.Mode);
    method public void drawDoubleRoundRect(android.graphics.RectF, float, float, android.graphics.RectF, float, float, android.graphics.Paint);
    method public void drawDoubleRoundRect(android.graphics.RectF, float[], android.graphics.RectF, float[], android.graphics.Paint);
    method public void drawLine(float, float, float, float, android.graphics.Paint);
    method public void drawLine(float, float, float, float, android.graphics.Paint);
    method public void drawLines(float[], int, int, android.graphics.Paint);
    method public void drawLines(float[], int, int, android.graphics.Paint);
    method public void drawLines(float[], android.graphics.Paint);
    method public void drawLines(float[], android.graphics.Paint);
+28 −0
Original line number Original line Diff line number Diff line
@@ -273,6 +273,32 @@ static void drawRect(JNIEnv* env, jobject, jlong canvasHandle, jfloat left, jflo
    get_canvas(canvasHandle)->drawRect(left, top, right, bottom, *paint);
    get_canvas(canvasHandle)->drawRect(left, top, right, bottom, *paint);
}
}


static void drawDoubleRoundRectXY(JNIEnv* env, jobject, jlong canvasHandle, jfloat outerLeft,
                    jfloat outerTop, jfloat outerRight, jfloat outerBottom, jfloat outerRx,
                    jfloat outerRy, jfloat innerLeft, jfloat innerTop, jfloat innerRight,
                    jfloat innerBottom, jfloat innerRx, jfloat innerRy, jlong paintHandle) {
    const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
    get_canvas(canvasHandle)->drawDoubleRoundRectXY(
                    outerLeft, outerTop, outerRight, outerBottom, outerRx, outerRy,
                    innerLeft, innerTop, innerRight, innerBottom, innerRx, innerRy, *paint);
}

static void drawDoubleRoundRectRadii(JNIEnv* env, jobject, jlong canvasHandle, jfloat outerLeft,
                     jfloat outerTop, jfloat outerRight, jfloat outerBottom, jfloatArray jouterRadii,
                     jfloat innerLeft, jfloat innerTop, jfloat innerRight,
                     jfloat innerBottom, jfloatArray jinnerRadii, jlong paintHandle) {
    const Paint* paint = reinterpret_cast<Paint*>(paintHandle);

    float outerRadii[8];
    float innerRadii[8];
    env->GetFloatArrayRegion(jouterRadii, 0, 8, outerRadii);
    env->GetFloatArrayRegion(jinnerRadii, 0, 8, innerRadii);
    get_canvas(canvasHandle)->drawDoubleRoundRectRadii(
                    outerLeft, outerTop, outerRight, outerBottom, outerRadii,
                    innerLeft, innerTop, innerRight, innerBottom, innerRadii, *paint);

}

static void drawRegion(JNIEnv* env, jobject, jlong canvasHandle, jlong regionHandle,
static void drawRegion(JNIEnv* env, jobject, jlong canvasHandle, jlong regionHandle,
                       jlong paintHandle) {
                       jlong paintHandle) {
    const SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
    const SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
@@ -651,6 +677,8 @@ static const JNINativeMethod gDrawMethods[] = {
    {"nDrawRect","(JFFFFJ)V", (void*) CanvasJNI::drawRect},
    {"nDrawRect","(JFFFFJ)V", (void*) CanvasJNI::drawRect},
    {"nDrawRegion", "(JJJ)V", (void*) CanvasJNI::drawRegion },
    {"nDrawRegion", "(JJJ)V", (void*) CanvasJNI::drawRegion },
    {"nDrawRoundRect","(JFFFFFFJ)V", (void*) CanvasJNI::drawRoundRect},
    {"nDrawRoundRect","(JFFFFFFJ)V", (void*) CanvasJNI::drawRoundRect},
    {"nDrawDoubleRoundRect", "(JFFFFFFFFFFFFJ)V", (void*) CanvasJNI::drawDoubleRoundRectXY},
    {"nDrawDoubleRoundRect", "(JFFFF[FFFFF[FJ)V", (void*) CanvasJNI::drawDoubleRoundRectRadii},
    {"nDrawCircle","(JFFFJ)V", (void*) CanvasJNI::drawCircle},
    {"nDrawCircle","(JFFFJ)V", (void*) CanvasJNI::drawCircle},
    {"nDrawOval","(JFFFFJ)V", (void*) CanvasJNI::drawOval},
    {"nDrawOval","(JFFFFJ)V", (void*) CanvasJNI::drawOval},
    {"nDrawArc","(JFFFFFFZJ)V", (void*) CanvasJNI::drawArc},
    {"nDrawArc","(JFFFFFFZJ)V", (void*) CanvasJNI::drawArc},
+57 −0
Original line number Original line Diff line number Diff line
@@ -376,6 +376,53 @@ public abstract class BaseCanvas {
        drawRoundRect(rect.left, rect.top, rect.right, rect.bottom, rx, ry, paint);
        drawRoundRect(rect.left, rect.top, rect.right, rect.bottom, rx, ry, paint);
    }
    }


    /**
     * Make lint happy.
     * See {@link Canvas#drawDoubleRoundRect(RectF, float, float, RectF, float, float, Paint)}
     */
    public void drawDoubleRoundRect(@NonNull RectF outer, float outerRx, float outerRy,
            @NonNull RectF inner, float innerRx, float innerRy, @NonNull Paint paint) {
        throwIfHasHwBitmapInSwMode(paint);
        float outerLeft = outer.left;
        float outerTop = outer.top;
        float outerRight = outer.right;
        float outerBottom = outer.bottom;

        float innerLeft = inner.left;
        float innerTop = inner.top;
        float innerRight = inner.right;
        float innerBottom = inner.bottom;
        nDrawDoubleRoundRect(mNativeCanvasWrapper, outerLeft, outerTop, outerRight, outerBottom,
                outerRx, outerRy, innerLeft, innerTop, innerRight, innerBottom, innerRx, innerRy,
                paint.getNativeInstance());
    }

    /**
     * Make lint happy.
     * See {@link Canvas#drawDoubleRoundRect(RectF, float[], RectF, float[], Paint)}
     */
    public void drawDoubleRoundRect(@NonNull RectF outer, float[] outerRadii,
            @NonNull RectF inner, float[] innerRadii, @NonNull Paint paint) {
        throwIfHasHwBitmapInSwMode(paint);
        if (innerRadii == null || outerRadii == null
                || innerRadii.length != 8 || outerRadii.length != 8) {
            throw new IllegalArgumentException("Both inner and outer radii arrays must contain "
                    + "exactly 8 values");
        }
        float outerLeft = outer.left;
        float outerTop = outer.top;
        float outerRight = outer.right;
        float outerBottom = outer.bottom;

        float innerLeft = inner.left;
        float innerTop = inner.top;
        float innerRight = inner.right;
        float innerBottom = inner.bottom;
        nDrawDoubleRoundRect(mNativeCanvasWrapper, outerLeft, outerTop, outerRight,
                outerBottom, outerRadii, innerLeft, innerTop, innerRight, innerBottom, innerRadii,
                paint.getNativeInstance());
    }

    public void drawText(@NonNull char[] text, int index, int count, float x, float y,
    public void drawText(@NonNull char[] text, int index, int count, float x, float y,
            @NonNull Paint paint) {
            @NonNull Paint paint) {
        if ((index | count | (index + count) |
        if ((index | count | (index + count) |
@@ -631,6 +678,16 @@ public abstract class BaseCanvas {
    private static native void nDrawRoundRect(long nativeCanvas, float left, float top, float right,
    private static native void nDrawRoundRect(long nativeCanvas, float left, float top, float right,
            float bottom, float rx, float ry, long nativePaint);
            float bottom, float rx, float ry, long nativePaint);


    private static native void nDrawDoubleRoundRect(long nativeCanvas, float outerLeft,
            float outerTop, float outerRight, float outerBottom, float outerRx, float outerRy,
            float innerLeft, float innerTop, float innerRight, float innerBottom, float innerRx,
            float innerRy, long nativePaint);

    private static native void nDrawDoubleRoundRect(long nativeCanvas, float outerLeft,
            float outerTop, float outerRight, float outerBottom, float[] outerRadii,
            float innerLeft, float innerTop, float innerRight, float innerBottom,
            float[] innerRadii, long nativePaint);

    private static native void nDrawPath(long nativeCanvas, long nativePath, long nativePaint);
    private static native void nDrawPath(long nativeCanvas, long nativePath, long nativePaint);


    private static native void nDrawRegion(long nativeCanvas, long nativeRegion, long nativePaint);
    private static native void nDrawRegion(long nativeCanvas, long nativeRegion, long nativePaint);
+30 −0
Original line number Original line Diff line number Diff line
@@ -376,6 +376,24 @@ public class BaseRecordingCanvas extends Canvas {
        drawRoundRect(rect.left, rect.top, rect.right, rect.bottom, rx, ry, paint);
        drawRoundRect(rect.left, rect.top, rect.right, rect.bottom, rx, ry, paint);
    }
    }


    @Override
    public final void drawDoubleRoundRect(@NonNull RectF outer, float outerRx, float outerRy,
            @NonNull RectF inner, float innerRx, float innerRy, @NonNull Paint paint) {
        nDrawDoubleRoundRect(mNativeCanvasWrapper,
                outer.left, outer.top, outer.right, outer.bottom, outerRx, outerRy,
                inner.left, inner.top, inner.right, inner.bottom, innerRx, innerRy,
                paint.getNativeInstance());
    }

    @Override
    public final void drawDoubleRoundRect(@NonNull RectF outer, float[] outerRadii,
            @NonNull RectF inner, float[] innerRadii, @NonNull Paint paint) {
        nDrawDoubleRoundRect(mNativeCanvasWrapper,
                outer.left, outer.top, outer.right, outer.bottom, outerRadii,
                inner.left, inner.top, inner.right, inner.bottom, innerRadii,
                paint.getNativeInstance());
    }

    @Override
    @Override
    public final void drawText(@NonNull char[] text, int index, int count, float x, float y,
    public final void drawText(@NonNull char[] text, int index, int count, float x, float y,
            @NonNull Paint paint) {
            @NonNull Paint paint) {
@@ -592,6 +610,18 @@ public class BaseRecordingCanvas extends Canvas {
    private static native void nDrawRoundRect(long nativeCanvas, float left, float top, float right,
    private static native void nDrawRoundRect(long nativeCanvas, float left, float top, float right,
            float bottom, float rx, float ry, long nativePaint);
            float bottom, float rx, float ry, long nativePaint);


    @FastNative
    private static native void nDrawDoubleRoundRect(long nativeCanvas,
            float outerLeft, float outerTop, float outerRight, float outerBottom,
            float outerRx, float outerRy, float innerLeft, float innerTop, float innerRight,
            float innerBottom, float innerRx, float innerRy, long nativePaint);

    @FastNative
    private static native void nDrawDoubleRoundRect(long nativeCanvas, float outerLeft,
            float outerTop, float outerRight, float outerBottom, float[] outerRadii,
            float innerLeft, float innerTop, float innerRight, float innerBottom,
            float[] innerRadii, long nativePaint);

    @FastNative
    @FastNative
    private static native void nDrawPath(long nativeCanvas, long nativePath, long nativePaint);
    private static native void nDrawPath(long nativeCanvas, long nativePath, long nativePaint);


+45 −0
Original line number Original line Diff line number Diff line
@@ -1876,6 +1876,51 @@ public class Canvas extends BaseCanvas {
        super.drawRoundRect(left, top, right, bottom, rx, ry, paint);
        super.drawRoundRect(left, top, right, bottom, rx, ry, paint);
    }
    }


    /**
     * Draws a double rounded rectangle using the specified paint. The resultant round rect
     * will be filled in the area defined between the outer and inner rectangular bounds if
     * the {@link Paint} configured with {@link Paint.Style#FILL}.
     * Otherwise if {@link Paint.Style#STROKE} is used, then 2 rounded rect strokes will
     * be drawn at the outer and inner rounded rectangles
     *
     * @param outer The outer rectangular bounds of the roundRect to be drawn
     * @param outerRx The x-radius of the oval used to round the corners on the outer rectangle
     * @param outerRy The y-radius of the oval used to round the corners on the outer rectangle
     * @param inner The inner rectangular bounds of the roundRect to be drawn
     * @param innerRx The x-radius of the oval used to round the corners on the inner rectangle
     * @param innerRy The y-radius of the oval used to round the corners on the outer rectangle
     * @param paint The paint used to draw the double roundRect
     */
    @Override
    public void drawDoubleRoundRect(@NonNull RectF outer, float outerRx, float outerRy,
            @NonNull RectF inner, float innerRx, float innerRy, @NonNull Paint paint) {
        super.drawDoubleRoundRect(outer, outerRx, outerRy, inner, innerRx, innerRy, paint);
    }

    /**
     * Draws a double rounded rectangle using the specified paint. The resultant round rect
     * will be filled in the area defined between the outer and inner rectangular bounds if
     * the {@link Paint} configured with {@link Paint.Style#FILL}.
     * Otherwise if {@link Paint.Style#STROKE} is used, then 2 rounded rect strokes will
     * be drawn at the outer and inner rounded rectangles
     *
     * @param outer The outer rectangular bounds of the roundRect to be drawn
     * @param outerRadii Array of 8 float representing the x, y corner radii for top left,
     *                   top right, bottom right, bottom left corners respectively on the outer
     *                   rounded rectangle
     *
     * @param inner The inner rectangular bounds of the roundRect to be drawn
     * @param innerRadii Array of 8 float representing the x, y corner radii for top left,
     *                   top right, bottom right, bottom left corners respectively on the
     *                   outer rounded rectangle
     * @param paint The paint used to draw the double roundRect
     */
    @Override
    public void drawDoubleRoundRect(@NonNull RectF outer, float[] outerRadii,
            @NonNull RectF inner, float[] innerRadii, @NonNull Paint paint) {
        super.drawDoubleRoundRect(outer, outerRadii, inner, innerRadii, paint);
    }

    /**
    /**
     * Draw the text, with origin at (x,y), using the specified paint. The origin is interpreted
     * Draw the text, with origin at (x,y), using the specified paint. The origin is interpreted
     * based on the Align setting in the paint.
     * based on the Align setting in the paint.
Loading