Skip to content

Commit 111b874

Browse files
committed
[GTK] Set useCairoAutoScale to true and remove getter
Change all implementations to not check it but act assume it is always true. This was the case anyway as Device.init explicitly set it that way.
1 parent 9e57eae commit 111b874

File tree

10 files changed

+55
-146
lines changed

10 files changed

+55
-146
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private static enum AutoScaleMethod { AUTO, NEAREST, SMOOTH }
4747
private static AutoScaleMethod autoScaleMethod = AutoScaleMethod.NEAREST;
4848

4949
private static String autoScaleValue;
50-
private static boolean useCairoAutoScale = false;
50+
private static boolean useCairoAutoScale = true;
5151

5252
/**
5353
* System property that controls the autoScale functionality.
@@ -635,10 +635,6 @@ public static void setUseCairoAutoScale (boolean cairoAutoScale) {
635635
useCairoAutoScale = cairoAutoScale;
636636
}
637637

638-
public static boolean useCairoAutoScale() {
639-
return useCairoAutoScale;
640-
}
641-
642638
public static int getZoomForAutoscaleProperty (int nativeDeviceZoom) {
643639
return getZoomForAutoscaleProperty(nativeDeviceZoom, autoScaleValue);
644640
}

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java

-2
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,6 @@ protected void init () {
698698
this.dpi = getDPI();
699699
DPIUtil.setDeviceZoom (getDeviceZoom ());
700700

701-
DPIUtil.setUseCairoAutoScale(true);
702-
703701
/* Initialize the system font slot */
704702
long [] defaultFontArray = new long [1];
705703
long defaultFont = 0;

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

+10-12
Original file line numberDiff line numberDiff line change
@@ -1621,18 +1621,16 @@ void fillGradientRectangleInPixels(int x, int y, int width, int height, boolean
16211621
long cairo = data.cairo;
16221622
long pattern;
16231623

1624-
if (DPIUtil.useCairoAutoScale() ) {
1625-
/*
1626-
* Here the co-ordinates passed are in points for GTK3.
1627-
* That means the user is expecting surface to be at
1628-
* device scale equal to current scale factor. So need
1629-
* to set the device scale to current scale factor
1630-
*/
1631-
long surface = Cairo.cairo_get_target(cairo);
1632-
if (surface != 0) {
1633-
float scaleFactor = DPIUtil.getDeviceZoom() / 100f;
1634-
Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);
1635-
}
1624+
/*
1625+
* Here the co-ordinates passed are in points for GTK3.
1626+
* That means the user is expecting surface to be at
1627+
* device scale equal to current scale factor. So need
1628+
* to set the device scale to current scale factor
1629+
*/
1630+
long surface = Cairo.cairo_get_target(cairo);
1631+
if (surface != 0) {
1632+
float scaleFactor = DPIUtil.getDeviceZoom() / 100f;
1633+
Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);
16361634
}
16371635

16381636
if (fromRGB.equals(toRGB)) {

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java

+5-22
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public Image(Device device, Image srcImage, int flag) {
283283
boolean hasAlpha = format == Cairo.CAIRO_FORMAT_ARGB32;
284284
surface = Cairo.cairo_image_surface_create(format, width, height);
285285
if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
286-
if (DPIUtil.getDeviceZoom() != currentDeviceZoom && DPIUtil.useCairoAutoScale()) {
286+
if (DPIUtil.getDeviceZoom() != currentDeviceZoom) {
287287
double scaleFactor = DPIUtil.getDeviceZoom() / 100f;
288288
Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);
289289
}
@@ -738,19 +738,6 @@ boolean refreshImageForZoom () {
738738
refreshed = true;
739739
currentDeviceZoom = deviceZoomLevel;
740740
}
741-
} else {
742-
if (!DPIUtil.useCairoAutoScale()) {
743-
int deviceZoomLevel = deviceZoom;
744-
if (deviceZoomLevel != currentDeviceZoom) {
745-
ImageData data = getImageDataAtCurrentZoom();
746-
destroy ();
747-
ImageData resizedData = DPIUtil.scaleImageData(device, data, deviceZoomLevel, currentDeviceZoom);
748-
init(resizedData);
749-
init();
750-
refreshed = true;
751-
currentDeviceZoom = deviceZoomLevel;
752-
}
753-
}
754741
}
755742
return refreshed;
756743
}
@@ -809,7 +796,7 @@ void createFromPixbuf(int type, long pixbuf) {
809796
// Initialize surface with dimensions received from the pixbuf and set device_scale appropriately
810797
surface = Cairo.cairo_image_surface_create(format, pixbufWidth, pixbufHeight);
811798
if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
812-
if (DPIUtil.useCairoAutoScale()) Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);
799+
Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);
813800

