Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8239589: JavaFX UI will not repaint after reconnecting via Remote Desktop #430

Closed

Conversation

kevinrushforth
Copy link
Member

@kevinrushforth kevinrushforth commented Mar 17, 2021

This is a fix for a long-standing bug where the D3D pipeline will stop rendering when a Windows remote desktop session is disconnected and then reconnected.

A preliminary Draft PR #315 by @Schmidor was a good first step in solving this. I took that and continued the work in my Draft PR #403. It is now ready for formal review in this new PR. You can see PR #403 for details on the history of the changes.

Evaluation

The root cause of this bug is that the D3D pipeline did not handle a return code of D3DERR_DEVICEREMOVED from TestCooperativeLevel. When that error occurs, an application needs to destroy and recreate the Direct3D device.

The solution is to implement a new D3DPipeline::reinitialize method that will destroy the native D3D device and dispose the existing ResourceFactory objects and their associated BaseContext objects upon receiving D3DERR_DEVICEREMOVED. Note that the D3DPipeline Java object singleton is not recreated (it remains a singleton). In support of this, I implemented proper disposal logic in BaseResourceFactory and BaseContext to clean everything up and also to avoid memory leaks.

Additionally, there were several places that assumed that some textures (and mesh vertices) could be made permanent and never need to handle the case of a lost device. These all had to be fixed to allow for the possibility of a lost device and associated resource factory. They included:

  • UploadingPainter and PresentingPainter need to set the resource factory to null when not ready, so it will get the (possibly new) factory the next time it tries.
  • The gradient texture cache in PaintHelper has to be cleared and recreated when the surface is lost
  • The 3D triangle mesh and Phong material classes need to be disposed when the resource factory is disposed.
  • WebView often renders to a texture image at a time other than from the main rendering job, so needs to directly handle the case of a resource factory that is lost.
  • Decora PPSRenderer assumed that the resource factory never went away; it also accessed it on the wrong thread. Both problems were addressed by deferring the initialization of the resource factory and handling the case where the device is disposed.
  • Snapshot needs to allow for the platform image to be null if the device has been disposed.

Notes to Reviewers

I created this PR from a branch that contains the original 4 commits by @Schmidor (rebased on top of the current master) and then a single commit on top of that to complete it. This allows anyone who is interested to easily see the diffs between this PR and Oliver's original Draft PR. Most reviewers can just go to the list of "Files" and see the aggregate diffs.

During the course of my testing I discovered three outstanding problems, which will be handled by filing follow-up issues. Once I file them, I'll add a comment to this PR with the bug IDs.

  1. Media: a media stream playing at the time of a reconnect doesn't continue playing. Reloading the media works fine. This is not directly related to this bug, since it also happens with the software pipeline.
  2. Canvas: doesn't preserve the contents after a device reconnect (noticed while running Zoomy, where the BG color is wrong after device reinitialization). This might point to a need to let the app know they have to repaint, since there is no possible way to preserve the contents of the texture when the device is lost.
  3. WebView: there is a possible memory leak when device isn't ready after first reset, due to a WCRenderQueueImpl::gc instance being held in a JNIGlobal. This looks like a preexisting condition that could happen with a page (re)load today. It happens rarely.

This is a complicated enough change that I'd like three reviewers. The bulk of the changes are Windows-specific, but there are changes in common code so at least a sanity check needs to be done on all platforms using both the HW and SW pipelines. The case of a disposed device can currently only happen on Windows with the D3D pipeline.

/reviewers 3
/contributor add Oliver Schmidtmer O.Schmidtmer@elo.com
/contributor add kcr


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8239589: JavaFX UI will not repaint after reconnecting via Remote Desktop

Reviewers

Contributors

  • Oliver Schmidtmer <O.Schmidtmer@elo.com>
  • Kevin Rushforth <kcr@openjdk.org>

Download

To checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jfx pull/430/head:pull/430
$ git checkout pull/430

To update a local copy of the PR:
$ git checkout pull/430
$ git pull https://git.openjdk.java.net/jfx pull/430/head

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 17, 2021

👋 Welcome back kcr! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label Mar 17, 2021
@openjdk
Copy link

openjdk bot commented Mar 17, 2021

@kevinrushforth
The number of required reviews for this PR is now set to 3 (with at least 1 of role reviewers).

@openjdk
Copy link

openjdk bot commented Mar 17, 2021

@kevinrushforth
Contributor Oliver Schmidtmer <O.Schmidtmer@elo.com> successfully added.

@openjdk
Copy link

openjdk bot commented Mar 17, 2021

@kevinrushforth
Contributor Kevin Rushforth <kcr@openjdk.org> successfully added.

@kevinrushforth
Copy link
Member Author

kevinrushforth commented Mar 17, 2021

NOTE: the Windows GitHub actions build is failing due to JDK-8259639. I'll merge that fix in from master once it is integrated.

@mlbridge
Copy link

mlbridge bot commented Mar 17, 2021

Webrevs

@kevinrushforth
Copy link
Member Author

kevinrushforth commented Mar 17, 2021

@Schmidor if you are able to review or test this, it would be appreciated.

Copy link
Member Author

@kevinrushforth kevinrushforth left a comment

I did a pass over the review and left a few inline comments pointing out minor changes that I plan to make (in print statements and comments).

@Schmidor
Copy link
Contributor

Schmidor commented Mar 18, 2021

I can confirm the reinitialization after RDP reconnect works for me, standalone as JFX application and embedded in Swing.
Even either the multiple reinit retries of earlier fix versions aren't necessary anymore or it is not showing in debug output.

@kevinrushforth
Copy link
Member Author

kevinrushforth commented Mar 18, 2021

Thanks for confirming. I got rid of all debugging code, so it wouldn't show in the output. If you want to see whether or not multiple re-inits are happening, you can run with the following env variable set:

    export NWT_TRACE_LEVEL=2

If you are getting a failure on first time init, it will say something like Zero adapters found.

Copy link
Member

@arapte arapte left a comment

The fix and Sanity testing looks all good.
I shall need some more time to do a detailed review.
Added minor comments, please address whenever you update next commit.

@kevinrushforth
Copy link
Member Author

kevinrushforth commented Mar 20, 2021

Deleted comment meant for another PR...

arapte
arapte approved these changes Mar 23, 2021
Copy link
Member

@arapte arapte left a comment

Fix looks good to me. Sanity testing with all three d3d, es2, sw pipelines behave as expected. Apps work as expected in case of remote desktop, sleep, screen lock.

Copy link
Member

@arun-Joseph arun-Joseph left a comment

Fix looks good. Tested WebView by reconnecting via remote desktop.

@kevinrushforth
Copy link
Member Author

kevinrushforth commented Mar 23, 2021

@Schmidor did you have any further comments or feedback?

Btw, I realized that you don't have a role in the openjfx project, so you can't formally review it. As such, I'll change the requirements back to 2 reviewers. I'll hold off integrating it until tomorrow in case you have additional feedback.

/reviewers 2

@openjdk
Copy link

openjdk bot commented Mar 23, 2021

@kevinrushforth
The number of required reviews for this PR is now set to 2 (with at least 1 of role reviewers).

@openjdk
Copy link

openjdk bot commented Mar 23, 2021

@kevinrushforth This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8239589: JavaFX UI will not repaint after reconnecting via Remote Desktop

Co-authored-by: Oliver Schmidtmer <O.Schmidtmer@elo.com>
Co-authored-by: Kevin Rushforth <kcr@openjdk.org>
Reviewed-by: arapte, ajoseph

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 3 new commits pushed to the master branch:

  • d4d57fb: 8263778: Fix monocle JNI signatures for instance methods
  • e23a2fe: 8263759: Update boot JDK to 15.0.2
  • a8a80b8: 8092439: [Monocle] Refactor monocle SPI to allow support for multiple screens

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Mar 23, 2021
@Schmidor
Copy link
Contributor

Schmidor commented Mar 23, 2021

@kevinrushforth No further concerns. I've checked embedded WebView and MediaPlayer in Swing and a standalone WebView. Looks good.

@kevinrushforth
Copy link
Member Author

kevinrushforth commented Mar 23, 2021

Thanks for the reply. I'll go ahead and integrate it then.

@kevinrushforth
Copy link
Member Author

kevinrushforth commented Mar 23, 2021

/integrate

@openjdk openjdk bot closed this Mar 23, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Mar 23, 2021
@openjdk
Copy link

openjdk bot commented Mar 23, 2021

@kevinrushforth Since your change was applied there have been 3 commits pushed to the master branch:

  • d4d57fb: 8263778: Fix monocle JNI signatures for instance methods
  • e23a2fe: 8263759: Update boot JDK to 15.0.2
  • a8a80b8: 8092439: [Monocle] Refactor monocle SPI to allow support for multiple screens

Your commit was automatically rebased without conflicts.

Pushed as commit 73e70fe.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@kevinrushforth kevinrushforth deleted the 8239589-rdp-reconnect branch Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated
4 participants