Skip to content

Commit 981e760

Browse files
committed
[GTK] Stop using DPIUtil (take 1)
It's a noop on cairo for quite some time and allows cleaning up code.
1 parent d4caabf commit 981e760

File tree

33 files changed

+113
-171
lines changed

33 files changed

+113
-171
lines changed

bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/org/eclipse/swt/awt/SWT_AWT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2019 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -231,7 +231,7 @@ public static Frame new_Frame (final Composite parent) {
231231
});
232232
break;
233233
case SWT.Resize:
234-
final Rectangle clientArea = DPIUtil.autoScaleUp(parent.getClientArea());
234+
final Rectangle clientArea = parent.getClientArea();
235235
EventQueue.invokeLater(() -> frame[0].setSize (clientArea.width, clientArea.height));
236236
break;
237237
}
@@ -241,7 +241,7 @@ public static Frame new_Frame (final Composite parent) {
241241

242242
parent.getDisplay().asyncExec(() -> {
243243
if (parent.isDisposed()) return;
244-
final Rectangle clientArea = DPIUtil.autoScaleUp(parent.getClientArea());
244+
final Rectangle clientArea = parent.getClientArea();
245245
EventQueue.invokeLater(() -> {
246246
frame[0].setSize (clientArea.width, clientArea.height);
247247
frame[0].validate ();
@@ -285,7 +285,7 @@ public void componentResized (ComponentEvent e) {
285285
display.syncExec (() -> {
286286
if (shell.isDisposed()) return;
287287
Dimension dim = parent.getSize ();
288-
shell.setSize (DPIUtil.autoScaleDown(new Point(dim.width, dim.height)));
288+
shell.setSize (new Point(dim.width, dim.height));
289289
});
290290
}
291291
};

bundles/org.eclipse.swt/Eclipse SWT Accessibility/gtk/org/eclipse/swt/accessibility/AccessibleObject.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4534,10 +4534,8 @@ static long toDisplay (long gdkResource, long x, long y) {
45344534
} else {
45354535
GDK.gdk_window_get_origin (gdkResource, origin_x, origin_y);
45364536
}
4537-
int scaledX = DPIUtil.autoScaleDown (origin_x [0]);
4538-
int scaledY = DPIUtil.autoScaleDown (origin_y [0]);
4539-
C.memmove (x, new int[] {scaledX}, 4);
4540-
C.memmove (y, new int[] {scaledY}, 4);
4537+
C.memmove (x, new int[] {origin_x [0]}, 4);
4538+
C.memmove (y, new int[] {origin_y [0]}, 4);
45414539
return 0;
45424540
}
45434541

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DropTarget.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2018 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -792,7 +792,7 @@ boolean setEventData(long context, int x, int y, int time, DNDEvent event) {
792792
long window = GTK3.gtk_widget_get_window (control.handle);
793793
GDK.gdk_window_get_origin(window, origin_x, origin_y);
794794
}
795-
Point coordinates = DPIUtil.autoScaleDown(new Point(origin_x[0] + x, origin_y[0] + y));
795+
Point coordinates = new Point(origin_x[0] + x, origin_y[0] + y);
796796

797797
event.widget = this;
798798
event.x = coordinates.x;

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDropTargetEffect.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -136,7 +136,7 @@ public void dragOver(DropTargetEvent event) {
136136
long handle = table.handle;
137137
int effect = checkEffect(event.feedback);
138138
Point coordinates = new Point(event.x, event.y);
139-
coordinates = DPIUtil.autoScaleUp(table.toControl(coordinates));
139+
coordinates = table.toControl(coordinates);
140140
long [] path = new long [1];
141141
GTK.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y, path, null, null, null);
142142
int index = -1;
@@ -154,7 +154,7 @@ public void dragOver(DropTargetEvent event) {
154154
} else {
155155
if (index != -1 && scrollIndex == index && scrollBeginTime != 0) {
156156
if (System.currentTimeMillis() >= scrollBeginTime) {
157-
if (coordinates.y < DPIUtil.autoScaleUp(table.getItemHeight())) {
157+
if (coordinates.y < table.getItemHeight()) {
158158
GTK.gtk_tree_path_prev(path[0]);
159159
} else {
160160
GTK.gtk_tree_path_next(path[0]);

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDropTargetEffect.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -150,7 +150,7 @@ public void dragOver(DropTargetEvent event) {
150150

151151
long handle = tree.handle;
152152
Point coordinates = new Point(event.x, event.y);
153-
coordinates = DPIUtil.autoScaleUp(tree.toControl(coordinates));
153+
coordinates = tree.toControl(coordinates);
154154
long [] path = new long [1];
155155
GTK.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y, path, null, null, null);
156156
int index = -1;

bundles/org.eclipse.swt/Eclipse SWT OpenGL/gtk/org/eclipse/swt/opengl/GLCanvas.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2018 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,7 +15,6 @@
1515

1616
import org.eclipse.swt.*;
1717
import org.eclipse.swt.graphics.*;
18-
import org.eclipse.swt.internal.*;
1918
import org.eclipse.swt.internal.gtk.*;
2019
import org.eclipse.swt.internal.gtk3.*;
2120
import org.eclipse.swt.internal.opengl.glx.*;
@@ -164,7 +163,7 @@ public GLCanvas (Composite parent, int style, GLData data) {
164163
GLX.glViewport (viewport [0],viewport [1],viewport [2],viewport [3]);
165164
break;
166165
case SWT.Resize:
167-
Rectangle clientArea = DPIUtil.autoScaleUp(getClientArea());
166+
Rectangle clientArea = getClientArea();
168167
GDK.gdk_window_move (glWindow, clientArea.x, clientArea.y);
169168
GDK.gdk_window_resize (glWindow, clientArea.width, clientArea.height);
170169
break;

bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,7 @@ void onDispose (Event e) {
18351835
}
18361836

18371837
void onResize (Event e) {
1838-
Rectangle rect = DPIUtil.autoScaleUp(browser.getClientArea ());
1838+
Rectangle rect = browser.getClientArea ();
18391839
if (webView == 0)
18401840
return;
18411841
GTK.gtk_widget_set_size_request (webView, rect.width, rect.height);

bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Path.java

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2021 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,7 +14,6 @@
1414
package org.eclipse.swt.graphics;
1515

1616
import org.eclipse.swt.*;
17-
import org.eclipse.swt.internal.*;
1817
import org.eclipse.swt.internal.cairo.*;
1918

2019
/**
@@ -219,10 +218,6 @@ public Path (Device device, PathData data) {
219218
public void addArc(float x, float y, float width, float height, float startAngle, float arcAngle) {
220219
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
221220
if (width == 0 || height == 0 || arcAngle == 0) return;
222-
x = DPIUtil.autoScaleUp(x);
223-
y = DPIUtil.autoScaleUp(y);
224-
width = DPIUtil.autoScaleUp(width);
225-
height = DPIUtil.autoScaleUp(height);
226221
addArcInPixels(x, y, width, height, startAngle, arcAngle);
227222
}
228223

@@ -292,10 +287,6 @@ public void addPath(Path path) {
292287
*/
293288
public void addRectangle(float x, float y, float width, float height) {
294289
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
295-
x = DPIUtil.autoScaleUp(x);
296-
y = DPIUtil.autoScaleUp(y);
297-
width = DPIUtil.autoScaleUp(width);
298-
height = DPIUtil.autoScaleUp(height);
299290
addRectangleInPixels(x, y, width, height);
300291
}
301292

@@ -326,11 +317,8 @@ public void addString(String string, float x, float y, Font font) {
326317
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
327318
if (font == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
328319
if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
329-
x = DPIUtil.autoScaleUp(x);
330-
y = DPIUtil.autoScaleUp(y);
331320
// Scale up the font
332321
FontData fd = font.getFontData()[0];
333-
fd.setHeight(DPIUtil.autoScaleUp(fd.getHeight()));
334322
Font scaledFont = new Font(font.getDevice(), fd);
335323
addStringInPixels(string, x, y, scaledFont);
336324
scaledFont.dispose(); // Dispose the scaled up font
@@ -384,8 +372,6 @@ public boolean contains(float x, float y, GC gc, boolean outline) {
384372
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
385373
if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
386374
if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
387-
x = DPIUtil.autoScaleUp(x);
388-
y = DPIUtil.autoScaleUp(y);
389375
return containsInPixels(x, y, gc, outline);
390376
}
391377
boolean containsInPixels(float x, float y, GC gc, boolean outline) {
@@ -423,12 +409,6 @@ boolean containsInPixels(float x, float y, GC gc, boolean outline) {
423409
*/
424410
public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) {
425411
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
426-
cx1 = DPIUtil.autoScaleUp(cx1);
427-
cy1 = DPIUtil.autoScaleUp(cy1);
428-
cx2 = DPIUtil.autoScaleUp(cx2);
429-
cy2 = DPIUtil.autoScaleUp(cy2);
430-
x = DPIUtil.autoScaleUp(x);
431-
y = DPIUtil.autoScaleUp(y);
432412
cubicToInPixels(cx1, cy1, cx2, cy2, x, y);
433413
}
434414
void cubicToInPixels(float cx1, float cy1, float cx2, float cy2, float x, float y) {
@@ -462,9 +442,6 @@ public void getBounds(float[] bounds) {
462442
if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
463443
if (bounds.length < 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
464444
getBoundsInPixels(bounds);
465-
for (int i = 0; i < bounds.length; i++) {
466-
bounds [i] = DPIUtil.autoScaleDown(bounds[i]);
467-
}
468445
}
469446
void getBoundsInPixels(float[] bounds) {
470447
long copy = Cairo.cairo_copy_path(handle);
@@ -540,9 +517,6 @@ void getBoundsInPixels(float[] bounds) {
540517
public void getCurrentPoint(float[] point) {
541518
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
542519
getCurrentPointInPixels(point);
543-
for (int i = 0; i < point.length; i++) {
544-
point [i] = DPIUtil.autoScaleDown(point[i]);
545-
}
546520
}
547521

548522
void getCurrentPointInPixels(float[] point) {
@@ -567,9 +541,7 @@ void getCurrentPointInPixels(float[] point) {
567541
*/
568542
public PathData getPathData() {
569543
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
570-
PathData result = getPathDataInPixels();
571-
result.points = DPIUtil.autoScaleDown(result.points);
572-
return result;
544+
return getPathDataInPixels();
573545
}
574546

575547
PathData getPathDataInPixels() {
@@ -647,8 +619,6 @@ PathData getPathDataInPixels() {
647619
*/
648620
public void lineTo(float x, float y) {
649621
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
650-
x = DPIUtil.autoScaleUp(x);
651-
y = DPIUtil.autoScaleUp(y);
652622
lineToInPixels(x, y);
653623
}
654624
void lineToInPixels(float x, float y) {
@@ -676,8 +646,6 @@ void lineToInPixels(float x, float y) {
676646
*/
677647
public void moveTo(float x, float y) {
678648
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
679-
x = DPIUtil.autoScaleUp(x);
680-
y = DPIUtil.autoScaleUp(y);
681649
moveToInPixels(x, y);
682650
}
683651
void moveToInPixels(float x, float y) {
@@ -707,10 +675,6 @@ void moveToInPixels(float x, float y) {
707675
*/
708676
public void quadTo(float cx, float cy, float x, float y) {
709677
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
710-
x = DPIUtil.autoScaleUp(x);
711-
y = DPIUtil.autoScaleUp(y);
712-
cx = DPIUtil.autoScaleUp(cx);
713-
cy = DPIUtil.autoScaleUp(cy);
714678
quadToInPixels(cx, cy, x, y);
715679
}
716680
void quadToInPixels(float cx, float cy, float x, float y) {

bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Pattern.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,7 +14,6 @@
1414
package org.eclipse.swt.graphics;
1515

1616
import org.eclipse.swt.*;
17-
import org.eclipse.swt.internal.*;
1817
import org.eclipse.swt.internal.cairo.*;
1918

2019
/**
@@ -173,10 +172,6 @@ public Pattern(Device device, float x1, float y1, float x2, float y2, Color colo
173172
*/
174173
public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) {
175174
super(device);
176-
x1 = DPIUtil.autoScaleUp(x1);
177-
y1 = DPIUtil.autoScaleUp(y1);
178-
x2 = DPIUtil.autoScaleUp(x2);
179-
y2 = DPIUtil.autoScaleUp(y2);
180175
if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
181176
if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
182177
if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);

bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Transform.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,7 +14,6 @@
1414
package org.eclipse.swt.graphics;
1515

1616
import org.eclipse.swt.*;
17-
import org.eclipse.swt.internal.*;
1817
import org.eclipse.swt.internal.cairo.*;
1918

2019
/**
@@ -147,7 +146,7 @@ public Transform (Device device, float m11, float m12, float m21, float m22, flo
147146
super(device);
148147
handle = new double[6];
149148
if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
150-
Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, DPIUtil.autoScaleUp(dx), DPIUtil.autoScaleUp(dy));
149+
Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, dx, dy);
151150
init();
152151
}
153152

@@ -184,8 +183,8 @@ public void getElements(float[] elements) {
184183
elements[1] = (float)handle[1];
185184
elements[2] = (float)handle[2];
186185
elements[3] = (float)handle[3];
187-
elements[4] = DPIUtil.autoScaleDown((float)handle[4]);
188-
elements[5] = DPIUtil.autoScaleDown((float)handle[5]);
186+
elements[4] = (float)handle[4];
187+
elements[5] = (float)handle[5];
189188
}
190189

191190
/**
@@ -320,7 +319,7 @@ public void scale(float scaleX, float scaleY) {
320319
*/
321320
public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
322321
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
323-
Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, DPIUtil.autoScaleUp(dx), DPIUtil.autoScaleUp(dy));
322+
Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, dx, dy);
324323
}
325324

326325
/**
@@ -362,11 +361,11 @@ public void transform(float[] pointArray) {
362361
double[] dx = new double[1], dy = new double[1];
363362
int length = pointArray.length / 2;
364363
for (int i = 0, j = 0; i < length; i++, j += 2) {
365-
dx[0] = DPIUtil.autoScaleUp(pointArray[j]);
366-
dy[0] = DPIUtil.autoScaleUp(pointArray[j + 1]);
364+
dx[0] = pointArray[j];
365+
dy[0] = pointArray[j + 1];
367366
Cairo.cairo_matrix_transform_point(handle, dx, dy);
368-
pointArray[j] = DPIUtil.autoScaleDown((float)dx[0]);
369-
pointArray[j + 1] = DPIUtil.autoScaleDown((float)dy[0]);
367+
pointArray[j] = (float)dx[0];
368+
pointArray[j + 1] = (float)dy[0];
370369
}
371370
}
372371

@@ -383,7 +382,7 @@ public void transform(float[] pointArray) {
383382
*/
384383
public void translate(float offsetX, float offsetY) {
385384
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
386-
Cairo.cairo_matrix_translate(handle, DPIUtil.autoScaleUp(offsetX), DPIUtil.autoScaleUp(offsetY));
385+
Cairo.cairo_matrix_translate(handle, offsetX, offsetY);
387386
}
388387

389388
/**

0 commit comments

Comments
 (0)