1

I just started making some of my first live wallpapers in Android, and I noticed an interesting behavior regarding the PixelFormat. If I use the SurfaceHolder's default PixelFormat, my live wallpaper is a bit laggy. If I set the PixelFormat to RGB_565 it seems to fix this problem. This really should not be too surprising. What was odd was profiling reveal that it was taking just as long to do the rendering in both formats. Could anyone explain this behavior.

Thanks, Xor

---Edit--- If it of any help, I am rendering on a Canvas. All I do is call drawColor and draw 3 fairly simple, anti-aliased paths. Not really much to it.

Steven Roberts
  • 300
  • 1
  • 3
  • 14

1 Answers1

2

PixelFormat shouldn't be a problem. You should be even able to set PixelFormat.RGBA_8888 with no performance hiccups. In some cases this format is useful to reduce color banding on gradients.

Using Handler for animation may be good for simple cases, but you should consider using separate thread for this task. Some time ago I've prepared simple live wallpaper template. You can download whole project for GitHub and experiment a bit with it. I'm sure that you'll get much better performance.

Chiral Code
  • 1,426
  • 2
  • 12
  • 12
  • Thanks for the answer, but it does not tell me what is causing the performance difference. I will take a look into your template, and see what I can find – Steven Roberts Dec 24 '13 at 20:50
  • See this answer: http://stackoverflow.com/questions/8829943/how-to-find-the-best-pixelformat-for-an-android-surfaceview – Chiral Code Dec 24 '13 at 21:02
  • After taking a look at your code, it appears your SurfaceHolder in the AnimationThread is accessed concurrently without synchronization. Generally SurfaceViews use the SurfaceHolder as a lock when updating the state and graphics. Could you explain this? I'm probably overlooking something. – Steven Roberts Dec 24 '13 at 21:02
  • I'm using Scene object for the same thing. – Chiral Code Dec 24 '13 at 21:13
  • Ok, I try not using the handler. Perhaps it will avoid the problem altogether. – Steven Roberts Dec 24 '13 at 21:22