Skip to content

Commit e4a4f35

Browse files
committed
[GTK][HiDpi] Code cleanup for removal of non-cairo scale path.
Fixes #1300
1 parent cec96e9 commit e4a4f35

File tree

52 files changed

+563
-1385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+563
-1385
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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, origin_x, 4);
4538+
C.memmove (y, origin_y, 4);
45414539
return 0;
45424540
}
45434541

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -1817,7 +1817,7 @@ void onDispose (Event e) {
18171817
}
18181818

18191819
void onResize (Event e) {
1820-
Rectangle rect = DPIUtil.autoScaleUp(browser.getClientArea ());
1820+
Rectangle rect = browser.getClientArea ();
18211821
if (webView == 0)
18221822
return;
18231823
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 & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,6 @@ public Path (Device device, PathData data) {
219219
public void addArc(float x, float y, float width, float height, float startAngle, float arcAngle) {
220220
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
221221
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);
226-
addArcInPixels(x, y, width, height, startAngle, arcAngle);
227-
}
228-
229-
void addArcInPixels(float x, float y, float width, float height, float startAngle, float arcAngle) {
230222
moved = true;
231223
if (width == height) {
232224
float angle = -startAngle * (float)Math.PI / 180;
@@ -292,14 +284,6 @@ public void addPath(Path path) {
292284
*/
293285
public void addRectangle(float x, float y, float width, float height) {
294286
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);
299-
addRectangleInPixels(x, y, width, height);
300-
}
301-
302-
void addRectangleInPixels(float x, float y, float width, float height) {
303287
moved = false;
304288
Cairo.cairo_rectangle(handle, x, y, width, height);
305289
closed = true;
@@ -326,19 +310,14 @@ public void addString(String string, float x, float y, Font font) {
326310
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
327311
if (font == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
328312
if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
329-
x = DPIUtil.autoScaleUp(x);
330-
y = DPIUtil.autoScaleUp(y);
331313
// Scale up the font
332314
FontData fd = font.getFontData()[0];
333-
fd.setHeight(DPIUtil.autoScaleUp(fd.getHeight()));
315+
fd.setHeight(fd.getHeight());
334316
Font scaledFont = new Font(font.getDevice(), fd);
335-
addStringInPixels(string, x, y, scaledFont);
336-
scaledFont.dispose(); // Dispose the scaled up font
337-
}
338-
void addStringInPixels(String string, float x, float y, Font font) {
339317
moved = false;
340318
GC.addCairoString(handle, string, x, y, font);
341319
closed = true;
320+
scaledFont.dispose(); // Dispose the scaled up font
342321
}
343322

344323
/**
@@ -384,11 +363,6 @@ public boolean contains(float x, float y, GC gc, boolean outline) {
384363
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
385364
if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
386365
if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
387-
x = DPIUtil.autoScaleUp(x);
388-
y = DPIUtil.autoScaleUp(y);
389-
return containsInPixels(x, y, gc, outline);
390-
}
391-
boolean containsInPixels(float x, float y, GC gc, boolean outline) {
392366
//TODO - see Windows
393367
gc.initCairo();
394368
gc.checkGC(GC.LINE_CAP | GC.LINE_JOIN | GC.LINE_STYLE | GC.LINE_WIDTH);
@@ -423,15 +397,6 @@ boolean containsInPixels(float x, float y, GC gc, boolean outline) {
423397
*/
424398
public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) {
425399
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);
432-
cubicToInPixels(cx1, cy1, cx2, cy2, x, y);
433-
}
434-
void cubicToInPixels(float cx1, float cy1, float cx2, float cy2, float x, float y) {
435400
if (!moved) {
436401
double[] currentX = new double[1], currentY = new double[1];
437402
Cairo.cairo_get_current_point(handle, currentX, currentY);
@@ -647,11 +612,6 @@ PathData getPathDataInPixels() {
647612
*/
648613
public void lineTo(float x, float y) {
649614
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
650-
x = DPIUtil.autoScaleUp(x);
651-
y = DPIUtil.autoScaleUp(y);
652-
lineToInPixels(x, y);
653-
}
654-
void lineToInPixels(float x, float y) {
655615
if (!moved) {
656616
double[] currentX = new double[1], currentY = new double[1];
657617
Cairo.cairo_get_current_point(handle, currentX, currentY);
@@ -676,11 +636,6 @@ void lineToInPixels(float x, float y) {
676636
*/
677637
public void moveTo(float x, float y) {
678638
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
679-
x = DPIUtil.autoScaleUp(x);
680-
y = DPIUtil.autoScaleUp(y);
681-
moveToInPixels(x, y);
682-
}
683-
void moveToInPixels(float x, float y) {
684639
/*
685640
* Bug in Cairo. If cairo_move_to() is not called at the
686641
* begining of a subpath, the first cairo_line_to() or
@@ -707,13 +662,6 @@ void moveToInPixels(float x, float y) {
707662
*/
708663
public void quadTo(float cx, float cy, float x, float y) {
709664
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);
714-
quadToInPixels(cx, cy, x, y);
715-
}
716-
void quadToInPixels(float cx, float cy, float x, float y) {
717665
double[] currentX = new double[1], currentY = new double[1];
718666
Cairo.cairo_get_current_point(handle, currentX, currentY);
719667
if (!moved) {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public Transform (Device device, float m11, float m12, float m21, float m22, flo
147147
super(device);
148148
handle = new double[6];
149149
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));
150+
Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, dx, dy);
151151
init();
152152
}
153153

@@ -320,7 +320,7 @@ public void scale(float scaleX, float scaleY) {
320320
*/
321321
public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
322322
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
323-
Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, DPIUtil.autoScaleUp(dx), DPIUtil.autoScaleUp(dy));
323+
Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, dx, dy);
324324
}
325325

326326
/**
@@ -362,8 +362,8 @@ public void transform(float[] pointArray) {
362362
double[] dx = new double[1], dy = new double[1];
363363
int length = pointArray.length / 2;
364364
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]);
365+
dx[0] = pointArray[j];
366+
dy[0] = pointArray[j + 1];
367367
Cairo.cairo_matrix_transform_point(handle, dx, dy);
368368
pointArray[j] = DPIUtil.autoScaleDown((float)dx[0]);
369369
pointArray[j + 1] = DPIUtil.autoScaleDown((float)dy[0]);
@@ -383,7 +383,7 @@ public void transform(float[] pointArray) {
383383
*/
384384
public void translate(float offsetX, float offsetY) {
385385
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
386-
Cairo.cairo_matrix_translate(handle, DPIUtil.autoScaleUp(offsetX), DPIUtil.autoScaleUp(offsetY));
386+
Cairo.cairo_matrix_translate(handle, offsetX, offsetY);
387387
}
388388

389389
/**

0 commit comments

Comments
 (0)