从上的文档CIContext drawImage:inRect:fromRect:
:
.. 在 iOS 6 上,此方法是异步的 ..
因此,如果我在CADisplayLink中使用它会遇到问题,因为它会继续以 60fps 的速度触发异步绘图,而实际绘图可能无法跟上。
- (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];
}
我该如何解决这个问题?
编辑 - 更多信息
我正在使用 CoreImage EAGLContext
(根据 WWDC 以获得更好的绘图性能)。
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);