Skip to content

Conversation

@prsadhuk
Copy link
Contributor

@prsadhuk prsadhuk commented May 21, 2025

Graphics copyArea overflow check bails out of copying pixels if there is overflow.
The spec says ""If a portion of the source rectangle lies outside the bounds of the component, or is obscured by another window or component, {@code copyArea} will be unable to copy the associated pixels"

which suggests that we should always copy the parts inside the bounds and never the parts outside the bounds
but it seems currently, in the case of overflow it no longer copies any pixels, including the parts that are inside.
So, the fix clips the copyarea region to clip bounds so it will only affect pixels within the valid bounds, and any pixels outside will be ignored.


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-8357299: Graphics copyArea doesn't copy any pixels when there is overflow (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25340

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 21, 2025

👋 Welcome back psadhukhan! 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
Copy link

openjdk bot commented May 21, 2025

@prsadhuk 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:

8357299: Graphics copyArea doesn't copy any pixels when there is overflow

Reviewed-by: achung, kizune, prr

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 614 new commits pushed to 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 rfr Pull request is ready for review label May 21, 2025
@openjdk
Copy link

openjdk bot commented May 21, 2025

@prsadhuk 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 May 21, 2025
@mlbridge
Copy link

mlbridge bot commented May 21, 2025

Webrevs


srcInfo.bounds.x1 = srcx;
srcInfo.bounds.y1 = srcy;
if (UNSAFE_TO_ADD(srcx, width) ||
Copy link
Member

Choose a reason for hiding this comment

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

isn't the MaskBlit_MaskBlit use the same pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But that doesn't cause any issue to the testcase given and existing testcase..Do you have any testcase which doesnt work because of MaskBlit pattern?

Copy link
Member

Choose a reason for hiding this comment

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

I have not tried to create a test for MaskBlit, only for a simple Blit. I will take a look at the possibility of reproducing it.

Copy link
Contributor

@alisenchung alisenchung left a comment

Choose a reason for hiding this comment

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

Tested locally on macOS and test fails before the change and passes after the change.

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.

Looks good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 23, 2025
dstInfo.bounds.y2 = dsty + height;
dstInfo.bounds.x2 = UNSAFE_TO_ADD(dstx, width)
? clipInfo.bounds.x2 : (dstx + width);
dstInfo.bounds.y2 = UNSAFE_TO_ADD(dsty, height)
Copy link
Contributor

Choose a reason for hiding this comment

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

why wouldn't you always want to limit it to the clip ?
I mean shouldn't it be like this ?
dstInfo.bounds.x2 = UNSAFE_TO_ADD(dstx, width) ? clipInfo.bounds.x2 : (((dstx + width) > clipInfo.bounds.x2) ? clipInfo.bounds.x2 : (dstx + width));
or maybe a bit more readable as
dstInfo.bounds.x2 = ((UNSAFE_TO_ADD(dstx, width) || ((dstx + width) > clipInfo.bounds.x2)) ? clipInfo.bounds.x2 : (dstx + width);

Copy link
Contributor Author

@prsadhuk prsadhuk May 26, 2025

Choose a reason for hiding this comment

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

That is because down below it anyway calls
SurfaceData_IntersectBounds(&dstInfo.bounds, &clipInfo.bounds);
so it should clip to clipInfo.bounds there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@prrace Since it is going to clip dstInfo.bounds to clipInfo.bounds in SurfaceData_IntersectBounds, I believe is not necessary to do the duplicate clip here.
Let me know if you think otherwise..

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

Copy link
Member

Choose a reason for hiding this comment

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

That is because down below it anyway calls SurfaceData_IntersectBounds(&dstInfo.bounds, &clipInfo.bounds);
so it should clip to clipInfo.bounds there.

In addition to intersecting dst with clip, you're also intersecting src with clip, which seems incorrect. A better approach might be to compute the drawable width based on the non-overflowing range for both src and dst, and then proceed with the original logic.

BTW I have not checked MaskBlit_MaskBlit yet it might require a similar update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have not found any problem with that part of code so far..We have addressed the issue that was raised.
MaskBlit might require similar update but since it was not proven to be problematic (we waited for your feedback) and since RDP1 is approaching, we will integrate this and you can come back with POC for us to check..

Copy link
Member

@mrserb mrserb May 30, 2025

Choose a reason for hiding this comment

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

We have not found any problem with that part of code so far..

This is incorrect because the clip bounds are relative to the destination (dst), so you cannot intersect them directly with the source (src) surface. The usage of UNSAFE_TO_SUB below is also wrong, we cannot just exists.

filed https://bugs.openjdk.org/browse/JDK-8358103 and https://bugs.openjdk.org/browse/JDK-8358107

dstInfo.bounds.y2 = dsty + height;
dstInfo.bounds.x2 = UNSAFE_TO_ADD(dstx, width)
? clipInfo.bounds.x2 : (dstx + width);
dstInfo.bounds.y2 = UNSAFE_TO_ADD(dsty, height)
Copy link
Member

Choose a reason for hiding this comment

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

That is because down below it anyway calls SurfaceData_IntersectBounds(&dstInfo.bounds, &clipInfo.bounds);
so it should clip to clipInfo.bounds there.

In addition to intersecting dst with clip, you're also intersecting src with clip, which seems incorrect. A better approach might be to compute the drawable width based on the non-overflowing range for both src and dst, and then proceed with the original logic.

BTW I have not checked MaskBlit_MaskBlit yet it might require a similar update.

dstInfo.bounds.y2 = UNSAFE_TO_ADD(dsty, height)
? clipInfo.bounds.y2 : (dsty + height);
if (UNSAFE_TO_SUB(srcx, dstx) ||
UNSAFE_TO_SUB(srcy, dsty)) {
Copy link
Member

@mrserb mrserb May 29, 2025

Choose a reason for hiding this comment

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

we also should check this part of the code, is it correct to simply exit here, or should we instead calculate and use the maximum distance we can handle?

@prsadhuk
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented May 30, 2025

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

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label May 30, 2025
@openjdk openjdk bot closed this May 30, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 30, 2025
@openjdk
Copy link

openjdk bot commented May 30, 2025

@prsadhuk Pushed as commit 64503c7.

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

@prsadhuk prsadhuk deleted the JDK-8357299 branch May 30, 2025 02:07
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.

5 participants