Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static enum AutoScaleMethod { AUTO, NEAREST, SMOOTH }
private static AutoScaleMethod autoScaleMethod = AutoScaleMethod.NEAREST;

private static String autoScaleValue;
private static boolean useCairoAutoScale = false;
private static boolean useCairoAutoScale = true;

/**
* System property that controls the autoScale functionality.
Expand Down Expand Up @@ -635,10 +635,6 @@ public static void setUseCairoAutoScale (boolean cairoAutoScale) {
useCairoAutoScale = cairoAutoScale;
}

public static boolean useCairoAutoScale() {
return useCairoAutoScale;
}

public static int getZoomForAutoscaleProperty (int nativeDeviceZoom) {
return getZoomForAutoscaleProperty(nativeDeviceZoom, autoScaleValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,6 @@ protected void init () {
this.dpi = getDPI();
DPIUtil.setDeviceZoom (getDeviceZoom ());

DPIUtil.setUseCairoAutoScale(true);

/* Initialize the system font slot */
long [] defaultFontArray = new long [1];
long defaultFont = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1621,18 +1621,16 @@ void fillGradientRectangleInPixels(int x, int y, int width, int height, boolean
long cairo = data.cairo;
long pattern;

if (DPIUtil.useCairoAutoScale() ) {
/*
* Here the co-ordinates passed are in points for GTK3.
* That means the user is expecting surface to be at
* device scale equal to current scale factor. So need
* to set the device scale to current scale factor
*/
long surface = Cairo.cairo_get_target(cairo);
if (surface != 0) {
float scaleFactor = DPIUtil.getDeviceZoom() / 100f;
Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);
}
/*
* Here the co-ordinates passed are in points for GTK3.
* That means the user is expecting surface to be at
* device scale equal to current scale factor. So need
* to set the device scale to current scale factor
*/
long surface = Cairo.cairo_get_target(cairo);
if (surface != 0) {
float scaleFactor = DPIUtil.getDeviceZoom() / 100f;
Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);
}

if (fromRGB.equals(toRGB)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public Image(Device device, Image srcImage, int flag) {
boolean hasAlpha = format == Cairo.CAIRO_FORMAT_ARGB32;
surface = Cairo.cairo_image_surface_create(format, width, height);
if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
if (DPIUtil.getDeviceZoom() != currentDeviceZoom && DPIUtil.useCairoAutoScale()) {
if (DPIUtil.getDeviceZoom() != currentDeviceZoom) {
double scaleFactor = DPIUtil.getDeviceZoom() / 100f;
Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);
}
Expand Down Expand Up @@ -738,19 +738,6 @@ boolean refreshImageForZoom () {
refreshed = true;
currentDeviceZoom = deviceZoomLevel;
}
} else {
if (!DPIUtil.useCairoAutoScale()) {
int deviceZoomLevel = deviceZoom;
if (deviceZoomLevel != currentDeviceZoom) {
ImageData data = getImageDataAtCurrentZoom();
destroy ();
ImageData resizedData = DPIUtil.scaleImageData(device, data, deviceZoomLevel, currentDeviceZoom);
init(resizedData);
init();
refreshed = true;
currentDeviceZoom = deviceZoomLevel;
}
}
}
return refreshed;
}
Expand Down Expand Up @@ -809,7 +796,7 @@ void createFromPixbuf(int type, long pixbuf) {
// Initialize surface with dimensions received from the pixbuf and set device_scale appropriately
surface = Cairo.cairo_image_surface_create(format, pixbufWidth, pixbufHeight);
if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
if (DPIUtil.useCairoAutoScale()) Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);
Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);

long data = Cairo.cairo_image_surface_get_data(surface);
int cairoStride = Cairo.cairo_image_surface_get_stride(surface);
Expand Down Expand Up @@ -1257,12 +1244,8 @@ void init(int width, int height) {
if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
// When we create a blank image we need to set it to 100 in GTK3 as we draw using 100% scale.
// Cairo will take care of scaling for us when image needs to be scaled.
if (DPIUtil.useCairoAutoScale()) {
currentDeviceZoom = 100;
Cairo.cairo_surface_set_device_scale(surface, 1f, 1f);
} else {
currentDeviceZoom = DPIUtil.getDeviceZoom();
}
currentDeviceZoom = 100;
Cairo.cairo_surface_set_device_scale(surface, 1f, 1f);
long cairo = Cairo.cairo_create(surface);
if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);
Cairo.cairo_set_source_rgb(cairo, 1, 1, 1);
Expand Down Expand Up @@ -1296,7 +1279,7 @@ void init(ImageData image) {
// Initialize surface with dimensions received from the ImageData and set device_scale appropriately
surface = Cairo.cairo_image_surface_create(format, imageDataWidth, imageDataHeight);
if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES);
if (DPIUtil.useCairoAutoScale()) Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);
Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);

