Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ff8784c

Browse files
DHowettRaj Seshasankaran
authored andcommitted
Fix the rendering issues that were causing #2095. (#2117)
* `-[CALayer renderInContext:]` has the ability to render a cached version of itself; it was doing so upside-down because it was using a Cairo implementation detail. * `-[UIImage drawAtPoint:]` squashed every image it rendered because it switched width & height. The bug in UIImage dates back to the Cairo implementation as well; the invalid size was passed to a function that ignored it. When our refactor made use of that parameter, things rapidly went south. We did not catch the second regression because all the images we drew with it were square. Fixes #2095.
1 parent 2eaddf0 commit ff8784c

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Frameworks/QuartzCore/CALayer.mm

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,20 @@ - (void)renderInContext:(CGContextRef)ctx {
427427
[priv->delegate drawLayer:self inContext:ctx];
428428
}
429429
} else {
430-
CGRect rect;
431-
432-
rect.origin.x = 0;
433-
rect.origin.y = priv->bounds.size.height * priv->contentsScale;
434-
rect.size.width = priv->bounds.size.width * priv->contentsScale;
435-
rect.size.height = -priv->bounds.size.height * priv->contentsScale;
436-
437-
_CGContextDrawImageRect(ctx, priv->contents, rect, destRect);
430+
// If the layer has cached contents, blit them directly.
431+
432+
// Since the layer was rendered in Quartz referential (ULO) AND the current context
433+
// is assumed to be Quartz referential (ULO), BUT the layer's cached contents
434+
// were captured in a CGImage (CGImage referential, LLO), we have to flip
435+
// the context again before we render it.
436+
437+
// |1 0 0| is the transformation matrix for flipping a rect anchored at 0,0 about its Y midpoint.
438+
// |0 -1 0|
439+
// |0 h 1|
440+
CGContextSaveGState(ctx);
441+
CGContextConcatCTM(ctx, CGAffineTransformMake(1, 0, 0, -1, 0, destRect.size.height));
442+
CGContextDrawImage(ctx, destRect, priv->contents);
443+
CGContextRestoreGState(ctx);
438444
}
439445

440446
// Draw sublayers

Frameworks/UIKit/UIImage.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ - (void)drawAtPoint:(CGPoint)point blendMode:(CGBlendMode)mode alpha:(float)alph
491491

492492
CGRect pos;
493493
pos.origin = point;
494-
pos.size.width = (img_height / _scale);
495-
pos.size.height = (img_width / _scale);
494+
pos.size.height = (img_height / _scale);
495+
pos.size.width = (img_width / _scale);
496496

497497
// |1 0 0| is the transformation matrix for flipping a rect about its Y midpoint m. (m = (y + h/2))
498498
// |0 -1 0|

0 commit comments

Comments
 (0)