> I’m not sure if you can create and manipulate a CALayer on a background > thread, all UI code must be run on main thread.
Yes, that's what I was suspecting, too. Interestingly, when I create a layer in the background, and add it to the main layer *in the background thread* , it helps a lot. The stuttering is much much better now! not 100% perfect, but OK to distribute, IMHO. Code is attached, just for reference, should someone else stumble in here. > > It’s worth noting that I’m using Lanczos scaling with cpu renderer because > I’m scaling relatively low-resolution images for print output so I need the > highest quality scaling regardless of performance. Do you scale up? or down? (I'm only scaling down, if any.) > According to this NSHipster guide (https://nshipster.com/image-resizing/) > simply getting an appropriate size via CGImageSourceCreateThumbnailAtIndex > should be your best option. You’re already doing this, so maybe you don’t > need CIImage at all? Yes, I have just removed CIImage functions completely. > > The CALayer animation should be using the GPU. Yes, I think, it does. > If loading the new image at the same time you’re starting the animation of > the current image causes a stutter, you could try delaying execution of your > block by a little (using dispatch_after instead of dispatch_async). Good idea ! I tried that and it seems to help a bit further against stuttering. So, thanks a million to you (and everyone else who chimed in)! You kept me experimenting. Best regards, Gabriel Encl.: This is my solution to the stuttering problem, at the moment. (Let's hope, Apple doesn't change the semantics of all the API's, LOL.) NSDictionary * imageOpts = @{ (id)kCGImageSourceCreateThumbnailWithTransform: (id)kCFBooleanTrue, // takes care of EXIF orientation, too (id)kCGImageSourceCreateThumbnailFromImageIfAbsent: (id)kCFBooleanTrue, (id)kCGImageSourceCreateThumbnailFromImageAlways: (id)kCFBooleanTrue, (id)kCGImageSourceShouldCacheImmediately: (id)kCFBooleanTrue, (id)kCGImageSourceThumbnailMaxPixelSize: @(8192) }; CGImageRef newImageRef = CGImageSourceCreateThumbnailAtIndex( new_image, 0, (__bridge CFDictionaryRef) imageOpts ); if ( prefetchLayer_ ) [prefetchLayer_ removeFromSuperlayer]; prefetchLayer_ = [CALayer layer]; prefetchLayer_.contents = (__bridge id)(newImageRef); prefetchLayer_.delegate = nil; prefetchLayer_.minificationFilter = kCAFilterTrilinear; // kCAFilterLinear is faster prefetchLayer_.magnificationFilter = imgLayer.minificationFilter; prefetchLayer_.bounds = NSRectToCGRect( drawRect_ ); prefetchLayer_.zPosition = -10.0; prefetchLayer_.opacity = 0.0; // hopefully, Apple never optimizes layers away b/c of zero opacity! [mainLayer_ addSublayer: prefetchLayer_];
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com