From 0102f8a87a7571b1ff537a1293d67ae8fa001167 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Tue, 14 Jan 2014 15:14:57 -0500 Subject: [PATCH] In nativeDecodeFileDescriptor, use fdopen. Instead of attempting to mmap the entire file, create an SkFILEStream from a FILE. BUG:11669944 BUG:11028218 Change-Id: If67da91484acc79f9f3dde6d05201409c0c75e41 --- core/jni/android/graphics/BitmapFactory.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index efa8ce7a1e142..d042ce95a0ba5 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -516,11 +517,14 @@ static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fi } } - SkAutoTUnref data(SkData::NewFromFD(descriptor)); - if (data.get() == NULL) { - return nullObjectReturn("NewFromFD failed in nativeDecodeFileDescriptor"); + FILE* file = fdopen(descriptor, "r"); + if (file == NULL) { + return nullObjectReturn("Could not open file"); } - SkAutoTUnref stream(new SkMemoryStream(data)); + + SkAutoTUnref stream(new SkFILEStream(file, + weOwnTheFD ? SkFILEStream::kCallerPasses_Ownership : + SkFILEStream::kCallerRetains_Ownership)); /* Allow purgeable iff we own the FD, i.e., in the puregeable and shareable case.