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.