0

CATiledLayer calls drawRect from multiple threads - this means that my model needs to be thread safe. It isn't - and making it thread safe would be 'tedious' to say the least (and threading is evil anyway :-)

Anyone know of a way to make CATiledLayer call drawRect on the main thread only?

Failing that, does anyone know how I can have an arbitrarily large view/layer (i.e. no backing store memory limitations.)

Thanks

Craig

Daniyar
  • 2,975
  • 2
  • 26
  • 39
Scotty
  • 2,019
  • 1
  • 20
  • 31

2 Answers2

0

There is no way to make CATiledLayer calling drawRect on main thread. Note that there is a reason why this layer does multithreading: drawing in iOS is painfully slow, so it tries to use all processor cores.

I am not sure that there is currently hard limit on backing store size (it existed but things may have changed). Anyway memory is limited resource in mobile devices, you can't have arbitrary large view if you override drawRec. You should use tiling to show only what is currently visible or use things like CAShapeLayer for drawing.

yurish
  • 1,515
  • 1
  • 15
  • 16
  • Tiling is indeed what I want - it's just the threads I can do without. Strikes me that tiling on the main thread would be a good compromise between complexity, speed and memory usage. Shape layers are ok - but tedious to do anything complicated (different colors/fills etc. all need their own layer) – Scotty Nov 19 '13 at 17:19
  • If you do not need fast scrolling you can create a view of screen size and just redraw the view content when user tries to scroll it. Also you can try to implement you own tiling solution. Look for example ScrollViewSuite Tiling project. Note however that if you try to draw on main thread you most likely will see jerking when scrolling – yurish Nov 19 '13 at 17:27
0

CATiledLayer has a private Class Method

+ (BOOL)shouldDrawOnMainThread;

So you can override and return YES. then all drawing cycle will be executed on main Thread.

snippet like this

+ (BOOL)shouldDrawOnMainThread
{
    return YES;
}
hippo
  • 87
  • 4