You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
implement Canvas.clipRect() using gtk_snapshot_push_clip()
This commit is contained in:
@@ -113,6 +113,22 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1scale
|
||||
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1concat
|
||||
(JNIEnv *, jobject, jlong, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_GskCanvas
|
||||
* Method: native_clipRect
|
||||
* Signature: (JFFFF)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1clipRect
|
||||
(JNIEnv *, jobject, jlong, jfloat, jfloat, jfloat, jfloat);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_GskCanvas
|
||||
* Method: native_pop
|
||||
* Signature: (JI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1pop
|
||||
(JNIEnv *, jobject, jlong, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -154,3 +154,16 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1concat(JNIEnv *en
|
||||
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
|
||||
gtk_snapshot_transform_matrix(snapshot, matrix);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1clipRect(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jfloat left, jfloat top, jfloat right, jfloat bottom)
|
||||
{
|
||||
GdkSnapshot *snapshot = GTK_SNAPSHOT(_PTR(snapshot_ptr));
|
||||
gtk_snapshot_push_clip(snapshot, &GRAPHENE_RECT_INIT(left, top, right - left, bottom - top));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1pop(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jint count)
|
||||
{
|
||||
GdkSnapshot *snapshot = GTK_SNAPSHOT(_PTR(snapshot_ptr));
|
||||
while (count--)
|
||||
gtk_snapshot_pop(snapshot);
|
||||
}
|
||||
|
||||
@@ -488,22 +488,20 @@ public class Canvas {
|
||||
}
|
||||
|
||||
public boolean clipRect(int left, int top, int right, int bottom) {
|
||||
Log.w("Canvas", "STUB: clipRect");
|
||||
return false;
|
||||
return clipRect((float)left, top, right, bottom);
|
||||
}
|
||||
|
||||
public boolean clipRect(float left, float top, float right, float bottom) {
|
||||
return false;
|
||||
gsk_canvas.snapshot = bitmap.getSnapshot();
|
||||
return gsk_canvas.clipRect(left, top, right, bottom);
|
||||
}
|
||||
|
||||
public boolean clipRect(Rect rect) {
|
||||
Log.w("Canvas", "STUB: clipRect");
|
||||
return false;
|
||||
return clipRect((float)rect.left, rect.top, rect.right, rect.bottom);
|
||||
}
|
||||
|
||||
public boolean clipRect(Rect rect, Region.Op op) {
|
||||
Log.w("Canvas", "STUB: clipRect");
|
||||
return false;
|
||||
return clipRect((float)rect.left, rect.top, rect.right, rect.bottom);
|
||||
}
|
||||
|
||||
public boolean clipPath(Path path) {
|
||||
@@ -521,18 +519,15 @@ public class Canvas {
|
||||
}
|
||||
|
||||
public boolean clipRect(RectF rect) {
|
||||
Log.v("Canvas", "STUB: clipRect");
|
||||
return false;
|
||||
return clipRect(rect.left, rect.top, rect.right, rect.bottom);
|
||||
}
|
||||
|
||||
public boolean clipRect(float left, float top, float right, float bottom, Region.Op op) {
|
||||
Log.v("Canvas", "STUB: clipRect");
|
||||
return false;
|
||||
return clipRect(left, top, right, bottom);
|
||||
}
|
||||
|
||||
public boolean clipRect(RectF rect, Region.Op op) {
|
||||
Log.v("Canvas", "STUB: clipRect");
|
||||
return false;
|
||||
return clipRect(rect.left, rect.top, rect.right, rect.bottom);
|
||||
}
|
||||
|
||||
public void drawArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean includeCenter, Paint paint) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package android.graphics;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* GskCanvas:
|
||||
* - implements Canvas for onscreen rendering inside GTKs snapshot function
|
||||
@@ -7,6 +9,7 @@ package android.graphics;
|
||||
public class GskCanvas extends Canvas {
|
||||
public long snapshot;
|
||||
private int save_count = 1;
|
||||
private int[] push_history = null;
|
||||
|
||||
private static Paint default_paint = new Paint();
|
||||
|
||||
@@ -22,6 +25,10 @@ public class GskCanvas extends Canvas {
|
||||
|
||||
@Override
|
||||
public void restore() {
|
||||
if (push_history != null && push_history.length > save_count && push_history[save_count] > 0) {
|
||||
native_pop(snapshot, push_history[save_count]);
|
||||
push_history[save_count] = 0;
|
||||
}
|
||||
save_count--;
|
||||
native_restore(snapshot);
|
||||
}
|
||||
@@ -146,6 +153,17 @@ public class GskCanvas extends Canvas {
|
||||
drawText(text.toString().substring(start, end), x, y, paint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clipRect(float left, float top, float right, float bottom) {
|
||||
native_clipRect(snapshot, left, top, right, bottom);
|
||||
if (push_history == null)
|
||||
push_history = new int[save_count+1];
|
||||
else if (push_history.length <= save_count)
|
||||
push_history = Arrays.copyOf(push_history, save_count+1);
|
||||
push_history[save_count]++;
|
||||
return right > left && bottom > top;
|
||||
}
|
||||
|
||||
protected native void native_drawBitmap(long snapshot, long texture, int x, int y, int width, int height, long paint);
|
||||
protected native void native_drawRect(long snapshot, float left, float top, float right, float bottom, long paint);
|
||||
protected native void native_drawPath(long snapshot, long path, long paint);
|
||||
@@ -159,4 +177,6 @@ public class GskCanvas extends Canvas {
|
||||
protected native void native_drawRoundRect(long snapshot, float left, float top, float right, float bottom, float rx, float ry, long paint);
|
||||
protected native void native_scale(long snapshot, float sx, float sy);
|
||||
protected native void native_concat(long snapshot, long matrix);
|
||||
protected native void native_clipRect(long snapshot, float left, float top, float right, float bottom);
|
||||
protected native void native_pop(long snapshot, int pop_count);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user