Redraw Problem with Layer-Backed View in Scroll View

  • I have a strange redraw problem for a layer-backed view that I have
    nested in an NSScrollView. The problem persists regardless of whether
    I also make the scroll view layer-backed.

    The problem is this: When the layer-backed view redraws, it seems to
    fade in. Without the scroll view, everything draws as expected, but
    with the scroll view, it looks like the view is flashing. I have put a
    video online showing the effect:

    http://tb.chem.vu.nl/~cormack/Public/Cocoa/CoreAnimationScrollViewProblem.m
    ov


    Some other facts:

    - Subviews of the layer-backed view seem to redraw fine, and do not
    fade in (see video)
    - Scrolling the scroll view also works fine, with no drawing issues
    - I have not set any CA effects for the view, such as transitions etc.

    Has anyone else seen this and/or know a workaround?

    Drew

    ---------------------------------------------------------
    Drew McCormack

    www.maccoremac.com
    www.macresearch.org
    www.macanics.net
  • On Nov 8, 2007, at 7:34 AM, Drew Mccormack wrote:
    > I have a strange redraw problem for a layer-backed view that I have
    > nested in an NSScrollView. The problem persists regardless of
    > whether I also make the scroll view layer-backed.
    >
    > The problem is this: When the layer-backed view redraws, it seems to
    > fade in. Without the scroll view, everything draws as expected, but
    > with the scroll view, it looks like the view is flashing. I have put
    > a video online showing the effect:
    >
    > http://tb.chem.vu.nl/~cormack/Public/Cocoa/CoreAnimationScrollViewProblem.m
    ov

    >
    > Some other facts:
    >
    > - Subviews of the layer-backed view seem to redraw fine, and do not
    > fade in (see video)
    > - Scrolling the scroll view also works fine, with no drawing issues
    > - I have not set any CA effects for the view, such as transitions etc.
    >
    > Has anyone else seen this and/or know a workaround?

    Hi Drew,

    The fade-in is due to NSScrollView's use of a tiled backing layer for
    its document view, to allow accommodating document views that exceed
    the maximum size for an ordinary CALayer (which is effectively the
    maximum texture size supported by the graphics hardware).

    This is pointed out in the Leopard AppKit release notes -- relevant
    section excerpted below.  If choosing an appropriate backgroundColor
    for your NSScrollView (as suggested in the relnotes) isn't sufficient
    to acceptably minimize the fade-in effect, you might consider using an
    ordinary empty NSView as your ScrollView's "document" view, and
    placing your actual document view in that view as a subview.  That
    will prevent your actual document view from being assigned a tiled
    backing layer.  You will need to be careful, however, that your
    document view does not exceed the 2046x2046 pixel size limit.  If it
    does, you will need to break it up into contiguous sibling views of
    that size or less (i.e. do the tiling yourself) to make it possible to
    render your document content in layer-backed mode.

    Excerpt from the Release Notes:
    (http://developer.apple.com/releasenotes/Cocoa/AppKit.html)

    > Layer Size Limits and Tiled Layers (New since WWDC 2007 Seed)
    >
    > One inherent limitation of rendering view content into a Core
    > Animation layer is that the size of ordinary CALayers is constrained
    > by the maximum OpenGL texture size supported by the host system's
    > graphics hardware. On most current graphics hardware the effective
    > limit is 2046x2046 pixels, beyond which size layer creation will
    > fail. Care should therefore be taken to insure that layer-backed
    > views do not exceed this size limit.
    >
    > To get around this limitation for potentially larger document views,
    > AppKit employs CATiledLayers to serve as the backing layers for the
    > document views of NSScrollViews. This specialized layer type caches
    > its content in a grid of "tiles" (of default size 256x256 pixels)
    > that are drawn as they become visible, and can be garbage-collected
    > when they go out of view. From the user's perspective, the tiles are
    > added asynchronously as they are revealed during scrolling. The
    > visual appearance of the tile addition can be minimized by enabling
    > the "drawsBackground" property for the enclosing NSScrollView (or,
    > equivalently, its NSClipView), and choosing a background color that
    > most closely matches the document view content being drawn.
    >
    > Note that when using layer-backed mode for an NSScrollView's
    > document view, it's necessary for the enclosing NSScrollView, or at
    > least its NSClipView ("content view"), to also be layer-backed in
    > order for scrolling to function correctly.

    --
    Troy Stephens
    Cocoa Frameworks
    Apple, Inc.
  • On 8 Nov 2007, at 19:34, Troy Stephens wrote:
    >
    > Hi Drew,
    >
    > The fade-in is due to NSScrollView's use of a tiled backing layer
    > for its document view, to allow accommodating document views that
    > exceed the maximum size for an ordinary CALayer (which is
    > effectively the maximum texture size supported by the graphics
    > hardware).
    >
    > This is pointed out in the Leopard AppKit release notes -- relevant
    > section excerpted below.  If choosing an appropriate backgroundColor
    > for your NSScrollView (as suggested in the relnotes) isn't
    > sufficient to acceptably minimize the fade-in effect, you might
    > consider using an ordinary empty NSView as your ScrollView's
    > "document" view, and placing your actual document view in that view
    > as a subview.  That will prevent your actual document view from
    > being assigned a tiled backing layer.  You will need to be careful,
    > however, that your document view does not exceed the 2046x2046 pixel
    > size limit.  If it does, you will need to break it up into
    > contiguous sibling views of that size or less (i.e. do the tiling
    > yourself) to make it possible to render your document content in
    > layer-backed mode.
    >
    >
    > Excerpt from the Release Notes:
    > (http://developer.apple.com/releasenotes/Cocoa/AppKit.html)
    >
    >> Layer Size Limits and Tiled Layers (New since WWDC 2007 Seed)
    >>
    >> One inherent limitation of rendering view content into a Core
    >> Animation layer is that the size of ordinary CALayers is
    >> constrained by the maximum OpenGL texture size supported by the
    >> host system's graphics hardware. On most current graphics hardware
    >> the effective limit is 2046x2046 pixels, beyond which size layer
    >> creation will fail. Care should therefore be taken to insure that
    >> layer-backed views do not exceed this size limit.
    >>
    >> To get around this limitation for potentially larger document
    >> views, AppKit employs CATiledLayers to serve as the backing layers
    >> for the document views of NSScrollViews. This specialized layer
    >> type caches its content in a grid of "tiles" (of default size
    >> 256x256 pixels) that are drawn as they become visible, and can be
    >> garbage-collected when they go out of view. From the user's
    >> perspective, the tiles are added asynchronously as they are
    >> revealed during scrolling. The visual appearance of the tile
    >> addition can be minimized by enabling the "drawsBackground"
    >> property for the enclosing NSScrollView (or, equivalently, its
    >> NSClipView), and choosing a background color that most closely
    >> matches the document view content being drawn.
    >>
    >> Note that when using layer-backed mode for an NSScrollView's
    >> document view, it's necessary for the enclosing NSScrollView, or at
    >> least its NSClipView ("content view"), to also be layer-backed in
    >> order for scrolling to function correctly.
    >
    >

    Hi Troy,

    Thanks for the explanation; I wasn't aware of the issue.

    It still seems strange to me though. It's like the tiles have a bad
    default set for the order in effect, ie, it is set to fade in instead
    of none.

    When the tiled layer is used, I would expect that if I scroll too
    fast, the tiles would not have time to draw, and that I'd see a bit of
    the scroll view's background. But I would think that once the drawing
    is complete, it should appear immediately on the screen --- I don't
    see why it would fade in.

    In case you want another look, the movie demonstrating the problem is
    here:

    http://tb.chem.vu.nl/~cormack/Public/Cocoa/CoreAnimationScrollViewProblem.m
    ov


    Kind regards,
    Drew
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today