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

Commit bee5e204 authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Add Canvas#drawColor(@ColorLong)

Bug: 120904891
Test: I857b8c1c9346285b2f6e4670c501c9d0d4053a0e

Change-Id: If08e8b805a4bba1a526efcd3cb05d4cd19f82eff
parent ffcf6e54
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -13766,8 +13766,10 @@ package android.graphics {
    method public void drawBitmapMesh(@NonNull android.graphics.Bitmap, int, int, @NonNull float[], int, @Nullable int[], int, @Nullable android.graphics.Paint);
    method public void drawCircle(float, float, float, @NonNull android.graphics.Paint);
    method public void drawColor(@ColorInt int);
    method public void drawColor(@ColorLong long);
    method @Deprecated public void drawColor(@ColorInt int, @NonNull android.graphics.PorterDuff.Mode);
    method public void drawColor(@ColorInt int, @NonNull android.graphics.BlendMode);
    method public void drawColor(@ColorLong long, @NonNull android.graphics.BlendMode);
    method public void drawDoubleRoundRect(@NonNull android.graphics.RectF, float, float, @NonNull android.graphics.RectF, float, float, @NonNull android.graphics.Paint);
    method public void drawDoubleRoundRect(@NonNull android.graphics.RectF, float[], @NonNull android.graphics.RectF, float[], @NonNull android.graphics.Paint);
    method public void drawLine(float, float, float, float, @NonNull android.graphics.Paint);
+13 −0
Original line number Diff line number Diff line
@@ -222,6 +222,18 @@ static void drawColor(JNIEnv* env, jobject, jlong canvasHandle, jint color, jint
    get_canvas(canvasHandle)->drawColor(color, mode);
}

static void drawColorLong(JNIEnv* env, jobject, jlong canvasHandle, jlong colorSpaceHandle,
        jlong colorLong, jint modeHandle) {
    SkColor4f color = GraphicsJNI::convertColorLong(colorLong);
    sk_sp<SkColorSpace> cs = GraphicsJNI::getNativeColorSpace(colorSpaceHandle);
    SkPaint p;
    p.setColor4f(color, cs.get());

    SkBlendMode mode = static_cast<SkBlendMode>(modeHandle);
    p.setBlendMode(mode);
    get_canvas(canvasHandle)->drawPaint(p);
}

static void drawPaint(JNIEnv* env, jobject, jlong canvasHandle, jlong paintHandle) {
    Paint* paint = reinterpret_cast<Paint*>(paintHandle);
    get_canvas(canvasHandle)->drawPaint(*paint);
@@ -677,6 +689,7 @@ static const JNINativeMethod gMethods[] = {
// If called from DisplayListCanvas they are @FastNative
static const JNINativeMethod gDrawMethods[] = {
    {"nDrawColor","(JII)V", (void*) CanvasJNI::drawColor},
    {"nDrawColor","(JJJI)V", (void*) CanvasJNI::drawColorLong},
    {"nDrawPaint","(JJ)V", (void*) CanvasJNI::drawPaint},
    {"nDrawPoint", "(JFFJ)V", (void*) CanvasJNI::drawPoint},
    {"nDrawPoints", "(J[FIIJ)V", (void*) CanvasJNI::drawPoints},
+14 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.graphics;

import android.annotation.ColorInt;
import android.annotation.ColorLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Size;
@@ -258,6 +259,16 @@ public abstract class BaseCanvas {
        nDrawColor(mNativeCanvasWrapper, color, mode.getXfermode().porterDuffMode);
    }

    /**
     * Make lint happy.
     * See {@link Canvas#drawColor(long, BlendMode)}
     */
    public void drawColor(@ColorLong long color, @NonNull BlendMode mode) {
        ColorSpace cs = Color.colorSpace(color);
        nDrawColor(mNativeCanvasWrapper, cs.getNativeInstance(), color,
                mode.getXfermode().porterDuffMode);
    }

    public void drawLine(float startX, float startY, float stopX, float stopY,
            @NonNull Paint paint) {
        throwIfHasHwBitmapInSwMode(paint);
@@ -669,6 +680,9 @@ public abstract class BaseCanvas {

    private static native void nDrawColor(long nativeCanvas, int color, int mode);

    private static native void nDrawColor(long nativeCanvas, long nativeColorSpace,
            @ColorLong long color, int mode);

    private static native void nDrawPaint(long nativeCanvas, long nativePaint);

    private static native void nDrawPoint(long canvasHandle, float x, float y, long paintHandle);
+12 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.graphics;

import android.annotation.ColorInt;
import android.annotation.ColorLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Size;
@@ -216,6 +217,13 @@ public class BaseRecordingCanvas extends Canvas {
        nDrawColor(mNativeCanvasWrapper, color, mode.getXfermode().porterDuffMode);
    }

    @Override
    public final void drawColor(@ColorLong long color, @NonNull BlendMode mode) {
        ColorSpace cs = Color.colorSpace(color);
        nDrawColor(mNativeCanvasWrapper, cs.getNativeInstance(), color,
                mode.getXfermode().porterDuffMode);
    }

    @Override
    public final void drawLine(float startX, float startY, float stopX, float stopY,
            @NonNull Paint paint) {
@@ -589,6 +597,10 @@ public class BaseRecordingCanvas extends Canvas {
    @FastNative
    private static native void nDrawColor(long nativeCanvas, int color, int mode);

    @FastNative
    private static native void nDrawColor(long nativeCanvas, long nativeColorSpace,
            @ColorLong long color, int mode);

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

+26 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.graphics;

import android.annotation.ColorInt;
import android.annotation.ColorLong;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -1681,6 +1682,18 @@ public class Canvas extends BaseCanvas {
        super.drawColor(color);
    }

    /**
     * Fill the entire canvas' bitmap (restricted to the current clip) with the specified color,
     * using srcover porterduff mode.
     *
     * @param color the color to draw onto the canvas
     * @throws IllegalArgumentException if the color space encoded in the long
     *                                  is invalid or unknown.
     */
    public void drawColor(@ColorLong long color) {
        super.drawColor(color, BlendMode.SRC_OVER);
    }

    /**
     * Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and
     * porter-duff xfermode.
@@ -1706,6 +1719,19 @@ public class Canvas extends BaseCanvas {
        super.drawColor(color, mode);
    }

    /**
     * Fill the entire canvas' bitmap (restricted to the current clip) with the specified color and
     * blendmode.
     *
     * @param color the color to draw with
     * @param mode the blendmode to apply to the color
     * @throws IllegalArgumentException if the color space encoded in the long
     *                                  is invalid or unknown.
     */
    public void drawColor(@ColorLong long color, @NonNull BlendMode mode) {
        super.drawColor(color, mode);
    }

    /**
     * Draw a line segment with the specified start and stop x,y coordinates, using the specified
     * paint.