Skip to content

Commit

Permalink
Have software rendering fallback on hardware acceleration when too la…
Browse files Browse the repository at this point in the history
…rge (#1190)

In cases where LottieAnimationView is large and software rendering is used, Android may not be able to generate a bitmap large enough which causes nothing to be shown. Rather than have this happen, fall back on hardware acceleration which is supported > api 11. Potentially taking a perf hit and displaying is better than a blank screen and not displaying at all.

Encountered this where upon rotation on a tablet, the view became big enough that generation of the bitmap failed.
  • Loading branch information
podarsmarty authored and gpeal committed Apr 25, 2019
1 parent 423c336 commit 4511815
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import java.util.List;
import java.util.Set;

import static com.airbnb.lottie.RenderMode.HARDWARE;
import static com.airbnb.lottie.RenderMode.SOFTWARE;

/**
* This view will load, deserialize, and display an After Effects animation exported with
* bodymovin (https://github.com/bodymovin/bodymovin).
Expand Down Expand Up @@ -806,6 +809,21 @@ private void clearComposition() {
lottieDrawable.clearComposition();
}

/**
* If rendering via software, Android will fail to generate a bitmap if the view is too large. Rather than displaying
* nothing, fallback on hardware acceleration which may incur a performance hit.
*
* @see #setRenderMode(RenderMode)
* @see com.airbnb.lottie.LottieDrawable#draw(android.graphics.Canvas)
*/
@Override
public void buildDrawingCache(boolean autoScale) {
super.buildDrawingCache(autoScale);
if (getLayerType() == LAYER_TYPE_SOFTWARE && getDrawingCache(autoScale) == null) {
setRenderMode(HARDWARE);
}
}

/**
* Call this to set whether or not to render with hardware or software acceleration.
* Lottie defaults to Automatic which will use hardware acceleration unless:
Expand Down

0 comments on commit 4511815

Please sign in to comment.