Canvas.drawRect() slower with android:hardwareAccelerated?

425 views
Skip to first unread message

Jon Shemitz

unread,
Mar 18, 2011, 9:25:09 PM3/18/11
to android-...@googlegroups.com
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?)

Rémi Coulom

unread,
Sep 29, 2013, 6:32:28 PM9/29/13
to android-...@googlegroups.com, she...@gmail.com
Hi,

This is a very old post, but I ran into the same problem, and can report some more details.

I had problems when drawing large rectangles with hardware acceleration. I did not really care about performance. My problem was that the logcat had a message that said "Shape rect too large to be rendered into a texture". So I replaced the drawRect() by 4 equivalent drawLines()'s (I was not filling the rect). Not only did the error message go away, but performance improved considerably!

Maybe that's supposed to be the normal behaviour, but I'd rather call it a bug. Failing to draw a rect because it is too large is really a very bad excuse in my opinion. Drawing large rects should be easy for any android.

Rémi
Reply all
Reply to author
Forward
0 new messages