mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Remove ASImageNode thread affinity asserts (#57).
This commit is contained in:
@@ -63,6 +63,17 @@ CGFloat ASDisplayNodeScreenScale()
|
|||||||
return screenScale;
|
return screenScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ASDisplayNodePerformBlockOnMainThread(void (^block)())
|
||||||
|
{
|
||||||
|
if ([NSThread isMainThread]) {
|
||||||
|
block();
|
||||||
|
} else {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
block();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+ (void)initialize
|
+ (void)initialize
|
||||||
{
|
{
|
||||||
if (self == [ASDisplayNode class]) {
|
if (self == [ASDisplayNode class]) {
|
||||||
|
|||||||
@@ -106,35 +106,35 @@
|
|||||||
|
|
||||||
- (void)setImage:(UIImage *)image
|
- (void)setImage:(UIImage *)image
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertThreadAffinity(self);
|
|
||||||
ASDN::MutexLocker l(_imageLock);
|
ASDN::MutexLocker l(_imageLock);
|
||||||
if (_image != image) {
|
if (_image != image) {
|
||||||
_image = image;
|
_image = image;
|
||||||
|
ASDisplayNodePerformBlockOnMainThread(^{
|
||||||
[self invalidateCalculatedSize];
|
[self invalidateCalculatedSize];
|
||||||
[self setNeedsDisplay];
|
[self setNeedsDisplay];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIImage *)image
|
- (UIImage *)image
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertThreadAffinity(self);
|
|
||||||
ASDN::MutexLocker l(_imageLock);
|
ASDN::MutexLocker l(_imageLock);
|
||||||
return _image;
|
return _image;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setTint:(ASImageNodeTint)tint
|
- (void)setTint:(ASImageNodeTint)tint
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertThreadAffinity(self);
|
|
||||||
ASDN::MutexLocker l(_imageLock);
|
ASDN::MutexLocker l(_imageLock);
|
||||||
if (_tint != tint) {
|
if (_tint != tint) {
|
||||||
_tint = tint;
|
_tint = tint;
|
||||||
|
ASDisplayNodePerformBlockOnMainThread(^{
|
||||||
[self setNeedsDisplay];
|
[self setNeedsDisplay];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ASImageNodeTint)tint
|
- (ASImageNodeTint)tint
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertThreadAffinity(self);
|
|
||||||
ASDN::MutexLocker l(_imageLock);
|
ASDN::MutexLocker l(_imageLock);
|
||||||
return _tint;
|
return _tint;
|
||||||
}
|
}
|
||||||
@@ -281,19 +281,16 @@
|
|||||||
#pragma mark - Cropping
|
#pragma mark - Cropping
|
||||||
- (BOOL)isCropEnabled
|
- (BOOL)isCropEnabled
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertThreadAffinity(self);
|
|
||||||
return _cropEnabled;
|
return _cropEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setCropEnabled:(BOOL)cropEnabled
|
- (void)setCropEnabled:(BOOL)cropEnabled
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertThreadAffinity(self);
|
|
||||||
[self setCropEnabled:cropEnabled recropImmediately:NO inBounds:self.bounds];
|
[self setCropEnabled:cropEnabled recropImmediately:NO inBounds:self.bounds];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setCropEnabled:(BOOL)cropEnabled recropImmediately:(BOOL)recropImmediately inBounds:(CGRect)cropBounds
|
- (void)setCropEnabled:(BOOL)cropEnabled recropImmediately:(BOOL)recropImmediately inBounds:(CGRect)cropBounds
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertThreadAffinity(self);
|
|
||||||
if (_cropEnabled == cropEnabled)
|
if (_cropEnabled == cropEnabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -303,23 +300,22 @@
|
|||||||
// If we have an image to display, display it, respecting our recrop flag.
|
// If we have an image to display, display it, respecting our recrop flag.
|
||||||
if (self.image)
|
if (self.image)
|
||||||
{
|
{
|
||||||
|
ASDisplayNodePerformBlockOnMainThread(^{
|
||||||
if (recropImmediately)
|
if (recropImmediately)
|
||||||
[self displayImmediately];
|
[self displayImmediately];
|
||||||
else
|
else
|
||||||
[self setNeedsDisplay];
|
[self setNeedsDisplay];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CGRect)cropRect
|
- (CGRect)cropRect
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertThreadAffinity(self);
|
|
||||||
return _cropRect;
|
return _cropRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setCropRect:(CGRect)cropRect
|
- (void)setCropRect:(CGRect)cropRect
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertThreadAffinity(self);
|
|
||||||
|
|
||||||
if (CGRectEqualToRect(_cropRect, cropRect))
|
if (CGRectEqualToRect(_cropRect, cropRect))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -332,8 +328,10 @@
|
|||||||
BOOL isCroppingImage = ((boundsSize.width < imageSize.width) || (boundsSize.height < imageSize.height));
|
BOOL isCroppingImage = ((boundsSize.width < imageSize.width) || (boundsSize.height < imageSize.height));
|
||||||
|
|
||||||
// Re-display if we need to.
|
// Re-display if we need to.
|
||||||
|
ASDisplayNodePerformBlockOnMainThread(^{
|
||||||
if (self.nodeLoaded && self.contentMode == UIViewContentModeScaleAspectFill && isCroppingImage)
|
if (self.nodeLoaded && self.contentMode == UIViewContentModeScaleAspectFill && isCroppingImage)
|
||||||
[self setNeedsDisplay];
|
[self setNeedsDisplay];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
BOOL ASDisplayNodeSubclassOverridesSelector(Class subclass, SEL selector);
|
BOOL ASDisplayNodeSubclassOverridesSelector(Class subclass, SEL selector);
|
||||||
CGFloat ASDisplayNodeScreenScale();
|
CGFloat ASDisplayNodeScreenScale();
|
||||||
|
void ASDisplayNodePerformBlockOnMainThread(void (^block)());
|
||||||
|
|
||||||
@class _ASPendingState;
|
@class _ASPendingState;
|
||||||
|
|
||||||
|
|||||||
@@ -138,15 +138,7 @@ static const CGFloat kInnerPadding = 10.0f;
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// set our image node's data
|
// set our image node's data
|
||||||
if (_imageNode.nodeLoaded) {
|
|
||||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
||||||
// once the node's view is loaded, the node should only be used on the main thread
|
|
||||||
_imageNode.image = [UIImage imageWithData:data];
|
_imageNode.image = [UIImage imageWithData:data];
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// if the node hasn't loaded, we can use it on a background thread
|
|
||||||
_imageNode.image = [UIImage imageWithData:data];
|
|
||||||
}
|
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user