Bug 568864 - [GTK] [HiDPI] GC.fillGradientRectangle sets device scale permanently
Summary: [GTK] [HiDPI] GC.fillGradientRectangle sets device scale permanently
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.17   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2020-11-16 14:22 EST by Phil Beauvoir CLA
Modified: 2021-10-04 04:33 EDT (History)
1 user (show)

See Also:


Attachments
Snippet that shows the problem (1.70 KB, text/plain)
2020-11-16 14:24 EST, Phil Beauvoir CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Phil Beauvoir CLA 2020-11-16 14:22:59 EST
Linux HiDPI GC.fillGradientRectangle sets device scale permanently

Linux Ubuntu 20.04
Hi-res display (200% scaling)

I am creating an SWT Image to a GC instance usng fillGradientRectangle() and drawing text to the same GC instance.

However, any GC methods used after calling fillGradientRectangle() draw at double-scale.

- Run the attached snippet and look at the generated image
- drawText() is called first and draws correctly
- fillGradientRectangle() is then called
- drawText() is then called again, but this time scaling is at 2x and so the text is double size
- If fillGradientRectangle() is commented out, then drawing is at the correct scale

It seems that once GC#fillGradientRectangle() is called any drawing after that is at double scale.

Note these lines in GC#fillGradientRectangleInPixels() :

if (DPIUtil.useCairoAutoScale() ) {
...
Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor);

Perhaps the scale should be set back to its original setting after drawing the gradient?
Comment 1 Phil Beauvoir CLA 2020-11-16 14:24:30 EST
Created attachment 284776 [details]
Snippet that shows the problem

Here's the snippet that shows the problem.
Comment 2 Andrey Loskutov CLA 2020-11-16 14:49:32 EST
Do you see from which Eclipse version the regression is coming? Do you want to provide a gerrit patch?
Comment 3 Phil Beauvoir CLA 2020-11-16 15:03:31 EST
(In reply to Andrey Loskutov from comment #2)
> Do you see from which Eclipse version the regression is coming?

I think it has been like this for some time.

> Do you want to provide a gerrit patch?

Normally I would try, but this is beyond my programming skills as it is in the C language (I think).
Comment 4 Phil Beauvoir CLA 2020-11-17 04:04:39 EST
(In reply to Phil Beauvoir from comment #3)
> (In reply to Andrey Loskutov from comment #2)
> > Do you see from which Eclipse version the regression is coming?
> 
> I think it has been like this for some time.
> 
> > Do you want to provide a gerrit patch?
> 
> Normally I would try, but this is beyond my programming skills as it is in
> the C language (I think).

I meant to say that the code calls some C functions.

I would not say this was a recent regression, this has been like this since 2018 or so.
Comment 5 Phil Beauvoir CLA 2021-10-04 04:33:58 EDT
Setting scaleFactor to 1.0 in this block fixes the issue:

	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);
		}
	}

Is this block of code needed?