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