int stride = Cairo.cairo_image_surface_get_stride(surface);
long data = Cairo.cairo_image_surface_get_data(surface);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,18 @@ public static long convertSurface(Image image) {
long newSurface = image.surface;
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();
}
Rectangle 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 @@ -120,15 +113,13 @@ public static long createPixbuf(long surface) {
*
* We have to do this as surface has inherent auto scaling capability but pixbuf doesnot
*/
if (DPIUtil.useCairoAutoScale()) {
double sx[] = new double[1];
double sy[] = new double[1];
Cairo.cairo_surface_get_device_scale(surface, sx, sy);
if (sx[0] > 1 && sy[0] > 1){
long oldPixbuf = pixbuf;
pixbuf = GDK.gdk_pixbuf_scale_simple(pixbuf, width/(int)sx[0], height/(int)sy[0], GDK.GDK_INTERP_BILINEAR);
OS.g_object_unref(oldPixbuf);
}
double sx[] = new double[1];
double sy[] = new double[1];
Cairo.cairo_surface_get_device_scale(surface, sx, sy);
if (sx[0] > 1 && sy[0] > 1){
long oldPixbuf = pixbuf;
pixbuf = GDK.gdk_pixbuf_scale_simple(pixbuf, width/(int)sx[0], height/(int)sy[0], GDK.GDK_INTERP_BILINEAR);
OS.g_object_unref(oldPixbuf);
}
return pixbuf;
}
Expand Down Expand Up @@ -295,12 +286,7 @@ void set (int index, Image image) {
w /= (int)sx[0];
h /= (int)sy[0];

Rectangle bounds;
if (DPIUtil.useCairoAutoScale()) {
bounds = image.getBounds();
} else {
bounds = image.getBoundsInPixels();
}
Rectangle bounds = image.getBounds();
if (w == 0) {
w = bounds.width;
}
Expand Down Expand Up @@ -334,26 +320,22 @@ long scaleSurface(Image image, int width, int height) {
long cairo = Cairo.cairo_create(scaledSurface);
if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES);

int w = Cairo.cairo_image_surface_get_width(image.surface);
int h = Cairo.cairo_image_surface_get_height(image.surface);
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);
}

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]);
if ((w == 0) && (h == 0)) {
bounds = image.getBounds();
} else {
bounds = image.getBoundsInPixels();
bounds = new Rectangle(0, 0, w, h);
}

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]);
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 @@ -2880,13 +2880,7 @@ void sendMeasureEvent (long cell, long width, long height) {
Image image = item.getImage (columnIndex);
int imageWidth = 0;
if (image != null) {
Rectangle bounds;
if (DPIUtil.useCairoAutoScale()) {
bounds = image.getBounds ();
} else {
bounds = image.getBoundsInPixels();
}
imageWidth = bounds.width;
imageWidth = image.getBounds ().width;
}
contentWidth [0] += imageWidth;
GC gc = new GC (this);
Expand Down Expand Up @@ -3143,13 +3137,7 @@ void rendererRender (long cell, long cr, long snapshot, long widget, long backgr
Image image = item.getImage (columnIndex);
int imageWidth = 0;
if (image != null) {
Rectangle bounds;
if (DPIUtil.useCairoAutoScale()) {
bounds = image.getBounds ();
} else {
bounds = image.getBoundsInPixels ();
}
imageWidth = bounds.width;
imageWidth = image.getBounds ().width;
}
contentX [0] -= imageWidth;
contentWidth [0] += imageWidth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,7 @@ Rectangle getTextBoundsInPixels (int index) {
Image image = _getImage(index);
int imageWidth = 0;
if (image != null) {
if (DPIUtil.useCairoAutoScale()) {
imageWidth = image.getBounds ().width;
} else {
imageWidth = image.getBoundsInPixels ().width;
}

imageWidth = image.getBounds ().width;
}
if (x [0] < imageWidth) {
rect.x += imageWidth;
Expand Down Expand Up @@ -1211,14 +1206,8 @@ public void setImage(int index, Image image) {
GTK.gtk_cell_renderer_get_fixed_size (pixbufRenderer, currentWidth, currentHeight);
if (!parent.pixbufSizeSet) {
if (image != null) {
int iWidth, iHeight;
if (DPIUtil.useCairoAutoScale()) {
iWidth = image.getBounds ().width;
iHeight = image.getBounds ().height;
} else {
iWidth = image.getBoundsInPixels ().width;
iHeight = image.getBoundsInPixels ().height;
}
int iWidth = image.getBounds ().width;
int iHeight = image.getBounds ().height;
if (iWidth > currentWidth [0] || iHeight > currentHeight [0]) {
GTK.gtk_cell_renderer_set_fixed_size (pixbufRenderer, iWidth, iHeight);
parent.pixbufHeight = iHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3079,14 +3079,7 @@ void sendMeasureEvent (long cell, long width, long height) {
Image image = item.getImage (columnIndex);
int imageWidth = 0;
if (image != null && !image.isDisposed()) {
Rectangle bounds;
if (DPIUtil.useCairoAutoScale()) {
bounds = image.getBounds ();
} else {
bounds = image.getBoundsInPixels ();
}
bounds = image.getBounds ();
imageWidth = bounds.width;
imageWidth = image.getBounds ().width;
}
contentWidth [0] += imageWidth;
GC gc = new GC (this);
Expand Down Expand Up @@ -3337,13 +3330,7 @@ void rendererRender (long cell, long cr, long snapshot, long widget, long backgr
Image image = item.getImage (columnIndex);
int imageWidth = 0;
if (image != null) {
Rectangle bounds;
if(DPIUtil.useCairoAutoScale()) {
bounds = image.getBounds ();
} else {
bounds = image.getBoundsInPixels ();
}
imageWidth = bounds.width;
imageWidth = image.getBounds ().width;
}
// Account for the image width on GTK3, see bug 535124.
if (cr != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,7 @@ Rectangle getTextBoundsInPixels (int index) {
Image image = _getImage(index);
int imageWidth = 0;
if (image != null) {
if (DPIUtil.useCairoAutoScale()) {
imageWidth = image.getBounds ().width;
} else {
imageWidth = image.getBoundsInPixels ().width;
}
imageWidth = image.getBounds ().width;
}
if (x [0] < imageWidth) {
rect.x += imageWidth;
Expand Down Expand Up @@ -1528,14 +1524,8 @@ public void setImage(int index, Image image) {
GTK.gtk_cell_renderer_get_fixed_size (pixbufRenderer, currentWidth, currentHeight);
if (!parent.pixbufSizeSet) {
if (image != null) {
int iWidth, iHeight;
if (DPIUtil.useCairoAutoScale()) {
iWidth = image.getBounds ().width;
iHeight = image.getBounds ().height;
} else {
iWidth = image.getBoundsInPixels ().width;
iHeight = image.getBoundsInPixels ().height;
}
int iWidth = image.getBounds ().width;
int iHeight = image.getBounds ().height;
if (iWidth > currentWidth [0] || iHeight > currentHeight [0]) {
GTK.gtk_cell_renderer_set_fixed_size (pixbufRenderer, iWidth, iHeight);
parent.pixbufSizeSet = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,17 @@
public class DPIUtilTests {

private int deviceZoom;
private boolean useCairoAutoScale;

@Before
public void setup() {
deviceZoom = DPIUtil.getDeviceZoom();
useCairoAutoScale = DPIUtil.useCairoAutoScale();
DPIUtil.setDeviceZoom(200);
DPIUtil.setUseCairoAutoScale(false);
}

@After
public void tearDown() {
DPIUtil.setUseCairoAutoScale(useCairoAutoScale);
DPIUtil.setUseCairoAutoScale(true);
DPIUtil.setDeviceZoom(deviceZoom);
}

Expand Down
Loading