FPS of Yykit Notes

Source: Internet
Author: User

FPS calculation method

FPS is the abbreviation for frame per second, which is the number of frames per second. This term is widely used in computer graphics, video capture, games and so on.

Cadisplaylink

Cadisplaylink is a timer that allows us to draw content to the screen at the same frequency as the screen refresh rate, create a new Cadisplaylink object, add it to a runloop, and provide it with a target and selector Called when the screen is refreshed. Once the Cadisplaylink has a specific mode registered to the Runloop lag, the runloop invokes the selector on the bound target whenever the screen needs to be refreshed. At this point, target can read the timestamp of each call to Cadisplaylink.

1     _link = [Cadisplaylink displaylinkwithtarget:[yyweakproxy proxywithtarget:self] Selector: @selector (tick:)]; 2     [_link Addtorunloop:[nsrunloop Mainrunloop] formode:nsrunloopcommonmodes];
1- (void) Tick: (Cadisplaylink *) Link {2     if(_lasttime = =0) {3_lasttime =Link.timestamp;4         return;5     }6     7_count++;8Nstimeinterval Delta = link.timestamp-_lasttime;9     if(Delta <1)return;Ten_lasttime =Link.timestamp; One     floatfps = _count/Delta; A_count =0; -      -CGFloat progress = fps/60.0; theUicolor *color = [Uicolor Colorwithhue:0.27* (Progress-0.2) Saturation:1Brightness:0.9Alpha1]; -      -nsmutableattributedstring *text = [[Nsmutableattributedstring alloc] initwithstring:[nsstring StringWithFormat:@"%d FPS",(int) Round (fps)]; -[Text Setcolor:color Range:nsmakerange (0, Text.length-3)]; +[Text Setcolor:[uicolor Whitecolor] Range:nsmakerange (Text.length-3,3)]; -Text.font =_font; +[Text Setfont:_subfont range:nsmakerange (Text.length-4,1)]; A      atSelf.attributedtext =text; -}

Code reference: Yyfpslabel.

Problem:

1. [Yyweakproxy Proxywithtarget:self] How to avoid circular references.

eg

  [NSTimer timerWithTimeInterval:1.f target:self selector:@selector(tick:) userInfo:nil repeats:YES];
CADisplayLink *_link = [CADisplayLink displayLinkWithTarget:self selector:@selector(tick:)];

 The above two usages, will be the self strong reference, at this time the timer holds self,self also holds the timer, the circular reference causes the page dismiss, both sides cannot release, causes the circular reference.
The use of __weak at this time cannot be solved effectively:

__weak typeof(self) weakSelf = self;_link = [CADisplayLink displayLinkWithTarget:weakSelf selector:@selector(tick:)];

FPS of Yykit Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.