814801
long data = Cairo.cairo_image_surface_get_data(surface);
815802
int cairoStride = Cairo.cairo_image_surface_get_stride(surface);
@@ -1257,12 +1244,8 @@ void init(int width, int height) {
12571244
if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
12581245
// When we create a blank image we need to set it to 100 in GTK3 as we draw using 100% scale.
12591246
// Cairo will take care of scaling for us when image needs to be scaled.
1260-
if (DPIUtil.useCairoAutoScale()) {
1261-
currentDeviceZoom = 100;
1262-
Cairo.cairo_surface_set_device_scale(surface, 1f, 1f);
1263-
} else {
1264-
currentDeviceZoom = DPIUtil.getDeviceZoom();
1265-
}
1247+
currentDeviceZoom = 100;
1248+
Cairo.cairo_surface_set_device_scale(surface, 1f, 1f);
12661249
long cairo = Cairo.cairo_create(surface);
12671250
if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);
12681251
Cairo.cairo_set_source_rgb(cairo, 1, 1, 1);
@@ -1296,7 +1279,7 @@ void init(ImageData image) {
12961279
// Initialize surface with dimensions received from the ImageData and set device_scale appropriately
12971280
surface = Cairo.cairo_image_surface_create(format, imageDataWidth, imageDataHeight);
12981281
if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
1299-
if (DPIUtil.useCairoAutoScale()) Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);
1282+
Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);
13001283

13011284
int stride = Cairo.cairo_image_surface_get_stride(surface);
13021285
long data = Cairo.cairo_image_surface_get_data(surface);

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java

