diff options
author | Sravan Kumar Lakkimsetti | 2015-05-20 17:27:04 +0000 |
---|---|---|
committer | Lakshmi Shanmugam | 2015-05-21 10:37:49 +0000 |
commit | 74b47282f9f1cd29fb3c6b10803cb0b040c8299e (patch) | |
tree | d2c54038da441de5ae0af84a94c89a7e7abdf532 | |
parent | 7f23ac89692a1157ac14417624d4694cea529e0e (diff) | |
download | eclipse.platform.swt-74b47282f9f1cd29fb3c6b10803cb0b040c8299e.tar.gz eclipse.platform.swt-74b47282f9f1cd29fb3c6b10803cb0b040c8299e.tar.xz eclipse.platform.swt-74b47282f9f1cd29fb3c6b10803cb0b040c8299e.zip |
Bug 467687 - SWT: Invalid thread access in GC.drawImage
On Windows created a new method getActualDPI() that works in non ui
threads as well and using this to get the dpi
On linux modified the getActualdpi() method to not use getbounds call
which is actually not required as we need on only x and y of the
display. these are always 0, 0 in all cases of getBounds.
Updated with review comments
Change-Id: I7154ca7a2493fc21d1e38388a2f19c885ce9e4bf
Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
4 files changed, 41 insertions, 16 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java index 53783d1ead..6fd1bce19e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java @@ -955,10 +955,15 @@ static long /*int*/ XIOErrorProc (long /*int*/ xDisplay) { return 0; } -int getActualDPI () { +/** + * Returns DPI in x direction. In the modern monitors DPI for + * X and Y directions is same. + * + * @return the horizontal DPI + */ +int _getDPIx () { long /*int*/ screen = OS.gdk_screen_get_default(); - Rectangle rect = getBounds(); - int monitor = OS.gdk_screen_get_monitor_at_point(screen, rect.x, rect.y); + int monitor = OS.gdk_screen_get_monitor_at_point(screen, 0, 0); GdkRectangle dest = new GdkRectangle (); OS.gdk_screen_get_monitor_geometry(screen, monitor, dest); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java index 0191a6cc92..e4c5450cc1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java @@ -762,7 +762,7 @@ public Image(Device device, ImageDataProvider imageDataProvider) { } int getDeviceZoom () { - return DPIUtil.mapDPIToZoom (device.getActualDPI ()); + return DPIUtil.mapDPIToZoom (device._getDPIx ()); } /** @@ -771,10 +771,10 @@ int getDeviceZoom () { * @return true if image is refreshed */ boolean refreshImageForZoom () { - int deviceZoomLevel = getDeviceZoom(); boolean refreshed = false; - if (deviceZoomLevel != currentDeviceZoom) { - if (imageFileNameProvider != null) { + if (imageFileNameProvider != null) { + int deviceZoomLevel = getDeviceZoom(); + if (deviceZoomLevel != currentDeviceZoom) { boolean[] found = new boolean[1]; String filename = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, deviceZoomLevel, found); /* Avoid re-creating the fall-back image, when current zoom is already 100% */ @@ -786,7 +786,11 @@ boolean refreshImageForZoom () { init (); refreshed = true; } - } else if (imageDataProvider != null) { + currentDeviceZoom = deviceZoomLevel; + } + } else if (imageDataProvider != null) { + int deviceZoomLevel = getDeviceZoom(); + if (deviceZoomLevel != currentDeviceZoom) { boolean[] found = new boolean[1]; ImageData data = DPIUtil.validateAndGetImageDataAtZoom (imageDataProvider, deviceZoomLevel, found); /* Avoid re-creating the fall-back image, when current zoom is already 100% */ @@ -797,8 +801,8 @@ boolean refreshImageForZoom () { init(); refreshed = true; } + currentDeviceZoom = deviceZoomLevel; } - currentDeviceZoom = deviceZoomLevel; } return refreshed; } 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 c71e47ff79..af0b77bae1 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 @@ -11,10 +11,10 @@ package org.eclipse.swt.graphics; +import org.eclipse.swt.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gdip.*; import org.eclipse.swt.internal.win32.*; -import org.eclipse.swt.*; /** * This class is the abstract superclass of all device objects, @@ -472,6 +472,18 @@ public Point getDPI () { } /** + * Returns DPI in x direction. In the modern monitors DPI for + * X and Y directions is same. + * + * @return the horizontal DPI + */ +int _getDPIx () { + long /*int*/ hDC = internal_new_GC (null); + int dpi = OS.GetDeviceCaps (hDC, OS.LOGPIXELSX); + internal_dispose_GC (hDC, null); + return dpi; +} +/** * Returns <code>FontData</code> objects which describe * the fonts that match the given arguments. If the * <code>faceName</code> is null, all fonts will be returned. 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 8e1f8b9ec4..c13f1755b7 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 @@ -708,7 +708,7 @@ public Image(Device device, ImageDataProvider imageDataProvider) { } int getDeviceZoom () { - return DPIUtil.mapDPIToZoom (device.getDPI ().x); + return DPIUtil.mapDPIToZoom (device._getDPIx ()); } /** @@ -717,10 +717,10 @@ int getDeviceZoom () { * @return true if image is refreshed */ boolean refreshImageForZoom () { - int deviceZoomLevel = getDeviceZoom(); boolean refreshed = false; - if (deviceZoomLevel != currentDeviceZoom) { - if (imageFileNameProvider != null) { + if (imageFileNameProvider != null) { + int deviceZoomLevel = getDeviceZoom(); + if (deviceZoomLevel != currentDeviceZoom) { boolean[] found = new boolean[1]; String filename = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, deviceZoomLevel, found); /* Avoid re-creating the fall-back image, when current zoom is already 100% */ @@ -732,7 +732,11 @@ boolean refreshImageForZoom () { init(); refreshed = true; } - } else if (imageDataProvider != null) { + currentDeviceZoom = deviceZoomLevel; + } + } else if (imageDataProvider != null) { + int deviceZoomLevel = getDeviceZoom(); + if (deviceZoomLevel != currentDeviceZoom) { boolean[] found = new boolean[1]; ImageData data = DPIUtil.validateAndGetImageDataAtZoom (imageDataProvider, deviceZoomLevel, found); /* Avoid re-creating the fall-back image, when current zoom is already 100% */ @@ -743,8 +747,8 @@ boolean refreshImageForZoom () { init(); refreshed = true; } + currentDeviceZoom = deviceZoomLevel; } - currentDeviceZoom = deviceZoomLevel; } return refreshed; } |