문제

I'm working on a Cocoa fullscreen application. I am using 1 NSView that has 1 CALayer that has multiple sublayers. Right now for testing - I am using any keystrokes to add dots (20 x 20 ) to the screen. This is just for testing of drawing the dots. My issue is that I am using a filter on my dot layers - specifically I am using CIDiscBlur - and once I reach about 30 dots - the drawing of the dots significantly slows down. There can be a 1 - 1.5 second delay between the key press and the appearance of the dot. I have noticed that if I remove setting the CIDisBlur filter on the layers - that there is no slow down.

Are there any best practices or tips I should be using when drawing this many sublayers? Any help would be great.

    CIFilter *blurFilter = [CIFilter filterWithName:@"CIDiscBlur"];
    [blurFilter setDefaults];
    [blurFilter setValue:(id)[NSNumber numberWithFloat:15.0] forKey:@"inputRadius"];

    dotFilters = [[NSArray arrayWithObjects:(id)blurFilter, nil] retain];

    CGColorRef purpleColor = CGColorCreateGenericRGB(0.604, 0.247, 0.463, 1.0);

    CALayer *dot = [[CALayer layer] retain];
    dot.backgroundColor = purpleColor;
    dot.cornerRadius = 15.0f;
    dot.filters = dotFilters;

    NSRect screenRect = [[self.window screen] frame];

    //  10 point border around the screen

    CGFloat width = screenRect.size.width - 20;
    CGFloat height = screenRect.size.height - 20;

    #define ARC4RANDOM_MAX      0x100000000
    width = ((CGFloat)arc4random() / ARC4RANDOM_MAX) * width + 10;
    height = ((CGFloat)arc4random() / ARC4RANDOM_MAX) * height + 10;

    dot.frame = CGRectMake(width, height, 20,20);//30, 30);


    [dot addSublayer:dotsLayer];

I also tried using masksToBounds = YES to see if that helped - but no luck.

도움이 되었습니까?

해결책

You can probably get a performance gain by not using corner radius to make your round layers. While it's a nice little shortcut to just make a round layer in a static context, when you're animating, it will degrade performance significantly. You'd be better off specifying a circular path to a CAShapeLayer or dropping down to Core Graphics and just drawing a circle in the drawInContext call. To test if I'm right, just comment out your call to set the corner radius and apply your filter. See if that speeds things up. If not, then I'm not sure what's up. It may mean you'll have to find a different way to get your effect without a filter. If you'll always have the same look for your dots, you'll can probably "cheat" by using an image.

Best regards.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top