Skip to content

Commit

Permalink
Remove the text rendering experiment. (#1531)
Browse files Browse the repository at this point in the history
* Remove the text rendering experiment. It decreased rendering speeds at a negligible improvement to OOMs.

* Adopt new ASGraphicsCreateImageWithOptions API
  • Loading branch information
garrettmoon authored and Adlai-Holler committed Jun 3, 2019
1 parent 62e5a8e commit a3f25d0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 44 deletions.
1 change: 0 additions & 1 deletion Schemas/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"exp_skip_clear_data",
"exp_did_enter_preload_skip_asm_layout",
"exp_dispatch_apply",
"exp_text_drawing",
"exp_oom_bg_dealloc_disable",
"exp_transaction_operation_retain_cycle",
"exp_remove_textkit_initialising_lock"
Expand Down
9 changes: 4 additions & 5 deletions Source/ASExperimentalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) {
ASExperimentalSkipClearData = 1 << 6, // exp_skip_clear_data
ASExperimentalDidEnterPreloadSkipASMLayout = 1 << 7, // exp_did_enter_preload_skip_asm_layout
ASExperimentalDispatchApply = 1 << 8, // exp_dispatch_apply
ASExperimentalTextDrawing = 1 << 9, // exp_text_drawing
ASExperimentalOOMBackgroundDeallocDisable = 1 << 10, // exp_oom_bg_dealloc_disable
ASExperimentalTransactionOperationRetainCycle = 1 << 11, // exp_transaction_operation_retain_cycle
ASExperimentalRemoveTextKitInitialisingLock = 1 << 12, // exp_remove_textkit_initialising_lock
ASExperimentalDrawingGlobal = 1 << 13, // exp_drawing_global
ASExperimentalOOMBackgroundDeallocDisable = 1 << 9, // exp_oom_bg_dealloc_disable
ASExperimentalTransactionOperationRetainCycle = 1 << 10, // exp_transaction_operation_retain_cycle
ASExperimentalRemoveTextKitInitialisingLock = 1 << 11, // exp_remove_textkit_initialising_lock
ASExperimentalDrawingGlobal = 1 << 12, // exp_drawing_global
ASExperimentalFeatureAll = 0xFFFFFFFF
};

Expand Down
1 change: 0 additions & 1 deletion Source/ASExperimentalFeatures.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
@"exp_skip_clear_data",
@"exp_did_enter_preload_skip_asm_layout",
@"exp_dispatch_apply",
@"exp_text_drawing",
@"exp_oom_bg_dealloc_disable",
@"exp_transaction_operation_retain_cycle",
@"exp_remove_textkit_initialising_lock",
Expand Down
40 changes: 5 additions & 35 deletions Source/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#import <AsyncDisplayKit/ASDisplayNodeExtras.h>
#import <AsyncDisplayKit/ASDisplayNodeInternal.h>
#import <AsyncDisplayKit/ASConfigurationInternal.h>
#import <AsyncDisplayKit/ASGraphicsContext.h>
#import <AsyncDisplayKit/ASHighlightOverlayLayer.h>

#import <AsyncDisplayKit/ASTextKitCoreTextAdditions.h>
Expand Down Expand Up @@ -559,40 +560,12 @@ + (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(NS_NOES
if (drawParameter->_bounds.size.width <= 0 || drawParameter->_bounds.size.height <= 0) {
return nil;
}

UIImage *result = nil;

UIColor *backgroundColor = drawParameter->_backgroundColor;
UIEdgeInsets textContainerInsets = drawParameter ? drawParameter->_textContainerInsets : UIEdgeInsetsZero;
ASTextKitRenderer *renderer = [drawParameter rendererForBounds:drawParameter->_bounds];
BOOL renderedWithGraphicsRenderer = NO;

if (AS_AVAILABLE_IOS_TVOS(10, 10)) {
if (ASActivateExperimentalFeature(ASExperimentalTextDrawing)) {
renderedWithGraphicsRenderer = YES;
UIGraphicsImageRenderer *graphicsRenderer = [[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(drawParameter->_bounds.size.width, drawParameter->_bounds.size.height)];
result = [graphicsRenderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
CGContextRef context = rendererContext.CGContext;
ASDisplayNodeAssert(context, @"This is no good without a context.");

CGContextSaveGState(context);
CGContextTranslateCTM(context, textContainerInsets.left, textContainerInsets.top);

// Fill background
if (backgroundColor != nil) {
[backgroundColor setFill];
UIRectFillUsingBlendMode(CGContextGetClipBoundingBox(context), kCGBlendModeCopy);
}

// Draw text
[renderer drawInContext:context bounds:drawParameter->_bounds];
CGContextRestoreGState(context);
}];
}
}

if (!renderedWithGraphicsRenderer) {
UIGraphicsBeginImageContextWithOptions(CGSizeMake(drawParameter->_bounds.size.width, drawParameter->_bounds.size.height), drawParameter->_opaque, drawParameter->_contentScale);


UIImage *result = ASGraphicsCreateImageWithOptions(CGSizeMake(drawParameter->_bounds.size.width, drawParameter->_bounds.size.height), drawParameter->_opaque, drawParameter->_contentScale, nil, nil, ^{
CGContextRef context = UIGraphicsGetCurrentContext();
ASDisplayNodeAssert(context, @"This is no good without a context.");

Expand All @@ -608,10 +581,7 @@ + (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(NS_NOES
// Draw text
[renderer drawInContext:context bounds:drawParameter->_bounds];
CGContextRestoreGState(context);

result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
});

return result;
}
Expand Down
2 changes: 0 additions & 2 deletions Tests/ASConfigurationTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
ASExperimentalSkipClearData,
ASExperimentalDidEnterPreloadSkipASMLayout,
ASExperimentalDispatchApply,
ASExperimentalTextDrawing,
ASExperimentalOOMBackgroundDeallocDisable,
ASExperimentalTransactionOperationRetainCycle,
ASExperimentalRemoveTextKitInitialisingLock,
Expand All @@ -53,7 +52,6 @@ + (NSArray *)names {
@"exp_skip_clear_data",
@"exp_did_enter_preload_skip_asm_layout",
@"exp_dispatch_apply",
@"exp_text_drawing",
@"exp_oom_bg_dealloc_disable",
@"exp_transaction_operation_retain_cycle",
@"exp_remove_textkit_initialising_lock",
Expand Down

0 comments on commit a3f25d0

Please sign in to comment.