• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Core Animation slow down
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Animation slow down


  • Subject: Core Animation slow down
  • From: <email@hidden>
  • Date: Mon, 23 Mar 2009 07:59:28 -0600

<pre>Hi all. I had some previous questions about Core Animation, this is
not related to that at all (so don't take the previously mentioned code and
methods into consideration).  </pre><pre>I have a transparent window, in
which I create a view, and a root layer, and from then on just create and
manage sublayers directly (code for that below).&nbsp;</pre><pre>My problem
is when I first run the app, it's very smooth (looking like 60fps). But
when I leave it running for a while (sometimes after a couple of minutes,
sometimes &nbsp;after half an hour) it slows down, really really down (e.g.
roughly 1fps).</pre><pre>&nbsp;</pre><pre>My setup is very simple: I am
setting up a timer:  [NSTimer
scheduledTimerWithTimeInterval:5&nbsp;target:self&nbsp;selector:@selector(animateFired:)&nbsp;userInfo:nil&nbsp;repeats:YES];&nbsp;</pre><pre>animateFired
does nothing other than applies simple random implicit animation to a
couple of layers (rotation, position, scale etc).</pre><pre>My CALayers are
are drawn via delegates which load (in the delegate init) and display PDF
content (in the drawLayer - code below).</pre><pre>I can see from the
console that the drawLayer is only being called once (during app init) as
expected.</pre><pre>I have no other code running and have no leaks (nothing
is allocated after init methods, the only code that runs is the timer
callback which simply sets layer properties). </pre><pre>&nbsp;</pre><pre>I
cannot understand why this slow down is, and why sometimes it's after a
couple minutes, and sometimes comes in a lot later.&nbsp;</pre><pre>Also
this does not happen on my dev machine, but 3 other machines I've tested on
(which all have similar but slightly lower spec).</pre><pre>I am about to
install xcode on the other machines as well, but was wondering if I am
missing anything (e.g. about window/view creation, other deep system issues
I need to care about. )?</pre><pre>&nbsp;</pre><pre>window &amp; view
creation:</pre><p style="font: normal normal normal 10px/normal Monaco;
margin: 0px">- (<span style="color:
#aa0d91">void</span>)applicationDidFinishLaunching:(<span style="color:
#5c2699">NSNotification</span>*)aNotification {</p><p style="font: normal
normal normal 10px/normal Monaco; color: #c41a16; margin: 0px"><span
style="color: #000000"><span class="Apple-tab-span" style="white-space:
pre">	</span></span><span style="color: #2e0d6e">NSLog</span><span
style="color:
#000000">(</span>@&quot;applicationDidFinishLaunching&quot;<span
style="color: #000000">);</span></p><p style="font: normal normal normal
10px/normal Monaco; color: #2e0d6e; margin: 0px"><span style="color:
#000000"><span class="Apple-tab-span" style="white-space:
pre">	</span>[[</span><span style="color:
#3f6e74">TransparentWindow</span><span style="color: #000000">
</span>alloc<span style="color: #000000">] </span><span style="color:
#26474b">initWithContentRect</span><span style="color:
#000000">:[[</span><span style="color: #5c2699">NSScreen</span><span
style="color: #000000"> </span>mainScreen<span style="color: #000000">]
</span>visibleFrame<span style="color:
#000000">]];</span></p><pre>}&nbsp;</pre><p style="font: normal normal
normal 10px/normal Monaco; margin: 0px">-(<span style="color:
#aa0d91">id</span>) initWithContentRect:(<span style="color:
#5c2699">NSRect</span>)windowRect {</p><p style="font: normal normal normal
10px/normal Monaco; color: #c41a16; margin: 0px"><span style="color:
#000000"><span class="Apple-tab-span" style="white-space:
pre">	</span></span><span style="color: #2e0d6e">NSLog</span><span
style="color:
#000000">(</span>@&quot;TransparentWindow::initWithContentRect&quot;<span
style="color: #000000">);</span></p><p style="font: normal normal normal
10px/normal Monaco; color: #2e0d6e; margin: 0px"><span style="color:
#000000"><span class="Apple-tab-span" style="white-space:
pre">	</span></span><span style="color: #aa0d91">if</span><span
style="color: #000000">(</span><span style="color:
#aa0d91">self</span><span style="color: #000000"> = [</span><span
style="color: #aa0d91">super</span><span style="color: #000000">
</span>initWithContentRect<span style="color: #000000">:windowRect
</span>styleMask<span style="color:
#000000">:</span>NSBorderlessWindowMask<span class="Apple-style-span"
style="color: #000000">&nbsp;</span>backing<span style="color:
#000000">:</span>NSBackingStoreBuffered<span style="color: #000000">
</span>defer<span style="color: #000000">:</span><span style="color:
#aa0d91">NO</span><span style="color: #000000">]) {</span></p><p
style="font: normal normal normal 10px/normal Monaco; color: #2e0d6e;
margin: 0px"><span style="color: #000000"><span class="Apple-tab-span"
style="white-space: pre">		</span>[</span><span style="color:
#aa0d91">self</span><span style="color: #000000"> </span>setOpaque<span
style="color: #000000">:</span><span style="color: #aa0d91">NO</span><span
style="color: #000000">];</span></p><p style="font: normal normal normal
10px/normal Monaco; color: #2e0d6e; margin: 0px"><span style="color:
#000000"><span class="Apple-tab-span" style="white-space:
pre">		</span>[</span><span style="color: #aa0d91">self</span><span
style="color: #000000"> </span>setBackgroundColor<span style="color:
#000000">:[</span><span style="color: #5c2699">NSColor</span><span
style="color: #000000"> </span>clearColor<span style="color:
#000000">]];&nbsp;</span></p><p style="font: normal normal normal
10px/normal Monaco; color: #2e0d6e; margin: 0px"><span style="color:
#000000"><span class="Apple-tab-span" style="white-space:
pre">		</span>[</span><span style="color: #aa0d91">self</span><span
style="color: #000000"> </span>setMovableByWindowBackground<span
style="color: #000000">:</span><span style="color: #aa0d91">NO</span><span
style="color: #000000">];&nbsp;</span></p><p style="font: normal normal
normal 10px/normal Monaco; color: #2e0d6e; margin: 0px"><span style="color:
#000000"><span class="Apple-tab-span" style="white-space:
pre">		</span>[</span><span style="color: #aa0d91">self</span><span
style="color: #000000"> </span>makeKeyAndOrderFront<span style="color:
#000000">:</span><span style="color: #aa0d91">nil</span><span style="color:
#000000">];</span></p><p style="font: normal normal normal 10px/normal
Monaco; color: #2e0d6e; margin: 0px"><span style="color: #000000"><span
class="Apple-tab-span" style="white-space: pre">		</span>[</span><span
style="color: #aa0d91">self</span><span style="color: #000000">
</span>setAcceptsMouseMovedEvents<span style="color: #000000">:</span><span
style="color: #aa0d91">YES</span><span style="color:
#000000">];</span></p><p style="font: normal normal normal 10px/normal
Monaco; min-height: 14px; margin: 0px"><span class="Apple-tab-span"
style="white-space: pre">		</span></p><p style="font: normal normal normal
10px/normal Monaco; color: #2e0d6e; margin: 0px"><span style="color:
#000000"><span class="Apple-tab-span" style="white-space:
pre">		</span>[</span><span style="color: #aa0d91">self</span><span
style="color: #000000"> </span>setContentView<span style="color:
#000000">:[[[</span><span style="color: #5c2699">NSView</span><span
style="color: #000000"> </span>alloc<span style="color: #000000">]
</span>initWithFrame<span style="color: #000000">:</span>NSMakeRect<span
style="color: #000000">(</span><span style="color: #1c00cf">0</span><span
style="color: #000000">, </span><span style="color: #1c00cf">0</span><span
style="color: #000000">, windowRect.</span><span style="color:
#5c2699">size</span><span style="color: #000000">.</span><span
style="color: #5c2699">width</span><span style="color: #000000">,
windowRect.</span><span style="color: #5c2699">size</span><span
style="color: #000000">.</span><span style="color:
#5c2699">height</span><span style="color: #000000">)]
</span>autorelease<span style="color: #000000">]];</span></p><p
style="font: normal normal normal 10px/normal Monaco; margin: 0px"><span
class="Apple-tab-span" style="white-space: pre">	</span>}</p><p
style="font: normal normal normal 10px/normal Monaco; color: #c41a16;
margin: 0px"><span style="color: #000000"><span class="Apple-tab-span"
style="white-space: pre">	</span></span><span style="color:
#2e0d6e">NSLog</span><span style="color:
#000000">(</span>@&quot;/TransparentWindow::initWithContentRect&quot;<span
style="color: #000000">);</span></p><p style="font: normal normal normal
10px/normal Monaco; color: #aa0d91; margin: 0px"><span style="color:
#000000"><span class="Apple-tab-span" style="white-space:
pre">	</span></span>return<span style="color: #000000"> </span>self<span
style="color: #000000">;</span></p><pre><span class="Apple-style-span"
style="font-family: Monaco; font-size: 10px; white-space: normal">}<span
class="Apple-tab-span" style="white-space: pre">		</span></span>&nbsp;
</pre><pre>Creating root layer:</pre><pre><p style="font: normal normal
normal 10px/normal Monaco; margin: 0px"><span style="color:
#5c2699">NSSize</span> windowSize<span class="Apple-tab-span"
style="white-space: pre">	</span>= [[<span style="color:
#5c2699">NSApplication</span> <span style="color:
#2e0d6e">sharedApplication</span>] <span style="color:
#2e0d6e">keyWindow</span>].frame.<span style="color:
#5c2699">size</span>;</p><p style="font: normal normal normal 10px/normal
Monaco; color: #2e0d6e; margin: 0px"><span style="color:
#3f6e74">rootView</span><span style="color: #000000"><span
class="Apple-tab-span" style="white-space: pre">		</span>= [[[</span><span
style="color: #5c2699">NSApplication</span><span style="color: #000000">
</span>sharedApplication<span style="color: #000000">]
</span>keyWindow<span style="color: #000000">] </span>contentView<span
style="color: #000000">];</span></p><p style="font: normal normal normal
10px/normal Monaco; margin: 0px"><span style="color:
#3f6e74">rootView</span>.wantsLayer<span class="Apple-tab-span"
style="white-space: pre">	</span>= <span style="color:
#aa0d91">YES</span>;</p><p style="font: normal normal normal 10px/normal
Monaco; min-height: 14px; margin: 0px">&nbsp;</p><p style="font: normal
normal normal 10px/normal Monaco; min-height: 14px; margin: 0px"><span
style="color: #5c2699">CATransform3D</span> sublayerTransform = <span
style="color: #2e0d6e">CATransform3DMakeTranslation</span>(windowSize.<span
style="color: #5c2699">width</span>/<span style="color: #1c00cf">2</span>,
windowSize.<span style="color: #5c2699">height</span>/<span style="color:
#1c00cf">2</span>, <span style="color: #1c00cf">0</span>);&nbsp;// offset
(0, 0) to center of layer</p><p style="font: normal normal normal
10px/normal Monaco; color: #007400; margin: 0px"><span style="color:
#000000">sublayerTransform.</span><span style="color:
#5c2699">m34</span><span style="color: #000000"> = -</span><span
style="color: #1c00cf">.0003</span><span style="color: #000000">;<span
class="Apple-tab-span" style="white-space: pre">	</span></span>//
perspective. bigger is more</p><p style="font: normal normal normal
10px/normal Monaco; margin: 0px"><span style="color:
#3f6e74">rootView</span>.layer.sublayerTransform<span
class="Apple-tab-span" style="white-space: pre">	</span>=
sublayerTransform;</p><p style="font: normal normal normal 10px/normal
Monaco; min-height: 14px; margin: 0px"><span class="Apple-style-span"
style="font-family: Verdana; font-size: 12px">&nbsp;</span></p><span
class="Apple-style-span" style="white-space: normal"><pre
style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size:
12px">CALayer Delegate drawRect:&nbsp;</pre><p style="font: normal normal
normal 10px/normal Monaco; margin: 0px">-(<span style="color:
#aa0d91">void</span>)drawLayer:(<span style="color:
#5c2699">CALayer</span>&nbsp;*)layer inContext:(<span style="color:
#5c2699">CGContextRef</span>)context {</p><p style="font: normal normal
normal 10px/normal Monaco; color: #c41a16; margin: 0px"><span style="color:
#2e0d6e"><span class="Apple-style-span" style="color: #000000">&nbsp;&nbsp;
&nbsp;</span>NSLog</span><span style="color:
#000000">(</span>@&quot;PDFLayerDelegate::drawLayer %@&quot;<span
style="color: #000000">,&nbsp;</span><span style="color:
#3f6e74">filename</span><span style="color: #000000">);</span></p><p
style="font: normal normal normal 10px/normal Monaco; min-height: 14px;
margin: 0px"><span class="Apple-style-span" style="color: #2e0d6e"><span
style="color: #5c2699"><span class="Apple-style-span" style="color:
#000000">&nbsp;&nbsp; &nbsp;</span>CGAffineTransform</span><span
style="color: #000000">&nbsp;m<span class="Apple-tab-span"
style="white-space:
pre">			</span>=&nbsp;</span>CGPDFPageGetDrawingTransform<span
style="color: #000000">(</span><span style="color:
#3f6e74">page</span><span style="color:
#000000">,&nbsp;</span>kCGPDFArtBox<span style="color:
#000000">,&nbsp;</span>CGContextGetClipBoundingBox<span style="color:
#000000">(context),&nbsp;</span><span style="color: #1c00cf">0</span><span
style="color: #000000">,&nbsp;</span><span style="color:
#aa0d91">NO</span><span style="color: #000000">);</span></span></p><p
style="font: normal normal normal 10px/normal Monaco; color: #2e0d6e;
margin: 0px"><span style="color: #000000">&nbsp;
&nbsp;&nbsp;</span>CGContextSaveGState<span style="color:
#000000">(context);</span></p><p style="font: normal normal normal
10px/normal Monaco; color: #2e0d6e; margin: 0px"><span style="color:
#000000">&nbsp; &nbsp;&nbsp;</span>CGContextConcatCTM<span style="color:
#000000">(context, m);</span></p><p style="font: normal normal normal
10px/normal Monaco; color: #2e0d6e; margin: 0px"><span style="color:
#000000">&nbsp; &nbsp;&nbsp;</span>CGContextClipToRect<span style="color:
#000000">(context,&nbsp;</span>CGPDFPageGetBoxRect<span style="color:
#000000">(</span><span style="color: #3f6e74">page</span><span
style="color: #000000">,&nbsp;</span>kCGPDFArtBox<span style="color:
#000000">));</span><span style="color: #007400">// 4</span></p><p
style="font: normal normal normal 10px/normal Monaco; color: #2e0d6e;
margin: 0px"><span style="color: #000000">&nbsp;
&nbsp;&nbsp;</span>CGContextDrawPDFPage<span style="color:
#000000">(context,&nbsp;</span><span style="color:
#3f6e74">page</span><span style="color: #000000">);</span></p><p
style="font: normal normal normal 10px/normal Monaco; color: #2e0d6e;
margin: 0px"><span style="color: #000000">&nbsp;
&nbsp;&nbsp;</span>CGContextRestoreGState<span style="color:
#000000">(context);</span></p><p style="font: normal normal normal
10px/normal Monaco; margin: 0px">}</p></span><p style="font: normal normal
normal 10px/normal Monaco; min-height: 14px; margin: 0px"><span
class="Apple-style-span" style="font-family: Verdana; font-size:
12px">&nbsp;</span>&nbsp;</p>&nbsp; </pre>

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Core Animation slow down
      • From: <email@hidden>
  • Prev by Date: Re: Are NSNumber objects some kind of numeric literals
  • Next by Date: Re: NSAppleScript - what is going on here?
  • Previous by thread: Re: Are NSNumber objects some kind of numeric literals
  • Next by thread: Re: Core Animation slow down
  • Index(es):
    • Date
    • Thread