Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use CIContext drawImage:inRect:fromRect: with a CADisplayLink
    primarykey
    data
    text
    <p><a href="http://developer.apple.com/library/ios/DOCUMENTATION/GraphicsImaging/Reference/QuartzCoreFramework/Classes/CIContext_Class/Reference/Reference.html#//apple_ref/occ/instm/CIContext/drawImage%3ainRect%3afromRect%3a" rel="nofollow">From the docs on <code>CIContext drawImage:inRect:fromRect:</code></a>:</p> <blockquote> <p>.. On iOS 6, this method is asynchronous ..</p> </blockquote> <p>So if I am using it in a <a href="http://developer.apple.com/library/ios/#documentation/QuartzCore/Reference/CADisplayLink_ClassRef/Reference/Reference.html" rel="nofollow">CADisplayLink</a> it runs into a problem since it will keep firing off asynchronous draws at 60fps while the actual drawing might not be able to keep up. </p> <pre><code>- (void) displayLinkDidFire:(CADisplayLink *)displatLink; { CFTimeInterval duration = [displatLink duration]; CGFloat fps = round (1.0 / duration); NSLog(@"%f fps", fps); // Always logs 60 fps since drawImage is async // This method is fast since a CIImage is just a 'recipe' for an image CIImage * result = [Helper generateCIImage]; // This drawing is unable to keep up with the calls to the displayLinkDidFire method [self.ciContext drawImage:result inRect:self.destFrame fromRect:self.targetFrame]; } </code></pre> <p>How do I get around this issue?</p> <hr> <p><strong>Edit - more info</strong></p> <p>I am using CoreImage with an <code>EAGLContext</code> (for better drawing performance according to WWDCs).</p> <pre><code>self.eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; self.ciContext = [CIContext contextWithEAGLContext:self.eaglContext options: @{kCIContextWorkingColorSpace:[NSNull null]} ]; GLKView *view = (GLKView *)self.view; view.context = self.eaglContext; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; NSURL * testImageURL = [[NSBundle mainBundle] URLForResource:@"image" withExtension:@"jpg"]; NSAssert(nil != testImageURL, @"Image not found"); self.image = [CIImage imageWithContentsOfURL:testImageURL options:@{ kCIImageColorSpace:[NSNull null] }]; [EAGLContext setCurrentContext:self.eaglContext]; self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkDidFire:)]; glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload