Skip to content

Commit 7cf1145

Browse files
amartya4256fedejeanne
authored andcommitted
Store Region in GC.SetClippingRegionOperation #62
This commit refactors GC.SetClippingRegionOperation to store Region and hence refactors GC:setClipping(Region) to call the Operation instead of GC:setClipping(long) for a better behaviour on a GC refresh. Contributes to #62 and #128
1 parent 3bfde61 commit 7cf1145

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4730,19 +4730,21 @@ void apply() {
47304730

47314731
private void setClipping(long clipRgn) {
47324732
checkNonDisposed();
4733-
storeAndApplyOperationForExistingHandle(new SetClippingRegionOperation(clipRgn));
4733+
setClippingRegion(clipRgn);
47344734
}
47354735

47364736
private class SetClippingRegionOperation extends Operation {
4737-
private final long clipRgn;
4737+
private final Region clipRgn;
47384738

4739-
SetClippingRegionOperation(long clipRgn) {
4740-
this.clipRgn = clipRgn;
4739+
SetClippingRegionOperation(Region clipRgn) {
4740+
this.clipRgn = clipRgn != null ? clipRgn.copy() : null;
4741+
registerForDisposal(this.clipRgn);
47414742
}
47424743

47434744
@Override
47444745
void apply() {
4745-
setClippingRegion(clipRgn);
4746+
// Reset clipping if clipRgn is null.
4747+
setClippingRegion(clipRgn != null ? Region.win32_getHandle(clipRgn, getZoom()) : 0);
47464748
}
47474749
}
47484750

@@ -4880,7 +4882,7 @@ void apply() {
48804882
public void setClipping (Rectangle rect) {
48814883
checkNonDisposed();
48824884
if (rect == null) {
4883-
setClipping(0);
4885+
storeAndApplyOperationForExistingHandle(new SetClippingRegionOperation(null));
48844886
} else {
48854887
storeAndApplyOperationForExistingHandle(new SetClippingOperation(rect));
48864888
}
@@ -4905,7 +4907,7 @@ public void setClipping (Rectangle rect) {
49054907
public void setClipping (Region region) {
49064908
checkNonDisposed();
49074909
if (region != null && region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
4908-
setClipping(region != null ? Region.win32_getHandle(region, getZoom()) : 0);
4910+
storeAndApplyOperationForExistingHandle(new SetClippingRegionOperation(region));
49094911
}
49104912

49114913
/**

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,12 @@ private RegionHandle getRegionHandle(int zoom) {
644644
return zoomToHandle.get(zoom);
645645
}
646646

647+
Region copy() {
648+
Region region = new Region();
649+
region.operations.addAll(operations);
650+
return region;
651+
}
652+
647653
/**
648654
* <b>IMPORTANT:</b> This method is not part of the public
649655
* API for Image. It is marked public only so that it

0 commit comments

Comments
 (0)