Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "GraphicsJNI.h" |
| 18 | #include "ImageDecoder.h" |
Leon Scroggins III | 127d31a | 2018-01-19 12:29:47 -0500 | [diff] [blame] | 19 | #include "Utils.h" |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 20 | |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 21 | #include <SkAndroidCodec.h> |
| 22 | #include <SkAnimatedImage.h> |
| 23 | #include <SkColorFilter.h> |
| 24 | #include <SkPicture.h> |
| 25 | #include <SkPictureRecorder.h> |
Leon Scroggins III | 5b7f426 | 2018-01-26 11:03:54 -0500 | [diff] [blame] | 26 | #include <hwui/AnimatedImageDrawable.h> |
Leon Scroggins III | 753a56f | 2019-12-11 11:02:15 -0500 | [diff] [blame] | 27 | #include <hwui/ImageDecoder.h> |
Leon Scroggins III | 5b7f426 | 2018-01-26 11:03:54 -0500 | [diff] [blame] | 28 | #include <hwui/Canvas.h> |
Leon Scroggins III | beaf5d9 | 2018-01-26 11:03:54 -0500 | [diff] [blame] | 29 | #include <utils/Looper.h> |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 30 | |
| 31 | using namespace android; |
| 32 | |
John Reck | 3998a01 | 2021-07-28 11:04:30 -0400 | [diff] [blame^] | 33 | static jclass gAnimatedImageDrawableClass; |
| 34 | static jmethodID gAnimatedImageDrawable_callOnAnimationEndMethodID; |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 35 | |
| 36 | // Note: jpostProcess holds a handle to the ImageDecoder. |
| 37 | static jlong AnimatedImageDrawable_nCreate(JNIEnv* env, jobject /*clazz*/, |
| 38 | jlong nativeImageDecoder, jobject jpostProcess, |
Leon Scroggins III | eac1423 | 2019-02-04 10:30:22 -0500 | [diff] [blame] | 39 | jint width, jint height, jlong colorSpaceHandle, |
| 40 | jboolean extended, jobject jsubset) { |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 41 | if (nativeImageDecoder == 0) { |
| 42 | doThrowIOE(env, "Cannot create AnimatedImageDrawable from null!"); |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | auto* imageDecoder = reinterpret_cast<ImageDecoder*>(nativeImageDecoder); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 47 | SkIRect subset; |
| 48 | if (jsubset) { |
| 49 | GraphicsJNI::jrect_to_irect(env, jsubset, &subset); |
| 50 | } else { |
| 51 | subset = SkIRect::MakeWH(width, height); |
| 52 | } |
| 53 | |
Leon Scroggins III | eb3b38e | 2018-03-20 11:11:13 -0400 | [diff] [blame] | 54 | bool hasRestoreFrame = false; |
Leon Scroggins III | eac1423 | 2019-02-04 10:30:22 -0500 | [diff] [blame] | 55 | if (imageDecoder->mCodec->getEncodedFormat() != SkEncodedImageFormat::kWEBP) { |
Leon Scroggins III | eb3b38e | 2018-03-20 11:11:13 -0400 | [diff] [blame] | 56 | const int frameCount = imageDecoder->mCodec->codec()->getFrameCount(); |
| 57 | for (int i = 0; i < frameCount; ++i) { |
| 58 | SkCodec::FrameInfo frameInfo; |
| 59 | if (!imageDecoder->mCodec->codec()->getFrameInfo(i, &frameInfo)) { |
| 60 | doThrowIOE(env, "Failed to read frame info!"); |
| 61 | return 0; |
| 62 | } |
| 63 | if (frameInfo.fDisposalMethod == SkCodecAnimation::DisposalMethod::kRestorePrevious) { |
| 64 | hasRestoreFrame = true; |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
Leon Scroggins III | eac1423 | 2019-02-04 10:30:22 -0500 | [diff] [blame] | 70 | auto info = imageDecoder->mCodec->getInfo().makeWH(width, height) |
| 71 | .makeColorSpace(GraphicsJNI::getNativeColorSpace(colorSpaceHandle)); |
| 72 | if (extended) { |
| 73 | info = info.makeColorType(kRGBA_F16_SkColorType); |
| 74 | } |
| 75 | |
Leon Scroggins III | eb3b38e | 2018-03-20 11:11:13 -0400 | [diff] [blame] | 76 | size_t bytesUsed = info.computeMinByteSize(); |
| 77 | // SkAnimatedImage has one SkBitmap for decoding, plus an extra one if there is a |
| 78 | // kRestorePrevious frame. AnimatedImageDrawable has two SkPictures storing the current |
| 79 | // frame and the next frame. (The former assumes that the image is animated, and the |
| 80 | // latter assumes that it is drawn to a hardware canvas.) |
| 81 | bytesUsed *= hasRestoreFrame ? 4 : 3; |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 82 | sk_sp<SkPicture> picture; |
| 83 | if (jpostProcess) { |
| 84 | SkRect bounds = SkRect::MakeWH(subset.width(), subset.height()); |
| 85 | |
| 86 | SkPictureRecorder recorder; |
| 87 | SkCanvas* skcanvas = recorder.beginRecording(bounds); |
| 88 | std::unique_ptr<Canvas> canvas(Canvas::create_canvas(skcanvas)); |
Leon Scroggins III | e5de9aa | 2018-01-10 20:56:51 -0500 | [diff] [blame] | 89 | postProcessAndRelease(env, jpostProcess, std::move(canvas)); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 90 | if (env->ExceptionCheck()) { |
| 91 | return 0; |
| 92 | } |
| 93 | picture = recorder.finishRecordingAsPicture(); |
Leon Scroggins III | eb3b38e | 2018-03-20 11:11:13 -0400 | [diff] [blame] | 94 | bytesUsed += picture->approximateBytesUsed(); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 95 | } |
| 96 | |
Derek Sollenberger | 2d14213 | 2018-01-22 10:25:26 -0500 | [diff] [blame] | 97 | |
| 98 | sk_sp<SkAnimatedImage> animatedImg = SkAnimatedImage::Make(std::move(imageDecoder->mCodec), |
Leon Scroggins III | eac1423 | 2019-02-04 10:30:22 -0500 | [diff] [blame] | 99 | info, subset, |
Derek Sollenberger | 2d14213 | 2018-01-22 10:25:26 -0500 | [diff] [blame] | 100 | std::move(picture)); |
| 101 | if (!animatedImg) { |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 102 | doThrowIOE(env, "Failed to create drawable"); |
| 103 | return 0; |
| 104 | } |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 105 | |
Leon Scroggins III | eb3b38e | 2018-03-20 11:11:13 -0400 | [diff] [blame] | 106 | bytesUsed += sizeof(animatedImg.get()); |
| 107 | |
| 108 | sk_sp<AnimatedImageDrawable> drawable(new AnimatedImageDrawable(std::move(animatedImg), |
| 109 | bytesUsed)); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 110 | return reinterpret_cast<jlong>(drawable.release()); |
| 111 | } |
| 112 | |
| 113 | static void AnimatedImageDrawable_destruct(AnimatedImageDrawable* drawable) { |
Derek Sollenberger | 2d14213 | 2018-01-22 10:25:26 -0500 | [diff] [blame] | 114 | SkSafeUnref(drawable); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static jlong AnimatedImageDrawable_nGetNativeFinalizer(JNIEnv* /*env*/, jobject /*clazz*/) { |
| 118 | return static_cast<jlong>(reinterpret_cast<uintptr_t>(&AnimatedImageDrawable_destruct)); |
| 119 | } |
| 120 | |
Leon Scroggins III | 5b7f426 | 2018-01-26 11:03:54 -0500 | [diff] [blame] | 121 | // Java's FINISHED relies on this being -1 |
| 122 | static_assert(SkAnimatedImage::kFinished == -1); |
| 123 | |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 124 | static jlong AnimatedImageDrawable_nDraw(JNIEnv* env, jobject /*clazz*/, jlong nativePtr, |
Derek Sollenberger | 2d14213 | 2018-01-22 10:25:26 -0500 | [diff] [blame] | 125 | jlong canvasPtr) { |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 126 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 127 | auto* canvas = reinterpret_cast<Canvas*>(canvasPtr); |
Derek Sollenberger | 2d14213 | 2018-01-22 10:25:26 -0500 | [diff] [blame] | 128 | return (jlong) canvas->drawAnimatedImage(drawable); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void AnimatedImageDrawable_nSetAlpha(JNIEnv* env, jobject /*clazz*/, jlong nativePtr, |
| 132 | jint alpha) { |
| 133 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
Derek Sollenberger | 2d14213 | 2018-01-22 10:25:26 -0500 | [diff] [blame] | 134 | drawable->setStagingAlpha(alpha); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static jlong AnimatedImageDrawable_nGetAlpha(JNIEnv* env, jobject /*clazz*/, jlong nativePtr) { |
| 138 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
Derek Sollenberger | 2d14213 | 2018-01-22 10:25:26 -0500 | [diff] [blame] | 139 | return drawable->getStagingAlpha(); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static void AnimatedImageDrawable_nSetColorFilter(JNIEnv* env, jobject /*clazz*/, jlong nativePtr, |
| 143 | jlong nativeFilter) { |
| 144 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
| 145 | auto* filter = reinterpret_cast<SkColorFilter*>(nativeFilter); |
Derek Sollenberger | 2d14213 | 2018-01-22 10:25:26 -0500 | [diff] [blame] | 146 | drawable->setStagingColorFilter(sk_ref_sp(filter)); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static jboolean AnimatedImageDrawable_nIsRunning(JNIEnv* env, jobject /*clazz*/, jlong nativePtr) { |
| 150 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
Derek Sollenberger | 2d14213 | 2018-01-22 10:25:26 -0500 | [diff] [blame] | 151 | return drawable->isRunning(); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 152 | } |
| 153 | |
Leon Scroggins III | 057c91a | 2018-01-24 13:02:16 -0500 | [diff] [blame] | 154 | static jboolean AnimatedImageDrawable_nStart(JNIEnv* env, jobject /*clazz*/, jlong nativePtr) { |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 155 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
Leon Scroggins III | 057c91a | 2018-01-24 13:02:16 -0500 | [diff] [blame] | 156 | return drawable->start(); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 157 | } |
| 158 | |
Leon Scroggins III | beaf5d9 | 2018-01-26 11:03:54 -0500 | [diff] [blame] | 159 | static jboolean AnimatedImageDrawable_nStop(JNIEnv* env, jobject /*clazz*/, jlong nativePtr) { |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 160 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
Leon Scroggins III | beaf5d9 | 2018-01-26 11:03:54 -0500 | [diff] [blame] | 161 | return drawable->stop(); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Leon Scroggins III | 127d31a | 2018-01-19 12:29:47 -0500 | [diff] [blame] | 164 | // Java's LOOP_INFINITE relies on this being the same. |
| 165 | static_assert(SkCodec::kRepetitionCountInfinite == -1); |
| 166 | |
Leon Scroggins III | 6de55b8 | 2018-02-23 16:11:37 -0500 | [diff] [blame] | 167 | static jint AnimatedImageDrawable_nGetRepeatCount(JNIEnv* env, jobject /*clazz*/, jlong nativePtr) { |
Leon Scroggins III | 1474b78 | 2018-02-23 09:38:12 -0500 | [diff] [blame] | 168 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
| 169 | return drawable->getRepetitionCount(); |
| 170 | } |
| 171 | |
Leon Scroggins III | 6de55b8 | 2018-02-23 16:11:37 -0500 | [diff] [blame] | 172 | static void AnimatedImageDrawable_nSetRepeatCount(JNIEnv* env, jobject /*clazz*/, jlong nativePtr, |
| 173 | jint loopCount) { |
Leon Scroggins III | 127d31a | 2018-01-19 12:29:47 -0500 | [diff] [blame] | 174 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
| 175 | drawable->setRepetitionCount(loopCount); |
| 176 | } |
| 177 | |
Leon Scroggins III | beaf5d9 | 2018-01-26 11:03:54 -0500 | [diff] [blame] | 178 | class InvokeListener : public MessageHandler { |
Leon Scroggins III | 127d31a | 2018-01-19 12:29:47 -0500 | [diff] [blame] | 179 | public: |
Leon Scroggins III | beaf5d9 | 2018-01-26 11:03:54 -0500 | [diff] [blame] | 180 | InvokeListener(JNIEnv* env, jobject javaObject) { |
Leon Scroggins III | 127d31a | 2018-01-19 12:29:47 -0500 | [diff] [blame] | 181 | LOG_ALWAYS_FATAL_IF(env->GetJavaVM(&mJvm) != JNI_OK); |
John Reck | 3998a01 | 2021-07-28 11:04:30 -0400 | [diff] [blame^] | 182 | mCallbackRef = env->NewGlobalRef(javaObject); |
Leon Scroggins III | 127d31a | 2018-01-19 12:29:47 -0500 | [diff] [blame] | 183 | } |
| 184 | |
Leon Scroggins III | beaf5d9 | 2018-01-26 11:03:54 -0500 | [diff] [blame] | 185 | ~InvokeListener() override { |
Leon Scroggins III | f97b29d2 | 2020-04-06 12:01:01 -0400 | [diff] [blame] | 186 | auto* env = requireEnv(mJvm); |
John Reck | 3998a01 | 2021-07-28 11:04:30 -0400 | [diff] [blame^] | 187 | env->DeleteGlobalRef(mCallbackRef); |
Leon Scroggins III | 127d31a | 2018-01-19 12:29:47 -0500 | [diff] [blame] | 188 | } |
| 189 | |
Leon Scroggins III | beaf5d9 | 2018-01-26 11:03:54 -0500 | [diff] [blame] | 190 | virtual void handleMessage(const Message&) override { |
Leon Scroggins III | 127d31a | 2018-01-19 12:29:47 -0500 | [diff] [blame] | 191 | auto* env = get_env_or_die(mJvm); |
John Reck | 3998a01 | 2021-07-28 11:04:30 -0400 | [diff] [blame^] | 192 | env->CallStaticVoidMethod(gAnimatedImageDrawableClass, |
| 193 | gAnimatedImageDrawable_callOnAnimationEndMethodID, mCallbackRef); |
Leon Scroggins III | 127d31a | 2018-01-19 12:29:47 -0500 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | private: |
| 197 | JavaVM* mJvm; |
John Reck | 3998a01 | 2021-07-28 11:04:30 -0400 | [diff] [blame^] | 198 | jobject mCallbackRef; |
Leon Scroggins III | beaf5d9 | 2018-01-26 11:03:54 -0500 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | class JniAnimationEndListener : public OnAnimationEndListener { |
| 202 | public: |
| 203 | JniAnimationEndListener(sp<Looper>&& looper, JNIEnv* env, jobject javaObject) { |
| 204 | mListener = new InvokeListener(env, javaObject); |
| 205 | mLooper = std::move(looper); |
| 206 | } |
| 207 | |
| 208 | void onAnimationEnd() override { mLooper->sendMessage(mListener, 0); } |
| 209 | |
| 210 | private: |
| 211 | sp<InvokeListener> mListener; |
| 212 | sp<Looper> mLooper; |
Leon Scroggins III | 127d31a | 2018-01-19 12:29:47 -0500 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | static void AnimatedImageDrawable_nSetOnAnimationEndListener(JNIEnv* env, jobject /*clazz*/, |
| 216 | jlong nativePtr, jobject jdrawable) { |
| 217 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
Leon Scroggins III | beaf5d9 | 2018-01-26 11:03:54 -0500 | [diff] [blame] | 218 | if (!jdrawable) { |
| 219 | drawable->setOnAnimationEndListener(nullptr); |
| 220 | } else { |
| 221 | sp<Looper> looper = Looper::getForThread(); |
| 222 | if (!looper.get()) { |
| 223 | doThrowISE(env, |
| 224 | "Must set AnimatedImageDrawable's AnimationCallback on a thread with a " |
| 225 | "looper!"); |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | drawable->setOnAnimationEndListener( |
| 230 | std::make_unique<JniAnimationEndListener>(std::move(looper), env, jdrawable)); |
| 231 | } |
Leon Scroggins III | 127d31a | 2018-01-19 12:29:47 -0500 | [diff] [blame] | 232 | } |
| 233 | |
Leon Scroggins III | eb3b38e | 2018-03-20 11:11:13 -0400 | [diff] [blame] | 234 | static jlong AnimatedImageDrawable_nNativeByteSize(JNIEnv* env, jobject /*clazz*/, jlong nativePtr) { |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 235 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
Leon Scroggins III | eb3b38e | 2018-03-20 11:11:13 -0400 | [diff] [blame] | 236 | return drawable->byteSize(); |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 237 | } |
| 238 | |
Leon Scroggins III | 5e8447f | 2018-03-05 14:22:51 -0500 | [diff] [blame] | 239 | static void AnimatedImageDrawable_nSetMirrored(JNIEnv* env, jobject /*clazz*/, jlong nativePtr, |
| 240 | jboolean mirrored) { |
| 241 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
| 242 | drawable->setStagingMirrored(mirrored); |
| 243 | } |
| 244 | |
Leon Scroggins III | be969ef | 2021-01-20 15:28:39 -0500 | [diff] [blame] | 245 | static void AnimatedImageDrawable_nSetBounds(JNIEnv* env, jobject /*clazz*/, jlong nativePtr, |
| 246 | jobject jrect) { |
| 247 | auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr); |
| 248 | SkRect rect; |
| 249 | GraphicsJNI::jrect_to_rect(env, jrect, &rect); |
| 250 | drawable->setStagingBounds(rect); |
| 251 | } |
| 252 | |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 253 | static const JNINativeMethod gAnimatedImageDrawableMethods[] = { |
John Reck | 3998a01 | 2021-07-28 11:04:30 -0400 | [diff] [blame^] | 254 | {"nCreate", "(JLandroid/graphics/ImageDecoder;IIJZLandroid/graphics/Rect;)J", |
| 255 | (void*)AnimatedImageDrawable_nCreate}, |
| 256 | {"nGetNativeFinalizer", "()J", (void*)AnimatedImageDrawable_nGetNativeFinalizer}, |
| 257 | {"nDraw", "(JJ)J", (void*)AnimatedImageDrawable_nDraw}, |
| 258 | {"nSetAlpha", "(JI)V", (void*)AnimatedImageDrawable_nSetAlpha}, |
| 259 | {"nGetAlpha", "(J)I", (void*)AnimatedImageDrawable_nGetAlpha}, |
| 260 | {"nSetColorFilter", "(JJ)V", (void*)AnimatedImageDrawable_nSetColorFilter}, |
| 261 | {"nIsRunning", "(J)Z", (void*)AnimatedImageDrawable_nIsRunning}, |
| 262 | {"nStart", "(J)Z", (void*)AnimatedImageDrawable_nStart}, |
| 263 | {"nStop", "(J)Z", (void*)AnimatedImageDrawable_nStop}, |
| 264 | {"nGetRepeatCount", "(J)I", (void*)AnimatedImageDrawable_nGetRepeatCount}, |
| 265 | {"nSetRepeatCount", "(JI)V", (void*)AnimatedImageDrawable_nSetRepeatCount}, |
| 266 | {"nSetOnAnimationEndListener", "(JLjava/lang/ref/WeakReference;)V", |
| 267 | (void*)AnimatedImageDrawable_nSetOnAnimationEndListener}, |
| 268 | {"nNativeByteSize", "(J)J", (void*)AnimatedImageDrawable_nNativeByteSize}, |
| 269 | {"nSetMirrored", "(JZ)V", (void*)AnimatedImageDrawable_nSetMirrored}, |
| 270 | {"nSetBounds", "(JLandroid/graphics/Rect;)V", (void*)AnimatedImageDrawable_nSetBounds}, |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 271 | }; |
| 272 | |
| 273 | int register_android_graphics_drawable_AnimatedImageDrawable(JNIEnv* env) { |
John Reck | 3998a01 | 2021-07-28 11:04:30 -0400 | [diff] [blame^] | 274 | gAnimatedImageDrawableClass = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 275 | FindClassOrDie(env, "android/graphics/drawable/AnimatedImageDrawable"))); |
| 276 | gAnimatedImageDrawable_callOnAnimationEndMethodID = |
| 277 | GetStaticMethodIDOrDie(env, gAnimatedImageDrawableClass, "callOnAnimationEnd", |
| 278 | "(Ljava/lang/ref/WeakReference;)V"); |
Leon Scroggins III | 127d31a | 2018-01-19 12:29:47 -0500 | [diff] [blame] | 279 | |
Leon Scroggins III | 671cce2 | 2018-01-14 16:52:17 -0500 | [diff] [blame] | 280 | return android::RegisterMethodsOrDie(env, "android/graphics/drawable/AnimatedImageDrawable", |
| 281 | gAnimatedImageDrawableMethods, NELEM(gAnimatedImageDrawableMethods)); |
| 282 | } |
| 283 | |