I just wrote a benchmark that fills a 1176x800 rectangle with a LinearGradient, and optionally draws some "rules" (two 3 high and two 5 high, solid-color rectangles) on top of that. I've tried to make this a fair test (below) but I get 47 fps for a fill without rules in software, and only 40 fps with hardware acceleration. When I add the rules, I get 44 and 40 fps. drawRect() is not on the "not supported" list on
Romain's 14 March blog post, and neither is LinearGradient.
- I start a timer running and read System.nanoTime(). In a custom View's onDraw() function, I draw, increment a frame counter, and invalidate(). When the timer fires, I read System.nanoTime() and divide the frame count by the elapsed time.
- I create all Paint and LinearGradient objects in a setup routine, before I read System.nanoTime(). I create an array of gradients and an array of solids that I cycle through on each draw (e.g., gradients[frameCount % GRADIENTS]) so that 'something's happening' while the test runs, but I don't change any of their properties.
- I do a 'burn in' run, before the 'real' timings, so each Paint has had a chance to initialize any caches before I do my timings.
- I tried cutting the number of gradient and solid Paint-s to two each, but that didn't change anything.
Is there still something I may be doing wrong, or is drawRect() really slower with hardware acceleration? (Does this depend in any way on any of our drivers?)