Skip to content

Commit

Permalink
[GTK][HiDpi] Code cleanup for removal of non-cairo scale path
Browse files Browse the repository at this point in the history
Fixes #1300
  • Loading branch information
deepika-u committed Jul 10, 2024
1 parent a335821 commit d9fbab8
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 403 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,18 @@ public static long convertSurface(Image image) {
int type = Cairo.cairo_surface_get_type(newSurface);
if (type != Cairo.CAIRO_SURFACE_TYPE_IMAGE) {
Rectangle bounds;
if (DPIUtil.useCairoAutoScale()) {
bounds = image.getBounds();
} else {
bounds = image.getBoundsInPixels();
}
bounds = image.getBounds();
int format = Cairo.cairo_surface_get_content(newSurface) == Cairo.CAIRO_CONTENT_COLOR ? Cairo.CAIRO_FORMAT_RGB24 : Cairo.CAIRO_FORMAT_ARGB32;
newSurface = Cairo.cairo_image_surface_create(format, bounds.width, bounds.height);
if (newSurface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
//retain device scale set in the original surface
if (DPIUtil.useCairoAutoScale()) {
double sx[] = new double[1];
double sy[] = new double[1];
Cairo.cairo_surface_get_device_scale(image.surface, sx, sy);
if (sx[0] == 0 || sy[0] == 0){
sx[0] = sy[0] = DPIUtil.getDeviceZoom() / 100f;
}
Cairo.cairo_surface_set_device_scale(newSurface, sx[0], sy[0]);
double sx[] = new double[1];
double sy[] = new double[1];
Cairo.cairo_surface_get_device_scale(image.surface, sx, sy);
if (sx[0] == 0 || sy[0] == 0){
sx[0] = sy[0] = DPIUtil.getDeviceZoom() / 100f;
}
Cairo.cairo_surface_set_device_scale(newSurface, sx[0], sy[0]);
long cairo = Cairo.cairo_create(newSurface);
if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);
Cairo.cairo_set_operator(cairo, Cairo.CAIRO_OPERATOR_SOURCE);
Expand Down Expand Up @@ -296,11 +290,7 @@ void set (int index, Image image) {
h /= (int)sy[0];

Rectangle bounds;
if (DPIUtil.useCairoAutoScale()) {
bounds = image.getBounds();
} else {
bounds = image.getBoundsInPixels();
}
bounds = image.getBounds();
if (w == 0) {
w = bounds.width;
}
Expand Down Expand Up @@ -335,25 +325,8 @@ long scaleSurface(Image image, int width, int height) {
if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);

Rectangle bounds;
if (DPIUtil.useCairoAutoScale()) {
int w = Cairo.cairo_image_surface_get_width(image.surface);
int h = Cairo.cairo_image_surface_get_height(image.surface);
if ((w == 0) && (h == 0)) {
bounds = image.getBounds();
} else {
bounds = new Rectangle(0, 0, w, h);
}
bounds = image.getBounds();

double sx[] = new double[1];
double sy[] = new double[1];
Cairo.cairo_surface_get_device_scale(image.surface, sx, sy);
if (sx[0] == 0 || sy[0] == 0){
sx[0] = sy[0] = DPIUtil.getDeviceZoom() / 100f;
}
Cairo.cairo_surface_set_device_scale(scaledSurface, sx[0], sy[0]);
} else {
bounds = image.getBoundsInPixels();
}
double scaleX = (double) width / (double) bounds.width;
double scaleY = (double) height / (double) bounds.height;
Cairo.cairo_scale(cairo, scaleX, scaleY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void addSelectionListener (SelectionListener listener) {
}

@Override
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
public Point computeSize(int wHint, int hHint, boolean changed) {
checkWidget ();
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.cairo.*;
import org.eclipse.swt.internal.gtk.*;

Expand Down Expand Up @@ -318,12 +317,6 @@ public void scroll (int destX, int destY, int x, int y, int width, int height, b
* as to why it's unneeded is left as a TODO. See bug 546274.
*/
if (GTK.GTK4) return;
Point destination = DPIUtil.autoScaleUp (new Point (destX, destY));
Rectangle srcRect = DPIUtil.autoScaleUp (new Rectangle (x, y, width, height));
scrollInPixels(destination.x, destination.y, srcRect.x, srcRect.y, srcRect.width, srcRect.height, all);
}

void scrollInPixels (int destX, int destY, int x, int y, int width, int height, boolean all) {
if ((style & SWT.MIRRORED) != 0) {
int clientWidth = getClientWidth ();
x = clientWidth - width - x;
Expand Down Expand Up @@ -435,10 +428,10 @@ void scrollInPixels (int destX, int destY, int x, int y, int width, int height,
Control [] children = _getChildren ();
for (int i=0; i<children.length; i++) {
Control child = children [i];
Rectangle rect = child.getBoundsInPixels ();
Rectangle rect = child.getBounds();
if (Math.min(x + width, rect.x + rect.width) >= Math.max (x, rect.x) &&
Math.min(y + height, rect.y + rect.height) >= Math.max (y, rect.y)) {
child.setLocationInPixels (rect.x + deltaX, rect.y + deltaY);
child.setLocation(rect.x + deltaX, rect.y + deltaY);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.cairo.*;
import org.eclipse.swt.internal.gtk.*;

Expand Down Expand Up @@ -142,14 +141,9 @@ private void drawInCellEditor(long window) {
* </ul>
*/
public Rectangle getBounds () {
checkWidget();
return DPIUtil.autoScaleDown(getBoundsInPixels());
}

Rectangle getBoundsInPixels () {
checkWidget();
if (image != null) {
Rectangle rect = image.getBoundsInPixels ();
Rectangle rect = image.getBounds ();
return new Rectangle (x, y, rect.width, rect.height);
} else {
if (width == 0) {
Expand Down Expand Up @@ -202,11 +196,6 @@ public Image getImage () {
* </ul>
*/
public Point getLocation () {
checkWidget();
return DPIUtil.autoScaleDown(getLocationInPixels());
}

Point getLocationInPixels () {
checkWidget();
return new Point (x, y);
}
Expand Down Expand Up @@ -237,14 +226,9 @@ public Canvas getParent () {
* </ul>
*/
public Point getSize () {
checkWidget();
return DPIUtil.autoScaleDown(getSizeInPixels());
}

Point getSizeInPixels () {
checkWidget();
if (image != null) {
Rectangle rect = image.getBoundsInPixels ();
Rectangle rect = image.getBounds();
return new Point (rect.width, rect.height);
} else {
if (width == 0) {
Expand Down Expand Up @@ -349,11 +333,6 @@ void releaseWidget () {
* </ul>
*/
public void setBounds (int x, int y, int width, int height) {
checkWidget();
setBounds (new Rectangle (x, y, width, height));
}

void setBoundsInPixels (int x, int y, int width, int height) {
checkWidget();
if (this.x == x && this.y == y && this.width == width && this.height == height) return;
boolean isFocus = isFocusCaret ();
Expand All @@ -378,15 +357,9 @@ void setBoundsInPixels (int x, int y, int width, int height) {
* </ul>
*/
public void setBounds (Rectangle rect) {
checkWidget();
rect = DPIUtil.autoScaleUp(rect);
setBoundsInPixels(rect);
}

void setBoundsInPixels (Rectangle rect) {
checkWidget();
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
setBoundsInPixels (rect.x, rect.y, rect.width, rect.height);
setBounds(rect.x, rect.y, rect.width, rect.height);
}

void setFocus () {
Expand Down Expand Up @@ -459,12 +432,7 @@ public void setImage (Image image) {
*/
public void setLocation (int x, int y) {
checkWidget();
setLocation (new Point (x, y));
}

void setLocationInPixels (int x, int y) {
checkWidget();
setBoundsInPixels (x, y, width, height);
setBounds(x, y, width, height);
}

/**
Expand All @@ -480,14 +448,9 @@ void setLocationInPixels (int x, int y) {
* </ul>
*/
public void setLocation (Point location) {
checkWidget();
setLocationInPixels (DPIUtil.autoScaleUp (location));
}

void setLocationInPixels (Point location) {
checkWidget();
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
setLocationInPixels (location.x, location.y);
setLocation(location.x, location.y);
}

/**
Expand All @@ -503,12 +466,7 @@ void setLocationInPixels (Point location) {
*/
public void setSize (int width, int height) {
checkWidget();
setSize (new Point (width,height));
}

void setSizeInPixels (int width, int height) {
checkWidget();
setBoundsInPixels (x, y, width, height);
setSize(new Point (width,height));
}

/**
Expand All @@ -525,14 +483,9 @@ void setSizeInPixels (int width, int height) {
* </ul>
*/
public void setSize (Point size) {
checkWidget();
setSizeInPixels(DPIUtil.autoScaleUp (size));
}

void setSizeInPixels (Point size) {
checkWidget();
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
setSizeInPixels (size.x, size.y);
setSize(size.x, size.y);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void clearText () {
}

@Override
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
public Point computeSize(int wHint, int hHint, boolean changed) {
checkWidget ();
return computeNativeSize (handle, wHint, hHint, changed);
}
Expand Down Expand Up @@ -1080,12 +1080,6 @@ long eventSurface () {
* @since 3.8
*/
public Point getCaretLocation () {
checkWidget ();
return DPIUtil.autoScaleDown(getCaretLocationInPixels());
}


Point getCaretLocationInPixels () {
checkWidget ();
if ((style & SWT.READ_ONLY) != 0) {
return new Point (0, 0);
Expand Down Expand Up @@ -1384,12 +1378,6 @@ String getText (int start, int stop) {
* </ul>
*/
public int getTextHeight () {
checkWidget();
return DPIUtil.autoScaleDown(getTextHeightInPixels());
}


int getTextHeightInPixels () {
checkWidget();
GtkRequisition requisition = new GtkRequisition ();
gtk_widget_get_preferred_size (handle, requisition);
Expand Down Expand Up @@ -2270,7 +2258,7 @@ void setBackgroundGdkRGBA (long context, long handle, GdkRGBA rgba) {
@Override
int setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
int newHeight = height;
if (resize) newHeight = Math.max (getTextHeightInPixels (), height);
if (resize) newHeight = Math.max (getTextHeight(), height);
return super.setBounds (x, y, width, newHeight, move, resize);
}

Expand Down
Loading

0 comments on commit d9fbab8

Please sign in to comment.