diff options
author | Leon Scroggins III <scroggo@google.com> | 2013-09-12 20:00:46 -0400 |
---|---|---|
committer | Leon Scroggins III <scroggo@google.com> | 2013-09-12 20:00:46 -0400 |
commit | 37b82e32324d0911aba897880c28b2fdedc3ec9a (patch) | |
tree | 69ed753e6e703b0481bb10a8572bd36af1499a3e /core/jni | |
parent | e4fdc84794923f9408fc400ed9177178329a08cd (diff) | |
download | frameworks_base-37b82e32324d0911aba897880c28b2fdedc3ec9a.zip frameworks_base-37b82e32324d0911aba897880c28b2fdedc3ec9a.tar.gz frameworks_base-37b82e32324d0911aba897880c28b2fdedc3ec9a.tar.bz2 |
Do not allocate so much memory on the stack.
Instead, allocate a smaller amount and grow as necessary.
BUG:10697851
Change-Id: Iec57a8a374a4a76a3770e241cf561d58f3c8e1dc
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp b/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp index 2d06b68..f773f59 100644 --- a/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp +++ b/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp @@ -159,17 +159,26 @@ SkStream* CreateJavaInputStreamAdaptor(JNIEnv* env, jobject stream, } -static SkMemoryStream* adaptor_to_mem_stream(SkStream* adaptor) { - SkASSERT(adaptor != NULL); - SkDynamicMemoryWStream wStream; - const int bufferSize = 256 * 1024; // 256 KB, same as ViewStateSerializer. - uint8_t buffer[bufferSize]; - do { - size_t bytesRead = adaptor->read(buffer, bufferSize); - wStream.write(buffer, bytesRead); - } while (!adaptor->isAtEnd()); - SkAutoTUnref<SkData> data(wStream.copyToData()); - return new SkMemoryStream(data.get()); +static SkMemoryStream* adaptor_to_mem_stream(SkStream* stream) { + SkASSERT(stream != NULL); + size_t bufferSize = 4096; + size_t streamLen = 0; + size_t len; + char* data = (char*)sk_malloc_throw(bufferSize); + + while ((len = stream->read(data + streamLen, + bufferSize - streamLen)) != 0) { + streamLen += len; + if (streamLen == bufferSize) { + bufferSize *= 2; + data = (char*)sk_realloc_throw(data, bufferSize); + } + } + data = (char*)sk_realloc_throw(data, streamLen); + + SkMemoryStream* streamMem = new SkMemoryStream(); + streamMem->setMemoryOwned(data, streamLen); + return streamMem; } SkStreamRewindable* CopyJavaInputStream(JNIEnv* env, jobject stream, |