Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 569147

Summary: [BigSur] Control#update() causes losing dirty state without displaying proper visual content with specific conditions.
Product: [Eclipse Project] Platform Reporter: Jeeeyul Lee <jeeeyul>
Component: SWTAssignee: Jeeeyul Lee <jeeeyul>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: a.nesheret, abelhv, lshanmug, niraj.modi, p.beauvoir, peter, sarika.sinha
Version: 4.18Flags: sarika.sinha: review+
lshanmug: review+
Target Milestone: 4.18 RC2   
Hardware: Macintosh   
OS: Mac OS X   
See Also: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172929
https://bugs.eclipse.org/bugs/show_bug.cgi?id=568964
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=3245fca267f65c8e358efdbdf597d388013ecea8
https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/173069
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=b1a96f8b7ddee3511eabccef091799dbc9900595
https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/173210
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=a5dacddabdeee4de3c9766e18ef771434e902c02
https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176269
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=6cf6f81de68006ed985bd70d657de1181cb1f107
https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/178526
https://bugs.eclipse.org/bugs/show_bug.cgi?id=574896
https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/184464
Whiteboard:
Bug Depends on:    
Bug Blocks: 565691    
Attachments:
Description Flags
Wrong displaying when displaying annotation. none

Description Jeeeyul Lee CLA 2020-11-24 20:00:00 EST
Some annotation painters which is activated by entering some text into text editors such as Matching Bracket Annotation causes gives wrong visual result. (See the attachment)

Steps to reproduce problem:

1. Open any Java Editor.
2. Enter several closing braces, eg: }}}
3. Enter several opening braces before closing brace.
4. '{' will not visible some while.
5. Text editor shows wrong content for while, or until scroll.

I could not specify the exact reason that causes this problem.

However, After digging about this, 
I realized that NSView.lockFocus() in Control#update() is related with this problem. lockFocus() / unlockFocus() are deprecated. And it seems that We can't avoid Automatic Differed Painting(ADP) mechanism anymore. Even we called lockFocus() / draw() / unlockFocus() manually, AppKit seems to draw once again for ADP.

Currently Control#update(boolean) checks availability of NSGraphicsContext. If it's not available then it try to lock focus to draw, and check graphics context again. This seems to be an indirect or direct cause.

When I removed this checking code, everything works fine again. I don't know these checking is still needed or not.

What if some one can give me explanation about this, than I will make Gerrit for this.

And I also noticed that:

