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