Merge "Fix start/pause behavior for AnimatedImageDrawable"
This commit is contained in:
committed by
Android (Google) Code Review
commit
6834ec8e54
@@ -72,7 +72,6 @@ static jlong AnimatedImageDrawable_nCreate(JNIEnv* env, jobject /*clazz*/,
|
||||
}
|
||||
|
||||
sk_sp<AnimatedImageDrawable> drawable(new AnimatedImageDrawable(animatedImg));
|
||||
drawable->start();
|
||||
return reinterpret_cast<jlong>(drawable.release());
|
||||
}
|
||||
|
||||
@@ -114,9 +113,9 @@ static jboolean AnimatedImageDrawable_nIsRunning(JNIEnv* env, jobject /*clazz*/,
|
||||
return drawable->isRunning();
|
||||
}
|
||||
|
||||
static void AnimatedImageDrawable_nStart(JNIEnv* env, jobject /*clazz*/, jlong nativePtr) {
|
||||
static jboolean AnimatedImageDrawable_nStart(JNIEnv* env, jobject /*clazz*/, jlong nativePtr) {
|
||||
auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr);
|
||||
drawable->start();
|
||||
return drawable->start();
|
||||
}
|
||||
|
||||
static void AnimatedImageDrawable_nStop(JNIEnv* env, jobject /*clazz*/, jlong nativePtr) {
|
||||
@@ -138,7 +137,7 @@ static const JNINativeMethod gAnimatedImageDrawableMethods[] = {
|
||||
{ "nGetAlpha", "(J)I", (void*) AnimatedImageDrawable_nGetAlpha },
|
||||
{ "nSetColorFilter", "(JJ)V", (void*) AnimatedImageDrawable_nSetColorFilter },
|
||||
{ "nIsRunning", "(J)Z", (void*) AnimatedImageDrawable_nIsRunning },
|
||||
{ "nStart", "(J)V", (void*) AnimatedImageDrawable_nStart },
|
||||
{ "nStart", "(J)Z", (void*) AnimatedImageDrawable_nStart },
|
||||
{ "nStop", "(J)V", (void*) AnimatedImageDrawable_nStop },
|
||||
{ "nNativeByteSize", "(J)J", (void*) AnimatedImageDrawable_nNativeByteSize },
|
||||
};
|
||||
|
||||
@@ -166,8 +166,7 @@ public class AnimatedImageDrawable extends Drawable implements Animatable {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (isRunning() == false) {
|
||||
nStart(mNativePtr);
|
||||
if (nStart(mNativePtr)) {
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
@@ -186,7 +185,7 @@ public class AnimatedImageDrawable extends Drawable implements Animatable {
|
||||
private static native int nGetAlpha(long nativePtr);
|
||||
private static native void nSetColorFilter(long nativePtr, long nativeFilter);
|
||||
private static native boolean nIsRunning(long nativePtr);
|
||||
private static native void nStart(long nativePtr);
|
||||
private static native boolean nStart(long nativePtr);
|
||||
private static native void nStop(long nativePtr);
|
||||
private static native long nNativeByteSize(long nativePtr);
|
||||
}
|
||||
|
||||
@@ -36,18 +36,27 @@ void AnimatedImageDrawable::syncProperties() {
|
||||
mColorFilter = mStagingColorFilter;
|
||||
}
|
||||
|
||||
void AnimatedImageDrawable::start() {
|
||||
bool AnimatedImageDrawable::start() {
|
||||
SkAutoExclusive lock(mLock);
|
||||
if (mSkAnimatedImage->isRunning()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mSnapshot.reset(mSkAnimatedImage->newPictureSnapshot());
|
||||
if (!mSnapshot) {
|
||||
mSnapshot.reset(mSkAnimatedImage->newPictureSnapshot());
|
||||
}
|
||||
|
||||
// While stopped, update() does not decode, but it does advance the time.
|
||||
// This prevents us from skipping ahead when we resume.
|
||||
const double currentTime = SkTime::GetMSecs();
|
||||
mSkAnimatedImage->update(currentTime);
|
||||
mSkAnimatedImage->start();
|
||||
return mSkAnimatedImage->isRunning();
|
||||
}
|
||||
|
||||
void AnimatedImageDrawable::stop() {
|
||||
SkAutoExclusive lock(mLock);
|
||||
mSkAnimatedImage->stop();
|
||||
mSnapshot.reset(nullptr);
|
||||
}
|
||||
|
||||
bool AnimatedImageDrawable::isRunning() {
|
||||
@@ -120,7 +129,7 @@ void AnimatedImageDrawable::onDraw(SkCanvas* canvas) {
|
||||
}
|
||||
|
||||
SkAutoExclusive lock(mLock);
|
||||
if (mSkAnimatedImage->isRunning()) {
|
||||
if (mSnapshot) {
|
||||
canvas->drawPicture(mSnapshot, nullptr, lazyPaint.getMaybeNull());
|
||||
} else {
|
||||
// TODO: we could potentially keep the cached surface around if there is a paint and we know
|
||||
|
||||
@@ -58,7 +58,8 @@ public:
|
||||
|
||||
double drawStaging(SkCanvas* canvas);
|
||||
|
||||
void start();
|
||||
// Returns true if the animation was started; false otherwise (e.g. it was already running)
|
||||
bool start();
|
||||
void stop();
|
||||
bool isRunning();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user