Drawing many thin vertical lines is very slow
Drawing many thin vertical lines is very slow
- Subject: Drawing many thin vertical lines is very slow
- From: Michael David Crawford <email@hidden>
- Date: Thu, 07 May 2015 21:43:23 -0700
My iOS app enables the user to toggle on and off a square grid. When
the grid is enabled, a tap inside a cell toggles the color of the cell
between black and blue. When the grid is disabled, one can use a
pinch-zoom gesture to adjust the sizes of the cells.
(I'm not so sure that's a sensible UI but that's not the problem I'm
looking into just now.)
If the pitch of the gride is fine, then there are many lines on the
screen. If I autorotate, redrawing the vertical lines takes hundreds
of times as long as redrawing the horizontal lines. That makes sense
as one can draw a horizontal line by incrementing a pointer into the
image buffer. To draw a vertical line one has to draw a pixel, then
calculate the memory address of the next pixel vertically downwards.
I wonder if there is a better way to do this? I'm using UIRectFill to
draw 1.0 point thick rectangles. I thought of using CoreGraphics
directly but Instruments tells me that all the time is spent way down
in the innards of CG.
Before I draw the grid, I erase the whole view to blue, then draw
black rectangles for my cells. A small optimization is that if two or
more cells are horizontal neighbors, I draw them in one UIRectFill
operation.
The vertical line drawing is so slow that it is disruptive to the user
when autorotating - the whole UI freezes for as long as two seconds,
looks distorted during that time then very quickly renders the desired
appearance.
One way would be to render a single vertical line into a tall, narrow
offscreen image buffer then copy that buffer into multiple locations
on the screen.
Another way would be for me to render the entire view in an offscreen
image buffer, which I expect I could do far more efficiently than by
making many calls into UIRectFill or even CoreGraphics.
I've done lots of direct memory pixel manipulations over the years,
that wouldn't be a problem for me to implement but before I do, do you
think it would be a good idea?
--
Michael David Crawford, Consulting Software Engineer
email@hidden
http://www.warplife.com/mdc/
Available for Software Development in the Portland, Oregon Metropolitan
Area.
_______________________________________________
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