Skip to content

Commit 1a73f3b

Browse files
committed
[GTK][HiDpi] Code cleanup for removal of non-cairo scale path
Fixes #1300
1 parent 15788c0 commit 1a73f3b

File tree

10 files changed

+118
-403
lines changed

10 files changed

+118
-403
lines changed

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

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,18 @@ public static long convertSurface(Image image) {
3434
int type = Cairo.cairo_surface_get_type(newSurface);
3535
if (type != Cairo.CAIRO_SURFACE_TYPE_IMAGE) {
3636
Rectangle bounds;
37-
if (DPIUtil.useCairoAutoScale()) {
38-
bounds = image.getBounds();
39-
} else {
40-
bounds = image.getBoundsInPixels();
41-
}
37+
bounds = image.getBounds();
4238
int format = Cairo.cairo_surface_get_content(newSurface) == Cairo.CAIRO_CONTENT_COLOR ? Cairo.CAIRO_FORMAT_RGB24 : Cairo.CAIRO_FORMAT_ARGB32;
4339
newSurface = Cairo.cairo_image_surface_create(format, bounds.width, bounds.height);
4440
if (newSurface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
4541
//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]);
42+
double sx[] = new double[1];
43+
double sy[] = new double[1];
44+
Cairo.cairo_surface_get_device_scale(image.surface, sx, sy);
45+
if (sx[0] == 0 || sy[0] == 0){
46+
sx[0] = sy[0] = DPIUtil.getDeviceZoom() / 100f;
5447
}
48+
Cairo.cairo_surface_set_device_scale(newSurface, sx[0], sy[0]);
5549
long cairo = Cairo.cairo_create(newSurface);
5650
if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);
5751
Cairo.cairo_set_operator(cairo, Cairo.CAIRO_OPERATOR_SOURCE);
@@ -296,11 +290,7 @@ void set (int index, Image image) {
296290
h /= (int)sy[0];
297291

298292
Rectangle bounds;
299-
if (DPIUtil.useCairoAutoScale()) {
300-
bounds = image.getBounds();
301-
} else {
302-
bounds = image.getBoundsInPixels();
303-
}
293+
bounds = image.getBounds();
304294
if (w == 0) {
305295
w = bounds.width;
306296
}
@@ -335,25 +325,8 @@ long scaleSurface(Image image, int width, int height) {
335325
if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);
336326

337327
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-
}
328+
bounds = image.getBounds();
346329

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]);
354-
} else {
355-
bounds = image.getBoundsInPixels();
356-
}
357330
double scaleX = (double) width / (double) bounds.width;
358331
double scaleY = (double) height / (double) bounds.height;
359332
Cairo.cairo_scale(cairo, scaleX, scaleY);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void addSelectionListener (SelectionListener listener) {
187187
}
188188

