mirror of
https://github.com/TextureGroup/Texture.git
synced 2026-04-07 19:17:39 +00:00
deprecate ASGraphicsCreateImageWithOptions (#1704)
This commit is contained in:
@@ -1499,7 +1499,7 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
|
||||
BOOL isRight = (idx == 1 || idx == 3);
|
||||
|
||||
CGSize size = CGSizeMake(radius + 1, radius + 1);
|
||||
UIImage *newContents = ASGraphicsCreateImageWithOptions(size, NO, self.contentsScaleForDisplay, nil, nil, ^{
|
||||
UIImage *newContents = ASGraphicsCreateImageWithTraitCollectionAndOptions(self.primitiveTraitCollection, size, NO, self.contentsScaleForDisplay, nil, ^{
|
||||
CGContextRef ctx = UIGraphicsGetCurrentContext();
|
||||
if (isRight == YES) {
|
||||
CGContextTranslateCTM(ctx, -radius + 1, 0);
|
||||
|
||||
+12
-10
@@ -52,7 +52,7 @@ typedef void (^ASImageNodeDrawParametersBlock)(ASWeakMapEntry *entry);
|
||||
ASDisplayNodeContextModifier _willDisplayNodeContentWithRenderingContext;
|
||||
ASDisplayNodeContextModifier _didDisplayNodeContentWithRenderingContext;
|
||||
ASImageNodeDrawParametersBlock _didDrawBlock;
|
||||
UIUserInterfaceStyle _userInterfaceStyle API_AVAILABLE(tvos(10.0), ios(12.0));
|
||||
ASPrimitiveTraitCollection _traitCollection;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -209,7 +209,10 @@ typedef void (^ASImageNodeDrawParametersBlock)(ASWeakMapEntry *entry);
|
||||
return nil;
|
||||
}
|
||||
|
||||
return ASGraphicsCreateImageWithOptions(size, NO, 1, nil, nil, ^{
|
||||
__instanceLock__.lock();
|
||||
ASPrimitiveTraitCollection tc = _primitiveTraitCollection;
|
||||
__instanceLock__.unlock();
|
||||
return ASGraphicsCreateImageWithTraitCollectionAndOptions(tc, size, NO, 1, nil, ^{
|
||||
AS::MutexLocker l(__instanceLock__);
|
||||
[_placeholderColor setFill];
|
||||
UIRectFill(CGRectMake(0, 0, size.width, size.height));
|
||||
@@ -329,9 +332,7 @@ typedef void (^ASImageNodeDrawParametersBlock)(ASWeakMapEntry *entry);
|
||||
drawParameters->_imageModificationBlock = _imageModificationBlock;
|
||||
drawParameters->_willDisplayNodeContentWithRenderingContext = _willDisplayNodeContentWithRenderingContext;
|
||||
drawParameters->_didDisplayNodeContentWithRenderingContext = _didDisplayNodeContentWithRenderingContext;
|
||||
if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
|
||||
drawParameters->_userInterfaceStyle = self.primitiveTraitCollection.userInterfaceStyle;
|
||||
}
|
||||
drawParameters->_traitCollection = _primitiveTraitCollection;
|
||||
|
||||
|
||||
// Hack for now to retain the weak entry that was created while this drawing happened
|
||||
@@ -436,8 +437,7 @@ typedef void (^ASImageNodeDrawParametersBlock)(ASWeakMapEntry *entry);
|
||||
contentsKey.imageModificationBlock = imageModificationBlock;
|
||||
|
||||
if (AS_AVAILABLE_IOS_TVOS(12, 10)) {
|
||||
UIUserInterfaceStyle userInterfaceStyle = drawParameter->_userInterfaceStyle;
|
||||
contentsKey.userInterfaceStyle = userInterfaceStyle;
|
||||
contentsKey.userInterfaceStyle = drawParameter->_traitCollection.userInterfaceStyle;
|
||||
}
|
||||
|
||||
if (isCancelled()) {
|
||||
@@ -492,18 +492,20 @@ static ASWeakMap<ASImageNodeContentsKey *, UIImage *> *cache = nil;
|
||||
}
|
||||
}
|
||||
|
||||
+ (UIImage *)createContentsForkey:(ASImageNodeContentsKey *)key drawParameters:(id)drawParameters isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled
|
||||
+ (UIImage *)createContentsForkey:(ASImageNodeContentsKey *)key drawParameters:(id)parameter isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled
|
||||
{
|
||||
// The following `ASGraphicsCreateImageWithOptions` call will sometimes take take longer than 5ms on an
|
||||
// The following `ASGraphicsCreateImageWithTraitCollectionAndOptions` call will sometimes take take longer than 5ms on an
|
||||
// A5 processor for a 400x800 backingSize.
|
||||
// Check for cancellation before we call it.
|
||||
if (isCancelled()) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
ASImageNodeDrawParameters *drawParameters = (ASImageNodeDrawParameters *)parameter;
|
||||
|
||||
// Use contentsScale of 1.0 and do the contentsScale handling in boundsSizeInPixels so ASCroppedImageBackingSizeAndDrawRectInBounds
|
||||
// will do its rounding on pixel instead of point boundaries
|
||||
UIImage *result = ASGraphicsCreateImageWithOptions(key.backingSize, key.isOpaque, 1.0, key.image, isCancelled, ^{
|
||||
UIImage *result = ASGraphicsCreateImageWithTraitCollectionAndOptions(drawParameters->_traitCollection, key.backingSize, key.isOpaque, 1.0, key.image, ^{
|
||||
BOOL contextIsClean = YES;
|
||||
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
|
||||
+1
-1
@@ -221,7 +221,7 @@
|
||||
|
||||
CGRect finalImageRect = CGRectMake(0, 0, image.size.width, image.size.height);
|
||||
|
||||
image = ASGraphicsCreateImageWithOptions(image.size, YES, image.scale, image, nil, ^{
|
||||
image = ASGraphicsCreateImageWithTraitCollectionAndOptions(strongSelf.primitiveTraitCollection, image.size, YES, image.scale, image, ^{
|
||||
[image drawAtPoint:CGPointZero];
|
||||
|
||||
UIImage *pinImage;
|
||||
|
||||
@@ -140,6 +140,7 @@ static ASTextKitRenderer *rendererForAttributes(ASTextKitAttributes attributes,
|
||||
CGFloat _contentScale;
|
||||
BOOL _opaque;
|
||||
CGRect _bounds;
|
||||
ASPrimitiveTraitCollection _traitCollection;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -151,6 +152,7 @@ static ASTextKitRenderer *rendererForAttributes(ASTextKitAttributes attributes,
|
||||
contentScale:(CGFloat)contentScale
|
||||
opaque:(BOOL)opaque
|
||||
bounds:(CGRect)bounds
|
||||
traitCollection: (ASPrimitiveTraitCollection)traitCollection
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
@@ -160,6 +162,7 @@ static ASTextKitRenderer *rendererForAttributes(ASTextKitAttributes attributes,
|
||||
_contentScale = contentScale;
|
||||
_opaque = opaque;
|
||||
_bounds = bounds;
|
||||
_traitCollection = traitCollection;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -554,7 +557,8 @@ static NSArray *DefaultLinkAttributeNames() {
|
||||
textContainerInsets:_textContainerInset
|
||||
contentScale:_contentsScaleForDisplay
|
||||
opaque:self.isOpaque
|
||||
bounds:[self threadSafeBounds]];
|
||||
bounds:[self threadSafeBounds]
|
||||
traitCollection:self.primitiveTraitCollection];
|
||||
}
|
||||
|
||||
+ (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(NS_NOESCAPE asdisplaynode_iscancelled_block_t)isCancelled
|
||||
@@ -569,7 +573,7 @@ static NSArray *DefaultLinkAttributeNames() {
|
||||
UIEdgeInsets textContainerInsets = drawParameter ? drawParameter->_textContainerInsets : UIEdgeInsetsZero;
|
||||
ASTextKitRenderer *renderer = [drawParameter rendererForBounds:drawParameter->_bounds];
|
||||
|
||||
UIImage *result = ASGraphicsCreateImageWithOptions(CGSizeMake(drawParameter->_bounds.size.width, drawParameter->_bounds.size.height), drawParameter->_opaque, drawParameter->_contentScale, nil, nil, ^{
|
||||
UIImage *result = ASGraphicsCreateImageWithTraitCollectionAndOptions(drawParameter->_traitCollection, CGSizeMake(drawParameter->_bounds.size.width, drawParameter->_bounds.size.height), drawParameter->_opaque, drawParameter->_contentScale, nil, ^{
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
ASDisplayNodeAssert(context, @"This is no good without a context.");
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ static BOOL __enableHitTestDebug = NO;
|
||||
UIColor *clipsBorderColor = [UIColor colorWithRed:30/255.0 green:90/255.0 blue:50/255.0 alpha:0.7];
|
||||
CGRect imgRect = CGRectMake(0, 0, 2.0 * borderWidth + 1.0, 2.0 * borderWidth + 1.0);
|
||||
|
||||
UIImage *debugHighlightImage = ASGraphicsCreateImageWithOptions(imgRect.size, NO, 1, nil, nil, ^{
|
||||
UIImage *debugHighlightImage = ASGraphicsCreateImageWithTraitCollectionAndOptions(self.primitiveTraitCollection, imgRect.size, NO, 1, nil, ^{
|
||||
[fillColor setFill];
|
||||
UIRectFill(imgRect);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
*
|
||||
* @return The rendered image. You can also render intermediary images using UIGraphicsGetImageFromCurrentImageContext.
|
||||
*/
|
||||
AS_EXTERN UIImage *ASGraphicsCreateImageWithOptions(CGSize size, BOOL opaque, CGFloat scale, UIImage * _Nullable sourceImage, asdisplaynode_iscancelled_block_t NS_NOESCAPE _Nullable isCancelled, void (NS_NOESCAPE ^work)(void));
|
||||
AS_EXTERN UIImage *ASGraphicsCreateImageWithOptions(CGSize size, BOOL opaque, CGFloat scale, UIImage * _Nullable sourceImage, asdisplaynode_iscancelled_block_t NS_NOESCAPE _Nullable isCancelled, void (NS_NOESCAPE ^work)(void)) ASDISPLAYNODE_DEPRECATED_MSG("Use ASGraphicsCreateImageWithTraitCollectionAndOptions instead");
|
||||
|
||||
/**
|
||||
* A wrapper for the UIKit drawing APIs.
|
||||
|
||||
@@ -12,6 +12,22 @@
|
||||
#import <AsyncDisplayKit/ASInternalHelpers.h>
|
||||
#import <AsyncDisplayKit/ASAvailability.h>
|
||||
|
||||
|
||||
#if AS_AT_LEAST_IOS13
|
||||
#define PERFORM_WORK_WITH_TRAIT_COLLECTION(work, traitCollection) \
|
||||
if (@available(iOS 13.0, *)) { \
|
||||
UITraitCollection *uiTraitCollection = ASPrimitiveTraitCollectionToUITraitCollection(traitCollection); \
|
||||
[uiTraitCollection performAsCurrentTraitCollection:^{ \
|
||||
work(); \
|
||||
}];\
|
||||
} else { \
|
||||
work(); \
|
||||
}
|
||||
#else
|
||||
#define PERFORM_WORK_WITH_TRAIT_COLLECTION(work, traitCollection) work();
|
||||
#endif
|
||||
|
||||
|
||||
NS_AVAILABLE_IOS(10)
|
||||
NS_INLINE void ASConfigureExtendedRange(UIGraphicsImageRendererFormat *format)
|
||||
{
|
||||
@@ -27,6 +43,10 @@ UIImage *ASGraphicsCreateImageWithOptions(CGSize size, BOOL opaque, CGFloat scal
|
||||
asdisplaynode_iscancelled_block_t NS_NOESCAPE isCancelled,
|
||||
void (^NS_NOESCAPE work)())
|
||||
{
|
||||
return ASGraphicsCreateImageWithTraitCollectionAndOptions(ASPrimitiveTraitCollectionMakeDefault(), size, opaque, scale, sourceImage, work);
|
||||
}
|
||||
|
||||
UIImage *ASGraphicsCreateImageWithTraitCollectionAndOptions(ASPrimitiveTraitCollection traitCollection, CGSize size, BOOL opaque, CGFloat scale, UIImage * sourceImage, void (NS_NOESCAPE ^work)()) {
|
||||
if (AS_AVAILABLE_IOS_TVOS(10, 10)) {
|
||||
if (ASActivateExperimentalFeature(ASExperimentalDrawingGlobal)) {
|
||||
// If they used default scale, reuse one of two preferred formats.
|
||||
@@ -77,38 +97,18 @@ UIImage *ASGraphicsCreateImageWithOptions(CGSize size, BOOL opaque, CGFloat scal
|
||||
format.scale = scale;
|
||||
ASConfigureExtendedRange(format);
|
||||
}
|
||||
|
||||
|
||||
return [[[UIGraphicsImageRenderer alloc] initWithSize:size format:format] imageWithActions:^(UIGraphicsImageRendererContext *rendererContext) {
|
||||
ASDisplayNodeCAssert(UIGraphicsGetCurrentContext(), @"Should have a context!");
|
||||
work();
|
||||
PERFORM_WORK_WITH_TRAIT_COLLECTION(work, traitCollection)
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
// Bad OS or experiment flag. Use UIGraphics* API.
|
||||
UIGraphicsBeginImageContextWithOptions(size, opaque, scale);
|
||||
work();
|
||||
UIImage *image = nil;
|
||||
if (isCancelled == nil || !isCancelled()) {
|
||||
image = UIGraphicsGetImageFromCurrentImageContext();
|
||||
}
|
||||
PERFORM_WORK_WITH_TRAIT_COLLECTION(work, traitCollection)
|
||||
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
return image;
|
||||
}
|
||||
|
||||
UIImage *ASGraphicsCreateImageWithTraitCollectionAndOptions(ASPrimitiveTraitCollection traitCollection, CGSize size, BOOL opaque, CGFloat scale, UIImage * sourceImage, void (NS_NOESCAPE ^work)()) {
|
||||
#if AS_AT_LEAST_IOS13
|
||||
if (@available(iOS 13.0, *)) {
|
||||
UITraitCollection *uiTraitCollection = ASPrimitiveTraitCollectionToUITraitCollection(traitCollection);
|
||||
return ASGraphicsCreateImageWithOptions(size, opaque, scale, sourceImage, nil, ^{
|
||||
[uiTraitCollection performAsCurrentTraitCollection:^{
|
||||
work();
|
||||
}];
|
||||
});
|
||||
} else {
|
||||
return ASGraphicsCreateImageWithOptions(size, opaque, scale, sourceImage, nil, work);
|
||||
}
|
||||
#else
|
||||
return ASGraphicsCreateImageWithOptions(size, opaque, scale, sourceImage, nil, work);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ using AS::MutexLocker;
|
||||
displayBlock = ^id{
|
||||
CHECK_CANCELLED_AND_RETURN_NIL();
|
||||
|
||||
UIImage *image = ASGraphicsCreateImageWithOptions(bounds.size, opaque, contentsScaleForDisplay, nil, isCancelledBlock, ^{
|
||||
UIImage *image = ASGraphicsCreateImageWithTraitCollectionAndOptions(self.primitiveTraitCollection, bounds.size, opaque, contentsScaleForDisplay, nil, ^{
|
||||
for (dispatch_block_t block in displayBlocks) {
|
||||
if (isCancelledBlock()) return;
|
||||
block();
|
||||
@@ -247,7 +247,7 @@ using AS::MutexLocker;
|
||||
};
|
||||
|
||||
if (shouldCreateGraphicsContext) {
|
||||
return ASGraphicsCreateImageWithOptions(bounds.size, opaque, contentsScaleForDisplay, nil, isCancelledBlock, workWithContext);
|
||||
return ASGraphicsCreateImageWithTraitCollectionAndOptions(self.primitiveTraitCollection, bounds.size, opaque, contentsScaleForDisplay, nil, workWithContext);
|
||||
} else {
|
||||
workWithContext();
|
||||
return image;
|
||||
|
||||
Reference in New Issue
Block a user