Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial invalidation in custom Android view with hardware acceleration

Tags:

android

I've got a custom View in my application which fills the entire activity.

In most cases, when I want to refresh the control I call invalidate() without any parameters.

However, in certain circumstances, where I'm only changing a small area of the control, I call invalidate(Rect) to avoid redrawing the entire screen. This is important because in these situations I need the update to be as fast as possible.

This seems to work fine, however, when I enable hardware acceleration in Honeycomb (i.e. set android:hardwareAccelerated="true"in AndroidManifest.xml), the partial redraw does not seem to work.

This can be seen if I do Log.d("FOO", canvas.getClipBounds()) in my onDraw() method; the output simply shows that the whole control is being updated, whereas with hardware acceleration disabled, I get the correct region being output.

Is there any way to make partial invalidation work when using hardware acceleraton?

Many thanks, Matt

like image 956
Matt Holgate Avatar asked Aug 29 '11 17:08

Matt Holgate


People also ask

Should I turn on hardware acceleration on android?

Hardware acceleration is enabled by default if your Target API level is >=14, but can also be explicitly enabled. If your application uses only standard views and Drawable s, turning it on globally should not cause any adverse drawing effects.

How do I enable hardware acceleration on my android?

We can enable hardware acceleration at application level by adding “android : hardwareAccelerated” attribute to application tag.

What is tethering hardware acceleration?

What is Tethering Hardware Acceleration? Tethering hardware acceleration refers to the transfer of tethering traffic onto hardware via a direct path between the modem and peripherals in order to improve a device's performance and decrease power consumption.


1 Answers

Partial redraw works just fine, only the specified region of the screen will get redrawn. What it won't do however is change the clip bounds on the Canvas. All the drawing operations will be recorded but only the ones intersecting with the dirty region will actually be executed.

Update: as of Lollipop (API 21), partial invalidation happens at the View level (i.e. you cannot invalidate less than an entire View).

like image 111
Romain Guy Avatar answered Oct 22 '22 15:10

Romain Guy