-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reviewed By: oprisnik Differential Revision: D8940188 fbshipit-source-id: de8186e95058214cbca263d53e50cc4d945c0490
- Loading branch information
1 parent
5d271f3
commit 2116559
Showing
3 changed files
with
67 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
animated-gif-lite/src/main/java/com/facebook/animated/giflite/MovieDrawer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
package com.facebook.animated.giflite; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.Canvas; | ||
import android.graphics.Movie; | ||
import android.support.annotation.Nullable; | ||
|
||
/** | ||
* Pronounced Draw-er Draws frames of a {@link Movie} to a bitmap. All methods are synchronized, so | ||
* can be used in parallel. The underlying {@link #mMovie} is not threadsafe, and should therefore | ||
* not be accessed outside of {@link MovieDrawer}. Attempts to optimize work done by the drawing | ||
* {@link Canvas} by detecting if the underlying {@link Bitmap} has changed. | ||
*/ | ||
class MovieDrawer { | ||
|
||
private final Movie mMovie; | ||
private final MovieScaleHolder mScaleHolder; | ||
private final Canvas mCanvas; | ||
|
||
private @Nullable Bitmap mPreviousBitmap; | ||
|
||
public MovieDrawer(Movie movie) { | ||
mMovie = movie; | ||
mScaleHolder = new MovieScaleHolder(movie.width(), movie.height()); | ||
mCanvas = new Canvas(); | ||
} | ||
|
||
public synchronized void drawFrame(int movieTime, int w, int h, Bitmap bitmap) { | ||
mMovie.setTime(movieTime); | ||
|
||
if (mPreviousBitmap != null && mPreviousBitmap.isRecycled()) { | ||
mPreviousBitmap = null; | ||
} | ||
if (mPreviousBitmap != bitmap) { | ||
mPreviousBitmap = bitmap; | ||
mCanvas.setBitmap(bitmap); | ||
} | ||
|
||
mScaleHolder.updateViewPort(w, h); | ||
|
||
mCanvas.save(); | ||
mCanvas.scale(mScaleHolder.getScale(), mScaleHolder.getScale()); | ||
mMovie.draw(mCanvas, mScaleHolder.getLeft(), mScaleHolder.getTop()); | ||
mCanvas.restore(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters