Denizen
Denizen

Reputation: 335

Hardware Accelerated Canvas

I an currently working on an intensive LiveWallpaper that draws to the canvas. I happened upon the following video: http://www.youtube.com/watch?v=v9S5EO7CLjo.

However when I tried to implement hardware acceleration, I get errors. Here is my code:

if (c != null && mStaticRects.length > 10 && c.isHardwareAccelerated())
                    drawSurfacePortrait(c);

if (c != null && mStaticRects.length < 20 && c.isHardwareAccelerated())
                    drawSurfaceLandscape(c);

When I run this, here is the corresponding error:

AndroidRuntime(382): java.lang.NoSuchMethodError: android.graphics.Canvas.isHardwareAccelerated

and finally here is my Manifest...

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="stuff.of.mine"
    android:versionCode="1"
    android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.VIBRATE" ></uses-permission>


<uses-feature
    android:name="android.software.live_wallpaper"
    android:required="true" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" 
    ***android:hardwareAccelerated="true"***>
    <service
        android:name=".SomeWPService"
        android:permission="android.permission.BIND_WALLPAPER" 
        ***android:hardwareAccelerated="true"***>
        <intent-filter>
            <action android:name="android.service.wallpaper.WallpaperService" />
        </intent-filter>

        <meta-data
            android:name="android.service.wallpaper"
            android:resource="@xml/mylwp" />
    </service>

</application>

Upvotes: 1

Views: 3412

Answers (3)

Mayur R. Amipara
Mayur R. Amipara

Reputation: 1223

You can control hardware acceleration at the following levels:

  • Application
  • Activity
  • Window
  • View

in your code,

<service
        android:name=".SomeWPService"
        android:permission="android.permission.BIND_WALLPAPER" 
        ***android:hardwareAccelerated="true"***>

service tag doesn't contain android:hardwareAccelerated !

Upvotes: 1

Denizen
Denizen

Reputation: 335

Ok, I was searching around stackoverflow and stumbled upon the answer to my own question

In fact, Romain Guy, one of the guys in the video answered on the following thread:

Canvas in SurfaceView - hardware acceleration

He says:

A Canvas returned by SurfaceView.lockCanvas() cannot be hardware accelerated at the moment.

What I want to know is how you can create a live wallpaper without SurfaceView.lock and unlockCanvas?

Upvotes: 5

Ben Ruijl
Ben Ruijl

Reputation: 5123

canvas.isHardwareAcceleratedis introduced in API 11 and your minSdkVersion is 7. Try changing that to 11.

Upvotes: 3

Related Questions