Re: Layer hosting views, geometryFlipped, and subviews
On Fri, 17 Dec 2010 07:03:52 +1000, Gideon King gid...@novamind.com said: The whole core animation stuff does feel a bit raw when you really try using it seriously Just to be clear, keep in mind what Kyle said at the outset. He didn't actually say Core Animation is, of itself, broken or problematic. After all, on iOS, *everything* is Core Animation, and it works great. The problem is that for 500 years (or however long it was) NextStep existed without Core Animation. It was a world of simple-minded NSViews where every NSView is responsible for its own rectangle and no more, and sibling views are not permitted to overlap (the only way to show one view in front of another is to make it a subview of that view). Everything that an NSView does is based on those assumptions. As Kyle said, the problem is the integration of Core Animation into that world. m. -- matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/ A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! http://www.apeth.net/matt/default.html#applescriptthings___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Layer hosting views, geometryFlipped, and subviews
On Dec 15, 2010, at 11:53 PM, Gideon King wrote: Hi, I have a layer *hosting* view which has to use the geometryFlipped option so that it behaves correctly, and need to add an NSTextView subview for editing sometimes, and an ordinary custom view for editing at other times. I am having trouble working out where to place the subview. It just seems to end up in strange places. I have noticed also that the subview is drawing with reversed flippedness. I am wondering if there is some workaround for this by either putting another layer or view in between my layer and the overlay view? I have tried some options but so far without success. I see that a previous question along very similar lines was asked by Kyle Sluder, but there didn't appear to be any replies to his question. Any suggestions would be most welcome. Mostly because this particular question is kinda thorny :). I think the best solution here is to use parallel view hierarchy that contains whatever AppKit views you need to add rather than trying to add them to the layer hosted tree. Something like this: Layer-backed view Layer-hosted view layer tree Layer-backed view appkit views -- David Duncan ___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Layer hosting views, geometryFlipped, and subviews
On Wed, Dec 15, 2010 at 11:53 PM, Gideon King gid...@novamind.com wrote: Hi, I have a layer *hosting* view which has to use the geometryFlipped option so that it behaves correctly, and need to add an NSTextView subview for editing sometimes, and an ordinary custom view for editing at other times. Ohhh, boy. :) After a year and a half, many Radars, and at least one DTS incident all spent dealing with layer-backed and layer-hosting views, I can only make the professional recommendation that you avoid using Core Animation for anything other than a convenient OpenGL scene graph management API. Core Animation's interaction with AppKit is simply broken. This is not to besmirch the hard work of David Duncan, et al., since this is a really hard problem. But at this point, I would be equally happy with either of the following scenarios: 1. Apple fixes layer-backed and layer-hosting views and rewrites *all* of AppKit with Core Animation to show that it can work. That means replacing NSCells with CALayers and otherwise factoring their drawing along the lines that a Core Animation user (or iOS developer) would expect. 2. Apple narrows Core Animation's scope to high-performance 2D and pseudo-3D OpenGL scene graph management, and removes layer backing from the API entirely. Perhaps, instead, they could focus their 2D acceleration back on QuartzGL. I am having trouble working out where to place the subview. It just seems to end up in strange places. You really don't have a layer-backed view. You have a layer-hosting view, which is what you need if you want to play around with its layers. Adding subviews to layer-hosting views is not supported (there's a bunch of voodoo going on behind the scenes to support naïve use of Quartz in a layer-backed context). David's suggestion to you was the same advice given to us: create a layer-backed peer view to your layer-hosting view in which to host your field editor and other ancillary views. I have noticed also that the subview is drawing with reversed flippedness. I am wondering if there is some workaround for this by either putting another layer or view in between my layer and the overlay view? I have tried some options but so far without success. Flippedness is broken. rdar://problem/8009542 That is a categorical, unequivocal statement of fact. The layer machinery cannot deal with views that return YES from -isFlipped. If you follow David's advice, you will find that your view will scroll in the opposite direction as intended, and will snap to bizarre sizes when the scroll view is resized. The only way I have found to fix that is to swizzle NSClipView's implementation of certain methods to call private LayerKitGlue API. Before the announcement of the App Store, this only worried me because it might go away or otherwise break despite our best efforts to guard against it. But now we're threatened with rejection for violating the terms of the Mac App Store. You will also need to deal with other undocumented behavior that LayerKitGlue relies upon to do its job. For example, your override of -resizeWithOldSuperviewSize: *must* call super's implementation, even if you specifically want to avoid super's effects. rdar://problem/8659667 Otherwise, you will get video garbage if you live-resize a view. Once you've got the layer geometry kinks worked out, there are some issues with drawing layer contents. For example, NSLayoutManager spellchecking is entirely broken. rdar://problem/8644121 It seems to suffer similar confusion about flippedness; it draws the underlines as if the graphics context is not flipped. It doesn't go through the public -drawUnderlineForGlyphRange:… API to draw the red-dotted underlines; there's a separate private API it uses (possibly to facilitate background thread spell checking, though we have disabled that). That's assuming you're able to recite the magic incantation to get subpixel antialiased text in the first place. For obvious reasons, subpixel antialiasing requires opaque contents in the backing store in order to do its job correctly. But merely filling your backing store before drawing your text is not enough; you must create your own CGBitmapContext with kCGImageAlphaPremultipliedFirst|kCGBitmapByteOrder32Host in which to do your drawing. There is no documentation indicating that this combination of flags is required for subpixel antialiased text. And when I say merely filling your backing store, that of course implies that you will mimic Core Animation's render process in order to precompose the underlying layers into your opaque text-carrying layers' backing stores, thus negating much of the benefit of using Core Animation in the first place. And you will need to go through great pains to match color spaces, or else your precomposed version of colors will differ slightly but noticeably from that used by Core Animation. There's no documentation about what color space Core Animation operates in, but I think we've worked it out
Re: Layer hosting views, geometryFlipped, and subviews
Oh wow! The voice of much pain speaking! Makes me want to cringe in the corner and say in a small voice but, but, but I just wanted to add a subview, sir. I got most of the way without having to use the geometryFlipped (using a transform to flip coordinates) - I had seen some of your, and others' posts about the issues, and tried to avoid it, but my stuff kept jumping around in my scroll view when I changed the bounds of it and tried to keep the viewport stable, and I couldn't find a way to fix that. Changing to geometryFlipped fixed that, but introduced these other problems. I have encountered the issue with printing, and worked around that by walking the drawing code as per the advice from OmniGroup. That gave me something workable so long as I made sure to avoid using a lot of the layer properties like the corner rounding, stroke and fill etc, and some of the layer classes like CAShapeLayer, unless I also duplicated the drawing code so that I could print. I did have to move away from the tiled layer as my base layer and use a view which draws itself, with a transparent view over the top of it to host the layers (which has implications for scaling etc), and a few other design compromises along the way. Lots of investigating and trying different things, but got it working well enough overall... I could not use a layer hosting view because of the lack of ordering capabilities of sibling views. One of the big reasons for going with a layer hosting view is that it allows me to order overlapping sibling sublayers - something critical to my application. Along the way, I also needed to support this for 10.5, and there were just too many bugs and limitations in 10.5 to be able to use layers, so I wrote my own NSView replacement that allows me to treat everything the same way as layers, and just draws the content (overlapping in the right order) into a view. This works fine, except that it of course doesn't make use of hardware graphics acceleration, so is significantly slower than the 10.6 compatible implementation. Seeing as only about 14% of our customers (and falling) are still on Leopard, I wasn't too concerned about that, but need something better going forward. I had not tried adding a text view to a non-geometryFlipped layer hosting view, but have now tried it, and indeed you are correct about it not showing up the spelling checking dots, even though it does otherwise obey the positioning I want it. The whole core animation stuff does feel a bit raw when you really try using it seriously, but at the same time, very promising, and heading in some nice directions. I expect Apple will be doing some serious work on it for Lion, and am expecting it to really shine there...but that really doesn't help me for now. I respect both your opinion and David's and might try David's suggested solution today, even though it does appear to require overlapping sibling views, which I have found can not be guaranteed what order they will appear in. The other option I am considering is just using a child window as an overlay and doing all my view stuff in there. I'll need to think it through, but it may well work well enough for my needs if I clip to my scroll view's clip view size and reposition things on the child window when the parent scrolls. I really don't want to completely throw out the CA implementation when I am so close, and have overcome all the other issues I have encountered and got the core system working so nicely for just about everything else. Thanks for taking the time to reply with all the feedback and suggestions. Time for me to try some more things out... Regards Gideon On 17/12/2010, at 5:09 AM, Kyle Sluder wrote: Ohhh, boy. :) [much stuff removed] My professional suggestion: avoid using Core Animation for anything related to traditional UI. CA is great for things like Front Row, sprite-based animation/games, overlays atop Core Video movie playback, data visualization (but be careful here! sometimes it's also the wrong tool for building data visualization)... it's not good for writing the next version of your productivity app's main content view. --Kyle Sluder ___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Layer hosting views, geometryFlipped, and subviews
Hi, I have a layer *hosting* view which has to use the geometryFlipped option so that it behaves correctly, and need to add an NSTextView subview for editing sometimes, and an ordinary custom view for editing at other times. I am having trouble working out where to place the subview. It just seems to end up in strange places. I have noticed also that the subview is drawing with reversed flippedness. I am wondering if there is some workaround for this by either putting another layer or view in between my layer and the overlay view? I have tried some options but so far without success. I see that a previous question along very similar lines was asked by Kyle Sluder, but there didn't appear to be any replies to his question. Any suggestions would be most welcome. Thanks Gideon ___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com