@@ -473,9 +473,17 @@ + (UIImage *)createContentsForkey:(ASImageNodeContentsKey *)key drawParameters:(
473
473
return nil ;
474
474
}
475
475
476
+ // If the image is opaque, and the draw rect contains the bounds rect, we can use an opaque context.
477
+ UIImage *image = key.image ;
478
+ const CGRect imageDrawRect = key.imageDrawRect ;
479
+ const CGRect contextBounds = { CGPointZero , key.backingSize };
480
+ const BOOL imageIsOpaque = ASImageAlphaInfoIsOpaque (CGImageGetAlphaInfo (image.CGImage ));
481
+ const BOOL imageFillsContext = CGRectContainsRect (imageDrawRect, contextBounds);
482
+ const BOOL contextIsOpaque = (imageIsOpaque && imageFillsContext) || key.isOpaque ;
483
+
476
484
// Use contentsScale of 1.0 and do the contentsScale handling in boundsSizeInPixels so ASCroppedImageBackingSizeAndDrawRectInBounds
477
485
// will do its rounding on pixel instead of point boundaries
478
- ASGraphicsBeginImageContextWithOptions (key. backingSize , key. isOpaque , 1.0 );
486
+ ASGraphicsBeginImageContextWithOptions (contextBounds. size , contextIsOpaque , 1.0 );
479
487
480
488
BOOL contextIsClean = YES ;
481
489
@@ -503,13 +511,12 @@ + (UIImage *)createContentsForkey:(ASImageNodeContentsKey *)key drawParameters:(
503
511
// upon removal of the object from the set when the operation completes.
504
512
// Another option is to have ASDisplayNode+AsyncDisplay coordinate these cases, and share the decoded buffer.
505
513
// Details tracked in https://github.com/facebook/AsyncDisplayKit/issues/1068
506
-
507
- UIImage *image = key.image ;
508
- BOOL canUseCopy = (contextIsClean || ASImageAlphaInfoIsOpaque (CGImageGetAlphaInfo (image.CGImage )));
514
+
515
+ BOOL canUseCopy = (contextIsClean || imageIsOpaque);
509
516
CGBlendMode blendMode = canUseCopy ? kCGBlendModeCopy : kCGBlendModeNormal ;
510
517
511
518
@synchronized (image) {
512
- [image drawInRect: key. imageDrawRect blendMode: blendMode alpha: 1 ];
519
+ [image drawInRect: imageDrawRect blendMode: blendMode alpha: 1 ];
513
520
}
514
521
515
522
if (context && key.didDisplayNodeContentWithRenderingContext ) {
0 commit comments