Skip to content

[Win32] Replace magic GDI+ image arrays#3244

Merged
HeikoKlare merged 1 commit into
eclipse-platform:masterfrom
HeikoKlare:hklare/pattern-gdip-image-record
Apr 18, 2026
Merged

[Win32] Replace magic GDI+ image arrays#3244
HeikoKlare merged 1 commit into
eclipse-platform:masterfrom
HeikoKlare:hklare/pattern-gdip-image-record

Conversation

@HeikoKlare
Copy link
Copy Markdown
Contributor

@HeikoKlare HeikoKlare commented Apr 16, 2026

Summary

  • replace the magic long[2] GDI+ image return value with a dedicated Image.GdipImage record
  • centralize temporary bitmap and heap buffer cleanup through GdipImage.destroy() in GC and Pattern
  • remove the stale Win32 import from Pattern

Why

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 as long[2] leaves the meaning of gdipImage[0] and gdipImage[1] implicit and pushes cleanup knowledge into each caller.

This change gives that result explicit semantics via Image.GdipImage, moves ownership cleanup to GdipImage.destroy(), and updates Pattern.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
  • This draft PR was created with Copilot.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 16, 2026

Test Results (win32)

   30 files  ±0     30 suites  ±0   4m 40s ⏱️ +12s
4 677 tests ±0  4 604 ✅ ±0  73 💤 ±0  0 ❌ ±0 
1 211 runs  ±0  1 187 ✅ ±0  24 💤 ±0  0 ❌ ±0 

Results for commit f6074a7. ± Comparison against base commit 75a088f.

♻️ This comment has been updated with latest results.

@HeikoKlare HeikoKlare force-pushed the hklare/pattern-gdip-image-record branch from 8bfb6d1 to 265afe3 Compare April 16, 2026 17:48
@HeikoKlare HeikoKlare marked this pull request as ready for review April 16, 2026 17:48
@HeikoKlare HeikoKlare requested a review from Copilot April 17, 2026 17:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 update Image#createGdipImage* to return it instead of long[].
  • Update GC#drawImage(...) to use GdipImage with try/finally-based cleanup.
  • Update Pattern image-pattern handling to track/destroy the temporary GDI+ image via GdipImage.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.

Comment on lines +330 to +332
Image.GdipImage image = gdipImage;
gdipImage = null;
image.destroy();
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
Image.GdipImage image = gdipImage;
gdipImage = null;
image.destroy();
Image.GdipImage tempGdipImage = gdipImage;
gdipImage = null;
tempGdipImage.destroy();

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the local to tempGdipImage and updated the branch. This is resolved now.

@HeikoKlare HeikoKlare force-pushed the hklare/pattern-gdip-image-record branch from 265afe3 to 81f0ab6 Compare April 17, 2026 18:50
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>
@HeikoKlare HeikoKlare force-pushed the hklare/pattern-gdip-image-record branch from 81f0ab6 to f6074a7 Compare April 17, 2026 18:50
@HeikoKlare HeikoKlare merged commit 1b54d33 into eclipse-platform:master Apr 18, 2026
18 checks passed
@HeikoKlare HeikoKlare deleted the hklare/pattern-gdip-image-record branch April 18, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants