Bug 571166 - [GTK] Line number ruler broken
Summary: [GTK] Line number ruler broken
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.19   Edit
Hardware: PC Linux
: P3 blocker (vote)
Target Milestone: 4.19 M3   Edit
Assignee: Sravan Kumar Lakkimsetti CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks: 569691
  Show dependency tree
 
Reported: 2021-02-12 09:55 EST by Andrey Loskutov CLA
Modified: 2021-02-18 04:27 EST (History)
6 users (show)

See Also:


Attachments
video with an example (31.23 MB, image/gif)
2021-02-12 09:55 EST, Andrey Loskutov CLA
no flags Details
Same cheese on String class (65.02 KB, image/png)
2021-02-12 12:17 EST, Andrey Loskutov CLA
no flags Details
Patch set 4 issues (68.72 KB, image/png)
2021-02-16 07:38 EST, Andrey Loskutov CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Loskutov CLA 2021-02-12 09:55:22 EST
Created attachment 285541 [details]
video with an example

See recorded video. Looks like we've broke repainting of line number ruler somehow, I see cheese while scrolling, and the cheese stays until next scroll or resize event. I can see the problem by mouse / keyboard scrolling in an editor on a small text, bigger input with number of lines > 99 seem to be not affected.
Comment 1 Andrey Loskutov CLA 2021-02-12 10:13:23 EST
good
eclipse-SDK-I20210207-1800-linux-gtk-x86_64

bad
eclipse-SDK-I20210208-1800-linux-gtk-x86_64
Comment 2 Andrey Loskutov CLA 2021-02-12 10:22:11 EST
This looks like regression from bug 569691 / patch https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/175409. 

Switching SWT to commit 05888fc3f9d93910f38df725911e4c04cf5688ff (and native SWT to 5bdae9a812ab4d1c84916f3e1e83f62dc2c3adc4) fixes the broken lines.

Paul, Sravan, could you please check that?
Comment 3 Andrey Loskutov CLA 2021-02-12 10:53:22 EST
Looking on patch for bug 569691 (and seeing nothing special) I wonder if there is some bug in the JFace, especially in LineNumberRulerColumn.doubleBufferPaint(GC) that is revealed now.

Thomas, Mickael - you know that ruler code - any ideas if some "caching" there could be broken on new SWT Image / Device code? I assume the offscreen painting on Image is where the bug happens.
Comment 4 Thomas Wolf CLA 2021-02-12 11:27:26 EST
No idea. That SWT commit does change Image, though.
Comment 5 Andrey Loskutov CLA 2021-02-12 12:17:31 EST
Created attachment 285543 [details]
Same cheese on String class

(In reply to Andrey Loskutov from comment #0)
> I can see the problem by mouse / keyboard scrolling
> in an editor on a small text, bigger input with number of lines > 99 seem to
> be not affected.

I've seen that also with larger lines count. Open String class, scroll to the bottom, and scroll a bit up and down with the mouse wheel there. Cheese...
Comment 6 Andrey Loskutov CLA 2021-02-12 12:28:45 EST
OK, it looks like a missing repaint somewhere. 

If I de-activate Eclipse window by clicking on the window shown next to it, cheese disappears.

Steps to reproduce:

Open String type
Scroll to last line in file
Put the cursor on first visible line
Press <Key Up> to scroll editor one line up
Cheese. 
With this steps, the same line is painted over and over again.
Comment 7 Mickael Istria CLA 2021-02-12 12:34:40 EST
Sorry, I don't have a clue here. I won't be available to investigate soon, but I imagine some logging in LineNumberRulerColumn about the redrawn areas should help to identify what's wrong.
Comment 8 Sravan Kumar Lakkimsetti CLA 2021-02-13 02:28:52 EST
I tried on Ubuntu, but can't reproduce this problem there. Are you using RHEL/CentOS?
Comment 9 Andrey Loskutov CLA 2021-02-13 02:43:32 EST
(In reply to Sravan Kumar Lakkimsetti from comment #8)
> I tried on Ubuntu, but can't reproduce this problem there. Are you using
> RHEL/CentOS?

RHEL 7.4, GTK 3.22.
Comment 10 Andrey Loskutov CLA 2021-02-13 05:13:54 EST
For me it looks like the GC.init() or GC.drawTextInPixels() or GC.drawImage() are related, may be GC must be adopted after change from gdk_window_create_similar_surface to cairo_image_surface_create.

The code path is
LineNumberRulerColumn.doubleBufferPaint(GC)
LineNumberRulerColumn.doPaint(GC, ILineRange)
LineNumberRulerColumn.paintLine(int, int, int, GC, Display)

and "special" on scrolling up code in LineNumberRulerColumn.doubleBufferPaint() is that only in this case we create a *second* offscreen image, see lines along:

// Some rulers may paint outside the line region. Let them paint in a new image,
// then copy the wanted bits.

So I believe that that GC.drawTextInPixels() or GC.drawImage() on the second image isn't working properly after gdk_window_create_similar_surface to cairo_image_surface_create change. 

I will push a patch for LineNumberRulerColumn with a "fix" that avoids using a second offscreen image, to demonstrate where the problem is, but the real bug is somewhere in SWT.
Comment 11 Eclipse Genie CLA 2021-02-13 05:16:16 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/176223
Comment 12 Andrey Loskutov CLA 2021-02-13 12:45:50 EST
I believe GC.copyAreaInPixels(int, int, int, int, int, int, boolean) called from 

https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/176223/1/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberRulerColumn.java#727

isn't working as expected after gdk_window_create_similar_surface to cairo_image_surface_create change. For whatever reason, this can't paint given area properly if the copy direction is down (we scroll up). In other direction it seem to work. ?!?

So we have 4 visible lines and want to scroll one line up, from this state:

2
3
4
5

we should see

1
2
3
4

but will see

1
2
2
2

On scrolling up one line the code in the ruler tries to copy (visible area - line) from the current gc to same gc via

bufferGC.copyArea(0, 0, size.x, height + dy, 0, -dy);

In the example above we are copying [234] area one line down, but get instead [222] content in the final image.

If I replace the code that copies from same gc to gc with the code that creates a temporary image, saves the current image to that one and copies from the temporary image back to original one, shifted by one line, it works!

// bufferGC.copyArea(0, 0, size.x, height + dy, 0, -dy);
Image tmpImg= new Image(fCanvas.getDisplay(), size.x, size.y);
GC tmpGC= new GC(tmpImg);
try {
	bufferGC.copyArea(tmpImg, 0, 0);
	tmpGC.copyArea(fBuffer, 0, dy);
} finally {
	tmpImg.dispose();
	tmpGC.dispose();
}
Comment 13 Thomas Wolf CLA 2021-02-14 06:12:38 EST
So in other words: the previous implementation in SWT was smart enough to detect the overlap between src and dst, and copied from the bottom to the top. The new implementation doesn't detect the overlap and just copies from top to bottom, and as result fills everything with the first line.
Comment 14 Andrey Loskutov CLA 2021-02-14 06:21:31 EST
(In reply to Thomas Wolf from comment #13)
> So in other words: the previous implementation in SWT was smart enough to
> detect the overlap between src and dst, and copied from the bottom to the
> top. The new implementation doesn't detect the overlap and just copies from
> top to bottom, and as result fills everything with the first line.

I believe this is not SWT fault directly, the most logic how that is copied is in GTK/Cairo, but I believe the difference is in different surface used now by SWT. Probably copying of image areas was working with gdk_window_create_similar_surface doesn't work with cairo_image_surface_create, and may be there is a "right" API in Cairo that isn't yet used by SWT. Or it could be just a bug in Cairo.
Comment 15 Mickael Istria CLA 2021-02-14 08:46:07 EST
@Paul: do you have any idea here? Are you familiar with these cairo APIs?
Comment 16 Sravan Kumar Lakkimsetti CLA 2021-02-15 08:12:38 EST
I am able to reproduce the problem on Ubuntu 20.04. Investigating now
Comment 17 Eclipse Genie CLA 2021-02-15 10:18:26 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176289
Comment 18 Andrey Loskutov CLA 2021-02-16 07:38:49 EST
Created attachment 285565 [details]
Patch set 4 issues

https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176289/4

Patch set 4 fixes rulers and doesn't crash SWT examples as patch set 3,
but it seem to break cell rendering, see attached image.
Comment 19 Sravan Kumar Lakkimsetti CLA 2021-02-16 09:39:34 EST
(In reply to Andrey Loskutov from comment #18)
> Created attachment 285565 [details]
> Patch set 4 issues
> 
> https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176289/4
> 
> Patch set 4 fixes rulers and doesn't crash SWT examples as patch set 3,
> but it seem to break cell rendering, see attached image.

@Andrey,

Can you please try patch 5?
Comment 20 Soraphol (Paul) Damrongpiriyapong CLA 2021-02-16 10:32:13 EST
(In reply to Mickael Istria from comment #15)
> @Paul: do you have any idea here? Are you familiar with these cairo APIs?

I have no clue to be honest. I'm not super familiar with the cairo APIs either to know the source of this bug. I will try to reproduce and look into this.
Comment 21 Andrey Loskutov CLA 2021-02-16 11:18:41 EST
(In reply to Sravan Kumar Lakkimsetti from comment #19)
> (In reply to Andrey Loskutov from comment #18)
> > Created attachment 285565 [details]
> > Patch set 4 issues
> > 
> > https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176289/4
> > 
> > Patch set 4 fixes rulers and doesn't crash SWT examples as patch set 3,
> > but it seem to break cell rendering, see attached image.
> 
> @Andrey,
> 
> Can you please try patch 5?

LGTM, so far I couldn't find any regression and line numbers are back to normal state.
Comment 22 Sravan Kumar Lakkimsetti CLA 2021-02-16 11:24:18 EST
(In reply to Andrey Loskutov from comment #21)
> (In reply to Sravan Kumar Lakkimsetti from comment #19)
> > (In reply to Andrey Loskutov from comment #18)
> > > Created attachment 285565 [details]
> > > Patch set 4 issues
> > > 
> > > https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176289/4
> > > 
> > > Patch set 4 fixes rulers and doesn't crash SWT examples as patch set 3,
> > > but it seem to break cell rendering, see attached image.
> > 
> > @Andrey,
> > 
> > Can you please try patch 5?
> 
> LGTM, so far I couldn't find any regression and line numbers are back to
> normal state.

Let me do couple more tests and finalize this.
Comment 23 Sravan Kumar Lakkimsetti CLA 2021-02-16 12:22:55 EST
Merged to master
Comment 25 Andrey Loskutov CLA 2021-02-17 04:16:50 EST
(In reply to Eclipse Genie from comment #24)
> Gerrit change
> https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176289 was
> merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=af9f5cee1641970fa03ce813da7ba1dfc6e94141

Unfortunately I've just found regression from that commit, see bug Bug 571242.