diff options
author | Niraj Modi | 2016-02-01 08:47:14 +0000 |
---|---|---|
committer | Niraj Modi | 2016-02-01 08:47:14 +0000 |
commit | d4a5fcd9f23c90751e93b918367299938f4ced42 (patch) | |
tree | bbf737019c19ca86368a7c6b6ee9e5cd286aeeea | |
parent | 7fc5ffd33011485e1ea8dc750811f34b600c70bf (diff) | |
download | eclipse.platform.swt-d4a5fcd9f23c90751e93b918367299938f4ced42.tar.gz eclipse.platform.swt-d4a5fcd9f23c90751e93b918367299938f4ced42.tar.xz eclipse.platform.swt-d4a5fcd9f23c90751e93b918367299938f4ced42.zip |
Bug 479614 - [Graphics] HiDPI support for eclipse platform
Change-Id: I10d1199d5480159973451115818c39431da56519
Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
5 files changed, 86 insertions, 166 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java index a775f639bf..5b54cc27a6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java @@ -82,24 +82,6 @@ public Device getDevice() { return device; } -/** - * Returns autoScaling settings for hiDpi screens - * - * @return boolean value for autoScaling - * @since 3.105 - * - */ -public boolean getEnableAutoScaling() { - return DPIUtil.getAutoScale(); -} -/** - * Sets autoScaling settings for hiDpi screens - * @since 3.105 - * - */ -void setEnableAutoScaling(boolean value) { - DPIUtil.setAutoScale(value); -} void init() { if (device.tracking) device.new_Object(this); } @@ -116,11 +98,4 @@ void init() { */ public abstract boolean isDisposed(); -/** - * @since 3.105 - */ -public int getDeviceZoom () { - return device.getDeviceZoom (); -} - }
\ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java index 9888f708bb..5c287a1796 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java @@ -1000,4 +1000,8 @@ void setEnableAutoScaling(boolean value) { enableAutoScaling = value; } +public int getDeviceZoom () { + return DPIUtil.mapDPIToZoom ( _getDPIx ()); +} + } 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 215f167035..9dbed7e0ec 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 @@ -170,7 +170,7 @@ public GC(Drawable drawable, int style) { if (device == null) device = Device.getDevice(); if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); this.device = data.device = device; - this.autoScaleEnabled = getEnableAutoScaling (); + this.autoScaleEnabled = DPIUtil.getAutoScale (); init (drawable, data, hDC); init(); } @@ -450,11 +450,8 @@ public void copyArea(Image image, int x, int y) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (autoScaleEnabled) { - float scaleFactor = ((float)this.getDeviceZoom()) / 100f; - x = (int)(x * scaleFactor); - y = (int)(y * scaleFactor); - } + x = DPIUtil.autoScaleUp(x, device); + y = DPIUtil.autoScaleUp(y, device); /* Copy the bitmap area */ Rectangle rect = image.getBounds(); long /*int*/ memHdc = OS.CreateCompatibleDC(handle); @@ -736,13 +733,8 @@ void disposeGdip() { public void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); - if (autoScaleEnabled) { - float scaleFactor = ((float)getDeviceZoom()) / 100f; - x = (int) (x * scaleFactor); - y = (int) (y * scaleFactor); - width = (int) (width * scaleFactor); - height = (int) (height * scaleFactor); - } + width = DPIUtil.autoScaleUp(width, device); + height = DPIUtil.autoScaleUp(height, device); if (width < 0) { x = x + width; width = -width; @@ -840,13 +832,11 @@ public void drawArc (int x, int y, int width, int height, int startAngle, int ar */ public void drawFocus (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (autoScaleEnabled) { - float scaleFactor = (float) getDeviceZoom()/100f; - x = (int) (x * scaleFactor); - y = (int) (y * scaleFactor); - width = (int) (width * scaleFactor); - height = (int) (height *scaleFactor); - } + x = DPIUtil.autoScaleUp (x, device); + y = DPIUtil.autoScaleUp (y, device); + width = DPIUtil.autoScaleUp (width, device); + height = DPIUtil.autoScaleUp (height, device); + if ((data.uiState & OS.UISF_HIDEFOCUS) != 0) return; data.focusDrawn = true; long /*int*/ hdc = handle; @@ -1698,13 +1688,10 @@ void drawBitmap(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, */ public void drawLine (int x1, int y1, int x2, int y2) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (autoScaleEnabled) { - float scaleFactor = (float) getDeviceZoom()/100f; - x1 = (int) (x1 * scaleFactor); - x2 = (int) (x2 * scaleFactor); - y1 = (int) (y1 * scaleFactor); - y2 = (int) (y2 *scaleFactor); - } + x1 = DPIUtil.autoScaleUp (x1, device); + x2 = DPIUtil.autoScaleUp (x2, device); + y1 = DPIUtil.autoScaleUp (y1, device); + y2 = DPIUtil.autoScaleUp (y2, device); checkGC(DRAW); long /*int*/ gdipGraphics = data.gdipGraphics; @@ -1755,13 +1742,11 @@ public void drawLine (int x1, int y1, int x2, int y2) { */ public void drawOval (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (autoScaleEnabled) { - float scaleFactor = (float) getDeviceZoom()/100f; - x = (int) (x * scaleFactor); - y = (int) (y * scaleFactor); - width = (int) (width * scaleFactor); - height = (int) (height *scaleFactor); - } + x = DPIUtil.autoScaleUp (x, device); + y = DPIUtil.autoScaleUp (y, device); + width = DPIUtil.autoScaleUp (width, device); + height = DPIUtil.autoScaleUp (height, device); + checkGC(DRAW); long /*int*/ gdipGraphics = data.gdipGraphics; if (gdipGraphics != 0) { @@ -1830,11 +1815,9 @@ public void drawPath (Path path) { */ public void drawPoint (int x, int y) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (autoScaleEnabled) { - float scaleFactor = (float) getDeviceZoom()/100f; - x = (int) (x * scaleFactor); - y = (int) (y * scaleFactor); - } + x = DPIUtil.autoScaleUp (x, device); + y = DPIUtil.autoScaleUp (y, device); + if (data.gdipGraphics != 0) { checkGC(DRAW); Gdip.Graphics_FillRectangle(data.gdipGraphics, getFgBrush(), x, y, 1, 1); @@ -1957,11 +1940,10 @@ public void drawPolyline(int[] pointArray) { public void drawRectangle (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (autoScaleEnabled) { - float scaleFactor = (float) getDeviceZoom()/100f; - x = (int) (x * scaleFactor); - y = (int) (y * scaleFactor); - width = (int) (width * scaleFactor); - height = (int) (height *scaleFactor); + x = DPIUtil.autoScaleUp (x, device); + y = DPIUtil.autoScaleUp (y, device); + width = DPIUtil.autoScaleUp (width, device); + height = DPIUtil.autoScaleUp (height, device); } checkGC(DRAW); long /*int*/ gdipGraphics = data.gdipGraphics; @@ -2039,15 +2021,13 @@ public void drawRectangle (Rectangle rect) { */ public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (autoScaleEnabled) { - float scaleFactor = (float) getDeviceZoom()/100f; - x = (int) (x * scaleFactor); - y = (int) (y * scaleFactor); - width = (int) (width * scaleFactor); - height = (int) (height *scaleFactor); - arcWidth = (int)(arcWidth *scaleFactor); - arcHeight = (int)(arcHeight * scaleFactor); - } + x = DPIUtil.autoScaleUp (x, device); + y = DPIUtil.autoScaleUp (y, device); + width = DPIUtil.autoScaleUp (width, device); + height = DPIUtil.autoScaleUp (height, device); + arcWidth = DPIUtil.autoScaleUp (arcWidth, device); + arcHeight = DPIUtil.autoScaleUp (arcHeight, device); + checkGC(DRAW); if (data.gdipGraphics != 0) { drawRoundRectangleGdip(data.gdipGraphics, data.gdipPen, x, y, width, height, arcWidth, arcHeight); @@ -2744,13 +2724,11 @@ public boolean equals (Object object) { */ public void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (autoScaleEnabled) { - float scaleFactor = (float) getDeviceZoom()/100f; - x = (int) (x * scaleFactor); - y = (int) (y * scaleFactor); - width = (int) (width * scaleFactor); - height = (int) (height *scaleFactor); - } + x = DPIUtil.autoScaleUp (x, device); + y = DPIUtil.autoScaleUp (y, device); + width = DPIUtil.autoScaleUp (width, device); + height = DPIUtil.autoScaleUp (height, device); + checkGC(FILL); if (width < 0) { x = x + width; @@ -2852,13 +2830,11 @@ public void fillArc (int x, int y, int width, int height, int startAngle, int ar */ public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (autoScaleEnabled) { - float scaleFactor = (float) getDeviceZoom()/100f; - x = (int) (x * scaleFactor); - y = (int) (y * scaleFactor); - width = (int) (width * scaleFactor); - height = (int) (height *scaleFactor); - } + x = DPIUtil.autoScaleUp (x, device); + y = DPIUtil.autoScaleUp (y, device); + width = DPIUtil.autoScaleUp (width, device); + height = DPIUtil.autoScaleUp (height, device); + if (width == 0 || height == 0) return; RGB backgroundRGB, foregroundRGB; @@ -2985,13 +2961,11 @@ public void fillGradientRectangle(int x, int y, int width, int height, boolean v */ public void fillOval (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (autoScaleEnabled) { - float scaleFactor = (float) getDeviceZoom()/100f; - x = (int) (x * scaleFactor); - y = (int) (y * scaleFactor); - width = (int) (width * scaleFactor); - height = (int) (height *scaleFactor); - } + x = DPIUtil.autoScaleUp (x, device); + y = DPIUtil.autoScaleUp (y, device); + width = DPIUtil.autoScaleUp (width, device); + height = DPIUtil.autoScaleUp (height, device); + checkGC(FILL); if (data.gdipGraphics != 0) { Gdip.Graphics_FillEllipse(data.gdipGraphics, data.gdipBrush, x, y, width, height); @@ -3094,11 +3068,10 @@ public void fillPolygon(int[] pointArray) { public void fillRectangle (int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (autoScaleEnabled) { - float scaleFactor = (float) getDeviceZoom()/100f; - x = (int) (x * scaleFactor); - y = (int) (y * scaleFactor); - width = (int) (width * scaleFactor); - height = (int) (height *scaleFactor); + x = DPIUtil.autoScaleUp (x, device); + y = DPIUtil.autoScaleUp (y, device); + width = DPIUtil.autoScaleUp (width, device); + height = DPIUtil.autoScaleUp (height, device); } checkGC(FILL); if (data.gdipGraphics != 0) { @@ -3163,15 +3136,13 @@ public void fillRectangle (Rectangle rect) { */ public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (autoScaleEnabled) { - float scaleFactor = this.getDeviceZoom() / 100f; - x = (int)(x * scaleFactor); - y = (int)(y * scaleFactor); - width = (int)(width * scaleFactor); - height = (int)(height * scaleFactor); - arcWidth = (int)(arcWidth *scaleFactor); - arcHeight = (int)(arcHeight * scaleFactor); - } + x = DPIUtil.autoScaleUp (x, device); + y = DPIUtil.autoScaleUp (y, device); + width = DPIUtil.autoScaleUp (width, device); + height = DPIUtil.autoScaleUp (height, device); + arcWidth = DPIUtil.autoScaleUp (arcWidth, device); + arcHeight = DPIUtil.autoScaleUp (arcHeight, device); + checkGC(FILL); if (data.gdipGraphics != 0) { fillRoundRectangleGdip(data.gdipGraphics, data.gdipBrush, x, y, width, height, arcWidth, arcHeight); @@ -3810,12 +3781,7 @@ public int getLineStyle() { */ public int getLineWidth() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - int returnVal = (int)data.lineWidth; - if (autoScaleEnabled) { - float scaleFactor = ((float)this.getDeviceZoom()) / 100f; - returnVal = (int)(returnVal / scaleFactor); - } - return returnVal; + return DPIUtil.autoScaleDown((int)data.lineWidth, device); } /** @@ -4887,10 +4853,8 @@ public void setLineStyle(int lineStyle) { */ public void setLineWidth(int lineWidth) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (autoScaleEnabled) { - float scaleFactor = ((float)this.getDeviceZoom()) / 100f; - lineWidth = (int)(lineWidth * scaleFactor); - } + lineWidth = DPIUtil.autoScaleUp (lineWidth, device); + if (data.lineWidth == lineWidth) return; data.lineWidth = lineWidth; data.state &= ~(LINE_WIDTH | DRAW_OFFSET); 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 6a9afc79bb..182eb50a8e 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 @@ -197,12 +197,8 @@ Image (Device device) { */ public Image(Device device, int width, int height) { super(device); - if (this.getEnableAutoScaling ()) { - currentDeviceZoom = getDeviceZoom(); - float scaleFactor = ((float)currentDeviceZoom / 100f); - width = (int)(width * scaleFactor); - height = (int)(height * scaleFactor); - } + width = DPIUtil.autoScaleUp (width, device); + height = DPIUtil.autoScaleUp (height, device); init(width, height); init(); } @@ -462,19 +458,9 @@ public Image(Device device, Image srcImage, int flag) { public Image(Device device, Rectangle bounds) { super(device); if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); -<<<<<<< HEAD - if (getEnableAutoScaling ()) { - currentDeviceZoom = getDeviceZoom(); - Rectangle bounds1 = DPIUtil.scale(bounds, currentDeviceZoom, 100); - init(bounds1.width, bounds1.height); - } else { - init(bounds.width, bounds.height); - } - init(); -======= + bounds = DPIUtil.autoScaleUp (bounds, device); init(bounds.width, bounds.height); init(); ->>>>>>> refs/remotes/origin/master } /** @@ -503,10 +489,7 @@ public Image(Device device, Rectangle bounds) { public Image(Device device, ImageData data) { super(device); if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (getEnableAutoScaling()) { - currentDeviceZoom = getDeviceZoom(); - data = DPIUtil.autoScaleImageData(data, currentDeviceZoom, 100); - } + data = DPIUtil.autoScaleUp (data, device); init(data); init(); } @@ -548,11 +531,8 @@ public Image(Device device, ImageData source, ImageData mask) { if (source.width != mask.width || source.height != mask.height) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } - if (getEnableAutoScaling()){ - currentDeviceZoom = getDeviceZoom(); - source = DPIUtil.autoScaleImageData(source, currentDeviceZoom, 100); - mask = DPIUtil.autoScaleImageData(mask, currentDeviceZoom, 100); - } + source = DPIUtil.autoScaleUp(source, device); + mask = DPIUtil.autoScaleUp(mask, device); mask = ImageData.convertMask(mask); init(this.device, this, source, mask); init(); @@ -689,14 +669,14 @@ public Image (Device device, String filename) { public Image(Device device, ImageFileNameProvider imageFileNameProvider) { super(device); this.imageFileNameProvider = imageFileNameProvider; - currentDeviceZoom = getDeviceZoom (); + currentDeviceZoom = device.getDeviceZoom (); boolean[] found = new boolean[1]; String fileName = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, currentDeviceZoom, found); if (found[0]) { initNative (fileName); if (this.handle == 0) init(new ImageData (fileName)); } else { - ImageData resizedData = DPIUtil.autoScaleImageFileName(fileName, currentDeviceZoom, 100); + ImageData resizedData = DPIUtil.autoScaleUp (new ImageData (fileName), device); init(resizedData); } init(); @@ -734,13 +714,13 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) { public Image(Device device, ImageDataProvider imageDataProvider) { super(device); this.imageDataProvider = imageDataProvider; - currentDeviceZoom = getDeviceZoom (); + currentDeviceZoom = device.getDeviceZoom (); boolean[] found = new boolean[1]; ImageData data = DPIUtil.validateAndGetImageDataAtZoom(imageDataProvider, currentDeviceZoom, found); if (found[0]) { init(data); } else { - ImageData resizedData = DPIUtil.autoScaleImageData(data, currentDeviceZoom, 100); + ImageData resizedData = DPIUtil.autoScaleUp(data, device); init (resizedData); } init(); @@ -754,7 +734,7 @@ public Image(Device device, ImageDataProvider imageDataProvider) { boolean refreshImageForZoom () { boolean refreshed = false; if (imageFileNameProvider != null) { - int deviceZoomLevel = getDeviceZoom(); + int deviceZoomLevel = device.getDeviceZoom(); if (deviceZoomLevel != currentDeviceZoom) { boolean[] found = new boolean[1]; String filename = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, deviceZoomLevel, found); @@ -770,7 +750,7 @@ boolean refreshImageForZoom () { if (!found[0]) { /* Release current native resources */ destroy (); - ImageData resizedData = DPIUtil.autoScaleImageFileName(filename, deviceZoomLevel, 100); + ImageData resizedData = DPIUtil.autoScaleUp (new ImageData (filename), device); init(resizedData); init (); refreshed = true; @@ -778,7 +758,7 @@ boolean refreshImageForZoom () { currentDeviceZoom = deviceZoomLevel; } } else if (imageDataProvider != null) { - int deviceZoomLevel = getDeviceZoom(); + int deviceZoomLevel = device.getDeviceZoom(); if (deviceZoomLevel != currentDeviceZoom) { boolean[] found = new boolean[1]; ImageData data = DPIUtil.validateAndGetImageDataAtZoom (imageDataProvider, deviceZoomLevel, found); @@ -793,7 +773,7 @@ boolean refreshImageForZoom () { if (!found[0]) { /* Release current native resources */ destroy (); - ImageData resizedData = DPIUtil.autoScaleImageData(data, deviceZoomLevel, 100); + ImageData resizedData = DPIUtil.autoScaleUp (data, device); init(resizedData); init(); refreshed = true; @@ -1396,15 +1376,12 @@ public Color getBackground() { public Rectangle getBounds() { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); Rectangle bounds = _getBounds(); - if (getEnableAutoScaling()) { - bounds = DPIUtil.scale(bounds, 100, currentDeviceZoom); - } - return bounds; + return DPIUtil.autoScaleDown (bounds, device); } /** * @return a rectangle specifying the image's bounds at current zoom. - */ + */ Rectangle _getBounds() { if (width != -1 && height != -1) { return new Rectangle(0, 0, width, height); @@ -1835,7 +1812,7 @@ ImageData _getImageData() { * </ul> * * @see ImageData - * + * * @since 3.105 */ public ImageData getImageData (int zoom) { @@ -1844,8 +1821,8 @@ public ImageData getImageData (int zoom) { } /** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to + * Returns an integer hash code for the receiver. Any two + * objects that return <code>true</code> when passed to ======= * Returns an integer hash code for the receiver. Any two * objects that return <code>true</code> when passed to diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java index ab09ad1f83..3670b3fec4 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java @@ -738,7 +738,7 @@ public void test_getBounds_Zoom() { Rectangle bounds = new Rectangle(0, 0, 10, 20); Rectangle bounds2 = new Rectangle(0, 0, 20, 40); Image image = new Image(display, bounds.width, bounds.height); - int zoom = image.getDeviceZoom(); + int zoom = image.getDevice ().getDeviceZoom(); image.dispose(); try { image.getBounds(zoom); |