Skip to content

Commit

Permalink
Fix issue where UIGraphicsRendererFormat is mutated
Browse files Browse the repository at this point in the history
As part of #1629, we use the
preferred or default UIGraphicsRendererFormat. This was pointing to a
static variable which content scale was mutated across several graphic
render passes and lead to pixelated views.
  • Loading branch information
rahul-malik committed Aug 27, 2019
1 parent bda0a5b commit ed3cda5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Source/Details/ASGraphicsContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ NS_INLINE void ASConfigureExtendedRange(UIGraphicsImageRendererFormat *format)
// sourceImage.imageRenderFormat it will assume a grayscale color space.
// This is not good because a template image should be able to tint to any color,
// so we'll just use the default here.
format = defaultFormat;
if (AS_AVAILABLE_IOS_TVOS(11, 11)) {
format = [UIGraphicsImageRendererFormat preferredFormat];
} else {
format = [UIGraphicsImageRendererFormat defaultFormat];
}
} else {
format = sourceImage.imageRendererFormat;
}
Expand Down
13 changes: 13 additions & 0 deletions Tests/ASImageNodeSnapshotTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,19 @@ - (void)testRoundedCornerBlock
ASSnapshotVerifyNode(node, nil);
}

- (void)testUIGraphicsRendererDrawingExperiment
{
// Test to ensure that rendering with UIGraphicsRenderer don't regress
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalDrawingGlobal;
[ASConfigurationManager test_resetWithConfiguration:config];

ASImageNode *imageNode = [[ASImageNode alloc] init];
imageNode.image = [self testImage];
ASDisplayNodeSizeToFitSize(imageNode, CGSizeMake(100, 100));
ASSnapshotVerifyNode(imageNode, nil);
}

#if AS_AT_LEAST_IOS13
- (void)testDynamicAssetImage
{
Expand Down
15 changes: 15 additions & 0 deletions Tests/ASTextNodeSnapshotTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,22 @@ - (void)testFontPointSizeScaling
}


- (void)testUIGraphicsRendererDrawingExperiment
{
// Test to ensure that rendering with UIGraphicsRenderer don't regress
ASConfiguration *config = [ASConfiguration new];
config.experimentalFeatures = ASExperimentalDrawingGlobal;
[ASConfigurationManager test_resetWithConfiguration:config];

// trivial test case to ensure ASSnapshotTestCase works
ASTextNode *textNode = [[ASTextNode alloc] init];
textNode.attributedText = [[NSAttributedString alloc] initWithString:@"judar"
attributes:@{NSFontAttributeName : [UIFont italicSystemFontOfSize:24]}];
textNode.textContainerInset = UIEdgeInsetsMake(0, 2, 0, 2);
ASDisplayNodeSizeToFitSizeRange(textNode, ASSizeRangeMake(CGSizeZero, CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)));

ASSnapshotVerifyNode(textNode, nil);
}

#if AS_AT_LEAST_IOS13

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ed3cda5

Please sign in to comment.