+28-46
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,18 @@ public static long convertSurface(Image image) {
3333
long newSurface = image.surface;
3434
int type = Cairo.cairo_surface_get_type(newSurface);
3535
if (type != Cairo.CAIRO_SURFACE_TYPE_IMAGE) {
36-
Rectangle bounds;
37-
if (DPIUtil.useCairoAutoScale()) {
38-
bounds = image.getBounds();
39-
} else {
40-
bounds = image.getBoundsInPixels();
41-
}
36+
Rectangle bounds = image.getBounds();
4237
int format = Cairo.cairo_surface_get_content(newSurface) == Cairo.CAIRO_CONTENT_COLOR ? Cairo.CAIRO_FORMAT_RGB24 : Cairo.CAIRO_FORMAT_ARGB32;
4338
newSurface = Cairo.cairo_image_surface_create(format, bounds.width, bounds.height);
4439
if (newSurface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
4540
//retain device scale set in the original surface
46-
if (DPIUtil.useCairoAutoScale()) {
47-
double sx[] = new double[1];
48-
double sy[] = new double[1];
49-
Cairo.cairo_surface_get_device_scale(image.surface, sx, sy);
50-
if (sx[0] == 0 || sy[0] == 0){
51-
sx[0] = sy[0] = DPIUtil.getDeviceZoom() / 100f;
52-
}
53-
Cairo.cairo_surface_set_device_scale(newSurface, sx[0], sy[0]);
41+
double sx[] = new double[1];
42+
double sy[] = new double[1];
43+
Cairo.cairo_surface_get_device_scale(image.surface, sx, sy);
44+
if (sx[0] == 0 || sy[0] == 0){
45+
sx[0] = sy[0] = DPIUtil.getDeviceZoom() / 100f;
5446
}
47+
Cairo.cairo_surface_set_device_scale(newSurface, sx[0], sy[0]);
5548
long cairo = Cairo.cairo_create(newSurface);
5649
if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);
5750
Cairo.cairo_set_operator(cairo, Cairo.CAIRO_OPERATOR_SOURCE);
@@ -120,15 +113,13 @@ public static long createPixbuf(long surface) {
120113
*
121114
* We have to do this as surface has inherent auto scaling capability but pixbuf doesnot
122115
*/
123-
if (DPIUtil.useCairoAutoScale()) {
124-
double sx[] = new double[1];
125-
double sy[] = new double[1];
126-
Cairo.cairo_surface_get_device_scale(surface, sx, sy);
127-
if (sx[0] > 1 && sy[0] > 1){
128-
long oldPixbuf = pixbuf;
129-
pixbuf = GDK.gdk_pixbuf_scale_simple(pixbuf, width/(int)sx[0], height/(int)sy[0], GDK.GDK_INTERP_BILINEAR);
130-
OS.g_object_unref(oldPixbuf);
131-
}
116+
double sx[] = new double[1];
117+
double sy[] = new double[1];
118+
Cairo.cairo_surface_get_device_scale(surface, sx, sy);
119+
if (sx[0] > 1 && sy[0] > 1){
120+
long oldPixbuf = pixbuf;
121+
pixbuf = GDK.gdk_pixbuf_scale_simple(pixbuf, width/(int)sx[0], height/(int)sy[0], GDK.GDK_INTERP_BILINEAR);
122+
OS.g_object_unref(oldPixbuf);
132123
}
133124
return pixbuf;
134125
}
@@ -295,12 +286,7 @@ void set (int index, Image image) {
295286
w /= (int)sx[0];
296287
h /= (int)sy[0];
297288

298-
Rectangle bounds;
299-
if (DPIUtil.useCairoAutoScale()) {
300-
bounds = image.getBounds();
301-
} else {
302-
bounds = image.getBoundsInPixels();
303-
}
289+
Rectangle bounds = image.getBounds();
304290
if (w == 0) {
305291
w = bounds.width;
306292
}
@@ -334,26 +320,22 @@ long scaleSurface(Image image, int width, int height) {
334320
long cairo = Cairo.cairo_create(scaledSurface);
335321
if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);
336322

323+
int w = Cairo.cairo_image_surface_get_width(image.surface);
324+
int h = Cairo.cairo_image_surface_get_height(image.surface);
337325
Rectangle bounds;
338-
if (DPIUtil.useCairoAutoScale()) {
339-
int w = Cairo.cairo_image_surface_get_width(image.surface);
340-
int h = Cairo.cairo_image_surface_get_height(image.surface);
341-
if ((w == 0) && (h == 0)) {
342-
bounds = image.getBounds();
343-
} else {
344-
bounds = new Rectangle(0, 0, w, h);
345-
}
346-
347-
double sx[] = new double[1];
348-
double sy[] = new double[1];
349-
Cairo.cairo_surface_get_device_scale(image.surface, sx, sy);
350-
if (sx[0] == 0 || sy[0] == 0){
351-
sx[0] = sy[0] = DPIUtil.getDeviceZoom() / 100f;
352-
}
353-
Cairo.cairo_surface_set_device_scale(scaledSurface, sx[0], sy[0]);
326+
if ((w == 0) && (h == 0)) {
327+
bounds = image.getBounds();
354328
} else {
355-
bounds = image.getBoundsInPixels();
329+
bounds = new Rectangle(0, 0, w, h);
330+
}
331+
332+
double sx[] = new double[1];
333+
double sy[] = new double[1];
334+
Cairo.cairo_surface_get_device_scale(image.surface, sx, sy);
335+
if (sx[0] == 0 || sy[0] == 0){
336+
sx[0] = sy[0] = DPIUtil.getDeviceZoom() / 100f;
356337
}
338+
Cairo.cairo_surface_set_device_scale(scaledSurface, sx[0], sy[0]);
357339
double scaleX = (double) width / (double) bounds.width;
358340
double scaleY = (double) height / (double) bounds.height;
359341
Cairo.cairo_scale(cairo, scaleX, scaleY);

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java

+2-14
Original file line numberDiff line numberDiff line change
@@ -2880,13 +2880,7 @@ void sendMeasureEvent (long cell, long width, long height) {
28802880
Image image = item.getImage (columnIndex);
28812881
int imageWidth = 0;
28822882
if (image != null) {
2883-
Rectangle bounds;
2884-
if (DPIUtil.useCairoAutoScale()) {
2885-
bounds = image.getBounds ();
2886-
} else {
2887-
bounds = image.getBoundsInPixels();
2888-
}
2889-
imageWidth = bounds.width;
2883+
imageWidth = image.getBounds ().width;
28902884
}
28912885
contentWidth [0] += imageWidth;
28922886
GC gc = new GC (this);
@@ -3143,13 +3137,7 @@ void rendererRender (long cell, long cr, long snapshot, long widget, long backgr
31433137
Image image = item.getImage (columnIndex);
31443138
int imageWidth = 0;
31453139
if (image != null) {
3146-
Rectangle bounds;
3147-
if (DPIUtil.useCairoAutoScale()) {
3148-
bounds = image.getBounds ();
3149-
} else {
3150-
bounds = image.getBoundsInPixels ();
3151-
}
3152-
imageWidth = bounds.width;
3140+
imageWidth = image.getBounds ().width;
31533141
}
31543142
contentX [0] -= imageWidth;
31553143
contentWidth [0] += imageWidth;

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java

+3-14
Original file line numberDiff line numberDiff line change
@@ -807,12 +807,7 @@ Rectangle getTextBoundsInPixels (int index) {
807807
Image image = _getImage(index);
808808
int imageWidth = 0;
809809
if (image != null) {
810-
if (DPIUtil.useCairoAutoScale()) {
811-
imageWidth = image.getBounds ().width;
812-
} else {
813-
imageWidth = image.getBoundsInPixels ().width;
814-
}
815-
810+
imageWidth = image.getBounds ().width;
816811
}
817812
if (x [0] < imageWidth) {
818813
rect.x += imageWidth;
@@ -1211,14 +1206,8 @@ public void setImage(int index, Image image) {
12111206
GTK.gtk_cell_renderer_get_fixed_size (pixbufRenderer, currentWidth, currentHeight);
12121207
if (!parent.pixbufSizeSet) {
12131208
if (image != null) {
1214-
int iWidth, iHeight;
1215-
if (DPIUtil.useCairoAutoScale()) {
1216-
iWidth = image.getBounds ().width;
1217-
iHeight = image.getBounds ().height;
1218-
} else {
1219-
iWidth = image.getBoundsInPixels ().width;
1220-
iHeight = image.getBoundsInPixels ().height;
1221-
}
1209+
int iWidth = image.getBounds ().width;
1210+
int iHeight = image.getBounds ().height;
12221211
if (iWidth > currentWidth [0] || iHeight > currentHeight [0]) {
12231212
GTK.gtk_cell_renderer_set_fixed_size (pixbufRenderer, iWidth, iHeight);
12241213
parent.pixbufHeight = iHeight;

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java

+2-15
Original file line numberDiff line numberDiff line change
@@ -3079,14 +3079,7 @@ void sendMeasureEvent (long cell, long width, long height) {
30793079
Image image = item.getImage (columnIndex);
30803080
int imageWidth = 0;
30813081
if (image != null && !image.isDisposed()) {
3082-
Rectangle bounds;
3083-
if (DPIUtil.useCairoAutoScale()) {
3084-
bounds = image.getBounds ();
3085-
} else {
3086-
bounds = image.getBoundsInPixels ();
3087-
}
3088-
bounds = image.getBounds ();
3089-
imageWidth = bounds.width;
3082+
imageWidth = image.getBounds ().width;
30903083
}
30913084
contentWidth [0] += imageWidth;
30923085
GC gc = new GC (this);
@@ -3337,13 +3330,7 @@ void rendererRender (long cell, long cr, long snapshot, long widget, long backgr
33373330
Image image = item.getImage (columnIndex);
33383331
int imageWidth = 0;
33393332
if (image != null) {
3340-
Rectangle bounds;
3341-
if(DPIUtil.useCairoAutoScale()) {
3342-
bounds = image.getBounds ();
3343-
} else {
3344-
bounds = image.getBoundsInPixels ();
3345-
}
3346-
imageWidth = bounds.width;
3333+
imageWidth = image.getBounds ().width;
33473334
}
33483335
// Account for the image width on GTK3, see bug 535124.
33493336
if (cr != 0) {

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java

+3-13
Original file line numberDiff line numberDiff line change
@@ -991,11 +991,7 @@ Rectangle getTextBoundsInPixels (int index) {
991991
Image image = _getImage(index);
992992
int imageWidth = 0;
993993
if (image != null) {
994-
if (DPIUtil.useCairoAutoScale()) {
995-
imageWidth = image.getBounds ().width;
996-
} else {
997-
imageWidth = image.getBoundsInPixels ().width;
998-
}
994+
imageWidth = image.getBounds ().width;
999995
}
1000996
if (x [0] < imageWidth) {
1001997
rect.x += imageWidth;
@@ -1528,14 +1524,8 @@ public void setImage(int index, Image image) {
15281524
GTK.gtk_cell_renderer_get_fixed_size (pixbufRenderer, currentWidth, currentHeight);
15291525
if (!parent.pixbufSizeSet) {
15301526
if (image != null) {
1531-
int iWidth, iHeight;
1532-
if (DPIUtil.useCairoAutoScale()) {
1533-
iWidth = image.getBounds ().width;
1534-
iHeight = image.getBounds ().height;
1535-
} else {
1536-
iWidth = image.getBoundsInPixels ().width;
1537-
iHeight = image.getBoundsInPixels ().height;
1538-
}
1527+
int iWidth = image.getBounds ().width;
1528+
int iHeight = image.getBounds ().height;
15391529
if (iWidth > currentWidth [0] || iHeight > currentHeight [0]) {
15401530
GTK.gtk_cell_renderer_set_fixed_size (pixbufRenderer, iWidth, iHeight);
15411531
parent.pixbufSizeSet = true;

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/DPIUtilTests.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,17 @@
3434
public class DPIUtilTests {
3535

3636
private int deviceZoom;
37-
private boolean useCairoAutoScale;
3837

3938
@Before
4039
public void setup() {
4140
deviceZoom = DPIUtil.getDeviceZoom();
42-
useCairoAutoScale = DPIUtil.useCairoAutoScale();
4341
DPIUtil.setDeviceZoom(200);
4442
DPIUtil.setUseCairoAutoScale(false);
4543
}
4644

4745
@After
4846
public void tearDown() {
49-
DPIUtil.setUseCairoAutoScale(useCairoAutoScale);
47+
DPIUtil.setUseCairoAutoScale(true);
5048
DPIUtil.setDeviceZoom(deviceZoom);
5149
}
5250

0 commit comments

Comments
 (0)