On Fri, 20 Aug 2021 22:22:51 GMT, Thiago Milczarek Sayao <tsa...@openjdk.org> 
wrote:

>> It seems raw images need to be converted BRGA -> RGBA.
>> 
>> It was being converted on gtk2 code path, but gtk3 only uses 
>> `gtk_drag_set_icon_pixbuf`.
>> 
>> I have simplified the gtk2 `DragView::View::expose` to paint with 
>> `gdk_cairo_set_source_pixbuf` (that is available since Gtk 2.8) because the 
>> old way was somehow converting  again.
>> 
>> Run the issue sample with `-Djdk.gtk.version=2` to test the gtk2 code path.
>> 
>> To test:
>> 
>> `./gradlew apps`
>> 
>> 
>> java @build/run.args -cp apps/toys/DragDrop/dist/DragDrop.jar 
>> dragdrop.DragDropWithControls
>> java @build/run.args -cp apps/toys/DragDrop/dist/DragDrop.jar 
>> dragdrop.DragDropColor 
>> 
>> java -Djdk.gtk.version=2 @build/run.args -cp 
>> apps/toys/DragDrop/dist/DragDrop.jar dragdrop.DragDropWithControls
>> java -Djdk.gtk.version=2 @build/run.args -cp 
>> apps/toys/DragDrop/dist/DragDrop.jar dragdrop.DragDropColor
>
> Thiago Milczarek Sayao has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Review requests.

This fix introduces a memory leak, but otherwise looks correct. I verified that 
with gtk3 the new manual test passes with the fix and fails without the fix 
(with gtk2 is passes before and after the fix).

modules/javafx.graphics/src/main/native-glass/gtk/glass_dnd.cpp line 916:

> 914: 
> 915:                         if (is_raw_image) {
> 916:                             data = (guchar*) convert_BGRA_to_RGBA((const 
> int*) data, w * 4, h);

This will leak memory, since the original buffer allocated by the call to 
`g_try_malloc0` on line 911 is never freed. I recommend something like this:


        guchar* origdata = data;
        data = (guchar*) convert_BGRA_to_RGBA((const int*) origdata, w * 4, h);
        g_free(origdata);

-------------

PR: https://git.openjdk.java.net/jfx/pull/599

Reply via email to