xref: /aosp_15_r20/frameworks/base/libs/hwui/jni/BitmapRegionDecoder.cpp (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
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 #include "BitmapRegionDecoder.h"
18 
19 #include <HardwareBitmapUploader.h>
20 #include <androidfw/Asset.h>
21 #include <sys/stat.h>
22 #include <utils/StatsUtils.h>
23 
24 #include <memory>
25 
26 #include "BitmapFactory.h"
27 #include "CreateJavaOutputStreamAdaptor.h"
28 #include "Gainmap.h"
29 #include "GraphicsJNI.h"
30 #include "SkBitmap.h"
31 #include "SkCodec.h"
32 #include "SkColorSpace.h"
33 #include "SkData.h"
34 #include "SkGainmapInfo.h"
35 #include "SkStream.h"
36 #include "SkStreamPriv.h"
37 #include "Utils.h"
38 
39 using namespace android;
40 
41 namespace android {
42 class BitmapRegionDecoderWrapper {
43 public:
Make(sk_sp<SkData> data)44     static std::unique_ptr<BitmapRegionDecoderWrapper> Make(sk_sp<SkData> data) {
45         std::unique_ptr<skia::BitmapRegionDecoder> mainImageBRD =
46                 skia::BitmapRegionDecoder::Make(std::move(data));
47         if (!mainImageBRD) {
48             return nullptr;
49         }
50 
51         SkGainmapInfo gainmapInfo;
52         std::unique_ptr<SkAndroidCodec> gainmapCodec;
53         std::unique_ptr<skia::BitmapRegionDecoder> gainmapBRD = nullptr;
54         if (!mainImageBRD->getGainmapBitmapRegionDecoder(&gainmapInfo, &gainmapBRD)) {
55             gainmapBRD = nullptr;
56         }
57 
58         return std::unique_ptr<BitmapRegionDecoderWrapper>(new BitmapRegionDecoderWrapper(
59                 std::move(mainImageBRD), std::move(gainmapBRD), gainmapInfo));
60     }
61 
getEncodedFormat()62     SkEncodedImageFormat getEncodedFormat() { return mMainImageBRD->getEncodedFormat(); }
63 
computeOutputColorType(SkColorType requestedColorType)64     SkColorType computeOutputColorType(SkColorType requestedColorType) {
65         return mMainImageBRD->computeOutputColorType(requestedColorType);
66     }
67 
computeOutputColorSpace(SkColorType outputColorType,sk_sp<SkColorSpace> prefColorSpace=nullptr)68     sk_sp<SkColorSpace> computeOutputColorSpace(SkColorType outputColorType,
69                                                 sk_sp<SkColorSpace> prefColorSpace = nullptr) {
70         return mMainImageBRD->computeOutputColorSpace(outputColorType, prefColorSpace);
71     }
72 
decodeRegion(SkBitmap * bitmap,skia::BRDAllocator * allocator,const SkIRect & desiredSubset,int sampleSize,SkColorType colorType,bool requireUnpremul,sk_sp<SkColorSpace> prefColorSpace)73     bool decodeRegion(SkBitmap* bitmap, skia::BRDAllocator* allocator, const SkIRect& desiredSubset,
74                       int sampleSize, SkColorType colorType, bool requireUnpremul,
75                       sk_sp<SkColorSpace> prefColorSpace) {
76         return mMainImageBRD->decodeRegion(bitmap, allocator, desiredSubset, sampleSize, colorType,
77                                            requireUnpremul, prefColorSpace);
78     }
79 
80     // Decodes the gainmap region. If decoding succeeded, returns true and
81     // populate outGainmap with the decoded gainmap. Otherwise, returns false.
82     //
83     // Note that the desiredSubset is the logical region within the source
84     // gainmap that we want to decode. This is used for scaling into the final
85     // bitmap, since we do not want to include portions of the gainmap outside
86     // of this region. desiredSubset is also _not_ guaranteed to be
87     // pixel-aligned, so it's not possible to simply resize the resulting
88     // bitmap to accomplish this.
decodeGainmapRegion(sp<uirenderer::Gainmap> * outGainmap,SkISize bitmapDimensions,const SkRect & desiredSubset,int sampleSize,bool requireUnpremul)89     bool decodeGainmapRegion(sp<uirenderer::Gainmap>* outGainmap, SkISize bitmapDimensions,
90                              const SkRect& desiredSubset, int sampleSize, bool requireUnpremul) {
91         SkColorType decodeColorType = mGainmapBRD->computeOutputColorType(kN32_SkColorType);
92         sk_sp<SkColorSpace> decodeColorSpace =
93                 mGainmapBRD->computeOutputColorSpace(decodeColorType, nullptr);
94         SkBitmap bm;
95         // Because we must match the dimensions of the base bitmap, we always use a
96         // recycling allocator even though we are allocating a new bitmap. This is to ensure
97         // that if a recycled bitmap was used for the base image that we match the relative
98         // dimensions of that base image. The behavior of BRD here is:
99         // if inBitmap is specified -> output dimensions are always equal to the inBitmap's
100         // if no bitmap is reused   -> output dimensions are the intersect of the desiredSubset &
101         //                           the image bounds
102         // The handling of the above conditionals are baked into the desiredSubset, so we
103         // simply need to ensure that the resulting bitmap is the exact same width/height as
104         // the specified desiredSubset regardless of the intersection to the image bounds.
105         // kPremul_SkAlphaType is used just as a placeholder as it doesn't change the underlying
106         // allocation type. RecyclingClippingPixelAllocator will populate this with the
107         // actual alpha type in either allocPixelRef() or copyIfNecessary()
108         sk_sp<Bitmap> nativeBitmap = Bitmap::allocateHeapBitmap(SkImageInfo::Make(
109                 bitmapDimensions, decodeColorType, kPremul_SkAlphaType, decodeColorSpace));
110         if (!nativeBitmap) {
111             ALOGE("OOM allocating Bitmap for Gainmap");
112             return false;
113         }
114 
115         sampleSize = std::max(sampleSize, 1);
116 
117         // Map the desired subset to the space of the decoded gainmap. The
118         // subset is repositioned relative to the resulting bitmap, and then
119         // scaled to respect the sampleSize.
120         // This assumes that the subset will not be modified by the decoder, which is true
121         // for existing gainmap formats.
122         SkRect logicalSubset = desiredSubset.makeOffset(-std::floorf(desiredSubset.left()),
123                                                         -std::floorf(desiredSubset.top()));
124         logicalSubset = scale(logicalSubset, 1.0f / sampleSize);
125 
126         // Round out the subset so that we decode a slightly larger region, in
127         // case the subset has fractional components. When we round, we need to
128         // round the downsampled subset to avoid possibly rounding down by accident.
129         // Consider this concrete example if we round the desired subset directly:
130         //
131         // * We are decoding a 18x18 corner of an image
132         //
133         // * Gainmap is 1/4 resolution, which is logically a 4.5x4.5 gainmap
134         // that we would want
135         //
136         // * The app wants to downsample by a factor of 2x
137         //
138         // * The desired gainmap dimensions are computed to be 3x3 to fit the
139         // downsampled gainmap, since we need to fill a 2.25x2.25 region that's
140         // later upscaled to 3x3
141         //
142         // * But, if we round out the desired gainmap region _first_, then we
143         // request to decode a 5x5 region, downsampled by 2, which actually
144         // decodes a 2x2 region since skia rounds down internally. But then we transfer
145         // the result to a 3x3 bitmap using a clipping allocator, which leaves an inset.
146         // Not only did we get a smaller region than we expected (so, our desired subset is
147         // not valid), but because the API allows for decoding regions using a recycled
148         // bitmap, we can't really safely fill in the inset since then we might
149         // extend the gainmap beyond intended the image bounds. Oops.
150         //
151         // * If we instead round out as if we downsampled, then we downsample
152         // the desired region to 2.25x2.25, round out to 3x3, then upsample back
153         // into the source gainmap space to get 6x6. Then we decode a 6x6 region
154         // downsampled into a 3x3 region, and everything's now correct.
155         //
156         // Note that we don't always run into this problem, because
157         // decoders actually round *up* for subsampling when decoding a subset
158         // that matches the dimensions of the image. E.g., if the original image
159         // size in the above example was a 20x20 image, so that the gainmap was
160         // 5x5, then we still manage to downsample into a 3x3 bitmap even with
161         // the "wrong" math. but that's what we wanted!
162         //
163         // Note also that if we overshoot the gainmap bounds with the requested
164         // subset it isn't a problem either, since now the decoded bitmap is too
165         // large, rather than too small, so now we can use the desired subset to
166         // avoid sampling "invalid" colors.
167         SkRect scaledSubset = scale(desiredSubset, 1.0f / sampleSize);
168         SkIRect roundedSubset = scale(scaledSubset.roundOut(), static_cast<float>(sampleSize));
169 
170         RecyclingClippingPixelAllocator allocator(nativeBitmap.get(), false, logicalSubset);
171         if (!mGainmapBRD->decodeRegion(&bm, &allocator, roundedSubset, sampleSize, decodeColorType,
172                                        requireUnpremul, decodeColorSpace)) {
173             ALOGE("Error decoding Gainmap region");
174             return false;
175         }
176         allocator.copyIfNecessary();
177         auto gainmap = sp<uirenderer::Gainmap>::make();
178         if (!gainmap) {
179             ALOGE("OOM allocating Gainmap");
180             return false;
181         }
182         gainmap->info = mGainmapInfo;
183         gainmap->bitmap = std::move(nativeBitmap);
184         *outGainmap = std::move(gainmap);
185         return true;
186     }
187 
188     struct Projection {
189         SkRect srcRect;
190         SkISize destSize;
191     };
calculateGainmapRegion(const SkIRect & mainImageRegion,SkISize dimensions)192     Projection calculateGainmapRegion(const SkIRect& mainImageRegion, SkISize dimensions) {
193         const float scaleX = ((float)mGainmapBRD->width()) / mMainImageBRD->width();
194         const float scaleY = ((float)mGainmapBRD->height()) / mMainImageBRD->height();
195 
196         if (uirenderer::Properties::resampleGainmapRegions()) {
197             const auto srcRect = SkRect::MakeLTRB(
198                     mainImageRegion.left() * scaleX, mainImageRegion.top() * scaleY,
199                     mainImageRegion.right() * scaleX, mainImageRegion.bottom() * scaleY);
200             // Request a slightly larger destination size so that the gainmap
201             // subset we want fits entirely in this size.
202             const auto destSize = SkISize::Make(std::ceil(dimensions.width() * scaleX),
203                                                 std::ceil(dimensions.height() * scaleY));
204             return Projection{.srcRect = srcRect, .destSize = destSize};
205         } else {
206             const auto srcRect = SkRect::Make(SkIRect::MakeLTRB(
207                     mainImageRegion.left() * scaleX, mainImageRegion.top() * scaleY,
208                     mainImageRegion.right() * scaleX, mainImageRegion.bottom() * scaleY));
209             const auto destSize =
210                     SkISize::Make(dimensions.width() * scaleX, dimensions.height() * scaleY);
211             return Projection{.srcRect = srcRect, .destSize = destSize};
212         }
213     }
214 
hasGainmap()215     bool hasGainmap() { return mGainmapBRD != nullptr; }
216 
width() const217     int width() const { return mMainImageBRD->width(); }
height() const218     int height() const { return mMainImageBRD->height(); }
219 
220 private:
BitmapRegionDecoderWrapper(std::unique_ptr<skia::BitmapRegionDecoder> mainImageBRD,std::unique_ptr<skia::BitmapRegionDecoder> gainmapBRD,SkGainmapInfo info)221     BitmapRegionDecoderWrapper(std::unique_ptr<skia::BitmapRegionDecoder> mainImageBRD,
222                                std::unique_ptr<skia::BitmapRegionDecoder> gainmapBRD,
223                                SkGainmapInfo info)
224             : mMainImageBRD(std::move(mainImageBRD))
225             , mGainmapBRD(std::move(gainmapBRD))
226             , mGainmapInfo(info) {}
227 
scale(SkRect rect,float scale) const228     SkRect scale(SkRect rect, float scale) const {
229         rect.fLeft *= scale;
230         rect.fTop *= scale;
231         rect.fRight *= scale;
232         rect.fBottom *= scale;
233         return rect;
234     }
235 
scale(SkIRect rect,float scale) const236     SkIRect scale(SkIRect rect, float scale) const {
237         rect.fLeft *= scale;
238         rect.fTop *= scale;
239         rect.fRight *= scale;
240         rect.fBottom *= scale;
241         return rect;
242     }
243 
244     std::unique_ptr<skia::BitmapRegionDecoder> mMainImageBRD;
245     std::unique_ptr<skia::BitmapRegionDecoder> mGainmapBRD;
246     SkGainmapInfo mGainmapInfo;
247 };
248 }  // namespace android
249 
createBitmapRegionDecoder(JNIEnv * env,sk_sp<SkData> data)250 static jobject createBitmapRegionDecoder(JNIEnv* env, sk_sp<SkData> data) {
251     auto brd = android::BitmapRegionDecoderWrapper::Make(std::move(data));
252     if (!brd) {
253         doThrowIOE(env, "Image format not supported");
254         return nullObjectReturn("CreateBitmapRegionDecoder returned null");
255     }
256 
257     return GraphicsJNI::createBitmapRegionDecoder(env, brd.release());
258 }
259 
nativeNewInstanceFromByteArray(JNIEnv * env,jobject,jbyteArray byteArray,jint offset,jint length)260 static jobject nativeNewInstanceFromByteArray(JNIEnv* env, jobject, jbyteArray byteArray,
261                                               jint offset, jint length) {
262     AutoJavaByteArray ar(env, byteArray);
263     return createBitmapRegionDecoder(env, SkData::MakeWithCopy(ar.ptr() + offset, length));
264 }
265 
nativeNewInstanceFromFileDescriptor(JNIEnv * env,jobject clazz,jobject fileDescriptor)266 static jobject nativeNewInstanceFromFileDescriptor(JNIEnv* env, jobject clazz,
267                                                    jobject fileDescriptor) {
268     NPE_CHECK_RETURN_ZERO(env, fileDescriptor);
269 
270     jint descriptor = jniGetFDFromFileDescriptor(env, fileDescriptor);
271 
272     struct stat fdStat;
273     if (fstat(descriptor, &fdStat) == -1) {
274         doThrowIOE(env, "broken file descriptor");
275         return nullObjectReturn("fstat return -1");
276     }
277 
278     return createBitmapRegionDecoder(env, SkData::MakeFromFD(descriptor));
279 }
280 
nativeNewInstanceFromStream(JNIEnv * env,jobject clazz,jobject is,jbyteArray storage)281 static jobject nativeNewInstanceFromStream(JNIEnv* env, jobject clazz, jobject is, // InputStream
282                                            jbyteArray storage) { // byte[]
283     jobject brd = nullptr;
284     sk_sp<SkData> data = CopyJavaInputStream(env, is, storage);
285 
286     if (data) {
287         brd = createBitmapRegionDecoder(env, std::move(data));
288     }
289     return brd;
290 }
291 
nativeNewInstanceFromAsset(JNIEnv * env,jobject clazz,jlong native_asset)292 static jobject nativeNewInstanceFromAsset(JNIEnv* env, jobject clazz, jlong native_asset) {
293     Asset* asset = reinterpret_cast<Asset*>(native_asset);
294     sk_sp<SkData> data = CopyAssetToData(asset);
295     if (!data) {
296         return nullptr;
297     }
298 
299     return createBitmapRegionDecoder(env, data);
300 }
301 
302 /*
303  * nine patch not supported
304  * purgeable not supported
305  * reportSizeToVM not supported
306  */
nativeDecodeRegion(JNIEnv * env,jobject,jlong brdHandle,jint inputX,jint inputY,jint inputWidth,jint inputHeight,jobject options,jlong inBitmapHandle,jlong colorSpaceHandle)307 static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint inputX,
308         jint inputY, jint inputWidth, jint inputHeight, jobject options, jlong inBitmapHandle,
309         jlong colorSpaceHandle) {
310 
311     // Set default options.
312     int sampleSize = 1;
313     SkColorType colorType = kN32_SkColorType;
314     bool requireUnpremul = false;
315     jobject javaBitmap = nullptr;
316     bool isHardware = false;
317     sk_sp<SkColorSpace> colorSpace = GraphicsJNI::getNativeColorSpace(colorSpaceHandle);
318     // Update the default options with any options supplied by the client.
319     if (NULL != options) {
320         sampleSize = env->GetIntField(options, gOptions_sampleSizeFieldID);
321         jobject jconfig = env->GetObjectField(options, gOptions_configFieldID);
322         colorType = GraphicsJNI::getNativeBitmapColorType(env, jconfig);
323         isHardware = GraphicsJNI::isHardwareConfig(env, jconfig);
324         requireUnpremul = !env->GetBooleanField(options, gOptions_premultipliedFieldID);
325         javaBitmap = env->GetObjectField(options, gOptions_bitmapFieldID);
326         // The Java options of ditherMode and preferQualityOverSpeed are deprecated.  We will
327         // ignore the values of these fields.
328 
329         // Initialize these fields to indicate a failure.  If the decode succeeds, we
330         // will update them later on.
331         env->SetIntField(options, gOptions_widthFieldID, -1);
332         env->SetIntField(options, gOptions_heightFieldID, -1);
333         env->SetObjectField(options, gOptions_mimeFieldID, 0);
334         env->SetObjectField(options, gOptions_outConfigFieldID, 0);
335         env->SetObjectField(options, gOptions_outColorSpaceFieldID, 0);
336     }
337 
338     // Recycle a bitmap if possible.
339     android::Bitmap* recycledBitmap = nullptr;
340     if (javaBitmap) {
341         recycledBitmap = &bitmap::toBitmap(inBitmapHandle);
342         if (recycledBitmap->isImmutable()) {
343             ALOGW("Warning: Reusing an immutable bitmap as an image decoder target.");
344         }
345     }
346 
347     auto* brd = reinterpret_cast<BitmapRegionDecoderWrapper*>(brdHandle);
348     SkColorType decodeColorType = brd->computeOutputColorType(colorType);
349 
350     if (isHardware) {
351         if (decodeColorType == kRGBA_F16_SkColorType &&
352             !uirenderer::HardwareBitmapUploader::hasFP16Support()) {
353             decodeColorType = kN32_SkColorType;
354         }
355         if (decodeColorType == kRGBA_1010102_SkColorType &&
356             !uirenderer::HardwareBitmapUploader::has1010102Support()) {
357             decodeColorType = kN32_SkColorType;
358         }
359     }
360 
361     // Set up the pixel allocator
362     skia::BRDAllocator* allocator = nullptr;
363     RecyclingClippingPixelAllocator recycleAlloc(recycledBitmap);
364     HeapAllocator heapAlloc;
365     if (javaBitmap) {
366         allocator = &recycleAlloc;
367         // We are required to match the color type of the recycled bitmap.
368         decodeColorType = recycledBitmap->info().colorType();
369     } else {
370         allocator = &heapAlloc;
371     }
372 
373     sk_sp<SkColorSpace> decodeColorSpace = brd->computeOutputColorSpace(
374             decodeColorType, colorSpace);
375 
376     // Decode the region.
377     const SkIRect subset = SkIRect::MakeXYWH(inputX, inputY, inputWidth, inputHeight);
378     SkBitmap bitmap;
379     if (!brd->decodeRegion(&bitmap, allocator, subset, sampleSize,
380             decodeColorType, requireUnpremul, decodeColorSpace)) {
381         return nullObjectReturn("Failed to decode region.");
382     }
383 
384     // If the client provided options, indicate that the decode was successful.
385     if (NULL != options) {
386         env->SetIntField(options, gOptions_widthFieldID, bitmap.width());
387         env->SetIntField(options, gOptions_heightFieldID, bitmap.height());
388 
389         env->SetObjectField(options, gOptions_mimeFieldID,
390                 getMimeTypeAsJavaString(env, brd->getEncodedFormat()));
391         if (env->ExceptionCheck()) {
392             return nullObjectReturn("OOM in encodedFormatToString()");
393         }
394 
395         jint configID = GraphicsJNI::colorTypeToLegacyBitmapConfig(decodeColorType);
396         if (isHardware) {
397             configID = GraphicsJNI::kHardware_LegacyBitmapConfig;
398         }
399         jobject config = env->CallStaticObjectMethod(gBitmapConfig_class,
400                 gBitmapConfig_nativeToConfigMethodID, configID);
401         env->SetObjectField(options, gOptions_outConfigFieldID, config);
402 
403         env->SetObjectField(options, gOptions_outColorSpaceFieldID,
404                 GraphicsJNI::getColorSpace(env, decodeColorSpace.get(), decodeColorType));
405     }
406 
407     if (javaBitmap) {
408         recycleAlloc.copyIfNecessary();
409     }
410 
411     sp<uirenderer::Gainmap> gainmap;
412     bool hasGainmap = brd->hasGainmap();
413     if (hasGainmap) {
414         SkISize gainmapDims = SkISize::Make(bitmap.width(), bitmap.height());
415         if (javaBitmap) {
416             // If we are recycling we must match the inBitmap's relative dimensions
417             gainmapDims.fWidth = recycledBitmap->width();
418             gainmapDims.fHeight = recycledBitmap->height();
419         }
420         BitmapRegionDecoderWrapper::Projection gainmapProjection =
421                 brd->calculateGainmapRegion(subset, gainmapDims);
422         if (!brd->decodeGainmapRegion(&gainmap, gainmapProjection.destSize,
423                                       gainmapProjection.srcRect, sampleSize, requireUnpremul)) {
424             // If there is an error decoding Gainmap - we don't fail. We just don't provide Gainmap
425             hasGainmap = false;
426         }
427     }
428 
429     // If we may have reused a bitmap, we need to indicate that the pixels have changed.
430     if (javaBitmap) {
431         if (hasGainmap) {
432             recycledBitmap->setGainmap(std::move(gainmap));
433         }
434         bitmap::reinitBitmap(env, javaBitmap, recycledBitmap->info(), !requireUnpremul);
435         uirenderer::logBitmapDecode(*recycledBitmap);
436         return javaBitmap;
437     }
438 
439     int bitmapCreateFlags = 0;
440     if (!requireUnpremul) {
441         bitmapCreateFlags |= android::bitmap::kBitmapCreateFlag_Premultiplied;
442     }
443 
444     if (isHardware) {
445         sk_sp<Bitmap> hardwareBitmap = Bitmap::allocateHardwareBitmap(bitmap);
446         if (hasGainmap) {
447             auto gm = uirenderer::Gainmap::allocateHardwareGainmap(gainmap);
448             if (gm) {
449                 hardwareBitmap->setGainmap(std::move(gm));
450             }
451         }
452         uirenderer::logBitmapDecode(*hardwareBitmap);
453         return bitmap::createBitmap(env, hardwareBitmap.release(), bitmapCreateFlags);
454     }
455     Bitmap* heapBitmap = heapAlloc.getStorageObjAndReset();
456     if (hasGainmap && heapBitmap != nullptr) {
457         heapBitmap->setGainmap(std::move(gainmap));
458     }
459     uirenderer::logBitmapDecode(*heapBitmap);
460     return android::bitmap::createBitmap(env, heapBitmap, bitmapCreateFlags);
461 }
462 
nativeGetHeight(JNIEnv * env,jobject,jlong brdHandle)463 static jint nativeGetHeight(JNIEnv* env, jobject, jlong brdHandle) {
464     auto* brd = reinterpret_cast<BitmapRegionDecoderWrapper*>(brdHandle);
465     return static_cast<jint>(brd->height());
466 }
467 
nativeGetWidth(JNIEnv * env,jobject,jlong brdHandle)468 static jint nativeGetWidth(JNIEnv* env, jobject, jlong brdHandle) {
469     auto* brd = reinterpret_cast<BitmapRegionDecoderWrapper*>(brdHandle);
470     return static_cast<jint>(brd->width());
471 }
472 
nativeClean(JNIEnv * env,jobject,jlong brdHandle)473 static void nativeClean(JNIEnv* env, jobject, jlong brdHandle) {
474     auto* brd = reinterpret_cast<BitmapRegionDecoderWrapper*>(brdHandle);
475     delete brd;
476 }
477 
478 ///////////////////////////////////////////////////////////////////////////////
479 
480 static const JNINativeMethod gBitmapRegionDecoderMethods[] = {
481     {   "nativeDecodeRegion",
482         "(JIIIILandroid/graphics/BitmapFactory$Options;JJ)Landroid/graphics/Bitmap;",
483         (void*)nativeDecodeRegion},
484 
485     {   "nativeGetHeight", "(J)I", (void*)nativeGetHeight},
486 
487     {   "nativeGetWidth", "(J)I", (void*)nativeGetWidth},
488 
489     {   "nativeClean", "(J)V", (void*)nativeClean},
490 
491     {   "nativeNewInstance",
492         "([BII)Landroid/graphics/BitmapRegionDecoder;",
493         (void*)nativeNewInstanceFromByteArray
494     },
495 
496     {   "nativeNewInstance",
497         "(Ljava/io/InputStream;[B)Landroid/graphics/BitmapRegionDecoder;",
498         (void*)nativeNewInstanceFromStream
499     },
500 
501     {   "nativeNewInstance",
502         "(Ljava/io/FileDescriptor;)Landroid/graphics/BitmapRegionDecoder;",
503         (void*)nativeNewInstanceFromFileDescriptor
504     },
505 
506     {   "nativeNewInstance",
507         "(J)Landroid/graphics/BitmapRegionDecoder;",
508         (void*)nativeNewInstanceFromAsset
509     },
510 };
511 
register_android_graphics_BitmapRegionDecoder(JNIEnv * env)512 int register_android_graphics_BitmapRegionDecoder(JNIEnv* env)
513 {
514     return android::RegisterMethodsOrDie(env, "android/graphics/BitmapRegionDecoder",
515             gBitmapRegionDecoderMethods, NELEM(gBitmapRegionDecoderMethods));
516 }
517