Skip to content

Commit fd18da9

Browse files
HeikoKlareakoch-yatta
authored andcommitted
[Win32] Remove superceded GC operations from history
The GC stores every operation changing the GC state to be able to repply it if a handle for a different zoom is requested. There are some operations which, if executing an operation of the same type subsequently, supercede each other. This, for example, applies to setting fonts, as when settings two fonts after each other, only the last one set is relevant. This change flags several GC operations as replaceable and implements the removal of previous operations from the operation history if a new operation is executed that supercedes the previous one. This slightly reduces the memory footprint.
1 parent b02fab8 commit fd18da9

File tree

1 file changed

+33
-9
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+33
-9
lines changed

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4799,7 +4799,7 @@ public void setBackground (Color color) {
47994799
storeAndApplyOperationForExistingHandle(new SetBackgroundOperation(color));
48004800
}
48014801

4802-
private class SetBackgroundOperation extends Operation {
4802+
private class SetBackgroundOperation extends ReplaceableOperation {
48034803
private final Color color;
48044804

48054805
SetBackgroundOperation(Color color) {
@@ -5113,7 +5113,7 @@ public void setFont (Font font) {
51135113
storeAndApplyOperationForExistingHandle(new SetFontOperation(font));
51145114
}
51155115

5116-
private class SetFontOperation extends Operation {
5116+
private class SetFontOperation extends ReplaceableOperation {
51175117
private final Font font;
51185118

51195119
SetFontOperation(Font font) {
@@ -5148,7 +5148,7 @@ public void setForeground (Color color) {
51485148
storeAndApplyOperationForExistingHandle(new SetForegroundOperation(color));
51495149
}
51505150

5151-
private class SetForegroundOperation extends Operation {
5151+
private class SetForegroundOperation extends ReplaceableOperation {
51525152
private final Color color;
51535153

51545154
SetForegroundOperation(Color color) {
@@ -5302,7 +5302,7 @@ public void setLineAttributes (LineAttributes attributes) {
53025302
storeAndApplyOperationForExistingHandle(new SetLineAttributesOperation(attributes));
53035303
}
53045304

5305-
private class SetLineAttributesOperation extends Operation {
5305+
private class SetLineAttributesOperation extends ReplaceableOperation {
53065306
private final LineAttributes attributes;
53075307

53085308
SetLineAttributesOperation(LineAttributes attributes) {
@@ -5432,7 +5432,7 @@ public void setLineCap(int cap) {
54325432
storeAndApplyOperationForExistingHandle(new SetLineCapOperation(cap));
54335433
}
54345434

5435-
private class SetLineCapOperation extends Operation {
5435+
private class SetLineCapOperation extends ReplaceableOperation {
54365436
private final int cap;
54375437

54385438
SetLineCapOperation(int cap) {
@@ -5477,7 +5477,7 @@ public void setLineDash(int[] dashes) {
54775477
storeAndApplyOperationForExistingHandle(new SetLineDashOperation(dashes));
54785478
}
54795479

5480-
private class SetLineDashOperation extends Operation {
5480+
private class SetLineDashOperation extends ReplaceableOperation {
54815481
private final int[] dashes;
54825482

54835483
SetLineDashOperation(int[] dashes) {
@@ -5529,7 +5529,7 @@ public void setLineJoin(int join) {
55295529
storeAndApplyOperationForExistingHandle(new SetLineJoinOperation(join));
55305530
}
55315531

5532-
private class SetLineJoinOperation extends Operation {
5532+
private class SetLineJoinOperation extends ReplaceableOperation {
55335533
private final int join;
55345534

55355535
SetLineJoinOperation(int join) {
@@ -5572,7 +5572,7 @@ public void setLineStyle(int lineStyle) {
55725572
storeAndApplyOperationForExistingHandle(new SetLineStyleOperation(lineStyle));
55735573
}
55745574

5575-
private class SetLineStyleOperation extends Operation {
5575+
private class SetLineStyleOperation extends ReplaceableOperation {
55765576
private final int lineStyle;
55775577

55785578
SetLineStyleOperation(int lineStyle) {
@@ -5626,7 +5626,7 @@ public void setLineWidth(int lineWidth) {
56265626
storeAndApplyOperationForExistingHandle(new SetLineWidthOperation(lineWidth));
56275627
}
56285628

5629-
private class SetLineWidthOperation extends Operation {
5629+
private class SetLineWidthOperation extends ReplaceableOperation {
56305630
private final int width;
56315631

56325632
SetLineWidthOperation(int width) {
@@ -6042,10 +6042,23 @@ int getZoom() {
60426042
}
60436043

60446044
private void storeAndApplyOperationForExistingHandle(Operation operation) {
6045+
removePreviousOperationIfSupercededBy(operation);
60456046
operations.add(operation);
60466047
operation.apply();
60476048
}
60486049

6050+
private void removePreviousOperationIfSupercededBy(Operation operation) {
6051+
if (operations.isEmpty()) {
6052+
return;
6053+
}
6054+
int lastIndex = operations.size() - 1;
6055+
Operation lastOperation = operations.get(lastIndex);
6056+
if (lastOperation.canBeReplacedBy(operation)) {
6057+
lastOperation.disposeAll();
6058+
operations.remove(lastIndex);
6059+
}
6060+
}
6061+
60496062
private void createGcHandle(Drawable drawable, GCData newData) {
60506063
long newHandle = drawable.internal_new_GC(newData);
60516064
if (newHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
@@ -6085,6 +6098,17 @@ void disposeAll() {
60856098
}
60866099
disposables.clear();
60876100
}
6101+
6102+
boolean canBeReplacedBy(Operation operation) {
6103+
return false;
6104+
}
6105+
}
6106+
6107+
private abstract class ReplaceableOperation extends Operation {
6108+
@Override
6109+
boolean canBeReplacedBy(Operation operation) {
6110+
return operation.getClass().equals(this.getClass());
6111+
}
60886112
}
60896113
}
60906114

0 commit comments

Comments
 (0)