Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions Frameworks/QuartzCore/CALayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,20 @@ - (void)renderInContext:(CGContextRef)ctx {
[priv->delegate drawLayer:self inContext:ctx];
}
} else {
CGRect rect;

rect.origin.x = 0;
rect.origin.y = priv->bounds.size.height * priv->contentsScale;
rect.size.width = priv->bounds.size.width * priv->contentsScale;
rect.size.height = -priv->bounds.size.height * priv->contentsScale;

_CGContextDrawImageRect(ctx, priv->contents, rect, destRect);
// If the layer has cached contents, blit them directly.

// Since the layer was rendered in Quartz referential (ULO) AND the current context
// is assumed to be Quartz referential (ULO), BUT the layer's cached contents
// were captured in a CGImage (CGImage referential, LLO), we have to flip
// the context again before we render it.

// |1 0 0| is the transformation matrix for flipping a rect anchored at 0,0 about its Y midpoint.
// |0 -1 0|
// |0 h 1|
CGContextSaveGState(ctx);
Copy link
Contributor

Choose a reason for hiding this comment

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

is saving/popping g-state relatively free? we should be able to get away with just reverting the CTM if not.

Copy link
Author

Choose a reason for hiding this comment

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

It's very cheap.

CGContextConcatCTM(ctx, CGAffineTransformMake(1, 0, 0, -1, 0, destRect.size.height));
Copy link
Contributor

Choose a reason for hiding this comment

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

CGAffineTransformMake [](start = 32, length = 21)

mind adding a comment calling out why this this transform is needed so that other people without the context can understand the reasoning behind. Thx!

Copy link
Author

Choose a reason for hiding this comment

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

CGContextDrawImage(ctx, destRect, priv->contents);
CGContextRestoreGState(ctx);
}

// Draw sublayers
Expand Down
4 changes: 2 additions & 2 deletions Frameworks/UIKit/UIImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ - (void)drawAtPoint:(CGPoint)point blendMode:(CGBlendMode)mode alpha:(float)alph

CGRect pos;
pos.origin = point;
pos.size.width = (img_height / _scale);
pos.size.height = (img_width / _scale);
pos.size.height = (img_height / _scale);
pos.size.width = (img_width / _scale);
Copy link
Author

Choose a reason for hiding this comment

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

@aballway might like this

Copy link
Contributor

Choose a reason for hiding this comment

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

typical think too fast or type too fast.


In reply to: 103579177 [](ancestors = 103579177)

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: position is a very silly name for a rect 😝

Copy link
Author

Choose a reason for hiding this comment

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

nit: oh well :)


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