189189
@Override
190-
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
190+
public Point computeSize(int wHint, int hHint, boolean changed) {
191191
checkWidget ();
192192
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
193193
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import org.eclipse.swt.*;
1818
import org.eclipse.swt.graphics.*;
19-
import org.eclipse.swt.internal.*;
2019
import org.eclipse.swt.internal.cairo.*;
2120
import org.eclipse.swt.internal.gtk.*;
2221

@@ -318,12 +317,6 @@ public void scroll (int destX, int destY, int x, int y, int width, int height, b
318317
* as to why it's unneeded is left as a TODO. See bug 546274.
319318
*/
320319
if (GTK.GTK4) return;
321-
Point destination = DPIUtil.autoScaleUp (new Point (destX, destY));
322-
Rectangle srcRect = DPIUtil.autoScaleUp (new Rectangle (x, y, width, height));
323-
scrollInPixels(destination.x, destination.y, srcRect.x, srcRect.y, srcRect.width, srcRect.height, all);
324-
}
325-
326-
void scrollInPixels (int destX, int destY, int x, int y, int width, int height, boolean all) {
327320
if ((style & SWT.MIRRORED) != 0) {
328321
int clientWidth = getClientWidth ();
329322
x = clientWidth - width - x;
@@ -435,10 +428,10 @@ void scrollInPixels (int destX, int destY, int x, int y, int width, int height,
435428
Control [] children = _getChildren ();
436429
for (int i=0; i<children.length; i++) {
437430
Control child = children [i];
438-
Rectangle rect = child.getBoundsInPixels ();
431+
Rectangle rect = child.getBounds();
439432
if (Math.min(x + width, rect.x + rect.width) >= Math.max (x, rect.x) &&
440433
Math.min(y + height, rect.y + rect.height) >= Math.max (y, rect.y)) {
441-
child.setLocationInPixels (rect.x + deltaX, rect.y + deltaY);
434+
child.setLocation(rect.x + deltaX, rect.y + deltaY);
442435
}
443436
}
444437
}

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

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import org.eclipse.swt.*;
1818
import org.eclipse.swt.graphics.*;
19-
import org.eclipse.swt.internal.*;
2019
import org.eclipse.swt.internal.cairo.*;
2120
import org.eclipse.swt.internal.gtk.*;
2221

@@ -142,14 +141,9 @@ private void drawInCellEditor(long window) {
142141
* </ul>
143142
*/
144143
public Rectangle getBounds () {
145-
checkWidget();
146-
return DPIUtil.autoScaleDown(getBoundsInPixels());
147-
}
148-
149-
Rectangle getBoundsInPixels () {
150144
checkWidget();
151145
if (image != null) {
152-
Rectangle rect = image.getBoundsInPixels ();
146+
Rectangle rect = image.getBounds ();
153147
return new Rectangle (x, y, rect.width, rect.height);
154148
} else {
155149
if (width == 0) {
@@ -202,11 +196,6 @@ public Image getImage () {
202196
* </ul>
203197
*/
204198
public Point getLocation () {
205-
checkWidget();
206-
return DPIUtil.autoScaleDown(getLocationInPixels());
207-
}
208-
209-
Point getLocationInPixels () {
210199
checkWidget();
211200
return new Point (x, y);
212201
}
@@ -237,14 +226,9 @@ public Canvas getParent () {
237226
* </ul>
238227
*/
239228
public Point getSize () {
240-
checkWidget();
241-
return DPIUtil.autoScaleDown(getSizeInPixels());
242-
}
243-
244-
Point getSizeInPixels () {
245229
checkWidget();
246230
if (image != null) {
247-
Rectangle rect = image.getBoundsInPixels ();
231+
Rectangle rect = image.getBounds();
248232
return new Point (rect.width, rect.height);
249233
} else {
250234
if (width == 0) {
@@ -349,11 +333,6 @@ void releaseWidget () {
349333
* </ul>
350334
*/
351335
public void setBounds (int x, int y, int width, int height) {
352-
checkWidget();
353-
setBounds (new Rectangle (x, y, width, height));
354-
}
355-
356-
void setBoundsInPixels (int x, int y, int width, int height) {
357336
checkWidget();
358337
if (this.x == x && this.y == y && this.width == width && this.height == height) return;
359338
boolean isFocus = isFocusCaret ();
@@ -378,15 +357,9 @@ void setBoundsInPixels (int x, int y, int width, int height) {
378357
* </ul>
379358
*/
380359
public void setBounds (Rectangle rect) {
381-
checkWidget();
382-
rect = DPIUtil.autoScaleUp(rect);
383-
setBoundsInPixels(rect);
384-
}
385-
386-
void setBoundsInPixels (Rectangle rect) {
387360
checkWidget();
388361
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
389-
setBoundsInPixels (rect.x, rect.y, rect.width, rect.height);
362+
setBounds(rect.x, rect.y, rect.width, rect.height);
390363
}
391364

392365
void setFocus () {
@@ -459,12 +432,7 @@ public void setImage (Image image) {
459432
*/
460433
public void setLocation (int x, int y) {
461434
checkWidget();
462-
setLocation (new Point (x, y));
463-
}
464-
465-
void setLocationInPixels (int x, int y) {
466-
checkWidget();
467-
setBoundsInPixels (x, y, width, height);
435+
setBounds(x, y, width, height);
468436
}
469437

470438
/**
@@ -480,14 +448,9 @@ void setLocationInPixels (int x, int y) {
480448
* </ul>
481449
*/
482450
public void setLocation (Point location) {
483-
checkWidget();
484-
setLocationInPixels (DPIUtil.autoScaleUp (location));
485-
}
486-
487-
void setLocationInPixels (Point location) {
488451
checkWidget();
489452
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
490-
setLocationInPixels (location.x, location.y);
453+
setLocation(location.x, location.y);
491454
}
492455

493456
/**
@@ -503,12 +466,7 @@ void setLocationInPixels (Point location) {
503466
*/
504467
public void setSize (int width, int height) {
505468
checkWidget();
506-
setSize (new Point (width,height));
507-
}
508-
509-
void setSizeInPixels (int width, int height) {
510-
checkWidget();
511-
setBoundsInPixels (x, y, width, height);
469+
setSize(new Point (width,height));
512470
}
513471

514472
/**
@@ -525,14 +483,9 @@ void setSizeInPixels (int width, int height) {
525483
* </ul>
526484
*/
527485
public void setSize (Point size) {
528-
checkWidget();
529-
setSizeInPixels(DPIUtil.autoScaleUp (size));
530-
}
531-
532-
void setSizeInPixels (Point size) {
533486
checkWidget();
534487
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
535-
setSizeInPixels (size.x, size.y);
488+
setSize(size.x, size.y);
536489
}
537490

538491
/**

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ void clearText () {
448448
}
449449

450450
@Override
451-
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
451+
public Point computeSize(int wHint, int hHint, boolean changed) {
452452
checkWidget ();
453453
return computeNativeSize (handle, wHint, hHint, changed);
454454
}
@@ -1080,12 +1080,6 @@ long eventSurface () {
10801080
* @since 3.8
10811081
*/
10821082
public Point getCaretLocation () {
1083-
checkWidget ();
1084-
return DPIUtil.autoScaleDown(getCaretLocationInPixels());
1085-
}
1086-
1087-
1088-
Point getCaretLocationInPixels () {
10891083
checkWidget ();
10901084
if ((style & SWT.READ_ONLY) != 0) {
10911085
return new Point (0, 0);
@@ -1384,12 +1378,6 @@ String getText (int start, int stop) {
13841378
* </ul>
13851379
*/
13861380
public int getTextHeight () {
1387-
checkWidget();
1388-
return DPIUtil.autoScaleDown(getTextHeightInPixels());
1389-
}
1390-
1391-
1392-
int getTextHeightInPixels () {
13931381
checkWidget();
13941382
GtkRequisition requisition = new GtkRequisition ();
13951383
gtk_widget_get_preferred_size (handle, requisition);
@@ -2270,7 +2258,7 @@ void setBackgroundGdkRGBA (long context, long handle, GdkRGBA rgba) {
22702258
@Override
22712259
int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
22722260
int newHeight = height;
2273-
if (resize) newHeight = Math.max (getTextHeightInPixels (), height);
2261+
if (resize) newHeight = Math.max (getTextHeight(), height);
22742262
return super.setBounds (x, y, width, newHeight, move, resize);
22752263
}
22762264

0 commit comments

Comments
 (0)