From d111acbae39f5c650e5c87748d9529d8c6f6a57b Mon Sep 17 00:00:00 2001 From: Sravan Kumar Lakkimsetti Date: Wed, 2 May 2018 17:37:59 +0530 Subject: Bug 530932 - Enable native scaling on Linux GTK Change-Id: I98a9fcd461739f27f62f0179c4df4ea6ece6f370 Signed-off-by: Sravan Kumar Lakkimsetti --- .../Eclipse SWT PI/cairo/library/cairo.c | 43 ++++++++++++++++++++++ .../Eclipse SWT PI/cairo/library/cairo_custom.h | 2 + .../Eclipse SWT PI/cairo/library/cairo_stats.c | 2 + .../Eclipse SWT PI/cairo/library/cairo_stats.h | 2 + .../org/eclipse/swt/internal/cairo/Cairo.java | 28 ++++++++++++++ .../gtk/org/eclipse/swt/internal/gtk/OS.java | 5 --- .../common/org/eclipse/swt/internal/DPIUtil.java | 11 +++++- .../gtk/org/eclipse/swt/graphics/Device.java | 1 + .../gtk/org/eclipse/swt/graphics/Image.java | 19 ++++++++++ .../gtk/org/eclipse/swt/internal/ImageList.java | 6 ++- .../gtk/org/eclipse/swt/widgets/MenuItem.java | 6 +++ .../gtk/org/eclipse/swt/widgets/Table.java | 4 +- .../gtk/org/eclipse/swt/widgets/TableItem.java | 19 ++++++++-- .../gtk/org/eclipse/swt/widgets/Tree.java | 4 +- .../gtk/org/eclipse/swt/widgets/TreeItem.java | 19 ++++++++-- 15 files changed, 152 insertions(+), 19 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo.c index e8d3ce9784..dc39bccf20 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo.c @@ -1219,6 +1219,31 @@ JNIEXPORT jint JNICALL Cairo_NATIVE(_1cairo_1surface_1get_1content) } #endif +#ifndef NO__1cairo_1surface_1get_1device_1scale +JNIEXPORT void JNICALL Cairo_NATIVE(_1cairo_1surface_1get_1device_1scale) + (JNIEnv *env, jclass that, jintLong arg0, jdoubleArray arg1, jdoubleArray arg2) +{ + jdouble *lparg1=NULL; + jdouble *lparg2=NULL; + Cairo_NATIVE_ENTER(env, that, _1cairo_1surface_1get_1device_1scale_FUNC); + if (arg1) if ((lparg1 = (*env)->GetDoubleArrayElements(env, arg1, NULL)) == NULL) goto fail; + if (arg2) if ((lparg2 = (*env)->GetDoubleArrayElements(env, arg2, NULL)) == NULL) goto fail; +/* + cairo_surface_get_device_scale((cairo_surface_t *)arg0, (double *)lparg1, (double *)lparg2); +*/ + { + Cairo_LOAD_FUNCTION(fp, cairo_surface_get_device_scale) + if (fp) { + ((void (CALLING_CONVENTION*)(cairo_surface_t *, double *, double *))fp)((cairo_surface_t *)arg0, (double *)lparg1, (double *)lparg2); + } + } +fail: + if (arg2 && lparg2) (*env)->ReleaseDoubleArrayElements(env, arg2, lparg2, 0); + if (arg1 && lparg1) (*env)->ReleaseDoubleArrayElements(env, arg1, lparg1, 0); + Cairo_NATIVE_EXIT(env, that, _1cairo_1surface_1get_1device_1scale_FUNC); +} +#endif + #ifndef NO__1cairo_1surface_1get_1type JNIEXPORT jint JNICALL Cairo_NATIVE(_1cairo_1surface_1get_1type) (JNIEnv *env, jclass that, jintLong arg0) @@ -1263,6 +1288,24 @@ JNIEXPORT void JNICALL Cairo_NATIVE(_1cairo_1surface_1reference) } #endif +#ifndef NO__1cairo_1surface_1set_1device_1scale +JNIEXPORT void JNICALL Cairo_NATIVE(_1cairo_1surface_1set_1device_1scale) + (JNIEnv *env, jclass that, jintLong arg0, jdouble arg1, jdouble arg2) +{ + Cairo_NATIVE_ENTER(env, that, _1cairo_1surface_1set_1device_1scale_FUNC); +/* + cairo_surface_set_device_scale((cairo_surface_t *)arg0, arg1, arg2); +*/ + { + Cairo_LOAD_FUNCTION(fp, cairo_surface_set_device_scale) + if (fp) { + ((void (CALLING_CONVENTION*)(cairo_surface_t *, jdouble, jdouble))fp)((cairo_surface_t *)arg0, arg1, arg2); + } + } + Cairo_NATIVE_EXIT(env, that, _1cairo_1surface_1set_1device_1scale_FUNC); +} +#endif + #ifndef NO__1cairo_1transform JNIEXPORT void JNICALL Cairo_NATIVE(_1cairo_1transform) (JNIEnv *env, jclass that, jintLong arg0, jdoubleArray arg1) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_custom.h b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_custom.h index 43082af563..2554ab6068 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_custom.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_custom.h @@ -33,6 +33,8 @@ #define cairo_region_num_rectangles_LIB LIB_CAIRO #define cairo_region_contains_point_LIB LIB_CAIRO #define cairo_region_get_rectangle_LIB LIB_CAIRO +#define cairo_surface_set_device_scale_LIB LIB_CAIRO +#define cairo_surface_get_device_scale_LIB LIB_CAIRO #ifdef CAIRO_HAS_XLIB_SURFACE #define cairo_xlib_surface_get_height_LIB LIB_CAIRO diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.c index 0511e14bde..68d31d2c6a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.c @@ -128,10 +128,12 @@ char * Cairo_nativeFunctionNames[] = { "_1cairo_1surface_1finish", "_1cairo_1surface_1flush", "_1cairo_1surface_1get_1content", + "_1cairo_1surface_1get_1device_1scale", "_1cairo_1surface_1get_1type", "_1cairo_1surface_1get_1user_1data", "_1cairo_1surface_1mark_1dirty", "_1cairo_1surface_1reference", + "_1cairo_1surface_1set_1device_1scale", "_1cairo_1transform", "_1cairo_1translate", "_1cairo_1user_1to_1device_1distance", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.h index 2a055a030a..13f3005169 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.h @@ -138,10 +138,12 @@ typedef enum { _1cairo_1surface_1finish_FUNC, _1cairo_1surface_1flush_FUNC, _1cairo_1surface_1get_1content_FUNC, + _1cairo_1surface_1get_1device_1scale_FUNC, _1cairo_1surface_1get_1type_FUNC, _1cairo_1surface_1get_1user_1data_FUNC, _1cairo_1surface_1mark_1dirty_FUNC, _1cairo_1surface_1reference_FUNC, + _1cairo_1surface_1set_1device_1scale_FUNC, _1cairo_1transform_FUNC, _1cairo_1translate_FUNC, _1cairo_1user_1to_1device_1distance_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java index 1194701344..27918325ef 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java @@ -849,6 +849,34 @@ public static final void cairo_scale(long /*int*/ cr, double sx, double sy) { lock.unlock(); } } +/** + * @method flags=dynamic + * @param cr cast=(cairo_surface_t *) + */ +public static final native void _cairo_surface_set_device_scale(long /*int*/ cr, double sx, double sy); +public static final void cairo_surface_set_device_scale(long /*int*/ cr, double sx, double sy) { + lock.lock(); + try { + _cairo_surface_set_device_scale(cr, sx, sy); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param cr cast=(cairo_surface_t *) + * @param sx cast=(double *) + * @param sy cast=(double *) + */ +public static final native void _cairo_surface_get_device_scale(long /*int*/ cr, double [] sx, double [] sy); +public static final void cairo_surface_get_device_scale(long /*int*/ cr, double [] sx, double [] sy) { + lock.lock(); + try { + _cairo_surface_get_device_scale(cr, sx, sy); + } finally { + lock.unlock(); + } +} /** * @param cr cast=(cairo_t *) * @param family cast=(const char *) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java index b83491e7ba..89115227c8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java @@ -74,11 +74,6 @@ public class OS extends C { /** Initialization; load native libraries */ static { - if (!OS.IsWin32) { - // only applicable for X11 but OS.isX11() is not available yet - String scalingProperty = "GDK_SCALE"; - C.setenv(ascii(scalingProperty), ascii("1"), 1); - } String propertyName = "SWT_GTK3"; String gtk3 = getEnvironmentalVariable (propertyName); if (gtk3 != null && gtk3.equals("0")) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java index 1ef8de15be..470dec5ee1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java @@ -40,6 +40,7 @@ public class DPIUtil { private static AutoScaleMethod autoScaleMethod = AutoScaleMethod.NEAREST; private static String autoScaleValue; + private static boolean isGtk3 = false; /** * System property that controls the autoScale functionality. @@ -269,7 +270,7 @@ public static Rectangle autoScaleBounds (Rectangle rect, int targetZoom, int cur */ public static ImageData autoScaleUp (Device device, final ImageData imageData) { if (deviceZoom == 100 || imageData == null || (device != null && !device.isAutoScalable())) return imageData; - float scaleFactor = getScalingFactor (); + float scaleFactor = deviceZoom / 100f; return autoScaleImageData(device, imageData, scaleFactor); } @@ -374,6 +375,9 @@ public static Rectangle autoScaleUp (Drawable drawable, Rectangle rect) { * @return float scaling factor */ private static float getScalingFactor () { + if (isGtk3) { + return 1; + } return deviceZoom / 100f; } @@ -436,6 +440,11 @@ public static void setDeviceZoom (int nativeDeviceZoom) { } } +public static void setIsGtk3 (boolean gtk3) { + isGtk3 = gtk3; +} + + public static int getZoomForAutoscaleProperty (int nativeDeviceZoom) { int zoom = 0; if (autoScaleValue != null) { 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 a0bdf6c886..9dd7efe83c 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 @@ -572,6 +572,7 @@ protected void init () { this.dpi = getDPI(); this.scaleFactor = getDeviceZoom (); DPIUtil.setDeviceZoom (scaleFactor); + DPIUtil.setIsGtk3(GTK.GTK3); //TODO: Remove; temporary code only boolean fixAIX = OS.IsAIX && C.PTR_SIZEOF == 8; 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 baa98024b3..9533a1155e 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 @@ -292,6 +292,10 @@ public Image(Device device, Image srcImage, int flag) { boolean hasAlpha = format == Cairo.CAIRO_FORMAT_ARGB32; surface = Cairo.cairo_image_surface_create(format, width, height); if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); + if (GTK.GTK3) { + double scaleFactor = DPIUtil.getDeviceZoom() / 100f; + Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor); + } long /*int*/ cairo = Cairo.cairo_create(surface); if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES); Cairo.cairo_set_operator(cairo, Cairo.CAIRO_OPERATOR_SOURCE); @@ -813,6 +817,10 @@ void createFromPixbuf(int type, long /*int*/ pixbuf) { int format = hasAlpha ? Cairo.CAIRO_FORMAT_ARGB32 : Cairo.CAIRO_FORMAT_RGB24; surface = Cairo.cairo_image_surface_create(format, width, height); if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); + if (GTK.GTK3) { + double scaleFactor = DPIUtil.getDeviceZoom() / 100f; + Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor); + } long /*int*/ data = Cairo.cairo_image_surface_get_data(surface); int cairoStride = Cairo.cairo_image_surface_get_stride(surface); int oa = 0, or = 0, og = 0, ob = 0; @@ -1376,6 +1384,13 @@ void init(int width, int height) { /* Create the pixmap */ surface = GDK.gdk_window_create_similar_surface(GDK.gdk_get_default_root_window(), Cairo.CAIRO_CONTENT_COLOR, width, height); if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); + // When we create a blank image we need to set it to 100 in GTK3 as we don't scale here. + // Cairo will scale for us + if (!GTK.GTK3) { + currentDeviceZoom = DPIUtil.getDeviceZoom(); + } else { + currentDeviceZoom = 100; + } long /*int*/ cairo = Cairo.cairo_create(surface); if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES); Cairo.cairo_set_source_rgb(cairo, 1, 1, 1); @@ -1398,6 +1413,10 @@ void init(ImageData image) { int format = hasAlpha ? Cairo.CAIRO_FORMAT_ARGB32 : Cairo.CAIRO_FORMAT_RGB24; surface = Cairo.cairo_image_surface_create(format, width, height); if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); + if (GTK.GTK3) { + double scaleFactor = DPIUtil.getDeviceZoom() / 100f; + Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor); + } int stride = Cairo.cairo_image_surface_get_stride(surface); long /*int*/ data = Cairo.cairo_image_surface_get_data(surface); int oa = 0, or = 0, og = 0, ob = 0; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java index a8853fc651..a611073ea1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java @@ -30,10 +30,14 @@ public static long /*int*/ convertSurface(Image image) { long /*int*/ newSurface = image.surface; int type = Cairo.cairo_surface_get_type(newSurface); if (type != Cairo.CAIRO_SURFACE_TYPE_IMAGE) { - Rectangle bounds = image.getBoundsInPixels(); + Rectangle bounds = image.getBounds(); int format = Cairo.cairo_surface_get_content(newSurface) == Cairo.CAIRO_CONTENT_COLOR ? Cairo.CAIRO_FORMAT_RGB24 : Cairo.CAIRO_FORMAT_ARGB32; newSurface = Cairo.cairo_image_surface_create(format, bounds.width, bounds.height); if (newSurface == 0) SWT.error(SWT.ERROR_NO_HANDLES); + if (GTK.GTK3) { + double scaleFactor = DPIUtil.getDeviceZoom() / 100f; + Cairo.cairo_surface_set_device_scale(newSurface, scaleFactor, scaleFactor); + } long /*int*/ cairo = Cairo.cairo_create(newSurface); if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES); Cairo.cairo_set_operator(cairo, Cairo.CAIRO_OPERATOR_SOURCE); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java index 5f77ce4ffe..77d64c53e0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java @@ -862,6 +862,12 @@ public void setImage (Image image) { } long /*int*/ pixbuf = imageList.getPixbuf (imageIndex); if (GTK.GTK3) { + Rectangle imgSize = image.getBounds(); + long /*int*/ scaledPixbuf = GDK.gdk_pixbuf_scale_simple(pixbuf, imgSize.width, imgSize.height, GDK.GDK_INTERP_BILINEAR); + if (scaledPixbuf !=0) { + pixbuf = scaledPixbuf; + } + if (!GTK.GTK_IS_MENU_ITEM (handle)) return; if (OS.SWT_PADDED_MENU_ITEMS && imageHandle != 0) { GTK.gtk_image_set_from_pixbuf(imageHandle, pixbuf); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java index 2ca2a38e0e..f081035078 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java @@ -2833,7 +2833,7 @@ void sendMeasureEvent (long /*int*/ cell, long /*int*/ width, long /*int*/ heigh Image image = item.getImage (columnIndex); int imageWidth = 0; if (image != null) { - Rectangle bounds = image.getBoundsInPixels (); + Rectangle bounds = image.getBounds (); imageWidth = bounds.width; } contentWidth [0] += imageWidth; @@ -3113,7 +3113,7 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo Image image = item.getImage (columnIndex); int imageWidth = 0; if (image != null) { - Rectangle bounds = image.getBoundsInPixels (); + Rectangle bounds = image.getBounds (); imageWidth = bounds.width; } // On gtk >3.9 and <3.14.8 the clip rectangle does not have image area into clip rectangle diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java index 587911a2da..d33c49fb3f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java @@ -796,7 +796,7 @@ Rectangle getTextBoundsInPixels (int index) { Image image = _getImage(index); int imageWidth = 0; if (image != null) { - imageWidth = image.getBoundsInPixels ().width; + imageWidth = image.getBounds ().width; } if (x [0] < imageWidth) { rect.x += imageWidth; @@ -1212,6 +1212,17 @@ public void setImage (int index, Image image) { * underlying GTK structure. */ if (GTK.GTK3) { + /* + * Bug in GTK the default renderer does scale again on pixbuf. + * Need to scaledown here and no need to scaledown id device scale is 1 + */ + if ((!parent.ownerDraw) && (image != null) && (DPIUtil.getDeviceZoom() != 100)) { + Rectangle imgSize = image.getBounds(); + long /*int*/ scaledPixbuf = GDK.gdk_pixbuf_scale_simple(pixbuf, imgSize.width, imgSize.height, GDK.GDK_INTERP_BILINEAR); + if (scaledPixbuf !=0) { + pixbuf = scaledPixbuf; + } + } long /*int*/parentHandle = parent.handle; long /*int*/ column = GTK.gtk_tree_view_get_column (parentHandle, index); long /*int*/ pixbufRenderer = parent.getPixbufRenderer (column); @@ -1220,8 +1231,8 @@ public void setImage (int index, Image image) { GTK.gtk_cell_renderer_get_fixed_size (pixbufRenderer, currentWidth, currentHeight); if (!parent.pixbufSizeSet) { if (image != null) { - int iWidth = image.getBoundsInPixels ().width; - int iHeight = image.getBoundsInPixels ().height; + int iWidth = image.getBounds ().width; + int iHeight = image.getBounds ().height; if (iWidth > currentWidth [0] || iHeight > currentHeight [0]) { GTK.gtk_cell_renderer_set_fixed_size (pixbufRenderer, iWidth, iHeight); parent.pixbufHeight = iHeight; @@ -1255,7 +1266,7 @@ public void setImage (int index, Image image) { int [] w = new int [1]; long /*int*/ pixbufRenderer = parent.getPixbufRenderer(column); gtk_tree_view_column_cell_get_position (column, pixbufRenderer, null, w); - if (w[0] < image.getBoundsInPixels().width) { + if (w[0] < image.getBounds().width) { /* * There is no direct way to clear the cell renderer width so we * are relying on the fact that it is done as part of modifying diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java index 16b2c5d997..7b0c6d4f18 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java @@ -2885,7 +2885,7 @@ void sendMeasureEvent (long /*int*/ cell, long /*int*/ width, long /*int*/ heigh Image image = item.getImage (columnIndex); int imageWidth = 0; if (image != null && !image.isDisposed()) { - Rectangle bounds = image.getBoundsInPixels (); + Rectangle bounds = image.getBounds (); imageWidth = bounds.width; } contentWidth [0] += imageWidth; @@ -3151,7 +3151,7 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo Image image = item.getImage (columnIndex); int imageWidth = 0; if (image != null) { - Rectangle bounds = image.getBoundsInPixels (); + Rectangle bounds = image.getBounds (); imageWidth = bounds.width; } // On gtk >3.9 and <3.14.8 the clip rectangle does not have image area into clip rectangle diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java index 074a3763b5..e897319ec9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java @@ -1015,7 +1015,7 @@ Rectangle getTextBoundsInPixels (int index) { Image image = _getImage(index); int imageWidth = 0; if (image != null) { - imageWidth = image.getBoundsInPixels ().width; + imageWidth = image.getBounds ().width; } if (x [0] < imageWidth) { rect.x += imageWidth; @@ -1566,6 +1566,17 @@ public void setImage (int index, Image image) { * underlying GTK structure. */ if (GTK.GTK3) { + /* + * Bug in GTK the default renderer does scale again on pixbuf. + * Need to scaledown here and no need to scaledown id device scale is 1 + */ + if ((!parent.ownerDraw) && (image != null) && (DPIUtil.getDeviceZoom() != 100)) { + Rectangle imgSize = image.getBounds(); + long /*int*/ scaledPixbuf = GDK.gdk_pixbuf_scale_simple(pixbuf, imgSize.width, imgSize.height, GDK.GDK_INTERP_BILINEAR); + if (scaledPixbuf !=0) { + pixbuf = scaledPixbuf; + } + } long /*int*/parentHandle = parent.handle; long /*int*/ column = GTK.gtk_tree_view_get_column (parentHandle, index); long /*int*/ pixbufRenderer = parent.getPixbufRenderer (column); @@ -1574,8 +1585,8 @@ public void setImage (int index, Image image) { GTK.gtk_cell_renderer_get_fixed_size (pixbufRenderer, currentWidth, currentHeight); if (!parent.pixbufSizeSet) { if (image != null) { - int iWidth = image.getBoundsInPixels ().width; - int iHeight = image.getBoundsInPixels ().height; + int iWidth = image.getBounds ().width; + int iHeight = image.getBounds ().height; if (iWidth > currentWidth [0] || iHeight > currentHeight [0]) { GTK.gtk_cell_renderer_set_fixed_size (pixbufRenderer, iWidth, iHeight); parent.pixbufSizeSet = true; @@ -1625,7 +1636,7 @@ public void setImage (int index, Image image) { int [] w = new int [1]; long /*int*/ pixbufRenderer = parent.getPixbufRenderer(column); gtk_tree_view_column_cell_get_position (column, pixbufRenderer, null, w); - if (w[0] < image.getBoundsInPixels().width) { + if (w[0] < image.getBounds().width) { /* * There is no direct way to clear the cell renderer width so we * are relying on the fact that it is done as part of modifying -- cgit v1.2.3