[ASDisplayNode][ASImageNode] Small refactorings (#2778)

* Comment out template code and fix another comment in ASDisplayNode

* Release instance lock a bit sooner and fix indentation in ASImageNode
This commit is contained in:
Huy Nguyen
2016-12-19 04:57:35 +00:00
committed by appleguy
parent a59a0f0a31
commit c0ae709b88
2 changed files with 37 additions and 48 deletions

View File

@@ -2013,7 +2013,7 @@ ASDISPLAYNODE_INLINE BOOL nodeIsInRasterizedTree(ASDisplayNode *node) {
ASDisplayNodeAssert(subnode, @"Cannot insert a nil subnode");
// Don't add subnode if it's already if it's already a subnodes
// Don't add if it's already a subnode
ASDisplayNode *oldParent = subnode.supernode;
if (!subnode || subnode == self || oldParent == self) {
return;
@@ -3063,10 +3063,10 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
oldState = _interfaceState;
_interfaceState = newState;
}
if ((newState & ASInterfaceStateMeasureLayout) != (oldState & ASInterfaceStateMeasureLayout)) {
// Trigger asynchronous measurement if it is not already cached or being calculated.
}
// TODO: Trigger asynchronous measurement if it is not already cached or being calculated.
// if ((newState & ASInterfaceStateMeasureLayout) != (oldState & ASInterfaceStateMeasureLayout)) {
// }
// For the Preload and Display ranges, we don't want to call -clear* if not being managed by a range controller.
// Otherwise we get flashing behavior from normal UIKit manipulations like navigation controller push / pop.

View File

@@ -273,35 +273,24 @@ struct ASImageNodeDrawParameters {
return nil;
}
CGRect drawParameterBounds = CGRectZero;
BOOL forceUpscaling = NO;
CGSize forcedSize = CGSizeZero;
BOOL cropEnabled = YES;
BOOL isOpaque = NO;
UIColor *backgroundColor = nil;
UIViewContentMode contentMode = UIViewContentModeScaleAspectFill;
CGFloat contentsScale = 0.0;
CGRect cropDisplayBounds = CGRectZero;
CGRect cropRect = CGRectZero;
asimagenode_modification_block_t imageModificationBlock;
ASImageNodeDrawParameters drawParameter;
{
ASDN::MutexLocker l(__instanceLock__);
ASImageNodeDrawParameters drawParameter = _drawParameter;
drawParameterBounds = drawParameter.bounds;
forceUpscaling = drawParameter.forceUpscaling;
forcedSize = drawParameter.forcedSize;
cropEnabled = drawParameter.cropEnabled;
isOpaque = drawParameter.opaque;
backgroundColor = drawParameter.backgroundColor;
contentMode = drawParameter.contentMode;
contentsScale = drawParameter.contentsScale;
cropDisplayBounds = drawParameter.cropDisplayBounds;
cropRect = drawParameter.cropRect;
imageModificationBlock = drawParameter.imageModificationBlock;
drawParameter = _drawParameter;
}
CGRect drawParameterBounds = drawParameter.bounds;
BOOL forceUpscaling = drawParameter.forceUpscaling;
CGSize forcedSize = drawParameter.forcedSize;
BOOL cropEnabled = drawParameter.cropEnabled;
BOOL isOpaque = drawParameter.opaque;
UIColor *backgroundColor = drawParameter.backgroundColor;
UIViewContentMode contentMode = drawParameter.contentMode;
CGFloat contentsScale = drawParameter.contentsScale;
CGRect cropDisplayBounds = drawParameter.cropDisplayBounds;
CGRect cropRect = drawParameter.cropRect;
asimagenode_modification_block_t imageModificationBlock = drawParameter.imageModificationBlock;
BOOL hasValidCropBounds = cropEnabled && !CGRectIsEmpty(cropDisplayBounds);
CGRect bounds = (hasValidCropBounds ? cropDisplayBounds : drawParameterBounds);
@@ -374,26 +363,26 @@ struct ASImageNodeDrawParameters {
return nil;
}
ASImageNodeContentsKey *contentsKey = [[ASImageNodeContentsKey alloc] init];
contentsKey.image = image;
contentsKey.backingSize = backingSize;
contentsKey.imageDrawRect = imageDrawRect;
contentsKey.isOpaque = isOpaque;
contentsKey.backgroundColor = backgroundColor;
contentsKey.preContextBlock = preContextBlock;
contentsKey.postContextBlock = postContextBlock;
contentsKey.imageModificationBlock = imageModificationBlock;
ASImageNodeContentsKey *contentsKey = [[ASImageNodeContentsKey alloc] init];
contentsKey.image = image;
contentsKey.backingSize = backingSize;
contentsKey.imageDrawRect = imageDrawRect;
contentsKey.isOpaque = isOpaque;
contentsKey.backgroundColor = backgroundColor;
contentsKey.preContextBlock = preContextBlock;
contentsKey.postContextBlock = postContextBlock;
contentsKey.imageModificationBlock = imageModificationBlock;
if (isCancelled()) {
return nil;
}
if (isCancelled()) {
return nil;
}
ASWeakMapEntry<UIImage *> *entry = [self.class contentsForkey:contentsKey isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled];
if (entry == nil) { // If nil, we were cancelled.
return nil;
}
_weakCacheEntry = entry; // Retain so that the entry remains in the weak cache
return entry.value;
ASWeakMapEntry<UIImage *> *entry = [self.class contentsForkey:contentsKey isCancelled:(asdisplaynode_iscancelled_block_t)isCancelled];
if (entry == nil) { // If nil, we were cancelled.
return nil;
}
_weakCacheEntry = entry; // Retain so that the entry remains in the weak cache
return entry.value;
}
static ASWeakMap<ASImageNodeContentsKey *, UIImage *> *cache = nil;