diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java index ebbbfbd1b0d..11469586c84 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java @@ -15,7 +15,6 @@ import java.util.*; -import java.util.List; import java.util.stream.*; import org.eclipse.swt.*; @@ -82,9 +81,6 @@ public final class GC extends Resource { Drawable drawable; GCData data; - private final GCData originalData = new GCData(); - - private final List operations = new ArrayList<>(); static final int FOREGROUND = 1 << 0; static final int BACKGROUND = 1 << 1; @@ -176,7 +172,6 @@ public GC(Drawable drawable, int style) { if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); GCData data = new GCData (); data.style = checkStyle(style); - data.copyTo(originalData); long hDC = drawable.internal_new_GC(data); Device device = data.device; if (device == null) device = Device.getDevice(); @@ -488,7 +483,7 @@ public void copyArea (Image image, int x, int y) { checkNonDisposed(); if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - storeAndApplyOperationForExistingHandle(new CopyAreaToImageOperation(image, x, y)); + applyOperationForExistingHandle(new CopyAreaToImageOperation(image, x, y)); } private class CopyAreaToImageOperation extends Operation { @@ -562,7 +557,7 @@ public void copyArea (int srcX, int srcY, int width, int height, int destX, int */ public void copyArea (int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new CopyAreaOperation(new Rectangle(srcX, srcY, width, height), new Rectangle(destX, destY, width, height), paint)); + applyOperationForExistingHandle(new CopyAreaOperation(new Rectangle(srcX, srcY, width, height), new Rectangle(destX, destY, width, height), paint)); } private class CopyAreaOperation extends Operation { @@ -824,7 +819,7 @@ void disposeGdip() { */ public void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new DrawArcOperation(new Rectangle(x, y, width, height), startAngle, arcAngle)); + applyOperationForExistingHandle(new DrawArcOperation(new Rectangle(x, y, width, height), startAngle, arcAngle)); } private class DrawArcOperation extends Operation { @@ -920,7 +915,7 @@ private void drawArcInPixels (int x, int y, int width, int height, int startAngl */ public void drawFocus (int x, int y, int width, int height) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new DrawFocusOperation(new Rectangle(x, y, width, height))); + applyOperationForExistingHandle(new DrawFocusOperation(new Rectangle(x, y, width, height))); } private class DrawFocusOperation extends Operation { @@ -1010,7 +1005,7 @@ public void drawImage (Image image, int x, int y) { checkNonDisposed(); if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - storeAndApplyOperationForExistingHandle(new DrawImageOperation(image, new Point(x, y))); + applyOperationForExistingHandle(new DrawImageOperation(image, new Point(x, y))); } private class DrawImageOperation extends Operation { @@ -1074,11 +1069,11 @@ public void drawImage (Image image, int srcX, int srcY, int srcWidth, int srcHei if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - storeAndApplyOperationForExistingHandle(new DrawScalingImageToImageOperation(image, new Rectangle(srcX, srcY, srcWidth, srcHeight), new Rectangle(destX, destY, destWidth, destHeight))); + applyOperationForExistingHandle(new DrawScalingImageToImageOperation(image, new Rectangle(srcX, srcY, srcWidth, srcHeight), new Rectangle(destX, destY, destWidth, destHeight))); } void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) { - storeAndApplyOperationForExistingHandle(new DrawImageToImageOperation(srcImage, new Rectangle(srcX, srcY, srcWidth, srcHeight), new Rectangle(destX, destY, destWidth, destHeight), simple)); + applyOperationForExistingHandle(new DrawImageToImageOperation(srcImage, new Rectangle(srcX, srcY, srcWidth, srcHeight), new Rectangle(destX, destY, destWidth, destHeight), simple)); } private class DrawScalingImageToImageOperation extends Operation { @@ -1820,7 +1815,7 @@ private void drawBitmapColor(long imageHandle, int srcX, int srcY, int srcWidth, */ public void drawLine (int x1, int y1, int x2, int y2) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new DrawLineOperation(x1, y1, x2, y2)); + applyOperationForExistingHandle(new DrawLineOperation(x1, y1, x2, y2)); } private class DrawLineOperation extends Operation { @@ -1886,7 +1881,7 @@ private void drawLineInPixels (int x1, int y1, int x2, int y2) { */ public void drawOval (int x, int y, int width, int height) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new DrawOvalOperation(new Rectangle(x, y, width, height))); + applyOperationForExistingHandle(new DrawOvalOperation(new Rectangle(x, y, width, height))); } private class DrawOvalOperation extends Operation { @@ -1945,7 +1940,7 @@ public void drawPath (Path path) { checkNonDisposed(); if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - storeAndApplyOperationForExistingHandle(new DrawPathOperation(path)); + applyOperationForExistingHandle(new DrawPathOperation(path)); } private class DrawPathOperation extends Operation { @@ -1988,7 +1983,7 @@ void apply() { */ public void drawPoint (int x, int y) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new DrawPointOperation(x, y)); + applyOperationForExistingHandle(new DrawPointOperation(x, y)); } private class DrawPointOperation extends Operation { @@ -2034,7 +2029,7 @@ private void drawPointInPixels (int x, int y) { public void drawPolygon (int[] pointArray) { checkNonDisposed(); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - storeAndApplyOperationForExistingHandle(new DrawPolygonOperation(pointArray)); + applyOperationForExistingHandle(new DrawPolygonOperation(pointArray)); } private class DrawPolygonOperation extends Operation { @@ -2096,7 +2091,7 @@ private void drawPolygonInPixels(int[] pointArray) { public void drawPolyline (int[] pointArray) { checkNonDisposed(); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - storeAndApplyOperationForExistingHandle(new DrawPolylineOperation(pointArray)); + applyOperationForExistingHandle(new DrawPolylineOperation(pointArray)); } private class DrawPolylineOperation extends Operation { @@ -2161,7 +2156,7 @@ private void drawPolylineInPixels(int[] pointArray) { */ public void drawRectangle (int x, int y, int width, int height) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new DrawRectangleOperation(new Rectangle(x, y, width, height))); + applyOperationForExistingHandle(new DrawRectangleOperation(new Rectangle(x, y, width, height))); } private class DrawRectangleOperation extends Operation { @@ -2230,7 +2225,7 @@ private void drawRectangleInPixels (int x, int y, int width, int height) { public void drawRectangle (Rectangle rect) { checkNonDisposed(); if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - storeAndApplyOperationForExistingHandle(new DrawRectangleOperation(rect)); + applyOperationForExistingHandle(new DrawRectangleOperation(rect)); } /** @@ -2256,7 +2251,7 @@ public void drawRectangle (Rectangle rect) { */ public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new DrawRoundRectangleOperation(new Rectangle(x, y, width, height), arcWidth, arcHeight)); + applyOperationForExistingHandle(new DrawRoundRectangleOperation(new Rectangle(x, y, width, height), arcWidth, arcHeight)); } private class DrawRoundRectangleOperation extends Operation { @@ -2368,7 +2363,7 @@ private void drawRoundRectangleGdip (long gdipGraphics, long pen, int x, int y, */ public void drawString (String string, int x, int y) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new DrawStringOperation(string, new Point(x, y), false)); + applyOperationForExistingHandle(new DrawStringOperation(string, new Point(x, y), false)); } /** @@ -2402,7 +2397,7 @@ public void drawString (String string, int x, int y, boolean isTransparent) { checkNonDisposed(); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (string.isEmpty()) return; - storeAndApplyOperationForExistingHandle(new DrawStringOperation(string, new Point(x, y), isTransparent)); + applyOperationForExistingHandle(new DrawStringOperation(string, new Point(x, y), isTransparent)); } private class DrawStringOperation extends Operation { @@ -2509,7 +2504,7 @@ public void drawText (String string, int x, int y) { checkNonDisposed(); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (string.isEmpty()) return; - storeAndApplyOperationForExistingHandle(new DrawTextOperation(string, new Point(x, y), SWT.DRAW_DELIMITER | SWT.DRAW_TAB)); + applyOperationForExistingHandle(new DrawTextOperation(string, new Point(x, y), SWT.DRAW_DELIMITER | SWT.DRAW_TAB)); } /** @@ -2542,7 +2537,7 @@ public void drawText (String string, int x, int y, boolean isTransparent) { if (string.isEmpty()) return; int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB; if (isTransparent) flags |= SWT.DRAW_TRANSPARENT; - storeAndApplyOperationForExistingHandle(new DrawTextOperation(string, new Point(x, y), flags)); + applyOperationForExistingHandle(new DrawTextOperation(string, new Point(x, y), flags)); } /** @@ -2588,7 +2583,7 @@ public void drawText (String string, int x, int y, int flags) { checkNonDisposed(); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (string.isEmpty()) return; - storeAndApplyOperationForExistingHandle(new DrawTextOperation(string, new Point(x, y), flags)); + applyOperationForExistingHandle(new DrawTextOperation(string, new Point(x, y), flags)); } private class DrawTextOperation extends Operation { @@ -2981,7 +2976,7 @@ public boolean equals (Object object) { */ public void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new FillArcOperation(new Rectangle(x, y, width, height), startAngle, arcAngle)); + applyOperationForExistingHandle(new FillArcOperation(new Rectangle(x, y, width, height), startAngle, arcAngle)); } private class FillArcOperation extends Operation { @@ -3075,7 +3070,7 @@ private void fillArcInPixels (int x, int y, int width, int height, int startAngl */ public void fillGradientRectangle (int x, int y, int width, int height, boolean vertical) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new FillGradientRectangleOperation(new Rectangle(x, y, width, height), vertical)); + applyOperationForExistingHandle(new FillGradientRectangleOperation(new Rectangle(x, y, width, height), vertical)); } private class FillGradientRectangleOperation extends FillRectangleOperation { @@ -3204,7 +3199,7 @@ private void fillGradientRectangleInPixels(int x, int y, int width, int height, */ public void fillOval (int x, int y, int width, int height) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new FillOvalOperation(new Rectangle(x, y, width, height))); + applyOperationForExistingHandle(new FillOvalOperation(new Rectangle(x, y, width, height))); } private class FillOvalOperation extends Operation { @@ -3259,7 +3254,7 @@ public void fillPath (Path path) { checkNonDisposed(); if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - storeAndApplyOperationForExistingHandle(new FillPathOperation(path)); + applyOperationForExistingHandle(new FillPathOperation(path)); } private class FillPathOperation extends Operation { @@ -3304,7 +3299,7 @@ void apply() { public void fillPolygon (int[] pointArray) { checkNonDisposed(); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - storeAndApplyOperationForExistingHandle(new FillPolygonOperation(pointArray)); + applyOperationForExistingHandle(new FillPolygonOperation(pointArray)); } private class FillPolygonOperation extends Operation { @@ -3366,7 +3361,7 @@ private void fillPolygonInPixels (int[] pointArray) { * @see #drawRectangle(int, int, int, int) */ public void fillRectangle (int x, int y, int width, int height) { - storeAndApplyOperationForExistingHandle(new FillRectangleOperation(new Rectangle(x, y, width, height))); + applyOperationForExistingHandle(new FillRectangleOperation(new Rectangle(x, y, width, height))); } private class FillRectangleOperation extends Operation { @@ -3420,7 +3415,7 @@ void fillRectangleInPixels (int x, int y, int width, int height) { public void fillRectangle (Rectangle rect) { checkNonDisposed(); if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - storeAndApplyOperationForExistingHandle(new FillRectangleOperation(rect)); + applyOperationForExistingHandle(new FillRectangleOperation(rect)); } /** @@ -3442,7 +3437,7 @@ public void fillRectangle (Rectangle rect) { */ public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new FillRoundRectangleOperation(new Rectangle(x, y, width, height), arcWidth, arcHeight)); + applyOperationForExistingHandle(new FillRoundRectangleOperation(new Rectangle(x, y, width, height), arcWidth, arcHeight)); } private class FillRoundRectangleOperation extends Operation { @@ -4464,7 +4459,7 @@ private float measureSpace(long font, long format) { */ public void setAdvanced(boolean advanced) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetAdvancedOperation(advanced)); + applyOperationForExistingHandle(new SetAdvancedOperation(advanced)); } private class SetAdvancedOperation extends Operation { @@ -4522,7 +4517,7 @@ void apply() { */ public void setAntialias(int antialias) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetAntialiasOperation(antialias)); + applyOperationForExistingHandle(new SetAntialiasOperation(antialias)); } private class SetAntialiasOperation extends Operation { @@ -4576,7 +4571,7 @@ void apply() { */ public void setAlpha(int alpha) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetAlphaOperation(alpha)); + applyOperationForExistingHandle(new SetAlphaOperation(alpha)); } private class SetAlphaOperation extends Operation { @@ -4622,7 +4617,7 @@ public void setBackground (Color color) { checkNonDisposed(); if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - storeAndApplyOperationForExistingHandle(new SetBackgroundOperation(color)); + applyOperationForExistingHandle(new SetBackgroundOperation(color)); } private class SetBackgroundOperation extends Operation { @@ -4668,7 +4663,7 @@ void apply() { public void setBackgroundPattern (Pattern pattern) { checkNonDisposed(); if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - storeAndApplyOperationForExistingHandle(new SetBackgroundPatternOperation(pattern)); + applyOperationForExistingHandle(new SetBackgroundPatternOperation(pattern)); } private class SetBackgroundPatternOperation extends Operation { @@ -4694,7 +4689,7 @@ void apply() { private void setClipping(long clipRgn) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetClippingRegionOperation(clipRgn)); + applyOperationForExistingHandle(new SetClippingRegionOperation(clipRgn)); } private class SetClippingRegionOperation extends Operation { @@ -4750,7 +4745,7 @@ private void setClippingRegion(long hRgn) { */ public void setClipping (int x, int y, int width, int height) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetClippingOperation(new Rectangle(x, y, width, height))); + applyOperationForExistingHandle(new SetClippingOperation(new Rectangle(x, y, width, height))); } private class SetClippingOperation extends Operation { @@ -4803,7 +4798,7 @@ private void setClippingInPixels (int x, int y, int width, int height) { public void setClipping (Path path) { checkNonDisposed(); if (path != null && path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - storeAndApplyOperationForExistingHandle(new SetClippingPathOperation(path)); + applyOperationForExistingHandle(new SetClippingPathOperation(path)); } private class SetClippingPathOperation extends Operation { @@ -4846,7 +4841,7 @@ public void setClipping (Rectangle rect) { if (rect == null) { setClipping(0); } else { - storeAndApplyOperationForExistingHandle(new SetClippingOperation(rect)); + applyOperationForExistingHandle(new SetClippingOperation(rect)); } } @@ -4890,7 +4885,7 @@ public void setClipping (Region region) { */ public void setFillRule(int rule) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetFillRuleOperation(rule)); + applyOperationForExistingHandle(new SetFillRuleOperation(rule)); } private class SetFillRuleOperation extends Operation { @@ -4931,7 +4926,7 @@ void apply() { public void setFont (Font font) { checkNonDisposed(); if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - storeAndApplyOperationForExistingHandle(new SetFontOperation(font)); + applyOperationForExistingHandle(new SetFontOperation(font)); } private class SetFontOperation extends Operation { @@ -4966,7 +4961,7 @@ public void setForeground (Color color) { checkNonDisposed(); if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - storeAndApplyOperationForExistingHandle(new SetForegroundOperation(color)); + applyOperationForExistingHandle(new SetForegroundOperation(color)); } private class SetForegroundOperation extends Operation { @@ -5011,7 +5006,7 @@ void apply() { public void setForegroundPattern (Pattern pattern) { checkNonDisposed(); if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - storeAndApplyOperationForExistingHandle(new SetForegroundPatternOperation(pattern)); + applyOperationForExistingHandle(new SetForegroundPatternOperation(pattern)); } private class SetForegroundPatternOperation extends Operation { @@ -5063,7 +5058,7 @@ void apply() { */ public void setInterpolation(int interpolation) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetInterpolationOperation(interpolation)); + applyOperationForExistingHandle(new SetInterpolationOperation(interpolation)); } private class SetInterpolationOperation extends Operation { @@ -5117,7 +5112,7 @@ void apply() { public void setLineAttributes (LineAttributes attributes) { if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetLineAttributesOperation(attributes)); + applyOperationForExistingHandle(new SetLineAttributesOperation(attributes)); } private class SetLineAttributesOperation extends Operation { @@ -5247,7 +5242,7 @@ private void setLineAttributesInPixels (LineAttributes attributes) { */ public void setLineCap(int cap) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetLineCapOperation(cap)); + applyOperationForExistingHandle(new SetLineCapOperation(cap)); } private class SetLineCapOperation extends Operation { @@ -5292,7 +5287,7 @@ void apply() { */ public void setLineDash(int[] dashes) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetLineDashOperation(dashes)); + applyOperationForExistingHandle(new SetLineDashOperation(dashes)); } private class SetLineDashOperation extends Operation { @@ -5344,7 +5339,7 @@ void apply() { */ public void setLineJoin(int join) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetLineJoinOperation(join)); + applyOperationForExistingHandle(new SetLineJoinOperation(join)); } private class SetLineJoinOperation extends Operation { @@ -5387,7 +5382,7 @@ void apply() { */ public void setLineStyle(int lineStyle) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetLineStyleOperation(lineStyle)); + applyOperationForExistingHandle(new SetLineStyleOperation(lineStyle)); } private class SetLineStyleOperation extends Operation { @@ -5441,7 +5436,7 @@ void apply() { */ public void setLineWidth(int lineWidth) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetLineWidthOperation(lineWidth)); + applyOperationForExistingHandle(new SetLineWidthOperation(lineWidth)); } private class SetLineWidthOperation extends Operation { @@ -5480,7 +5475,7 @@ private void setLineWidthInPixels(int lineWidth) { */ public void setXORMode(boolean xor) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetXORModeOperation(xor)); + applyOperationForExistingHandle(new SetXORModeOperation(xor)); } private class SetXORModeOperation extends Operation { @@ -5526,7 +5521,7 @@ void apply() { */ public void setTextAntialias(int antialias) { checkNonDisposed(); - storeAndApplyOperationForExistingHandle(new SetTextAntialiasOperation(antialias)); + applyOperationForExistingHandle(new SetTextAntialiasOperation(antialias)); } private class SetTextAntialiasOperation extends Operation { @@ -5593,7 +5588,7 @@ void apply() { public void setTransform(Transform transform) { checkNonDisposed(); if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - storeAndApplyOperationForExistingHandle(new SetTransformOperation(transform)); + applyOperationForExistingHandle(new SetTransformOperation(transform)); } private class SetTransformOperation extends Operation { @@ -5752,17 +5747,6 @@ Point textExtentInPixels(String string, int flags) { return new Point(rect.right, rect.bottom); } -void refreshFor(Drawable drawable, int zoom) { - if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (zoom == getZoom()) { - return; - } - destroy(); - GCData newData = new GCData(); - originalData.copyTo(newData); - createGcHandle(drawable, newData, zoom); -} - /** * Returns a string containing a concise, human-readable * description of the receiver. @@ -5794,7 +5778,6 @@ public String toString () { */ public static GC win32_new(Drawable drawable, GCData data) { GC gc = new GC(); - data.copyTo(gc.originalData); long hDC = drawable.internal_new_GC(data); gc.device = data.device; gc.init(drawable, data, hDC); @@ -5826,7 +5809,6 @@ public static GC win32_new(long hDC, GCData data) { if ((flags & OS.LAYOUT_RTL) != 0) { data.style |= SWT.RIGHT_TO_LEFT | SWT.MIRRORED; } - data.copyTo(gc.originalData); gc.init(null, data, hDC); return gc; } @@ -5861,21 +5843,10 @@ int getZoom() { return DPIUtil.getZoomForAutoscaleProperty(data.nativeZoom); } -private void storeAndApplyOperationForExistingHandle(Operation operation) { - operations.add(operation); +private void applyOperationForExistingHandle(Operation operation) { operation.apply(); } -private void createGcHandle(Drawable drawable, GCData newData, int nativeZoom) { - newData.nativeZoom = nativeZoom; - long newHandle = drawable.internal_new_GC(newData); - if (newHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES); - init(drawable, newData, newHandle); - for (Operation operation : operations) { - operation.apply(); - } -} - private abstract class Operation { abstract void apply(); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java index 9530d94fb4c..010cc9ae943 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java @@ -1707,7 +1707,7 @@ private long configureGC(GCData data, int zoom) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } - if (Device.strictChecks) { + if(Device.strictChecks) { checkImageTypeForValidCustomDrawing(zoom); } /* Create a compatible HDC for the device */ @@ -1885,6 +1885,11 @@ public Collection getPreservedZoomLevels() { abstract AbstractImageProviderWrapper createCopy(Image image); ImageData getScaledImageData (int zoom) { + // if a GC is initialized with an Image (memGC != null), the image data must not be resized, because it would + // be a destructive operation. Therefor, always the current image data must be returned + if (memGC != null) { + return getImageDataAtCurrentZoom(); + } TreeSet availableZooms = new TreeSet<>(zoomLevelToImageHandle.keySet()); int closestZoom = Optional.ofNullable(availableZooms.higher(zoom)).orElse(availableZooms.lower(zoom)); return DPIUtil.scaleImageData(device, getImageMetadata(closestZoom).getImageData(), zoom, closestZoom); @@ -2118,11 +2123,6 @@ ImageData newImageData(int zoom) { if (zoomLevelToImageHandle.isEmpty()) { return createBaseHandle(zoom).getImageData(); } - // if a GC is initialized with an Image (memGC != null), the image data must not be resized, because it would - // be a destructive operation. Therefor, a new handle is created for the requested zoom - if (memGC != null) { - return newImageHandle(zoom).getImageData(); - } return getScaledImageData(zoom); } @@ -2131,28 +2131,18 @@ protected ImageHandle newImageHandle(int zoom) { if (zoomLevelToImageHandle.isEmpty()) { return createBaseHandle(zoom); } - if (memGC != null) { - GC currentGC = memGC; - memGC = null; - createHandle(zoom); - currentGC.refreshFor(new DrawableWrapper(Image.this, zoom), zoom); - return zoomLevelToImageHandle.get(zoom); - } return super.newImageHandle(zoom); } + private ImageHandle createBaseHandle(int zoom) { + long handle = initBaseHandle(zoom); baseZoom = zoom; - return createHandle(zoom); - } - - private ImageHandle createHandle(int zoom) { - long handle = initHandle(zoom); ImageHandle imageHandle = new ImageHandle(handle, zoom); zoomLevelToImageHandle.put(zoom, imageHandle); return imageHandle; } - private long initHandle(int zoom) { + private long initBaseHandle(int zoom) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); int scaledWidth = Win32DPIUtils.pointToPixel (width, zoom); int scaledHeight = Win32DPIUtils.pointToPixel (height, zoom); @@ -2564,6 +2554,7 @@ protected ImageHandle newImageHandle(int zoom) { } GC gc = new GC(new DrawableWrapper(image, zoom), gcStyle); try { + gc.data.nativeZoom = zoom; drawer.drawOn(gc, width, height); ImageData imageData = image.getImageMetadata(zoom).getImageData(); drawer.postProcess(imageData); @@ -2575,6 +2566,26 @@ protected ImageHandle newImageHandle(int zoom) { } } + private class DrawableWrapper implements Drawable { + private final Image image; + private final int zoom; + + public DrawableWrapper(Image image, int zoom) { + this.image = image; + this.zoom = zoom; + } + + @Override + public long internal_new_GC(GCData data) { + return this.image.configureGC(data, zoom); + } + + @Override + public void internal_dispose_GC(long handle, GCData data) { + this.image.internal_dispose_GC(handle, data); + } + } + @Override Object getProvider() { return drawer; @@ -2597,26 +2608,6 @@ public boolean equals(Object otherProvider) { } } -private static class DrawableWrapper implements Drawable { - private final Image image; - private final int zoom; - - public DrawableWrapper(Image image, int zoom) { - this.image = image; - this.zoom = zoom; - } - - @Override - public long internal_new_GC(GCData data) { - return this.image.configureGC(data, zoom); - } - - @Override - public void internal_dispose_GC(long handle, GCData data) { - this.image.internal_dispose_GC(handle, data); - } -} - private class ImageHandle { private long handle; private final int zoom; diff --git a/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Regression2243_ApplyOperationPatternOnGC.java b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Regression2243_ApplyOperationPatternOnGC.java new file mode 100644 index 00000000000..9d2c0f718b7 --- /dev/null +++ b/tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Regression2243_ApplyOperationPatternOnGC.java @@ -0,0 +1,54 @@ +package org.eclipse.swt.tests.manual; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.GCData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +/** + * Introduced by https://github.com/eclipse-platform/eclipse.platform.swt/pull/2243 + */ +public class Regression2243_ApplyOperationPatternOnGC { + public static void main (String [] args) { + Display display = new Display (); + Shell shell = new Shell (display); + shell.setText("GC Redraw"); + shell.setLayout(new FillLayout()); + int width = 150, height = 200; + Image image = new Image (display, width, height); + Image imageToDraw = new Image(display, 1, 1); + + GCData data = new GCData(); + GC gc = GC.win32_new(image, data); + gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); + gc.fillRectangle (0, 0, width, height); + gc.drawLine (0, 0, width, height); + gc.drawLine (0, height, width, 0); + gc.drawText ("Default Image", 10, 10); + gc.drawImage(imageToDraw, 0, 0); + imageToDraw.dispose(); + final Point origin = new Point (0, 0); + final Canvas canvas = new Canvas (shell, SWT.NONE); + canvas.addListener (SWT.Paint, e -> { + GC gc2 = e.gc; + gc2.getGCData().nativeZoom = 150; + gc2.drawImage (image, origin.x, origin.y); + gc2.getGCData().nativeZoom = 200; + gc2.drawImage (image, origin.x + 300, origin.y); + }); + shell.setSize (1000, 1000); + shell.open (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + gc.dispose (); + image.dispose(); + display.dispose (); + } +} +