[androidkit] introduce clipping to java Canvas
clipPath(), clipRect(), clipRRect(), clipShader() Change-Id: Iee2571c6ab7c3f8cdfbfc4df223fd59d307b5c62 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/420880 Commit-Queue: Jorge Betancourt <jmbetancourt@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
This commit is contained in:
parent
d0eb770756
commit
0ce582790a
@ -8,6 +8,8 @@
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkColor.h"
|
||||
#include "include/core/SkPaint.h"
|
||||
#include "include/core/SkRRect.h"
|
||||
#include "include/core/SkShader.h"
|
||||
#include "modules/androidkit/src/Utils.h"
|
||||
|
||||
#include <jni.h>
|
||||
@ -91,6 +93,39 @@ void Canvas_Scale(JNIEnv* env, jobject, jlong native_instance, jfloat sx, jfloat
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas_ClipPath(JNIEnv* env, jobject, jlong native_instance, jlong native_path,
|
||||
jint native_clipOp, jboolean doAA) {
|
||||
if (auto* canvas = reinterpret_cast<SkCanvas*>(native_instance)) {
|
||||
if (auto* path = reinterpret_cast<SkPath*>(native_path)) {
|
||||
canvas->clipPath(*path, static_cast<SkClipOp>(native_clipOp), doAA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas_ClipRect(JNIEnv* env, jobject, jlong native_instance, jfloat l, jfloat t, jfloat r, jfloat b,
|
||||
jint native_clipOp, jboolean doAA) {
|
||||
if (auto* canvas = reinterpret_cast<SkCanvas*>(native_instance)) {
|
||||
canvas->clipRect(SkRect::MakeLTRB(l, t, r, b), static_cast<SkClipOp>(native_clipOp), doAA);
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas_ClipRRect(JNIEnv* env, jobject, jlong native_instance, jfloat l, jfloat t, jfloat r, jfloat b,
|
||||
jfloat xRad, jfloat yRad,
|
||||
jint native_clipOp, jboolean doAA) {
|
||||
if (auto* canvas = reinterpret_cast<SkCanvas*>(native_instance)) {
|
||||
canvas->clipRRect(SkRRect::MakeRectXY(SkRect::MakeLTRB(l, t, r, b), xRad, yRad),
|
||||
static_cast<SkClipOp>(native_clipOp), doAA);
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas_ClipShader(JNIEnv* env, jobject, jlong native_instance, jlong native_shader, jint native_clipOp) {
|
||||
if (auto* canvas = reinterpret_cast<SkCanvas*>(native_instance)) {
|
||||
if (auto* shader = reinterpret_cast<SkShader*>(native_shader)) {
|
||||
canvas->clipShader(sk_ref_sp(shader), static_cast<SkClipOp>(native_clipOp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas_DrawColor(JNIEnv* env, jobject, jlong native_instance,
|
||||
float r, float g, float b, float a) {
|
||||
if (auto* canvas = reinterpret_cast<SkCanvas*>(native_instance)) {
|
||||
@ -134,21 +169,25 @@ void Canvas_DrawPath(JNIEnv* env, jobject, jlong native_instance, jlong native_p
|
||||
|
||||
int register_androidkit_Canvas(JNIEnv* env) {
|
||||
static const JNINativeMethod methods[] = {
|
||||
{"nGetWidth" , "(J)I" , reinterpret_cast<void*>(Canvas_GetWidth) },
|
||||
{"nGetHeight" , "(J)I" , reinterpret_cast<void*>(Canvas_GetHeight) },
|
||||
{"nSave" , "(J)I" , reinterpret_cast<void*>(Canvas_Save) },
|
||||
{"nSaveLayer" , "(JJ)I" , reinterpret_cast<void*>(Canvas_SaveLayer) },
|
||||
{"nRestore" , "(J)V" , reinterpret_cast<void*>(Canvas_Restore) },
|
||||
{"nRestoreToCount" , "(JI)V" , reinterpret_cast<void*>(Canvas_RestoreToCount)},
|
||||
{"nGetLocalToDevice", "(J)J" , reinterpret_cast<void*>(Canvas_LocalToDevice) },
|
||||
{"nConcat" , "(JJ)V" , reinterpret_cast<void*>(Canvas_Concat) },
|
||||
{"nConcat16f" , "(J[F)V" , reinterpret_cast<void*>(Canvas_Concat16f) },
|
||||
{"nTranslate" , "(JFFF)V" , reinterpret_cast<void*>(Canvas_Translate) },
|
||||
{"nScale" , "(JFFF)V" , reinterpret_cast<void*>(Canvas_Scale) },
|
||||
{"nDrawColor" , "(JFFFF)V" , reinterpret_cast<void*>(Canvas_DrawColor) },
|
||||
{"nDrawRect" , "(JFFFFJ)V" , reinterpret_cast<void*>(Canvas_DrawRect) },
|
||||
{"nDrawImage" , "(JJFFIFF)V", reinterpret_cast<void*>(Canvas_DrawImage) },
|
||||
{"nDrawPath" , "(JJJ)V" , reinterpret_cast<void*>(Canvas_DrawPath) },
|
||||
{"nGetWidth" , "(J)I" , reinterpret_cast<void*>(Canvas_GetWidth) },
|
||||
{"nGetHeight" , "(J)I" , reinterpret_cast<void*>(Canvas_GetHeight) },
|
||||
{"nSave" , "(J)I" , reinterpret_cast<void*>(Canvas_Save) },
|
||||
{"nSaveLayer" , "(JJ)I" , reinterpret_cast<void*>(Canvas_SaveLayer) },
|
||||
{"nRestore" , "(J)V" , reinterpret_cast<void*>(Canvas_Restore) },
|
||||
{"nRestoreToCount" , "(JI)V" , reinterpret_cast<void*>(Canvas_RestoreToCount)},
|
||||
{"nGetLocalToDevice", "(J)J" , reinterpret_cast<void*>(Canvas_LocalToDevice) },
|
||||
{"nConcat" , "(JJ)V" , reinterpret_cast<void*>(Canvas_Concat) },
|
||||
{"nConcat16f" , "(J[F)V" , reinterpret_cast<void*>(Canvas_Concat16f) },
|
||||
{"nTranslate" , "(JFFF)V" , reinterpret_cast<void*>(Canvas_Translate) },
|
||||
{"nScale" , "(JFFF)V" , reinterpret_cast<void*>(Canvas_Scale) },
|
||||
{"nClipPath" , "(JJIZ)V" , reinterpret_cast<void*>(Canvas_ClipPath) },
|
||||
{"nClipRect" , "(JFFFFIZ)V" , reinterpret_cast<void*>(Canvas_ClipRect) },
|
||||
{"nClipRRect" , "(JFFFFFFIZ)V", reinterpret_cast<void*>(Canvas_ClipRRect) },
|
||||
{"nClipShader" , "(JJI)V" , reinterpret_cast<void*>(Canvas_ClipShader) },
|
||||
{"nDrawColor" , "(JFFFF)V" , reinterpret_cast<void*>(Canvas_DrawColor) },
|
||||
{"nDrawRect" , "(JFFFFJ)V" , reinterpret_cast<void*>(Canvas_DrawRect) },
|
||||
{"nDrawImage" , "(JJFFIFF)V" , reinterpret_cast<void*>(Canvas_DrawImage) },
|
||||
{"nDrawPath" , "(JJJ)V" , reinterpret_cast<void*>(Canvas_DrawPath) },
|
||||
};
|
||||
|
||||
const auto clazz = env->FindClass("org/skia/androidkit/Canvas");
|
||||
|
@ -74,6 +74,24 @@ public class Canvas {
|
||||
nScale(mNativeInstance, sx ,sy, 1);
|
||||
}
|
||||
|
||||
public void clipPath(Path path, ClipOp op, boolean antiAliasing) {
|
||||
nClipPath(mNativeInstance, path.getNativeInstance(), op.mNativeInt, antiAliasing);
|
||||
}
|
||||
|
||||
public void clipRect(float left, float top, float right, float bottom,
|
||||
ClipOp op, boolean antiAliasing) {
|
||||
nClipRect(mNativeInstance, left, top, right, bottom, op.mNativeInt, antiAliasing);
|
||||
}
|
||||
|
||||
public void clipRRect(float left, float top, float right, float bottom, float xRad, float yRad,
|
||||
ClipOp op, boolean antiAliasing) {
|
||||
nClipRRect(mNativeInstance, left, top, right, bottom, xRad, yRad, op.mNativeInt, antiAliasing);
|
||||
}
|
||||
|
||||
public void clipShader(Shader shader, ClipOp op) {
|
||||
nClipShader(mNativeInstance, shader.getNativeInstance(), op.mNativeInt);
|
||||
}
|
||||
|
||||
public void drawRect(float left, float top, float right, float bottom, Paint paint) {
|
||||
nDrawRect(mNativeInstance, left, top, right, bottom, paint.getNativeInstance());
|
||||
}
|
||||
@ -129,6 +147,16 @@ public class Canvas {
|
||||
private static native void nTranslate(long nativeInstance, float tx, float ty, float tz);
|
||||
private static native void nScale(long nativeInstance, float sx, float sy, float sz);
|
||||
|
||||
private static native void nClipPath(long nativeInstance, long nativePath, int clipOp,
|
||||
boolean doAA);
|
||||
private static native void nClipRect(long nativeInstance, float left, float top, float right,
|
||||
float bottom, int clipOp, boolean doAA);
|
||||
private static native void nClipRRect(long nativeInstance, float left, float top, float right,
|
||||
float bottom, float xRad, float yRad,
|
||||
int clipOp, boolean doAA);
|
||||
private static native void nClipShader(long nativeInstance, long nativeShader, int clipOp);
|
||||
|
||||
|
||||
private static native void nDrawColor(long nativeInstance, float r, float g, float b, float a);
|
||||
|
||||
private static native void nDrawRect(long nativeInstance,
|
||||
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2021 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package org.skia.androidkit;
|
||||
|
||||
public enum ClipOp {
|
||||
DIFFERENCE(0),
|
||||
INTERSECT(1);
|
||||
|
||||
ClipOp(int nativeInt) {
|
||||
this.mNativeInt = nativeInt;
|
||||
}
|
||||
|
||||
int mNativeInt;
|
||||
}
|
Loading…
Reference in New Issue
Block a user