Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Have image nodes draw into opaque contexts automatically if possible" #1443

Merged
merged 1 commit into from
Apr 4, 2019
Merged
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
17 changes: 5 additions & 12 deletions Source/ASImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,9 @@ + (UIImage *)createContentsForkey:(ASImageNodeContentsKey *)key drawParameters:(
return nil;
}

// If the image is opaque, and the draw rect contains the bounds rect, we can use an opaque context.
UIImage *image = key.image;
const CGRect imageDrawRect = key.imageDrawRect;
const CGRect contextBounds = { CGPointZero, key.backingSize };
const BOOL imageIsOpaque = ASImageAlphaInfoIsOpaque(CGImageGetAlphaInfo(image.CGImage));
const BOOL imageFillsContext = CGRectContainsRect(imageDrawRect, contextBounds);
const BOOL contextIsOpaque = (imageIsOpaque && imageFillsContext) || key.isOpaque;

// Use contentsScale of 1.0 and do the contentsScale handling in boundsSizeInPixels so ASCroppedImageBackingSizeAndDrawRectInBounds
// will do its rounding on pixel instead of point boundaries
ASGraphicsBeginImageContextWithOptions(contextBounds.size, contextIsOpaque, 1.0);
ASGraphicsBeginImageContextWithOptions(key.backingSize, key.isOpaque, 1.0);

BOOL contextIsClean = YES;

Expand Down Expand Up @@ -511,12 +503,13 @@ + (UIImage *)createContentsForkey:(ASImageNodeContentsKey *)key drawParameters:(
// upon removal of the object from the set when the operation completes.
// Another option is to have ASDisplayNode+AsyncDisplay coordinate these cases, and share the decoded buffer.
// Details tracked in https://github.com/facebook/AsyncDisplayKit/issues/1068

BOOL canUseCopy = (contextIsClean || imageIsOpaque);

UIImage *image = key.image;
BOOL canUseCopy = (contextIsClean || ASImageAlphaInfoIsOpaque(CGImageGetAlphaInfo(image.CGImage)));
CGBlendMode blendMode = canUseCopy ? kCGBlendModeCopy : kCGBlendModeNormal;

@synchronized(image) {
[image drawInRect:imageDrawRect blendMode:blendMode alpha:1];
[image drawInRect:key.imageDrawRect blendMode:blendMode alpha:1];
}

if (context && key.didDisplayNodeContentWithRenderingContext) {
Expand Down