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

8288325: [windows] Actual and Preferred Size of AWT Non-resizable frame are different #9954

Closed
wants to merge 8 commits into from

Conversation

honkar-jdk
Copy link
Contributor

@honkar-jdk honkar-jdk commented Aug 19, 2022

On Windows, the insets obtained for a Non-Resizable AWT Frame was different when frame.pack() was called and subsequent call to frame.getInsets() or frame.getPreferredSize(). Due to this, the actual and preferred size differed when frame.pack() was called for Non-Resizable frame (on Windows).

Earlier the insets returned when frame.getInsets() was called, was that of a Resizable frame and not the correct insets associated with Non-Resizable frame. Fix is added to native code to get the correct insets. The test - AwtFramePackTest.java has been updated to test actual and expected/preferred size for both Resizable and Non-Resizable Frames.

The test is generic though the issue and fix is on Windows platform because the condition
frame.getSize() == frame.getPreferredSize() should be true on all platforms when frame.pack() is called.

Following is the link to Windows System Metrics (used for native insets) - https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8288325: [windows] Actual and Preferred Size of AWT Non-resizable frame are different

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9954/head:pull/9954
$ git checkout pull/9954

Update a local copy of the PR:
$ git checkout pull/9954
$ git pull https://git.openjdk.org/jdk pull/9954/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 9954

View PR using the GUI difftool:
$ git pr show -t 9954

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9954.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 19, 2022

👋 Welcome back honkar! 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 Pull request is ready for review label Aug 19, 2022
@openjdk
Copy link

openjdk bot commented Aug 19, 2022

@honkar-jdk The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Aug 19, 2022
@mlbridge
Copy link

mlbridge bot commented Aug 19, 2022

Comment on lines 1412 to 1413
m_insets.right < 0 || m_insets.bottom < 0 ||
JNU_IsInstanceOfByName(env, target, "java/awt/Frame") > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean that now we will always request the insets from the platform?

Was this code run before the frame was changed from resizeable to non-resizeable? Therefore the insets weren't updated correctly.

Is this applicable to windows?

Copy link
Contributor Author

@honkar-jdk honkar-jdk Aug 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean that now we will always request the insets from the platform?

Yes the following block of code runs when window isn't sized yet (first time) or when the incoming taget is a frame to obtain platform insets

Was this code run before the frame was changed from resizeable to non-resizeable? Therefore the insets weren't updated correctly.

Previously this block of code was executed for resizable frame only for the first time (when frame is being sized for the first time). The issue was with the cached insets. The first time when frame,pack() is called on non-resizable frame the correct insets associated with it is returned and the frame is sized accordingly. But any subsequent calls to frame.getInsets() or frame.getPreferredSize() which gets the cached insets from WPanelPeer was returning the cached insets of Resizable frame and not that of the Non-Resizable frame

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is unclear to me. The frame is set to non-resizeable, frame.pack() is called. This, I assume, results in this code block being executed, so the calculated insets should be cached.

Why do the following calls to getInsets or getPreferredSize return the resizeable insets if the cached ones are non-resizeable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this applicable to windows?

I mean to Window objects.

Copy link
Contributor Author

@honkar-jdk honkar-jdk Sep 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is unclear to me. The frame is set to non-resizeable, frame.pack() is called. This, I assume, results in this code block being executed, so the calculated insets should be cached.

Why do the following calls to getInsets or getPreferredSize return the resizeable insets if the cached ones are non-resizeable?

Initially the cause for swapping of insets was unclear to me as well. After looking closely at the native debug logs, it was found that the insets calculated using Client & Non-Client Rects were different in comparison to the native insets obtained from system metrics for Non-Resizable frame.

test/jdk/java/awt/Frame/AwtFramePackTest.java Show resolved Hide resolved
@honkar-jdk honkar-jdk marked this pull request as draft September 8, 2022 16:57
@openjdk openjdk bot removed the rfr Pull request is ready for review label Sep 8, 2022
@honkar-jdk
Copy link
Contributor Author

honkar-jdk commented Sep 19, 2022

In AwtWindow::UpdateInsets, insets are obtained in two ways:

  1. By subtracting Client rect from Non-Client rect: If the insets obtained by this approach returns a negative value for either top, bottom, left or right it means that the window isn't sized yet and we need to get the associated default native insets through approach 2.

  2. Through Default native insets - Obtained using GetSystemMetrics(<appropriate_metric>) on Windows. Once the frame is sized, the insets obtained by step 1 are taken as final insets and cached in the respective peers.

For the Non-Resizable Frame these two approaches returned different values, because of which the actual size and preferred size differed when frame.pack() is called. Earlier the metric used for Non-Resizable frame was SM_CXDLGFRAME/ SM_CXFIXEDFRAME, which returned slightly smaller inset values compared to that returned by Client and Non-Client rects. To match the insets returned in both the cases, SM_CXSIZEFRAME/ SM_CYSIZEFRAME is used as system metric for both - Resizable/ Non-Resizable frames in the updated fix. This ensures that the same inset values are returned for Non-Resizable frame.
Previous fix changes reverted - type of target object check no longer required.

Debug logs added to the JBS issue - JDK-8288325

@honkar-jdk honkar-jdk marked this pull request as ready for review September 19, 2022 23:26
@honkar-jdk honkar-jdk marked this pull request as draft September 19, 2022 23:26
@honkar-jdk honkar-jdk marked this pull request as ready for review September 21, 2022 16:57
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 21, 2022
@honkar-jdk
Copy link
Contributor Author

Additionally extraBottomInsets variable which is initialized to zero from the start, does not seem to change anything and can be removed as part of this PR changes.

Copy link
Member

