Fix #3037: implement pushClip/popClip on Android port#5016
Merged
Conversation
The Android port inherited the empty default pushClip(Object) / popClip(Object) bodies from CodenameOneImplementation -- iOS, JavaSE, and JavaScript all override them but Android never did. That made Graphics.pushClip() / popClip() silent no-ops on Android: any clip narrowed inside a pushClip/popClip block (especially a polygon clip created under a non-identity transform via clipRect-under-rotation) leaked out to the rest of paint(), so geometry drawn after popClip() was still clipped to the inner shape. Visible in the graphics-clip-under-rotation screenshot test: the navy axis-aligned reference outline drawn after popClip() was getting clipped by the leftover rotated-inner-rect polygon clip and the green sentinel dot was missing. Same symptom in graphics-clip. iOS Metal was fixed in 6b553ff ("Update iOS Metal golden -- stencil clip now matches GL"); this commit brings Android to parity. Wiring: - AndroidGraphics.pushClip() does canvas.save() and stashes the current clipSet flag onto a pushedClipSetStack, then resets clipSet=false so a setClip/setClipRaw inside the push/pop block doesn't restore (and prematurely pop) our outer save. popClip() restores the inner setClip save first if clipSet became true, then pops the outer save and restores the saved clipSet. - AsyncGraphics (the form-graphics path) overrides pushClip / popClip to push and pop the async-side clip state (clip Rectangle, clipP Path, clipGP GeneralPath, clipIsPath flag) onto a savedClipStack. Subsequent AsyncOps capture the restored clip in their constructors, so no extra canvas.save / canvas.restore op needs to be queued for the underlying canvas -- each AsyncOp's executeWithClip already manages the underlying clip via setClipRaw. - AndroidImplementation.pushClip(Object) / popClip(Object) now forward to AndroidGraphics, matching the iOS / JavaSE / JS delegate pattern. Verified locally on the cn1Api34Arm AVD: graphics-clip-under-rotation now renders with the navy outline fully visible and the red rect 30deg-tilted overhanging the diagonal corners, matching the iOS Metal / GL reference. The Android golden for that test (and the graphics-clip golden, which is broken the same way) will be regenerated from the CI artifact in a follow-up commit on this branch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Compared 110 screenshots: 110 matched. Native Android coverage
✅ Native Android screenshot tests passed. Native Android coverage
Benchmark ResultsDetailed Performance Metrics
|
Both goldens encoded the pushClip/popClip no-op bug fixed in the previous commit. The Android-default-8 CI job on PR #5016 captured the post-fix renders (Default: 8 is configured without CN1SS_FAIL_ON_MISMATCH, so the actual emulator screenshots are uploaded to the emulator-screenshot artifact even when they don't match the golden); promote those exact bytes here so the JDK 17 / JDK 21 matrix variants -- which do fail on mismatch -- now pass. graphics-clip-under-rotation: post-fix render shows the navy axis-aligned reference outline fully visible, the red rect is 30deg-tilted and overhangs the navy outline at the two diagonal corners, and the green sentinel dot drawn after popClip() is visible at each panel's top-left. Matches iOS Metal / GL. graphics-clip: post-fix render shows the green sentinel dot at each panel's bottom-right -- it was getting clipped away by the leftover triangular clip from the previous pushClip block on the old Android render. Bytes are the CI artifact captured by the Default 8 emulator at PR #5016 run 26334855513. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
SpotBugs RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE flagged the `(prev != null) && prev.booleanValue()` guard on the Boolean popped from pushedClipSetStack. ArrayDeque rejects null elements at push time, so a successful pop() can never return null, and we already guarded the empty-stack case with `pushedClipSetStack.isEmpty()` at the top of popClip(). Replace with a direct `.pop().booleanValue()`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
✅ Continuous Quality ReportTest & Coverage
Static Analysis
Generated automatically by the PR CI workflow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pushClip(Object)/popClip(Object)bodies fromCodenameOneImplementation-- iOS, JavaSE, and JavaScript all override them but Android never did.Graphics.pushClip()/popClip()were silent no-ops on Android, so any clip narrowed inside a push/pop block (especially a polygon clip created under a non-identity transform viaclipRect-under-rotation) leaked to whatever was drawn afterpopClip().graphics-clip-under-rotationscreenshot test: the navy axis-aligned reference outline drawn afterpopClip()was being clipped by the leftover rotated-inner-rect polygon clip, and the green sentinel dot was missing. Same symptom ingraphics-clip. iOS Metal was fixed in 6b553ff; this brings Android to parity.AndroidGraphics.pushClip/popClipusescanvas.save()/canvas.restore()with apushedClipSetStack(Deque<Boolean>) to preserve the existingclipSet-flag pairing.AsyncGraphicsoverrides save/restore the async-side clip state (clip,clipP,clipGP,clipIsPath) onto asavedClipStack; subsequentAsyncOps capture the restored clip via their constructor so no extra canvas op needs to be queued.AndroidImplementationdelegates the impl-level calls toAndroidGraphics.cn1Api34ArmAVD:graphics-clip-under-rotationnow matches the iOS Metal / GL reference (navy outline fully visible, red rect 30deg-tilted overhanging diagonal corners, green sentinel dot present).Test plan
graphics-clip-under-rotationAndroid golden mismatch (expected on first run); update golden from CI capture artifact in a follow-up commit on this branchgraphics-clipAndroid golden also likely needs refresh (same root cause); update from CI capture if it mismatchesClipandClipUnderRotation)🤖 Generated with Claude Code