Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | #define LOG_TAG "BitmapRegionDecoder" |
| 18 | |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame^] | 19 | #include "AutoDecodeCancel.h" |
| 20 | #include "BitmapFactory.h" |
| 21 | #include "CreateJavaOutputStreamAdaptor.h" |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 22 | #include "SkBitmap.h" |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 23 | #include "SkData.h" |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 24 | #include "GraphicsJNI.h" |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame^] | 25 | #include "SkImageEncoder.h" |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 26 | #include "SkUtils.h" |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 27 | #include "SkPixelRef.h" |
| 28 | #include "SkStream.h" |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 29 | #include "Utils.h" |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 30 | #include "android_nio_utils.h" |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame^] | 31 | #include "android_util_Binder.h" |
| 32 | #include "core_jni_helpers.h" |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 33 | |
Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame^] | 34 | #include <JNIHelp.h> |
| 35 | #include <androidfw/Asset.h> |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 36 | #include <binder/Parcel.h> |
| 37 | #include <jni.h> |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 38 | #include <sys/stat.h> |
| 39 | |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 40 | using namespace android; |
| 41 | |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 42 | class SkBitmapRegionDecoder { |
| 43 | public: |
| 44 | SkBitmapRegionDecoder(SkImageDecoder* decoder, int width, int height) { |
| 45 | fDecoder = decoder; |
| 46 | fWidth = width; |
| 47 | fHeight = height; |
| 48 | } |
| 49 | ~SkBitmapRegionDecoder() { |
| 50 | SkDELETE(fDecoder); |
| 51 | } |
| 52 | |
| 53 | bool decodeRegion(SkBitmap* bitmap, const SkIRect& rect, |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 54 | SkColorType pref, int sampleSize) { |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 55 | fDecoder->setSampleSize(sampleSize); |
Leon Scroggins | cc11f15 | 2014-03-31 16:52:13 -0400 | [diff] [blame] | 56 | return fDecoder->decodeSubset(bitmap, rect, pref); |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | SkImageDecoder* getDecoder() const { return fDecoder; } |
| 60 | int getWidth() const { return fWidth; } |
| 61 | int getHeight() const { return fHeight; } |
| 62 | |
| 63 | private: |
| 64 | SkImageDecoder* fDecoder; |
| 65 | int fWidth; |
| 66 | int fHeight; |
| 67 | }; |
| 68 | |
Leon Scroggins III | 3449789 | 2015-01-20 15:52:43 -0500 | [diff] [blame] | 69 | // Takes ownership of the SkStreamRewindable. For consistency, deletes stream even |
| 70 | // when returning null. |
Derek Sollenberger | ed79ff0 | 2013-11-20 14:50:51 -0500 | [diff] [blame] | 71 | static jobject createBitmapRegionDecoder(JNIEnv* env, SkStreamRewindable* stream) { |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 72 | SkImageDecoder* decoder = SkImageDecoder::Factory(stream); |
| 73 | int width, height; |
| 74 | if (NULL == decoder) { |
Leon Scroggins III | 3449789 | 2015-01-20 15:52:43 -0500 | [diff] [blame] | 75 | SkDELETE(stream); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 76 | doThrowIOE(env, "Image format not supported"); |
| 77 | return nullObjectReturn("SkImageDecoder::Factory returned null"); |
| 78 | } |
| 79 | |
Patrick Dubroy | e4ac2d6 | 2010-12-01 11:23:13 -0800 | [diff] [blame] | 80 | JavaPixelAllocator *javaAllocator = new JavaPixelAllocator(env); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 81 | decoder->setAllocator(javaAllocator); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 82 | javaAllocator->unref(); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 83 | |
Leon Scroggins III | 3449789 | 2015-01-20 15:52:43 -0500 | [diff] [blame] | 84 | // This call passes ownership of stream to the decoder, or deletes on failure. |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 85 | if (!decoder->buildTileIndex(stream, &width, &height)) { |
| 86 | char msg[100]; |
| 87 | snprintf(msg, sizeof(msg), "Image failed to decode using %s decoder", |
| 88 | decoder->getFormatName()); |
| 89 | doThrowIOE(env, msg); |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 90 | SkDELETE(decoder); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 91 | return nullObjectReturn("decoder->buildTileIndex returned false"); |
| 92 | } |
| 93 | |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 94 | SkBitmapRegionDecoder *bm = new SkBitmapRegionDecoder(decoder, width, height); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 95 | return GraphicsJNI::createBitmapRegionDecoder(env, bm); |
| 96 | } |
| 97 | |
| 98 | static jobject nativeNewInstanceFromByteArray(JNIEnv* env, jobject, jbyteArray byteArray, |
Ashok Bhat | b091d47 | 2014-01-08 14:32:49 +0000 | [diff] [blame] | 99 | jint offset, jint length, jboolean isShareable) { |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 100 | /* If isShareable we could decide to just wrap the java array and |
| 101 | share it, but that means adding a globalref to the java array object |
| 102 | For now we just always copy the array's data if isShareable. |
| 103 | */ |
| 104 | AutoJavaByteArray ar(env, byteArray); |
Derek Sollenberger | ed79ff0 | 2013-11-20 14:50:51 -0500 | [diff] [blame] | 105 | SkMemoryStream* stream = new SkMemoryStream(ar.ptr() + offset, length, true); |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 106 | |
Leon Scroggins III | 3449789 | 2015-01-20 15:52:43 -0500 | [diff] [blame] | 107 | // the decoder owns the stream. |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 108 | jobject brd = createBitmapRegionDecoder(env, stream); |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 109 | return brd; |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static jobject nativeNewInstanceFromFileDescriptor(JNIEnv* env, jobject clazz, |
| 113 | jobject fileDescriptor, jboolean isShareable) { |
| 114 | NPE_CHECK_RETURN_ZERO(env, fileDescriptor); |
| 115 | |
Elliott Hughes | a3804cf | 2011-04-11 16:50:19 -0700 | [diff] [blame] | 116 | jint descriptor = jniGetFDFromFileDescriptor(env, fileDescriptor); |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 117 | |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 118 | struct stat fdStat; |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 119 | if (fstat(descriptor, &fdStat) == -1) { |
| 120 | doThrowIOE(env, "broken file descriptor"); |
| 121 | return nullObjectReturn("fstat return -1"); |
| 122 | } |
| 123 | |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 124 | SkAutoTUnref<SkData> data(SkData::NewFromFD(descriptor)); |
| 125 | SkMemoryStream* stream = new SkMemoryStream(data); |
Wei-Ta Chen | 58c1579c | 2010-10-21 20:56:28 -0700 | [diff] [blame] | 126 | |
Leon Scroggins III | 3449789 | 2015-01-20 15:52:43 -0500 | [diff] [blame] | 127 | // the decoder owns the stream. |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 128 | jobject brd = createBitmapRegionDecoder(env, stream); |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 129 | return brd; |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static jobject nativeNewInstanceFromStream(JNIEnv* env, jobject clazz, |
| 133 | jobject is, // InputStream |
| 134 | jbyteArray storage, // byte[] |
| 135 | jboolean isShareable) { |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 136 | jobject brd = NULL; |
Leon Scroggins III | ca32021 | 2013-08-20 17:59:39 -0400 | [diff] [blame] | 137 | // for now we don't allow shareable with java inputstreams |
Leon Scroggins III | c779752 | 2013-09-03 11:35:00 -0400 | [diff] [blame] | 138 | SkStreamRewindable* stream = CopyJavaInputStream(env, is, storage); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 139 | |
| 140 | if (stream) { |
Leon Scroggins III | 3449789 | 2015-01-20 15:52:43 -0500 | [diff] [blame] | 141 | // the decoder owns the stream. |
Leon Scroggins III | ca32021 | 2013-08-20 17:59:39 -0400 | [diff] [blame] | 142 | brd = createBitmapRegionDecoder(env, stream); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 143 | } |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 144 | return brd; |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static jobject nativeNewInstanceFromAsset(JNIEnv* env, jobject clazz, |
Ashok Bhat | b091d47 | 2014-01-08 14:32:49 +0000 | [diff] [blame] | 148 | jlong native_asset, // Asset |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 149 | jboolean isShareable) { |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 150 | Asset* asset = reinterpret_cast<Asset*>(native_asset); |
Leon Scroggins III | 3449789 | 2015-01-20 15:52:43 -0500 | [diff] [blame] | 151 | SkMemoryStream* stream = CopyAssetToStream(asset); |
| 152 | if (NULL == stream) { |
Leon Scroggins III | ca32021 | 2013-08-20 17:59:39 -0400 | [diff] [blame] | 153 | return NULL; |
| 154 | } |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 155 | |
Leon Scroggins III | 3449789 | 2015-01-20 15:52:43 -0500 | [diff] [blame] | 156 | // the decoder owns the stream. |
| 157 | jobject brd = createBitmapRegionDecoder(env, stream); |
Derek Sollenberger | 5827cb5 | 2013-07-26 14:58:06 -0400 | [diff] [blame] | 158 | return brd; |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /* |
| 162 | * nine patch not supported |
| 163 | * |
| 164 | * purgeable not supported |
| 165 | * reportSizeToVM not supported |
| 166 | */ |
Ashok Bhat | b091d47 | 2014-01-08 14:32:49 +0000 | [diff] [blame] | 167 | static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, |
| 168 | jint start_x, jint start_y, jint width, jint height, jobject options) { |
| 169 | SkBitmapRegionDecoder *brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle); |
Owen Lin | f970c2e | 2012-04-25 18:49:09 +0800 | [diff] [blame] | 170 | jobject tileBitmap = NULL; |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 171 | SkImageDecoder *decoder = brd->getDecoder(); |
| 172 | int sampleSize = 1; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 173 | SkColorType prefColorType = kUnknown_SkColorType; |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 174 | bool doDither = true; |
Wei-Ta Chen | 953f909 | 2010-12-03 14:06:18 -0800 | [diff] [blame] | 175 | bool preferQualityOverSpeed = false; |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 176 | bool requireUnpremultiplied = false; |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 177 | |
| 178 | if (NULL != options) { |
| 179 | sampleSize = env->GetIntField(options, gOptions_sampleSizeFieldID); |
| 180 | // initialize these, in case we fail later on |
| 181 | env->SetIntField(options, gOptions_widthFieldID, -1); |
| 182 | env->SetIntField(options, gOptions_heightFieldID, -1); |
| 183 | env->SetObjectField(options, gOptions_mimeFieldID, 0); |
| 184 | |
| 185 | jobject jconfig = env->GetObjectField(options, gOptions_configFieldID); |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 186 | prefColorType = GraphicsJNI::getNativeBitmapColorType(env, jconfig); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 187 | doDither = env->GetBooleanField(options, gOptions_ditherFieldID); |
Wei-Ta Chen | 953f909 | 2010-12-03 14:06:18 -0800 | [diff] [blame] | 188 | preferQualityOverSpeed = env->GetBooleanField(options, |
| 189 | gOptions_preferQualityOverSpeedFieldID); |
Owen Lin | f970c2e | 2012-04-25 18:49:09 +0800 | [diff] [blame] | 190 | // Get the bitmap for re-use if it exists. |
| 191 | tileBitmap = env->GetObjectField(options, gOptions_bitmapFieldID); |
Leon Scroggins III | 2cc409a | 2013-08-26 14:27:15 -0400 | [diff] [blame] | 192 | requireUnpremultiplied = !env->GetBooleanField(options, gOptions_premultipliedFieldID); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | decoder->setDitherImage(doDither); |
Wei-Ta Chen | 953f909 | 2010-12-03 14:06:18 -0800 | [diff] [blame] | 196 | decoder->setPreferQualityOverSpeed(preferQualityOverSpeed); |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 197 | decoder->setRequireUnpremultipliedColors(requireUnpremultiplied); |
| 198 | AutoDecoderCancel adc(options, decoder); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 199 | |
| 200 | // To fix the race condition in case "requestCancelDecode" |
| 201 | // happens earlier than AutoDecoderCancel object is added |
| 202 | // to the gAutoDecoderCancelMutex linked list. |
| 203 | if (NULL != options && env->GetBooleanField(options, gOptions_mCancelID)) { |
| 204 | return nullObjectReturn("gOptions_mCancelID");; |
| 205 | } |
| 206 | |
| 207 | SkIRect region; |
| 208 | region.fLeft = start_x; |
| 209 | region.fTop = start_y; |
| 210 | region.fRight = start_x + width; |
| 211 | region.fBottom = start_y + height; |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 212 | SkBitmap bitmap; |
Owen Lin | f970c2e | 2012-04-25 18:49:09 +0800 | [diff] [blame] | 213 | |
| 214 | if (tileBitmap != NULL) { |
| 215 | // Re-use bitmap. |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 216 | GraphicsJNI::getSkBitmap(env, tileBitmap, &bitmap); |
Owen Lin | f970c2e | 2012-04-25 18:49:09 +0800 | [diff] [blame] | 217 | } |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 218 | |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 219 | if (!brd->decodeRegion(&bitmap, region, prefColorType, sampleSize)) { |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 220 | return nullObjectReturn("decoder->decodeRegion returned false"); |
| 221 | } |
| 222 | |
| 223 | // update options (if any) |
| 224 | if (NULL != options) { |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 225 | env->SetIntField(options, gOptions_widthFieldID, bitmap.width()); |
| 226 | env->SetIntField(options, gOptions_heightFieldID, bitmap.height()); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 227 | // TODO: set the mimeType field with the data from the codec. |
| 228 | // but how to reuse a set of strings, rather than allocating new one |
| 229 | // each time? |
| 230 | env->SetObjectField(options, gOptions_mimeFieldID, |
| 231 | getMimeTypeString(env, decoder->getFormat())); |
| 232 | } |
| 233 | |
Owen Lin | f970c2e | 2012-04-25 18:49:09 +0800 | [diff] [blame] | 234 | if (tileBitmap != NULL) { |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 235 | bitmap.notifyPixelsChanged(); |
Owen Lin | f970c2e | 2012-04-25 18:49:09 +0800 | [diff] [blame] | 236 | return tileBitmap; |
| 237 | } |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 238 | |
Patrick Dubroy | afde46e | 2010-12-15 11:52:01 -0800 | [diff] [blame] | 239 | JavaPixelAllocator* allocator = (JavaPixelAllocator*) decoder->getAllocator(); |
Chris Craik | 1abf5d6 | 2013-08-16 12:47:03 -0700 | [diff] [blame] | 240 | |
| 241 | int bitmapCreateFlags = 0; |
| 242 | if (!requireUnpremultiplied) bitmapCreateFlags |= GraphicsJNI::kBitmapCreateFlag_Premultiplied; |
John Reck | f29ed28 | 2015-04-07 07:32:03 -0700 | [diff] [blame] | 243 | return GraphicsJNI::createBitmap(env, allocator->getStorageObjAndReset(), |
| 244 | bitmapCreateFlags); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 245 | } |
| 246 | |
Ashok Bhat | b091d47 | 2014-01-08 14:32:49 +0000 | [diff] [blame] | 247 | static jint nativeGetHeight(JNIEnv* env, jobject, jlong brdHandle) { |
| 248 | SkBitmapRegionDecoder *brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle); |
| 249 | return static_cast<jint>(brd->getHeight()); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 250 | } |
| 251 | |
Ashok Bhat | b091d47 | 2014-01-08 14:32:49 +0000 | [diff] [blame] | 252 | static jint nativeGetWidth(JNIEnv* env, jobject, jlong brdHandle) { |
| 253 | SkBitmapRegionDecoder *brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle); |
| 254 | return static_cast<jint>(brd->getWidth()); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 255 | } |
| 256 | |
Ashok Bhat | b091d47 | 2014-01-08 14:32:49 +0000 | [diff] [blame] | 257 | static void nativeClean(JNIEnv* env, jobject, jlong brdHandle) { |
| 258 | SkBitmapRegionDecoder *brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 259 | delete brd; |
| 260 | } |
| 261 | |
| 262 | /////////////////////////////////////////////////////////////////////////////// |
| 263 | |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 264 | static JNINativeMethod gBitmapRegionDecoderMethods[] = { |
| 265 | { "nativeDecodeRegion", |
Ashok Bhat | b091d47 | 2014-01-08 14:32:49 +0000 | [diff] [blame] | 266 | "(JIIIILandroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;", |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 267 | (void*)nativeDecodeRegion}, |
| 268 | |
Ashok Bhat | b091d47 | 2014-01-08 14:32:49 +0000 | [diff] [blame] | 269 | { "nativeGetHeight", "(J)I", (void*)nativeGetHeight}, |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 270 | |
Ashok Bhat | b091d47 | 2014-01-08 14:32:49 +0000 | [diff] [blame] | 271 | { "nativeGetWidth", "(J)I", (void*)nativeGetWidth}, |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 272 | |
Ashok Bhat | b091d47 | 2014-01-08 14:32:49 +0000 | [diff] [blame] | 273 | { "nativeClean", "(J)V", (void*)nativeClean}, |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 274 | |
| 275 | { "nativeNewInstance", |
| 276 | "([BIIZ)Landroid/graphics/BitmapRegionDecoder;", |
| 277 | (void*)nativeNewInstanceFromByteArray |
| 278 | }, |
| 279 | |
| 280 | { "nativeNewInstance", |
| 281 | "(Ljava/io/InputStream;[BZ)Landroid/graphics/BitmapRegionDecoder;", |
| 282 | (void*)nativeNewInstanceFromStream |
| 283 | }, |
| 284 | |
| 285 | { "nativeNewInstance", |
| 286 | "(Ljava/io/FileDescriptor;Z)Landroid/graphics/BitmapRegionDecoder;", |
| 287 | (void*)nativeNewInstanceFromFileDescriptor |
| 288 | }, |
| 289 | |
| 290 | { "nativeNewInstance", |
Ashok Bhat | b091d47 | 2014-01-08 14:32:49 +0000 | [diff] [blame] | 291 | "(JZ)Landroid/graphics/BitmapRegionDecoder;", |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 292 | (void*)nativeNewInstanceFromAsset |
| 293 | }, |
| 294 | }; |
| 295 | |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 296 | int register_android_graphics_BitmapRegionDecoder(JNIEnv* env) |
| 297 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 298 | return android::RegisterMethodsOrDie(env, "android/graphics/BitmapRegionDecoder", |
| 299 | gBitmapRegionDecoderMethods, NELEM(gBitmapRegionDecoderMethods)); |
Wei-Ta Chen | 6b849e2 | 2010-09-07 17:32:18 +0800 | [diff] [blame] | 300 | } |