# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1615233235 0 # Node ID fad0821cb953d51be39a9764b81b51fff5fadc47 # Parent dfb52d2bddaa95cc069a818c9a2129b7bc1201df Add new function dw_render_redraw() which will trigger expose event on render widgets. This is to help optimize drawing on GTK4 and GTK3 with Wayland. To make existing code function on GTK4 and GTK3 with Wayland, drawing outside of a callback will mark widgets dirty and dw_flush() will trigger draw/expose callbacks on them. This may result in double drawing the widgets. dw_render_redraw() will allow you to just trigger the draw event without actually attempting to draw, allowing one draw pass in the expose callback. Only tested on Windows, may require fixes on other platforms. diff -r dfb52d2bddaa -r fad0821cb953 dw.h --- a/dw.h Mon Mar 08 19:24:21 2021 +0000 +++ b/dw.h Mon Mar 08 19:53:55 2021 +0000 @@ -1812,6 +1812,7 @@ void API dw_exit(int exitcode); void API dw_shutdown(void); HWND API dw_render_new(unsigned long id); +void API dw_render_redraw(HWND handle); void API dw_color_foreground_set(unsigned long value); void API dw_color_background_set(unsigned long value); unsigned long API dw_color_choose(unsigned long value); diff -r dfb52d2bddaa -r fad0821cb953 gtk/dw.c --- a/gtk/dw.c Mon Mar 08 19:24:21 2021 +0000 +++ b/gtk/dw.c Mon Mar 08 19:53:55 2021 +0000 @@ -8274,6 +8274,21 @@ return tmp; } +/* + * Invalidate the render widget triggering an expose event. + * Parameters: + * handle: A handle to a render widget to be redrawn. + */ +void API dw_render_redraw(HWND handle) +{ + int _locked_by_me = FALSE; + + DW_MUTEX_LOCK; + if(handle && GTK_IS_WIDGET(handle)) + gtk_widget_queue_draw(handle); + DW_MUTEX_UNLOCK; +} + /* Returns a GdkColor from a DW color */ static GdkColor _internal_color(unsigned long value) { diff -r dfb52d2bddaa -r fad0821cb953 gtk3/dw.c --- a/gtk3/dw.c Mon Mar 08 19:24:21 2021 +0000 +++ b/gtk3/dw.c Mon Mar 08 19:53:55 2021 +0000 @@ -7125,6 +7125,21 @@ return tmp; } +/* + * Invalidate the render widget triggering an expose event. + * Parameters: + * handle: A handle to a render widget to be redrawn. + */ +void API dw_render_redraw(HWND handle) +{ + int _locked_by_me = FALSE; + + DW_MUTEX_LOCK; + if(handle && GTK_IS_WIDGET(handle)) + gtk_widget_queue_draw(handle); + DW_MUTEX_UNLOCK; +} + /* Returns a GdkRGBA from a DW color */ static GdkRGBA _internal_color(unsigned long value) { diff -r dfb52d2bddaa -r fad0821cb953 gtk4/dw.c --- a/gtk4/dw.c Mon Mar 08 19:24:21 2021 +0000 +++ b/gtk4/dw.c Mon Mar 08 19:53:55 2021 +0000 @@ -6385,6 +6385,21 @@ DW_FUNCTION_RETURN_THIS(tmp); } +/* + * Invalidate the render widget triggering an expose event. + * Parameters: + * handle: A handle to a render widget to be redrawn. + */ +void API dw_render_redraw(HWND handle) +DW_FUNCTION_DEFINITION(dw_render_redraw, void, HWND handle) +DW_FUNCTION_ADD_PARAM1(handle) +DW_FUNCTION_NO_RETURN(dw_render_redraw) +DW_FUNCTION_RESTORE_PARAM1(handle, HWND) +{ + if(handle && GTK_IS_WIDGET(handle)) + gtk_widget_queue_draw(handle); +} + /* Returns a GdkRGBA from a DW color */ static GdkRGBA _dw_internal_color(unsigned long value) { diff -r dfb52d2bddaa -r fad0821cb953 mac/dw.m --- a/mac/dw.m Mon Mar 08 19:24:21 2021 +0000 +++ b/mac/dw.m Mon Mar 08 19:53:55 2021 +0000 @@ -6690,6 +6690,18 @@ return render; } +/* + * Invalidate the render widget triggering an expose event. + * Parameters: + * handle: A handle to a render widget to be redrawn. + */ +void API dw_render_redraw(HWND handle) +{ + DWRender *render = (DWRender *)handle; + + [render setNeedsDisplay:YES]; +} + /* Sets the current foreground drawing color. * Parameters: * red: red value. diff -r dfb52d2bddaa -r fad0821cb953 os2/dw.c --- a/os2/dw.c Mon Mar 08 19:24:21 2021 +0000 +++ b/os2/dw.c Mon Mar 08 19:53:55 2021 +0000 @@ -4975,6 +4975,16 @@ } /* + * Invalidate the render widget triggering an expose event. + * Parameters: + * handle: A handle to a render widget to be redrawn. + */ +void API dw_render_redraw(HWND handle) +{ + WinInvalidateRect(handle, NULL, FALSE); +} + +/* * Changes a window's parent to newparent. * Parameters: * handle: The window handle to destroy. diff -r dfb52d2bddaa -r fad0821cb953 template/dw.c --- a/template/dw.c Mon Mar 08 19:24:21 2021 +0000 +++ b/template/dw.c Mon Mar 08 19:53:55 2021 +0000 @@ -1357,6 +1357,15 @@ return 0; } +/* + * Invalidate the render widget triggering an expose event. + * Parameters: + * handle: A handle to a render widget to be redrawn. + */ +void API dw_render_redraw(HWND handle) +{ +} + /* Sets the current foreground drawing color. * Parameters: * red: red value. diff -r dfb52d2bddaa -r fad0821cb953 win/dw.c --- a/win/dw.c Mon Mar 08 19:24:21 2021 +0000 +++ b/win/dw.c Mon Mar 08 19:53:55 2021 +0000 @@ -11063,6 +11063,16 @@ return tmp; } +/* + * Invalidate the render widget triggering an expose event. + * Parameters: + * handle: A handle to a render widget to be redrawn. + */ +void API dw_render_redraw(HWND handle) +{ + InvalidateRect(handle, NULL, FALSE); +} + /* Sets the current foreground drawing color. * Parameters: * red: red value.