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

8303904: [macos]Transparent Windows Paint Wrong (Opaque, Pixelated) w/o Volatile Buffering #23430

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

anass-baya
Copy link
Contributor

@anass-baya anass-baya commented Feb 4, 2025

The PR includes two fix :
1 - The first fix targets proper rendering of the transparent image.
2 - The second fix ensures the image is painted at the correct resolution to avoid pixelation.


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-8303904: [macos]Transparent Windows Paint Wrong (Opaque, Pixelated) w/o Volatile Buffering (Bug - P3)

Reviewers without OpenJDK IDs

Contributors

  • Jeremy mickleness <mickleness@gmail.com>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23430

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

Using diff file

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

Using Webrev

Link to Webrev Comment

Sorry, something went wrong.

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 4, 2025

👋 Welcome back anass-baya! 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 Feb 4, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot changed the title JDK-8303904 [macos]Transparent Windows Paint Wrong (Opaque, Pixelated) w/o Volatile Buffering 8303904: [macos]Transparent Windows Paint Wrong (Opaque, Pixelated) w/o Volatile Buffering Feb 4, 2025
@openjdk
Copy link

openjdk bot commented Feb 4, 2025

@anass-baya 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 client client-libs-dev@openjdk.org rfr Pull request is ready for review labels Feb 4, 2025
@mlbridge
Copy link

mlbridge bot commented Feb 4, 2025

Webrevs

float scaleFactor = getDevice().getScaleFactor();
int fullResWidth = Math.round( scaleFactor * width);
int fullResHeight = Math.round( scaleFactor * height);
WritableRaster wr = model.createCompatibleWritableRaster(fullResWidth, fullResHeight);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for working on this. :)

I have a couple of questions:

  1. This math looks great for the simple case of a 200% high-res monitor; is the rounding safe for non-integer resolutions?

For ex if width is 33 and scaleFactor is 1.25, then we'll call round(41.25), so fullResWidth = 41.

Will the native windowing system allocate 41px for our Window? (Because if so: great. We have a perfect fit.) Or could it allocate 42px? (In which case we may have a thin border on the right/bottom that becomes unpaintable...)

  1. I'm assuming if fullResWidth/fullResHeight is ever zero we'll get a RTE. I don't think it's stated, but the preexisting code suggests width and height were never zero. Is it possible scaleFactor can ever be less than .5? (I've never observed that in my day-to-day life, but I'm just thinking about edge cases and RTE's...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @mickleness ,
Thank you for your review.
It is well known that we can lose a fraction of a pixel. For example in #23183 we allowed a 1-pixel margin of error to compensate for that as the rounding error could accumulate

returnValue.scale(scaleFactor, scaleFactor);
return returnValue;
}
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be outside the scope of this ticket, but I'm seeing similar code in Win32GraphicsConfig#createAcceleratedImage(..), X11GraphicsConfig#createAcceleratedImage(..), and GLXGraphicsConfig#createAcceleratedImage(..) .

Should those be looked at, or is there another ticket to explore those? (That is: are they also going to be opaque and the wrong resolution?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @mickleness,
The problem is not reproduced on windows !! I can see it only on mac

Copy link
Contributor

Choose a reason for hiding this comment

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

tldr: Wow / huh. You're right. Thanks for checking.

That code looks so suspicious that I did some digging:

(A. On Windows the TransparentWindowTest says it fails because Image.getTransparency() is OPAQUE, but the test is wrong: the window looks fine.)
B. It works because on Windows we end up using the TranslucentWindowPainter. We never invoke Win32GraphicsConfig#createAcceleratedImage(..) at all (unless the TransparentWindowTest invokes it directly).

I tested:
A. repainting on a timer (so we'd explicitly go through the RepaintManager), and
B. an ellipse fill instead of a rectangle fill (to double-check that transparent pixels really were transparent).
C. using Window.setShape(..) instead of changing the window's background color to transparent (to make sure it followed the same path)

(... and I don't have access to any other platforms to make sure Linux is doing the right thing.)

Copy link
Contributor Author

@anass-baya anass-baya Feb 5, 2025

Choose a reason for hiding this comment

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

Hello @mickleness,
Yes, on Windows we use TranslucentWindowPainter.
I moved the PR to draft since I'm trying to simplify the scaling handler logic. I'll come back to you once I'm done with that.
This test is only for macOS. On Windows, it will fail because we don’t explicitly set the Translucent flag.

returnValue.scale(scaleFactor, scaleFactor);
return returnValue;
}
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this new createAcceleratedImage(..) logic be moved to CGraphicsConfig?

This looks like copied and pasted code in two subclasses that could be abstracted into the parent class. (I could be wrong here; I just wanted to check opinions...?)

It looks like these two classes (MTLGraphicsConfig and CGLGraphicsConfig) are the only subclasses for CGraphicsConfig.

@aivanov-jdk
Copy link
Member

@anass-baya If your fix is based on @mickleness's previous PR, you should him as co-author using the /contributor command.

@openjdk
Copy link

openjdk bot commented Feb 4, 2025

@anass-baya @mickleness was not found in the census.

Syntax: /contributor (add|remove) [@user | openjdk-user | Full Name <email@address>]. For example:

  • /contributor add @openjdk-bot
  • /contributor add duke
  • /contributor add J. Duke <duke@openjdk.org>

User names can only be used for users in the census associated with this repository. For other contributors you need to supply the full name and email address.

@anass-baya
Copy link
Contributor Author

/contributor add Jeremy mickleness mickleness@gmail.com

@openjdk
Copy link

openjdk bot commented Feb 4, 2025

@anass-baya
Contributor Jeremy mickleness <mickleness@gmail.com> successfully added.

@aivanov-jdk
Copy link
Member

@mickleness I wonder what is your preferred email address and name. You were referenced by another email in your recent contribution.

@anass-baya anass-baya marked this pull request as draft February 5, 2025 14:26
@openjdk openjdk bot removed the rfr Pull request is ready for review label Feb 5, 2025
@anass-baya anass-baya marked this pull request as ready for review February 24, 2025 08:38
@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 24, 2025

Image img = getLWGC().createAcceleratedImage(getTarget(), scaledWidth, scaledHeight);
if(ScaleX == 1 || ScaleY == 1)
return img;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be && instead of ||?

Copy link
Contributor

@mickleness mickleness 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 to me (note I'm not an official OpenJDK reviewer). I'm not a fan of the instanceof Graphics2D check, but any alternative I propose would be more lines of code so I accept this is good enough.

import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

I know in other PRs reviewers have asked to expand wildcard imports. (I haven't studied that topic closely enough to have an informed opinion.)

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 rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

None yet

4 participants