Skip to content

Commit

Permalink
64-byte alignment is an even more robust choice for all of the variou…
Browse files Browse the repository at this point in the history
…s GPUs. Bump the metadata version

so that image tables created with the previous 32-byte alignment can be tossed.
  • Loading branch information
Mallory Paine committed Oct 23, 2013
1 parent 8b6800c commit 8d7d53d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion FastImageCache/FICImageTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ - (instancetype)initWithFormat:(FICImageFormat *)imageFormat {
_screenScale = [[UIScreen mainScreen] scale];

int bytesPerPixel = 4;
_imageRowLength = FICByteAlignForCoreAnimation([_imageFormat pixelSize].width * bytesPerPixel, bytesPerPixel);
_imageRowLength = FICByteAlignForCoreAnimation([_imageFormat pixelSize].width * bytesPerPixel);
_imageLength = _imageRowLength * (NSInteger)[_imageFormat pixelSize].height;

_chunkDictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL); // Non-retained keys and values
Expand Down
2 changes: 1 addition & 1 deletion FastImageCache/FICImageTableEntry.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ - (void)dealloc {
#pragma mark - Other Accessors

+ (NSInteger)metadataVersion {
return 7;
return 8;
}

- (FICImageTableEntryMetadata *)_metadata {
Expand Down
2 changes: 1 addition & 1 deletion FastImageCache/FICUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "FICImports.h"

size_t FICByteAlign(size_t bytesPerRow, size_t alignment);
size_t FICByteAlignForCoreAnimation(size_t bytesPerRow, size_t bytesPerPixel);
size_t FICByteAlignForCoreAnimation(size_t bytesPerRow);

NSString * FICStringWithUUIDBytes(CFUUIDBytes UUIDBytes);
CFUUIDBytes FICUUIDBytesWithString(NSString *string);
Expand Down
8 changes: 3 additions & 5 deletions FastImageCache/FICUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@

#pragma mark Internal Definitions

#define FIC_CA_BACKING_STORE_ALIGNMENT_PIXELS 8
// Core Animation will make a copy of any image that a client application provides whose backing store isn't properly byte-aligned.
// This copy operation can be prohibitively expensive, so we want to avoid this by properly aligning any UIImages we're working with.
// To produce a UIImage that is properly aligned, we need to ensure that the backing store's bytes per row is a multiple of
// (bytes per pixel * FIC_CA_BACKING_STORE_ALIGNMENT_PIXELS).
// To produce a UIImage that is properly aligned, we need to ensure that the backing store's bytes per row is a multiple of 64.

#pragma mark - Byte Alignment

inline size_t FICByteAlign(size_t width, size_t alignment) {
return ((width + (alignment - 1)) / alignment) * alignment;
}

inline size_t FICByteAlignForCoreAnimation(size_t bytesPerRow, size_t bytesPerPixel) {
return FICByteAlign(bytesPerRow, (bytesPerPixel * FIC_CA_BACKING_STORE_ALIGNMENT_PIXELS));
inline size_t FICByteAlignForCoreAnimation(size_t bytesPerRow) {
return FICByteAlign(bytesPerRow, 64);
}

#pragma mark - Strings and UUIDs
Expand Down

0 comments on commit 8d7d53d

Please sign in to comment.