View.draw(): draw background, content, children in same order as AOSP

This commit is contained in:
Julian Winkler
2024-05-26 15:53:24 +02:00
committed by Mis012
parent e8eabb2027
commit c5e0f8a7fd
8 changed files with 61 additions and 24 deletions

View File

@@ -199,14 +199,6 @@ extern "C" {
#define android_view_View_TEXT_DIRECTION_LTR 3L
#undef android_view_View_TEXT_DIRECTION_RTL
#define android_view_View_TEXT_DIRECTION_RTL 4L
/*
* Class: android_view_View
* Method: native_onDraw
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_view_View_native_1onDraw
(JNIEnv *, jobject, jlong, jlong);
/*
* Class: android_view_View
* Method: setOnTouchListener
@@ -303,6 +295,22 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1setBackgroundDrawable
JNIEXPORT void JNICALL Java_android_view_View_native_1queueAllocate
(JNIEnv *, jobject, jlong);
/*
* Class: android_view_View
* Method: native_drawBackground
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_view_View_native_1drawBackground
(JNIEnv *, jobject, jlong, jlong);
/*
* Class: android_view_View
* Method: native_drawContent
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_view_View_native_1drawContent
(JNIEnv *, jobject, jlong, jlong);
/*
* Class: android_view_View
* Method: nativeInvalidate

View File

@@ -215,6 +215,14 @@ JNIEXPORT void JNICALL Java_android_view_ViewGroup_native_1addView
JNIEXPORT void JNICALL Java_android_view_ViewGroup_native_1removeView
(JNIEnv *, jobject, jlong, jlong);
/*
* Class: android_view_ViewGroup
* Method: native_drawChildren
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_view_ViewGroup_native_1drawChildren
(JNIEnv *, jobject, jlong, jlong);
#ifdef __cplusplus
}
#endif

View File

@@ -584,8 +584,17 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1queueAllocate(JNIEnv *env,
gtk_widget_queue_allocate(GTK_WIDGET(_PTR(widget_ptr)));
}
JNIEXPORT void JNICALL Java_android_view_View_native_1onDraw(JNIEnv *env, jobject this, jlong widget_ptr, jlong snapshot_ptr)
JNIEXPORT void JNICALL Java_android_view_View_native_1drawBackground(JNIEnv *env, jobject this, jlong widget_ptr, jlong snapshot_ptr)
{
WrapperWidget *wrapper = WRAPPER_WIDGET(gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr))));
wrapper_widget_draw_children(wrapper, GDK_SNAPSHOT(_PTR(snapshot_ptr)));
GdkSnapshot *snapshot = GDK_SNAPSHOT(_PTR(snapshot_ptr));
if (wrapper->background)
gtk_widget_snapshot_child(&wrapper->parent_instance, wrapper->background, snapshot);
}
JNIEXPORT void JNICALL Java_android_view_View_native_1drawContent(JNIEnv *env, jobject this, jlong widget_ptr, jlong snapshot_ptr)
{
WrapperWidget *wrapper = WRAPPER_WIDGET(gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr))));
GdkSnapshot *snapshot = GDK_SNAPSHOT(_PTR(snapshot_ptr));
gtk_widget_snapshot_child(&wrapper->parent_instance, wrapper->child, snapshot);
}

View File

@@ -47,3 +47,10 @@ JNIEXPORT void JNICALL Java_android_view_ViewGroup_native_1removeView(JNIEnv *en
{
gtk_widget_unparent(gtk_widget_get_parent(GTK_WIDGET(_PTR(child))));
}
JNIEXPORT void JNICALL Java_android_view_ViewGroup_native_1drawChildren(JNIEnv *env, jobject this, jlong widget_ptr, jlong snapshot_ptr)
{
WrapperWidget *wrapper = WRAPPER_WIDGET(gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr))));
GdkSnapshot *snapshot = GDK_SNAPSHOT(_PTR(snapshot_ptr));
gtk_widget_snapshot_child(&wrapper->parent_instance, wrapper->child, snapshot);
}

View File

@@ -94,16 +94,6 @@ void wrapper_widget_allocate(GtkWidget *widget, int width, int height, int basel
gtk_widget_size_allocate(wrapper->background, &allocation, baseline);
}
void wrapper_widget_draw_children(WrapperWidget *wrapper, GdkSnapshot *snapshot)
{
GtkWidget *widget = &wrapper->parent_instance;
GtkWidget *child = gtk_widget_get_first_child(widget);
while (child) {
gtk_widget_snapshot_child(widget, child, snapshot);
child = gtk_widget_get_next_sibling(child);
}
}
static void wrapper_widget_snapshot(GtkWidget *widget, GdkSnapshot *snapshot)
{
WrapperWidget *wrapper = WRAPPER_WIDGET(widget);
@@ -117,7 +107,12 @@ static void wrapper_widget_snapshot(GtkWidget *widget, GdkSnapshot *snapshot)
if ((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env);
} else {
wrapper_widget_draw_children(wrapper, snapshot);
GtkWidget *widget = &wrapper->parent_instance;
GtkWidget *child = gtk_widget_get_first_child(widget);
while (child) {
gtk_widget_snapshot_child(widget, child, snapshot);
child = gtk_widget_get_next_sibling(child);
}
}
if (wrapper->real_height > 0 && wrapper->real_width > 0) {
gtk_snapshot_pop(snapshot);

View File

@@ -35,7 +35,6 @@ void wrapper_widget_set_jobject(WrapperWidget *wrapper, JNIEnv *env, jobject job
void wrapper_widget_queue_draw(WrapperWidget *wrapper);
void wrapper_widget_set_layout_params(WrapperWidget *wrapper, int width, int height);
void wrapper_widget_set_background(WrapperWidget *wrapper, GdkPaintable *paintable);
void wrapper_widget_draw_children(WrapperWidget *wrapper, GdkSnapshot *snapshot);
void _setOnTouchListener(JNIEnv *env, jobject this, GtkWidget *widget, jobject on_touch_listener);

View File

@@ -900,13 +900,16 @@ public class View implements Drawable.Callback {
return null;
}
protected native void native_onDraw(long widget, long snapshot);
public void onDraw(Canvas canvas) {
if (canvas instanceof GskCanvas)
native_onDraw(widget, ((GskCanvas)canvas).snapshot);
native_drawContent(widget, ((GskCanvas)canvas).snapshot);
}
public void draw(Canvas canvas) {
if (canvas instanceof GskCanvas)
native_drawBackground(widget, ((GskCanvas)canvas).snapshot);
onDraw(canvas);
if (canvas instanceof GskCanvas)
native_drawChildren(widget, ((GskCanvas)canvas).snapshot);
}
public View(Context context) {
@@ -982,6 +985,10 @@ public class View implements Drawable.Callback {
protected native void native_setBackgroundDrawable(long widget, long paintable);
protected native void native_queueAllocate(long widget);
protected native void native_drawBackground(long widget, long snapshot);
protected native void native_drawContent(long widget, long snapshot);
protected void native_drawChildren(long widget, long snapshot) {} // override in ViewGroup
// --- stubs
public void setContentDescription(CharSequence contentDescription) {}

View File

@@ -133,6 +133,10 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
protected native void native_addView(long widget, long child, int index, LayoutParams params);
protected native void native_removeView(long widget, long child);
@Override
protected native void native_drawChildren(long widget, long snapshot);
@Override
protected void native_drawContent(long widget, long snapshot) {}
public View getChildAt(int index) {
try {