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

Prasanta Sadhukhan psadhukhan at openjdk.org
Wed May 28 03:31:53 UTC 2025


On Fri, 23 May 2025 20:59:41 GMT, Phil Race <prr at openjdk.org> wrote:

>> 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.
>
> src/java.desktop/share/native/libawt/java2d/loops/Blit.c line 85:
> 
>> 83:     dstInfo.bounds.x2 = UNSAFE_TO_ADD(dstx, width)
>> 84:                         ? clipInfo.bounds.x2 : (dstx + width);
>> 85:     dstInfo.bounds.y2 = UNSAFE_TO_ADD(dsty, height)
> 
> 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);

@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..

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25340#discussion_r2110814256


More information about the client-libs-dev mailing list