Skip to content

Commit c2984a9

Browse files
Fix iOS gradient rendering issues on screen and mutable images
- Fixed `DrawGradient.m` (OpenGL): - Corrected vertex sizes to use requested width/height instead of power-of-two texture dimensions to prevent overflow/overlap. - Implemented correct texture coordinate mapping (`maxS`, `maxT`) to avoid including padding. - Updated vertex array logic to use `GL_FLOAT` for texture coordinates. - Swapped logic for `GRADIENT_TYPE_HORIZONTAL` and `GRADIENT_TYPE_VERTICAL` to match standard coordinate system orientation. - Fixed `IOSNative.m` (Mutable Images/CoreGraphics): - Updated `fillRectRadialGradientMutable` to respect the `x` and `y` arguments for both the fill rect and the radial gradient center point, preventing it from always drawing at (0,0). - Added proper clipping (`CGContextClipToRect`) to `fillRectRadialGradientMutable` to prevent gradients from bleeding outside their bounds. - Added missing `CGGradientRelease` to fix a memory leak. - Properly wrapped drawing calls in `CGContextSaveGState`/`CGContextRestoreGState` to isolate state changes.
1 parent 3190c91 commit c2984a9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Ports/iOSPort/nativeSources/IOSNative.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,12 +2348,16 @@ void com_codename1_impl_ios_IOSNative_fillRectRadialGradientMutable___int_int_in
23482348
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
23492349
CGGradientRef myGradient = CGGradientCreateWithColorComponents (colorSpace, components, locations, num_locations);
23502350
[UIColorFromRGB(n2, 255) set];
2351+
CGContextSaveGState(UIGraphicsGetCurrentContext());
2352+
CGContextClipToRect(UIGraphicsGetCurrentContext(), CGRectMake(n3, n4, width, height));
23512353
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(n3, n4, width, height));
23522354
CGPoint myCentrePoint = CGPointMake(n3 + relativeX * width, n4 + relativeY * height);
23532355
float myRadius = MIN(width, height) * relativeSize;
23542356
CGContextDrawRadialGradient (UIGraphicsGetCurrentContext(), myGradient, myCentrePoint,
23552357
0, myCentrePoint, myRadius,
23562358
kCGGradientDrawsAfterEndLocation);
2359+
CGGradientRelease(myGradient);
2360+
CGContextRestoreGState(UIGraphicsGetCurrentContext());
23572361
CGColorSpaceRelease(colorSpace);
23582362
POOL_END();
23592363
}

0 commit comments

Comments
 (0)