Search code examples
macoscocoacore-animationcore-imagecifilter

How to detect hardware acceleration for Core Image?


In my app I'm using a "CIMotionBlur" CIFilter during CALayer animation. The problem is that the filter does not work properly when hardware acceleration is not available:

  • In OS X Safe Mode the layer becomes invisible during animation;
  • When using VMWare Fusion the animation is unbearably slow and makes testing the app harder;

Animation works fine without the filter. I'd like to apply filter only when hardware acceleration is available.

What's the highest level API that would let me know when to disable the filter? I'm going to look for clues in IOKit.


Solution

  • I found the answer in Technical Q&A QA1218
    "How do I tell if a particular display is being hardware accelerated by Quartz Extreme?"

    It's as simple as this:

    NSNumber* curScreenNum = [self.window.screen.deviceDescription objectForKey:@"NSScreenNumber"];
    if (CGDisplayUsesOpenGLAcceleration(curScreenNum.integerValue))
    {
        // Do accelerated stuff
    }
    

    Works as expected in my cases.