@azuev-java azuev-java left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final version looks good to me.

@openjdk
Copy link

openjdk bot commented Sep 22, 2022

@honkar-jdk 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:

8288325: [windows] Actual and Preferred Size of AWT Non-resizable frame are different

Reviewed-by: kizune, aivanov, tr

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 12 new commits pushed to the master branch:

  • 2e20e7e: 8294271: Remove use of ThreadDeath from make utilities
  • e45f3d5: 8294281: Allow warnings to be disabled on a per-file basis
  • 664e5b1: 8294187: RISC-V: Unify all relocations for the backend into AbstractAssembler::relocate()
  • acd75e0: 8294053: Unneeded local variable in handle_safefetch()
  • 0b56b82: 8293991: java/lang/Float/Binary16ConversionNaN.java fails on silent NaN conversions
  • acd5bcf: 8289610: Degrade Thread.stop
  • 05c8cab: 8293532: Use lighter jmod compression levels in build config
  • eec992c: 8292602: ZGC: C2 late barrier analysis uses invalid dominator information
  • f6d78cd: 8293657: sun/management/jmxremote/bootstrap/RmiBootstrapTest.java#id1 failed with "SSLHandshakeException: Remote host terminated the handshake"
  • a4dc035: 8290910: Wrong memory state is picked in SuperWord::co_locate_pack()
  • ... and 2 more: https://git.openjdk.org/jdk/compare/5285035ed9bb43a40108e4d046e0de317730f193...master

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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@azuev-java, @aivanov-jdk) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 22, 2022
Comment on lines 1410 to 1411
m_insets.right < 0 || m_insets.bottom < 0)
{
m_insets.right < 0 || m_insets.bottom < 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion here, yet I'd rather leave these lines unchanged. Having the opening brace on its own line avoids the confusion between the condition and the code in the body; on the other hand, it starts with a comment which visually separates the condition from the code inside the if-block.

Comment on lines 1416 to 1419
m_insets.left = m_insets.right =
::GetSystemMetrics(SM_CXSIZEFRAME) + extraPaddedBorderInsets;
m_insets.top = m_insets.bottom =
::GetSystemMetrics(SM_CYSIZEFRAME) + extraPaddedBorderInsets;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding a comment clarifying why the style isn't checked? Maybe not, since now it's gone from the code. On the other hand, a reader may wonder why we always uses the sizing frame insets even for non-resizeable frames.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aivanov-jdk I agree, comment would add more clarity. Additionally instead of using SM_CXSIZEFRAME (the name can be ambiguous too) can we change it to SM_CXFRAME ? Since both are mentioned to be same metrics in the documentation https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally instead of using SM_CXSIZEFRAME (the name can be ambiguous too) can we change it to SM_CXFRAME ?

Yes, SM_CXFRAME is neutral, it doesn't refer to either resizeable or non-resizeable frame.

@@ -1479,7 +1475,6 @@ BOOL AwtWindow::UpdateInsets(jobject insets)
// to reflect that change
env->CallVoidMethod(peer, AwtComponent::replaceSurfaceDataLaterMID);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, this line could remain.

Comment on lines 1418 to 1419
// SM_CXFRAME is the width of the horizontal border in pixels.
// SM_CYFRAME is the height of the vertical border in pixels.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the meaning of CX/CYFRAME is quite obvious.

The first sentence about the metrics being the same is helpful.

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Sep 22, 2022
@openjdk
Copy link

openjdk bot commented Sep 22, 2022

@honkar-jdk
Your change (at version b6f90ab) is now ready to be sponsored by a Committer.

@honkar-jdk honkar-jdk marked this pull request as draft September 22, 2022 20:42
@openjdk openjdk bot removed the rfr Pull request is ready for review label Sep 22, 2022
@honkar-jdk honkar-jdk marked this pull request as ready for review September 22, 2022 20:56
@openjdk openjdk bot added rfr Pull request is ready for review and removed sponsor Pull request is ready to be sponsored labels Sep 22, 2022
@honkar-jdk
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Sep 23, 2022
@openjdk
Copy link

openjdk bot commented Sep 23, 2022

@honkar-jdk
Your change (at version edcb53a) is now ready to be sponsored by a Committer.

@aivanov-jdk
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Sep 23, 2022

Going to push as commit eca9749.
Since your change was applied there have been 12 commits pushed to the master branch:

  • 2e20e7e: 8294271: Remove use of ThreadDeath from make utilities
  • e45f3d5: 8294281: Allow warnings to be disabled on a per-file basis
  • 664e5b1: 8294187: RISC-V: Unify all relocations for the backend into AbstractAssembler::relocate()
  • acd75e0: 8294053: Unneeded local variable in handle_safefetch()
  • 0b56b82: 8293991: java/lang/Float/Binary16ConversionNaN.java fails on silent NaN conversions
  • acd5bcf: 8289610: Degrade Thread.stop
  • 05c8cab: 8293532: Use lighter jmod compression levels in build config
  • eec992c: 8292602: ZGC: C2 late barrier analysis uses invalid dominator information
  • f6d78cd: 8293657: sun/management/jmxremote/bootstrap/RmiBootstrapTest.java#id1 failed with "SSLHandshakeException: Remote host terminated the handshake"
  • a4dc035: 8290910: Wrong memory state is picked in SuperWord::co_locate_pack()
  • ... and 2 more: https://git.openjdk.org/jdk/compare/5285035ed9bb43a40108e4d046e0de317730f193...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 23, 2022
@openjdk openjdk bot closed this Sep 23, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Sep 23, 2022
@openjdk
Copy link

openjdk bot commented Sep 23, 2022

@aivanov-jdk @honkar-jdk Pushed as commit eca9749.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants