Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bzlmod/build #634

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ Carthage/Build
.swiftpm/
.build/
Package.resolved

bazel-*
33 changes: 33 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
objc_library(
name = "PINRemoteImage",
srcs = glob(
["Source/Classes/**/*.m"],
allow_empty = False,
),
hdrs = glob(
["Source/Classes/**/*.h"],
allow_empty = False,
),
copts = [
"-Wno-deprecated-declarations",
"-Wno-shadow-ivar",
],
defines = [
"PIN_WEBP",
"USE_PINCACHE",
"BAZEL"
],
sdk_frameworks = [
"Accelerate",
"CoreServices",
"ImageIO",
],
visibility = [
"//visibility:public",
],
deps = [
"@PINCache",
"@PINOperation",
"@libwebp//:webp",
],
)
10 changes: 5 additions & 5 deletions Source/Classes/AnimatedImages/PINAnimatedImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2017 Pinterest. All rights reserved.
//

#import "PINAnimatedImage.h"
#import "Source/Classes/include/PINAnimatedImage.h"

NSErrorDomain const kPINAnimatedImageErrorDomain = @"kPINAnimatedImageErrorDomain";

Expand All @@ -25,7 +25,7 @@ + (NSInteger)maximumFramesPerSecond
{
static dispatch_once_t onceToken;
static NSInteger maximumFramesPerSecond = 60;

dispatch_once(&onceToken, ^{
#if PIN_TARGET_IOS
if (@available(iOS 10.3, tvOS 10.3, *)) {
Expand Down Expand Up @@ -87,15 +87,15 @@ - (NSTimeInterval)minimumFrameInterval
dispatch_once(&onceToken, ^{
kGreatestCommonDivisorPrecision = 2.0 / (1.0 / [PINAnimatedImage maximumFramesPerSecond]);
});

// Scales the frame delays by `kGreatestCommonDivisorPrecision`
// then converts it to an UInteger for in order to calculate the GCD.
NSUInteger scaledGCD = lrint([self durationAtIndex:0] * kGreatestCommonDivisorPrecision);
for (NSUInteger durationIdx = 1; durationIdx < self.frameCount; durationIdx++) {
CFTimeInterval duration = [self durationAtIndex:durationIdx];
scaledGCD = gcd(lrint(duration * kGreatestCommonDivisorPrecision), scaledGCD);
}

// Reverse to scale to get the value back into seconds.
return (scaledGCD / kGreatestCommonDivisorPrecision);
}
Expand All @@ -106,7 +106,7 @@ static NSUInteger gcd(NSUInteger a, NSUInteger b)
{
// http://en.wikipedia.org/wiki/Greatest_common_divisor
NSCAssert(a > 0 && b > 0, @"A and B must be greater than 0");

while (a != b) {
if (a > b) {
a = a - b;
Expand Down
62 changes: 31 additions & 31 deletions Source/Classes/AnimatedImages/PINAnimatedImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// Created by Garrett Moon on 4/17/18.
//

#import "PINAnimatedImageView.h"
#import "Source/Classes/include/PINAnimatedImageView.h"

#import "PINRemoteLock.h"
#import "PINDisplayLink.h"
#import "PINImage+DecodedImage.h"
#import "PINRemoteWeakProxy.h"
#import "Source/Classes/PINRemoteLock.h"
#import "Source/Classes/PINDisplayLink.h"
#import "Source/Classes/Categories/PINImage+DecodedImage.h"
#import "Source/Classes/PINRemoteWeakProxy.h"

@interface PINAnimatedImageView ()
{
Expand Down Expand Up @@ -63,7 +63,7 @@ - (void)commonInit:(PINCachedAnimatedImage *)animatedImage
_animatedImage = animatedImage;
_animatedImageRunLoopMode = NSRunLoopCommonModes;
_durations = NULL;

if (animatedImage) {
[self initializeAnimatedImage:animatedImage];
}
Expand All @@ -79,7 +79,7 @@ - (void)initializeAnimatedImage:(nonnull PINCachedAnimatedImage *)animatedImage
[self coverImageCompleted:coverImage];
});
};

animatedImage.playbackReadyCallback = ^{
dispatch_async(dispatch_get_main_queue(), ^{
// In this case the lock is already gone we have to call the unlocked version therefore
Expand All @@ -90,7 +90,7 @@ - (void)initializeAnimatedImage:(nonnull PINCachedAnimatedImage *)animatedImage
if (animatedImage.playbackReady) {
[self checkIfShouldAnimate];
}

[self resetDurationsWithAnimatedImage:animatedImage];
}

Expand All @@ -112,19 +112,19 @@ - (void)setAnimatedImage:(PINCachedAnimatedImage *)animatedImage
if (_animatedImage == animatedImage && animatedImage.playbackReady) {
return;
}

PINCachedAnimatedImage *previousAnimatedImage = _animatedImage;

_animatedImage = animatedImage;

if (animatedImage != nil) {
[self initializeAnimatedImage:animatedImage];
} else {
// Clean up after ourselves.
self.layer.contents = nil;
[self setCoverImage:nil];
}

// Animated Image can take a while to dealloc, let's try and do it off main.
__block PINCachedAnimatedImage *strongAnimatedImage = previousAnimatedImage;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
Expand All @@ -147,9 +147,9 @@ - (NSString *)animatedImageRunLoopMode
- (void)setAnimatedImageRunLoopMode:(NSString *)newRunLoopMode
{
PINAssertMain();

NSString *runLoopMode = newRunLoopMode ?: NSRunLoopCommonModes;

if (_displayLink != nil) {
[_displayLink removeFromRunLoop:[NSRunLoop mainRunLoop] forMode:_animatedImageRunLoopMode];
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:runLoopMode];
Expand All @@ -166,7 +166,7 @@ - (BOOL)isPlaybackPaused
- (void)setPlaybackPaused:(BOOL)playbackPaused
{
PINAssertMain();

_playbackPaused = playbackPaused;
[self checkIfShouldAnimate];
}
Expand All @@ -175,7 +175,7 @@ - (void)coverImageCompleted:(PINImage *)coverImage
{
PINAssertMain();
BOOL setCoverImage = (_displayLink == nil) || _displayLink.paused;

if (setCoverImage) {
[self setCoverImage:coverImage];
}
Expand Down Expand Up @@ -206,21 +206,21 @@ - (void)checkIfShouldAnimate
- (void)startAnimating
{
PINAssertMain();

if (_playbackPaused) {
return;
}

if (_animatedImage.playbackReady == NO) {
return;
}

if ([self canBeVisible] == NO) {
return;
}

NSUInteger frameInterval = self.animatedImage.frameInterval;

if (_displayLink == nil) {
_playHead = 0;
_displayLink = [PINDisplayLink displayLinkWithTarget:[PINRemoteWeakProxy weakProxyWithTarget:self] selector:@selector(displayLinkFired:)];
Expand All @@ -236,7 +236,7 @@ - (void)startAnimating
}
#endif
_lastSuccessfulFrameIndex = NSUIntegerMax;

[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:self.animatedImageRunLoopMode];
} else {
_displayLink.paused = NO;
Expand All @@ -249,7 +249,7 @@ - (void)stopAnimating

_displayLink.paused = YES;
_lastDisplayLinkFire = 0;

[_animatedImage clearAnimatedImageCache];
}

Expand Down Expand Up @@ -282,7 +282,7 @@ - (void)setImage:(PINImage *)image
if (image) {
self.animatedImage = nil;
}

super.image = image;
}

Expand Down Expand Up @@ -367,28 +367,28 @@ - (void)displayLinkFired:(PINDisplayLink *)displayLink
} else {
timeBetweenLastFire = CACurrentMediaTime() - self.lastDisplayLinkFire;
}

self.lastDisplayLinkFire = CACurrentMediaTime();

_playHead += timeBetweenLastFire;

while (_playHead > self.animatedImage.totalDuration) {
// Set playhead to zero to keep from showing different frames on different playthroughs
_playHead = 0;
_playedLoops++;
}

if (self.animatedImage.loopCount > 0 && _playedLoops >= self.animatedImage.loopCount) {
[self stopAnimating];
return;
}

NSUInteger frameIndex = [self frameIndexAtPlayHeadPosition:_playHead];
if (frameIndex == _lastSuccessfulFrameIndex) {
return;
}
CGImageRef frameImage = [self.animatedImage imageAtIndex:frameIndex];

if (frameImage == nil) {
//Pause the display link until we get a file ready notification
displayLink.paused = YES;
Expand Down Expand Up @@ -428,7 +428,7 @@ - (NSUInteger)frameIndexAtPlayHeadPosition:(CFTimeInterval)playHead
{
PINAssertMain();
int low = 0, high = (int)_animatedImage.frameCount - 1;

while (low <= high) {
int mid = low + (high - low) / 2;
if (_durations[mid] < playHead) {
Expand Down