2

Those two functions are currently my bottleneck. I am working with very large bitmaps.

How can I improve their performance?

Rob Keniger
  • 45,830
  • 6
  • 101
  • 134
Erik Sapir
  • 23,209
  • 28
  • 81
  • 141
  • You're not giving us much to go on. Please describe what you're drawing, what size the bitmaps are and what sort of performance issues you're seeing. Please also post any relevant drawing code. – Rob Keniger Jul 08 '11 at 14:16
  • I use bitmaps of size 2930 x 5750 pixels (each pixel is 4 bytes, RGBA). I fill the bitmaps with a background color using CGContextFillRect (and CGContextSetRGBFillColor before). – Erik Sapir Jul 08 '11 at 14:20

2 Answers2

2

You could cache smaller versions of your bitmaps which you create before drawing the first time and then simply draw the downscaled samples instead of the full-blown 15 megapixel stuff.

Then again make sure you are only drawing what is necessary i.e. in 'drawRect: (NSRect) rect' only draw inside the rect (unless absolutely necessary). And try not do perform drawings outside of that method.

iolo
  • 1,090
  • 1
  • 9
  • 20
1

If you're drawing large background images with content in the foreground that moves, consider using a layer-backed NSView, adding a layer and setting its background image. You can then draw your content in a other layers (or layer-backed NSViews) above the background layer, and the view will never need to redraw the background image because it is stored in the GPU's texture memory. Your current image is too large for a single CALayer (CALayers are limited to the maximum OpenGL texture size of 2048 x 2048) so you will probably need to break it up into tiles.

Otherwise, as @iolo mentioned, you should make sure that you only redraw the parts of the view that really need updating.

Rob Keniger
  • 45,830
  • 6
  • 101
  • 134