Skip to content

Commit daf36ff

Browse files
Refactor: Move GTK-specific DPI logic to GtkDPIUtil
This commit introduces a dedicated `GtkDPIUtil` class to isolate GTK-specific DPI logic, improving platform separation and maintainability. Since the GTK scaling factor is always 1, the `autoScaleUp` and `autoScaleDown` methods effectively return the input unchanged. These methods and their usages have been removed from the GTK implementation to eliminate unnecessary code. Also clarifies that `autoScale` no longer applies to the Win32 implementation and is being decoupled accordingly.
1 parent 51fed8e commit daf36ff

File tree

4 files changed

+99
-93
lines changed

4 files changed

+99
-93
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public static ImageData scaleImageData (Device device, final ElementAtZoom<Image
284284
return scaleImageData(device, elementAtZoom.element(), targetZoom, elementAtZoom.zoom());
285285
}
286286

287-
private static ImageData autoScaleImageData (Device device, final ImageData imageData, float scaleFactor) {
287+
public static ImageData autoScaleImageData (Device device, final ImageData imageData, float scaleFactor) {
288288
// Guards are already implemented in callers: if (deviceZoom == 100 || imageData == null || scaleFactor == 1.0f) return imageData;
289289
int width = imageData.width;
290290
int height = imageData.height;

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

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ void checkGC (int mask) {
343343
Cairo.cairo_set_line_join(cairo, join_style);
344344
}
345345
if ((state & LINE_WIDTH) != 0) {
346-
Cairo.cairo_set_line_width(cairo, data.lineWidth == 0 ? DPIUtil.autoScaleUp(drawable, 1) : data.lineWidth);
346+
Cairo.cairo_set_line_width(cairo, data.lineWidth == 0 ? 1 : data.lineWidth);
347347
switch (data.lineStyle) {
348348
case SWT.LINE_DOT:
349349
case SWT.LINE_DASH:
@@ -467,7 +467,7 @@ public void copyArea(Image image, int x, int y) {
467467
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
468468
if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
469469
if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
470-
Point loc = DPIUtil.autoScaleUp(drawable, new Point(x, y));
470+
Point loc = new Point(x, y);
471471
copyAreaInPixels(image, loc.x, loc.y);
472472
}
473473
void copyAreaInPixels(Image image, int x, int y) {
@@ -507,8 +507,8 @@ void copyAreaInPixels(Image image, int x, int y) {
507507
*/
508508
public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) {
509509
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
510-
Rectangle src = DPIUtil.autoScaleUp(drawable, new Rectangle(srcX, srcY, width, height));
511-
Point dest = DPIUtil.autoScaleUp(drawable, new Point(destX, destY));
510+
Rectangle src = new Rectangle(srcX, srcY, width, height);
511+
Point dest = new Point(destX, destY);
512512
copyAreaInPixels(src.x, src.y, src.width, src.height, dest.x, dest.y);
513513
}
514514

@@ -535,8 +535,8 @@ void copyAreaInPixels(int srcX, int srcY, int width, int height, int destX, int
535535
*/
536536
public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
537537
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
538-
Rectangle srcLoc = DPIUtil.autoScaleUp(drawable, new Rectangle(srcX, srcY, width, height));
539-
Point destLoc = DPIUtil.autoScaleUp(drawable, new Point(destX, destY));
538+
Rectangle srcLoc = new Rectangle(srcX, srcY, width, height);
539+
Point destLoc = new Point(destX, destY);
540540
copyAreaInPixels(srcLoc.x, srcLoc.y, srcLoc.width, srcLoc.height, destLoc.x, destLoc.y, paint);
541541
}
542542
void copyAreaInPixels(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
@@ -726,7 +726,7 @@ void destroy() {
726726
*/
727727
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
728728
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
729-
Rectangle loc = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
729+
Rectangle loc = new Rectangle(x, y, width, height);
730730
drawArcInPixels(loc.x, loc.y, loc.width, loc.height, startAngle, arcAngle);
731731
}
732732
void drawArcInPixels(int x, int y, int width, int height, int startAngle, int arcAngle) {
@@ -781,7 +781,7 @@ void drawArcInPixels(int x, int y, int width, int height, int startAngle, int ar
781781
*/
782782
public void drawFocus(int x, int y, int width, int height) {
783783
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
784-
Rectangle loc = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
784+
Rectangle loc = new Rectangle(x, y, width, height);
785785
drawFocusInPixels(loc.x, loc.y, loc.width, loc.height);
786786
}
787787
void drawFocusInPixels(int x, int y, int width, int height) {
@@ -814,7 +814,7 @@ public void drawImage(Image image, int x, int y) {
814814
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
815815
if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
816816
if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
817-
Point loc = DPIUtil.autoScaleUp(drawable, new Point(x, y));
817+
Point loc = new Point(x, y);
818818
drawImageInPixels(image, loc.x, loc.y);
819819
}
820820
void drawImageInPixels(Image image, int x, int y) {
@@ -861,7 +861,7 @@ public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeig
861861
}
862862
if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
863863
if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
864-
Rectangle destRect = DPIUtil.autoScaleUp(drawable, new Rectangle(destX, destY, destWidth, destHeight));
864+
Rectangle destRect = new Rectangle(destX, destY, destWidth, destHeight);
865865
drawImage(image, srcX, srcY, srcWidth, srcHeight, destRect.x, destRect.y, destRect.width, destRect.height, false);
866866
}
867867
void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
@@ -939,8 +939,8 @@ void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight,
939939
*/
940940
public void drawLine(int x1, int y1, int x2, int y2) {
941941
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
942-
Point loc1 = DPIUtil.autoScaleUp(drawable, new Point(x1, y1));
943-
Point loc2 = DPIUtil.autoScaleUp(drawable, new Point(x2, y2));
942+
Point loc1 = new Point(x1, y1);
943+
Point loc2 = new Point(x2, y2);
944944
drawLineInPixels(loc1.x, loc1.y, loc2.x, loc2.y);
945945
}
946946
void drawLineInPixels(int x1, int y1, int x2, int y2) {
@@ -978,7 +978,7 @@ void drawLineInPixels(int x1, int y1, int x2, int y2) {
978978
*/
979979
public void drawOval(int x, int y, int width, int height) {
980980
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
981-
Rectangle rect = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
981+
Rectangle rect = new Rectangle(x, y, width, height);
982982
drawOvalInPixels(rect.x, rect.y, rect.width, rect.height);
983983
}
984984
void drawOvalInPixels(int x, int y, int width, int height) {
@@ -1065,7 +1065,7 @@ public void drawPath(Path path) {
10651065
*/
10661066
public void drawPoint (int x, int y) {
10671067
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
1068-
Point loc = DPIUtil.autoScaleUp(drawable, new Point(x, y));
1068+
Point loc = new Point(x, y);
10691069
drawPointInPixels(loc.x, loc.y);
10701070
}
10711071
void drawPointInPixels (int x, int y) {
@@ -1095,7 +1095,7 @@ void drawPointInPixels (int x, int y) {
10951095
public void drawPolygon(int[] pointArray) {
10961096
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
10971097
if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
1098-
int [] scaledPointArray = DPIUtil.autoScaleUp(drawable, pointArray);
1098+
int [] scaledPointArray = pointArray;
10991099
drawPolygonInPixels(scaledPointArray);
11001100
}
11011101
void drawPolygonInPixels(int[] pointArray) {
@@ -1125,7 +1125,7 @@ void drawPolygonInPixels(int[] pointArray) {
11251125
public void drawPolyline(int[] pointArray) {
11261126
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
11271127
if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
1128-
int [] scaledPointArray = DPIUtil.autoScaleUp(drawable, pointArray);
1128+
int [] scaledPointArray = pointArray;
11291129
drawPolylineInPixels(scaledPointArray);
11301130
}
11311131
void drawPolylineInPixels(int[] pointArray) {
@@ -1199,7 +1199,7 @@ void drawRectangleInPixels(int x, int y, int width, int height) {
11991199
*/
12001200
public void drawRectangle(Rectangle rect) {
12011201
if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
1202-
drawRectangleInPixels(DPIUtil.autoScaleUp(drawable, rect));
1202+
drawRectangleInPixels(rect);
12031203
}
12041204
void drawRectangleInPixels(Rectangle rect) {
12051205
drawRectangleInPixels (rect.x, rect.y, rect.width, rect.height);
@@ -1227,8 +1227,8 @@ void drawRectangleInPixels(Rectangle rect) {
12271227
*/
12281228
public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
12291229
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
1230-
Rectangle rect = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
1231-
Point arcSize = DPIUtil.autoScaleUp(drawable, new Point(arcWidth, arcHeight));
1230+
Rectangle rect = new Rectangle(x, y, width, height);
1231+
Point arcSize = new Point(arcWidth, arcHeight);
12321232
drawRoundRectangleInPixels(rect.x, rect.y, rect.width, rect.height, arcSize.x, arcSize.y);
12331233
}
12341234
void drawRoundRectangleInPixels(int x, int y, int width, int height, int arcWidth, int arcHeight) {
@@ -1333,7 +1333,7 @@ void drawStringInPixels (String string, int x, int y) {
13331333
public void drawString(String string, int x, int y, boolean isTransparent) {
13341334
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
13351335
if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
1336-
Point loc = DPIUtil.autoScaleUp(drawable, new Point(x, y));
1336+
Point loc = new Point(x, y);
13371337
drawStringInPixels(string, loc.x, loc.y, isTransparent);
13381338
}
13391339

@@ -1395,7 +1395,7 @@ void drawTextInPixels(String string, int x, int y) {
13951395
* </ul>
13961396
*/
13971397
public void drawText(String string, int x, int y, boolean isTransparent) {
1398-
Point loc = DPIUtil.autoScaleUp(drawable, new Point (x, y));
1398+
Point loc = new Point (x, y);
13991399
drawTextInPixels(string, loc.x, loc.y, isTransparent);
14001400
}
14011401
void drawTextInPixels(String string, int x, int y, boolean isTransparent) {
@@ -1444,7 +1444,7 @@ void drawTextInPixels(String string, int x, int y, boolean isTransparent) {
14441444
* </ul>
14451445
*/
14461446
public void drawText (String string, int x, int y, int flags) {
1447-
Point loc = DPIUtil.autoScaleUp(drawable, new Point (x, y));
1447+
Point loc = new Point (x, y);
14481448
drawTextInPixels(string, loc.x, loc.y, flags);
14491449
}
14501450
void drawTextInPixels (String string, int x, int y, int flags) {
@@ -1530,7 +1530,7 @@ public boolean equals(Object object) {
15301530
*/
15311531
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
15321532
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
1533-
Rectangle rect = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
1533+
Rectangle rect = new Rectangle(x, y, width, height);
15341534
fillArcInPixels(rect.x, rect.y, rect.width, rect.height, startAngle, arcAngle);
15351535
}
15361536
void fillArcInPixels(int x, int y, int width, int height, int startAngle, int arcAngle) {
@@ -1589,7 +1589,7 @@ void fillArcInPixels(int x, int y, int width, int height, int startAngle, int ar
15891589
*/
15901590
public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
15911591
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
1592-
Rectangle rect = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
1592+
Rectangle rect = new Rectangle(x, y, width, height);
15931593
fillGradientRectangleInPixels(rect.x, rect.y, rect.width, rect.height, vertical);
15941594
}
15951595

@@ -1673,7 +1673,7 @@ void fillGradientRectangleInPixels(int x, int y, int width, int height, boolean
16731673
*/
16741674
public void fillOval(int x, int y, int width, int height) {
16751675
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
1676-
Rectangle rect = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
1676+
Rectangle rect = new Rectangle(x, y, width, height);
16771677
fillOvalInPixels(rect.x, rect.y, rect.width, rect.height);
16781678
}
16791679
void fillOvalInPixels(int x, int y, int width, int height) {
@@ -1758,7 +1758,7 @@ public void fillPath (Path path) {
17581758
public void fillPolygon(int[] pointArray) {
17591759
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
17601760
if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
1761-
int [] scaledPointArray = DPIUtil.autoScaleUp(drawable, pointArray);
1761+
int [] scaledPointArray = pointArray;
17621762
fillPolygonInPixels(scaledPointArray);
17631763
}
17641764
void fillPolygonInPixels(int[] pointArray) {
@@ -1824,7 +1824,7 @@ void fillRectangleInPixels(int x, int y, int width, int height) {
18241824
public void fillRectangle(Rectangle rect) {
18251825
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
18261826
if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
1827-
fillRectangleInPixels(DPIUtil.autoScaleUp(drawable, rect));
1827+
fillRectangleInPixels(rect);
18281828
}
18291829
void fillRectangleInPixels(Rectangle rect) {
18301830
fillRectangleInPixels(rect.x, rect.y, rect.width, rect.height);
@@ -1849,8 +1849,8 @@ void fillRectangleInPixels(Rectangle rect) {
18491849
*/
18501850
public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
18511851
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
1852-
Rectangle rect = DPIUtil.autoScaleUp(drawable, new Rectangle(x, y, width, height));
1853-
Point arcSize = DPIUtil.autoScaleUp(drawable, new Point(arcWidth, arcHeight));
1852+
Rectangle rect = new Rectangle(x, y, width, height);
1853+
Point arcSize = new Point(arcWidth, arcHeight);
18541854
fillRoundRectangleInPixels(rect.x, rect.y, rect.width, rect.height, arcSize.x, arcSize.y);
18551855
}
18561856
void fillRoundRectangleInPixels(int x, int y, int width, int height, int arcWidth, int arcHeight) {
@@ -2074,7 +2074,7 @@ public int getCharWidth(char ch) {
20742074
*/
20752075
public Rectangle getClipping() {
20762076
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
2077-
return DPIUtil.autoScaleDown(drawable, getClippingInPixels());
2077+
return getClippingInPixels();
20782078
}
20792079
Rectangle getClippingInPixels() {
20802080
/* Calculate visible bounds in device space */
@@ -2251,11 +2251,11 @@ public FontMetrics getFontMetrics() {
22512251
FontMetrics fm = new FontMetrics();
22522252
int ascent = OS.pango_font_metrics_get_ascent(metrics);
22532253
int descent = OS.pango_font_metrics_get_descent(metrics);
2254-
int ascentInPoints = DPIUtil.autoScaleDown(drawable, OS.PANGO_PIXELS(ascent));
2254+
int ascentInPoints = OS.PANGO_PIXELS(ascent);
22552255
fm.ascentInPoints = ascentInPoints;
2256-
int heightInPoints = DPIUtil.autoScaleDown(drawable, OS.PANGO_PIXELS(ascent + descent));
2256+
int heightInPoints = OS.PANGO_PIXELS(ascent + descent);
22572257
fm.descentInPoints = heightInPoints - ascentInPoints;
2258-
fm.averageCharWidthInPoints = DPIUtil.autoScaleDown(drawable, OS.PANGO_PIXELS(OS.pango_font_metrics_get_approximate_char_width(metrics)));
2258+
fm.averageCharWidthInPoints = OS.PANGO_PIXELS(OS.pango_font_metrics_get_approximate_char_width(metrics));
22592259
OS.pango_font_metrics_unref(metrics);
22602260
return fm;
22612261
}
@@ -2352,7 +2352,7 @@ public int getInterpolation() {
23522352
public LineAttributes getLineAttributes() {
23532353
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
23542354
LineAttributes attributes = getLineAttributesInPixels();
2355-
attributes.width = DPIUtil.autoScaleDown(drawable, attributes.width);
2355+
attributes.width = attributes.width;
23562356
return attributes;
23572357
}
23582358
LineAttributes getLineAttributesInPixels() {
@@ -2453,7 +2453,7 @@ public int getLineStyle() {
24532453
*/
24542454
public int getLineWidth() {
24552455
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
2456-
return (int)DPIUtil.autoScaleDown(drawable, data.lineWidth);
2456+
return getLineWidthInPixels();
24572457
}
24582458
int getLineWidthInPixels() {
24592459
return (int)data.lineWidth;
@@ -3112,7 +3112,7 @@ void setClipping(long clipRgn) {
31123112
*/
31133113
public void setClipping(int x, int y, int width, int height) {
31143114
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
3115-
setClippingInPixels(DPIUtil.autoScaleUp(drawable, x), DPIUtil.autoScaleUp(drawable, y), DPIUtil.autoScaleUp(drawable, width), DPIUtil.autoScaleUp(drawable, height));
3115+
setClippingInPixels(x, y, width, height);
31163116
}
31173117
void setClippingInPixels(int x, int y, int width, int height) {
31183118
if (width < 0) {
@@ -3190,7 +3190,7 @@ public void setClipping(Path path) {
31903190
*/
31913191
public void setClipping(Rectangle rect) {
31923192
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
3193-
setClippingInPixels(DPIUtil.autoScaleUp(drawable, rect));
3193+
setClippingInPixels(rect);
31943194
}
31953195
void setClippingInPixels(Rectangle rect) {
31963196
if (rect == null) {
@@ -3415,7 +3415,7 @@ public void setInterpolation(int interpolation) {
34153415
public void setLineAttributes(LineAttributes attributes) {
34163416
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
34173417
if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
3418-
attributes.width = DPIUtil.autoScaleUp(drawable, attributes.width);
3418+
attributes.width = attributes.width;
34193419
setLineAttributesInPixels(attributes);
34203420
}
34213421
void setLineAttributesInPixels(LineAttributes attributes) {
@@ -3669,7 +3669,7 @@ public void setLineStyle(int lineStyle) {
36693669
*/
36703670
public void setLineWidth(int lineWidth) {
36713671
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
3672-
setLineWidthInPixels(DPIUtil.autoScaleUp(drawable, lineWidth));
3672+
setLineWidthInPixels(lineWidth);
36733673
}
36743674
void setLineWidthInPixels(int lineWidth) {
36753675
if (data.lineWidth == lineWidth) return;
@@ -3853,7 +3853,7 @@ public void setXORMode(boolean xor) {
38533853
* </ul>
38543854
*/
38553855
public Point stringExtent(String string) {
3856-
return DPIUtil.autoScaleDown(drawable, stringExtentInPixels(string));
3856+
return stringExtentInPixels(string);
38573857
}
38583858
Point stringExtentInPixels(String string) {
38593859
return textExtentInPixels(string, 0);
@@ -3879,7 +3879,7 @@ Point stringExtentInPixels(String string) {
38793879
* </ul>
38803880
*/
38813881
public Point textExtent(String string) {
3882-
return DPIUtil.autoScaleDown(drawable, textExtentInPixels(string));
3882+
return textExtentInPixels(string);
38833883
}
38843884

38853885
Point textExtentInPixels(String string) {
@@ -3920,7 +3920,7 @@ Point textExtentInPixels(String string) {
39203920
public Point textExtent(String string, int flags) {
39213921
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
39223922
if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
3923-
return DPIUtil.autoScaleDown(drawable, textExtentInPixels(string, flags));
3923+
return textExtentInPixels(string, flags);
39243924
}
39253925
Point textExtentInPixels(String string, int flags) {
39263926
setString(string, flags);

0 commit comments

Comments
 (0)