* All the NSView uses buffer now (It's not an option).
* We can't avoid Automatic Differed Painting mechanism.
* ADP will merge buffers of NSViews with direty regions just before displaying on screen.
* So I think that the update() is pointless. 
* The update() causes rendering synchronously, However it is rendered on it's own buffer. And it will not visible unitl the ADP merges buffers to display it. 
* So, actually we don't have to do anything update(). Even just blank implementation works fine.
Comment 1 Jeeeyul Lee CLA 2020-11-24 20:01:01 EST
Created attachment 284879 [details]
Wrong displaying when displaying annotation.
Comment 2 LeChuck MonkeyIsland CLA 2020-11-25 04:26:37 EST
I have the same issue after update to Big Sur
Comment 3 Lakshmi P Shanmugam CLA 2020-11-25 07:06:44 EST
(In reply to Jeeeyul Lee from comment #0)
@Jeeeyl, thanks for the steps and investigation, I'm able to reproduce the problem.

> 
> However, After digging about this, 
> I realized that NSView.lockFocus() in Control#update() is related with this
> problem. lockFocus() / unlockFocus() are deprecated. And it seems that We
> can't avoid Automatic Differed Painting(ADP) mechanism anymore. Even we
> called lockFocus() / draw() / unlockFocus() manually, AppKit seems to draw
> once again for ADP.
> 
> Currently Control#update(boolean) checks availability of NSGraphicsContext.
> If it's not available then it try to lock focus to draw, and check graphics
> context again. This seems to be an indirect or direct cause.
> 
> When I removed this checking code, everything works fine again. I don't know
> these checking is still needed or not.
> 
> What if some one can give me explanation about this, than I will make Gerrit
> for this.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=540357#c7 has some discussion on this issue.
Bug 547399 fixed the NPEs caused by null NSGraphicsContext, but it caused Cheese in the editor when scrolling horizontally - Bug 548491. Please see https://bugs.eclipse.org/bugs/show_bug.cgi?id=548491#c8 for the explanation of the fix, that added lockFocusIfCanDraw in update(boolean).
Comment 4 Jeeeyul Lee CLA 2020-11-27 00:31:58 EST
(In reply to Lakshmi P Shanmugam from comment #3)

> https://bugs.eclipse.org/bugs/show_bug.cgi?id=540357#c7 has some discussion
> on this issue.
> Bug 547399 fixed the NPEs caused by null NSGraphicsContext, but it caused
> Cheese in the editor when scrolling horizontally - Bug 548491. Please see
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=548491#c8 for the explanation
> of the fix, that added lockFocusIfCanDraw in update(boolean).

@Lakshmi Thanks for the explanation. 

I could not reproduce the cheese problem on JavaEditor anymore at least on BigSur.

As commented in https://bugs.eclipse.org/bugs/show_bug.cgi?id=548491#c8 by Till Brychcy, IMHO, I think that the entire implementation of the update() is pointless at this point. Bigsur seems to force the use of the ADP mechanism.

Currently, Control update() causes that:

1. What if there is dirty region, Painting on NSView's buffer occurs synchronously against of the dirty region.
2. Painting occurred once again aginst of the full area the control  just before displaying on screen

It makes all the GEF editors very slow.

Below code just works fine and fast for me:

boolean update (boolean all) {
  if (OS.isBigSurOrLater()) {
    return true;
  }
  ...
Comment 5 Eclipse Genie CLA 2020-11-27 07:28:58 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172929
Comment 6 Lakshmi P Shanmugam CLA 2020-11-27 07:48:41 EST
(In reply to Jeeeyul Lee from comment #4)
> 
> Below code just works fine and fast for me:
> 
> boolean update (boolean all) {
>   if (OS.isBigSurOrLater()) {
>     return true;
>   }
>   ...
@Jeeeyul, I've created a patch with this change (set you as the author) and tested it out. It fixes the problem in the child eclipse and doesn't cause the cheese issue.
But, we need to make sure that this works fine with the base Eclipse. The difference being, Eclipse launcher is built with macOS SDK 10.12 and the new behaviour was initially only for Applications linked with 10.14 and later. Since we see this on base Eclipse in BigSur, seems like this has changed.

Let's try this in the Eclipse build and see if works as expected. I think Bug 568964 is similar and may benefit from this fix. I can't reproduce that problem consistently so cannot verify it.

As a side note, will open a separate bug to build Eclipse launcher with newer SDK for 4.19.
Comment 7 Lakshmi P Shanmugam CLA 2020-11-27 07:56:52 EST
@Sarika,
This patch addresses the serious performance issue in the editor while typing. Bug 568964 also looks related. This patch only affects BigSur. Please see comment#6 for details.
Comment 8 Sarika Sinha CLA 2020-11-27 09:34:39 EST
Patch looks localized and important for BigSur.

+1 for RC2.
Comment 10 Phil Beauvoir CLA 2020-11-27 12:52:05 EST
This seems to have fixed Bug 568964

Thank-you for the fix.
Comment 11 Lakshmi P Shanmugam CLA 2020-11-27 13:13:11 EST
(In reply to Phil Beauvoir from comment #10)
> This seems to have fixed Bug 568964
> 
> Thank-you for the fix.

Thanks for testing Phil.

Request you to use the latest build [1] for a couple of days and report if you see any drawing/repaint related issues.

[1] https://download.eclipse.org/eclipse/downloads/drops4/I20201127-1010/download.php?dropFile=eclipse-SDK-I20201127-1010-macosx-cocoa-x86_64.dmg
Comment 12 Lakshmi P Shanmugam CLA 2020-11-27 13:14:46 EST
@Jeeeyul, thanks for the fix.

Request you to use the latest build [1] for a couple of days and report if you see any drawing/repaint related issues.

[1] https://download.eclipse.org/eclipse/downloads/drops4/I20201127-1010/download.php?dropFile=eclipse-SDK-I20201127-1010-macosx-cocoa-x86_64.dmg
Comment 13 Phil Beauvoir CLA 2020-11-27 13:18:56 EST
(In reply to Lakshmi P Shanmugam from comment #11)
> (In reply to Phil Beauvoir from comment #10)
> > This seems to have fixed Bug 568964
> > 
> > Thank-you for the fix.
> 
> Thanks for testing Phil.
> 
> Request you to use the latest build [1] for a couple of days and report if
> you see any drawing/repaint related issues.
> 
> [1]
> https://download.eclipse.org/eclipse/downloads/drops4/I20201127-1010/
> download.php?dropFile=eclipse-SDK-I20201127-1010-macosx-cocoa-x86_64.dmg

I'm on it.

Many of our Mac users are also testing these I-builds in our RCP app, Archi [1].

[1] https://www.archimatetool.com/beta/
Comment 14 Lakshmi P Shanmugam CLA 2020-11-27 13:47:28 EST
> As a side note, will open a separate bug to build Eclipse launcher with
> newer SDK for 4.19.

Opened Bug 569257 to track this.
Comment 16 Lakshmi P Shanmugam CLA 2020-12-01 05:55:32 EST
*** Bug 568964 has been marked as a duplicate of this bug. ***
Comment 17 Lakshmi P Shanmugam CLA 2020-12-01 12:29:19 EST
Verified with I20201201-0600.
Comment 18 Eclipse Genie CLA 2020-12-02 05:25:12 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/173210
Comment 19 Lakshmi P Shanmugam CLA 2020-12-02 05:35:38 EST
(In reply to Eclipse Genie from comment #18)
> New Gerrit change created:
> https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/173210

Update to javadoc
Comment 21 Eclipse Genie CLA 2021-02-15 14:59:05 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176269
Comment 23 Eclipse Genie CLA 2021-04-01 05:57:16 EDT
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/178526
Comment 24 Eclipse Genie CLA 2021-08-26 08:58:08 EDT
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/184464