Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Live Wallpapers -- OpenGL vs Canvas

I am a fairly "newb" Android developer, and I would like one of my first projects to be a live wallpaper, however I am conflicted on whether I should be focusing on Canvas or OpenGL for it. Being new to this I know I should master Canvas first since it is easier to use, but I prefer to learn from real world projects that I have an interest in, even if it's a little backwards at times.

I have used both before in very basic ways, and I understand the general concepts to them, but I am not sure how they transfer over to the realm of live wallpapers. I figure that the full blown speed of OpenGL isn't required on a live wallpaper, since running it at max FPS would just run down the battery more than it necessary, but at the same time I am worried that using Canvas would cause lags and stutters when doing things like changing home screens.

I have been leaning towards using OpenGL ES 2.0, both to keep performance optimal and because my initial ideas for the wallpaper involve a lot of layering that I am not sure Canvas is capable of, but I'd like a more experienced developers opinion on whether or not all of the extra work involved in using OpenGL (especially in relation to live wallpapers, from what I've read) is worth it.

like image 750
Shamrock Avatar asked Jun 26 '11 17:06

Shamrock


People also ask

Does Live wallpaper affect performance Android?

Live wallpapers don't draw a lot of power if they are well crafted, if you don't spend a lot of time on your home screen, and if you set your screen to shut off fairly soon after you stop interacting with it.

What are the disadvantages of live wallpaper?

Firstly, live wallpapers are always running on the home screen– they are almost like a video playing behind the screen, and thus take processing power (and RAM too). Not only does this result in the device becoming slower due to the loss in processing power, they also consume battery due to their continuous operation.

Does Android still have live wallpaper?

You can make a live wallpaper on iPhone using live photos or on Android using a third-party app. If you want to convert a video to a live wallpaper on either iPhone or Android, you'll need a separate app. Those who want to use a video from TikTok or a GIF will have to convert them to live photos first.


2 Answers

If you can get away with just drawing to a canvas (e.g. cube example in SDK), that's much less work. Because of the simplicity of the animation (no bitmaps), the cube is able to achieve a high frame rate without difficulty.

If you want to use OpenGL, you will need to use a supplemental package, such as GLWallpaperService, AndEngine, or RenderScript.

http://www.rbgrn.net/content/354-glsurfaceview-adapted-3d-live-wallpapers

http://www.andengine.org/forums/tutorials/live-wallpaper-template-t258.html

Browse the Android source code to see how the stock wallpapers (e.g. Grass, Galaxy) are implemented using RenderScript. This link may work, but no guarantees: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.1.1_r1/com/android/wallpaper/ (then scroll down to the wallpapers)

Moonblink has discontinued his project, but if you're really keen, you can try researching his work (Substrate) starting here: http://code.google.com/p/moonblink/source/browse/wiki/Setup.wiki

like image 65
George Freeman Avatar answered Sep 28 '22 03:09

George Freeman


I ended up using OpenGL as halfway through the project, canvas drawing proved to be too slow for what I was trying to achieve. Using OpenGL caused a massive performance boost. Unfortunately I had to refactor my code, so I would reccomend using OpenGL from the start. Dirty rendering is supported by OpenGL as well as the wallpaperservice's structure doesn't rely on the way you render things so you would still be able to create a wallpaper that doesn't drain the battery. Actually a well programmed wallpaper doesn't render when it's hidden. As the wallpapers shipped with android don't follow that pattern, live wallpapers now have the bad name of being battery suckers. Really a shame..

like image 22
Will Kru Avatar answered Sep 28 '22 04:09

Will Kru