summaryrefslogtreecommitdiffstats
path: root/graphics/jni
diff options
context:
space:
mode:
authorRomain Guy <romainguy@android.com>2009-08-31 14:06:43 -0700
committerRomain Guy <romainguy@android.com>2009-08-31 14:06:43 -0700
commit650a3eb7d621dc8e81573142a4498bbd07bcde27 (patch)
treecd6622f813c00317a8d382ecaf031b90924d1170 /graphics/jni
parentde5cd3d8646f312987062f46616466ae191aa984 (diff)
downloadframeworks_base-650a3eb7d621dc8e81573142a4498bbd07bcde27.zip
frameworks_base-650a3eb7d621dc8e81573142a4498bbd07bcde27.tar.gz
frameworks_base-650a3eb7d621dc8e81573142a4498bbd07bcde27.tar.bz2
Load bitmap resources entirely from native code.
Change-Id: I6660baec241794c40611bce79b7f9ce9479e52ba
Diffstat (limited to 'graphics/jni')
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 2550181..3ed3327 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -26,7 +26,13 @@
#include <ui/Surface.h>
#include <core/SkBitmap.h>
+#include <core/SkPixelRef.h>
+#include <core/SkStream.h>
+#include <core/SkTemplates.h>
+#include <images/SkImageDecoder.h>
+#include <utils/Asset.h>
+#include <utils/ResourceTypes.h>
#include "jni.h"
#include "JNIHelp.h"
@@ -397,6 +403,32 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean g
}
static int
+nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jint native_asset)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+
+ Asset* asset = reinterpret_cast<Asset*>(native_asset);
+ SkBitmap bitmap;
+ SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(),
+ &bitmap, SkBitmap::kNo_Config, SkImageDecoder::kDecodePixels_Mode);
+
+ SkBitmap::Config config = bitmap.getConfig();
+
+ RsElementPredefined e = SkBitmapToPredefined(config);
+
+ if (e != RS_ELEMENT_USER_U8) {
+ bitmap.lockPixels();
+ const int w = bitmap.width();
+ const int h = bitmap.height();
+ const void* ptr = bitmap.getPixels();
+ jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElementPredefined)dstFmt, e, genMips, ptr);
+ bitmap.unlockPixels();
+ return id;
+ }
+ return 0;
+}
+
+static int
nAllocationCreateFromBitmapBoxed(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
@@ -1239,6 +1271,7 @@ static JNINativeMethod methods[] = {
{"nAllocationCreateSized", "(II)I", (void*)nAllocationCreateSized },
{"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap },
{"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed },
+{"nAllocationCreateFromAssetStream","(IZI)I", (void*)nAllocationCreateFromAssetStream },
{"nAllocationUploadToTexture", "(II)V", (void*)nAllocationUploadToTexture },
{"nAllocationUploadToBufferObject","(I)V", (void*)nAllocationUploadToBufferObject },
{"nAllocationData", "(I[II)V", (void*)nAllocationData_i },