[Win32] Replace magic GDI+ image arrays#3244
Conversation
8bfb6d1 to
265afe3
Compare
There was a problem hiding this comment.
Pull request overview
This PR replaces the implicit long[2] GDI+ image/pixels tuple with an explicit Image.GdipImage record, centralizing GDI+ bitmap + heap pixel-buffer cleanup via GdipImage.destroy() and updating Win32 drawing/brush code to use it.
Changes:
- Introduce
Image.GdipImage(bitmap, pixels)and updateImage#createGdipImage*to return it instead oflong[]. - Update
GC#drawImage(...)to useGdipImagewithtry/finally-based cleanup. - Update
Patternimage-pattern handling to track/destroy the temporary GDI+ image viaGdipImage.destroy()and remove an unused Win32 import.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java |
Switch image-pattern temporary bitmap tracking/cleanup to Image.GdipImage.destroy(); remove unused Win32 import. |
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java |
Add GdipImage record and return it from createGdipImage* to make ownership/cleanup explicit. |
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java |
Use GdipImage in the GDI+ draw path and ensure centralized cleanup in a finally block. |
| Image.GdipImage image = gdipImage; | ||
| gdipImage = null; | ||
| image.destroy(); |
There was a problem hiding this comment.
In cleanupBitmap(), the local variable name image shadows the enclosing Pattern's image field and reads ambiguously (it’s actually the temporary GDI+ image wrapper). Rename the local to something like gdipToDestroy/tempGdipImage to avoid confusion during maintenance.
| Image.GdipImage image = gdipImage; | |
| gdipImage = null; | |
| image.destroy(); | |
| Image.GdipImage tempGdipImage = gdipImage; | |
| gdipImage = null; | |
| tempGdipImage.destroy(); |
There was a problem hiding this comment.
Renamed the local to tempGdipImage and updated the branch. This is resolved now.
265afe3 to
81f0ab6
Compare
Use a small record to carry the temporary GDI+ bitmap together with its optional heap-backed pixel buffer, and centralize cleanup at the value boundary. Also update Pattern cleanup to track bitmap ownership explicitly instead of relying on the returned array length. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
81f0ab6 to
f6074a7
Compare
Summary
long[2]GDI+ image return value with a dedicatedImage.GdipImagerecordGdipImage.destroy()inGCandPatternPatternWhy
createGdipImageFromHandle()always returns the same two-part result: the temporary GDI+ bitmap and an optional heap-backed pixel buffer that must be freed together. Representing that value aslong[2]leaves the meaning ofgdipImage[0]andgdipImage[1]implicit and pushes cleanup knowledge into each caller.This change gives that result explicit semantics via
Image.GdipImage, moves ownership cleanup toGdipImage.destroy(), and updatesPattern.cleanupBitmap()to track whether a temporary image is present directly instead of inferring state from the returned array length.Notes
Pattern.cleanupBitmap()now tracks ownership explicitly instead of relying on the returned array length