Loading graphics/java/android/renderscript/Allocation.java +12 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,18 @@ public class Allocation extends BaseObj { subData1D(0, mType.getElementCount(), d); } public void updateFromBitmap(Bitmap b) throws IllegalArgumentException { mRS.validate(); if(mType.getX() != b.getWidth() || mType.getY() != b.getHeight()) { throw new IllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch"); } mRS.nAllocationUpdateFromBitmap(mID, b); } public void subData(int xoff, FieldPacker fp) { int eSize = mType.mElement.getSizeBytes(); final byte[] data = fp.getData(); Loading graphics/java/android/renderscript/RenderScript.java +4 −0 Original line number Diff line number Diff line Loading @@ -186,6 +186,10 @@ public class RenderScript { synchronized int nAllocationCreateTyped(int type) { return rsnAllocationCreateTyped(mContext, type); } native void rsnAllocationUpdateFromBitmap(int con, int alloc, Bitmap bmp); synchronized void nAllocationUpdateFromBitmap(int alloc, Bitmap bmp) { rsnAllocationUpdateFromBitmap(mContext, alloc, bmp); } native int rsnAllocationCreateFromBitmap(int con, int dstFmt, boolean genMips, Bitmap bmp); synchronized int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp) { return rsnAllocationCreateFromBitmap(mContext, dstFmt, genMips, bmp); Loading graphics/jni/android_renderscript_RenderScript.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -423,6 +423,23 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint dst return 0; } static void nAllocationUpdateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap) { SkBitmap const * nativeBitmap = (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); const SkBitmap& bitmap(*nativeBitmap); SkBitmap::Config config = bitmap.getConfig(); RsElement e = SkBitmapToPredefined(config); if (e) { bitmap.lockPixels(); const void* ptr = bitmap.getPixels(); rsAllocationUpdateFromBitmap(con, (RsAllocation)alloc, e, ptr); bitmap.unlockPixels(); } } static void ReleaseBitmapCallback(void *bmp) { SkBitmap const * nativeBitmap = (SkBitmap const *)bmp; Loading Loading @@ -1234,6 +1251,7 @@ static JNINativeMethod methods[] = { {"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData }, {"rsnAllocationCreateTyped", "(II)I", (void*)nAllocationCreateTyped }, {"rsnAllocationUpdateFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationUpdateFromBitmap }, {"rsnAllocationCreateFromBitmap", "(IIZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap }, {"rsnAllocationCreateBitmapRef", "(IILandroid/graphics/Bitmap;)I", (void*)nAllocationCreateBitmapRef }, {"rsnAllocationCreateFromAssetStream","(IIZI)I", (void*)nAllocationCreateFromAssetStream }, Loading libs/rs/rs.spec +6 −0 Original line number Diff line number Diff line Loading @@ -127,6 +127,12 @@ AllocationCreateSized { ret RsAllocation } AllocationUpdateFromBitmap { param RsAllocation alloc param RsElement srcFmt param const void * data } AllocationCreateBitmapRef { param RsType type param void * bmpPtr Loading libs/rs/rsAllocation.cpp +40 −3 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ #include <OpenGl/glext.h> #endif #include "utils/StopWatch.h" using namespace android; using namespace android::renderscript; Loading Loading @@ -150,6 +152,8 @@ void Allocation::uploadToTexture(const Context *rsc) return; } bool isFirstUpload = false; if (!mTextureID) { glGenTextures(1, &mTextureID); Loading @@ -162,6 +166,7 @@ void Allocation::uploadToTexture(const Context *rsc) mUploadDefered = true; return; } isFirstUpload = true; } glBindTexture(GL_TEXTURE_2D, mTextureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); Loading @@ -171,9 +176,15 @@ void Allocation::uploadToTexture(const Context *rsc) adapt.setLOD(lod+mTextureLOD); uint16_t * ptr = static_cast<uint16_t *>(adapt.getElement(0,0)); if(isFirstUpload) { glTexImage2D(GL_TEXTURE_2D, lod, format, adapt.getDimX(), adapt.getDimY(), 0, format, type, ptr); } else { glTexSubImage2D(GL_TEXTURE_2D, lod, 0, 0, adapt.getDimX(), adapt.getDimY(), format, type, ptr); } } if (mTextureGenMipmap) { #ifndef ANDROID_RS_BUILD_FOR_HOST Loading Loading @@ -751,6 +762,32 @@ RsAllocation rsi_AllocationCreateBitmapRef(Context *rsc, RsType vtype, return alloc; } void rsi_AllocationUpdateFromBitmap(Context *rsc, RsAllocation va, RsElement _src, const void *data) { Allocation *texAlloc = static_cast<Allocation *>(va); const Element *src = static_cast<const Element *>(_src); const Element *dst = texAlloc->getType()->getElement(); uint32_t w = texAlloc->getType()->getDimX(); uint32_t h = texAlloc->getType()->getDimY(); bool genMips = texAlloc->getType()->getDimLOD(); ElementConverter_t cvt = pickConverter(dst, src); if (cvt) { cvt(texAlloc->getPtr(), data, w * h); if (genMips) { Adapter2D adapt(rsc, texAlloc); Adapter2D adapt2(rsc, texAlloc); for(uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) { adapt.setLOD(lod); adapt2.setLOD(lod + 1); mip(adapt2, adapt); } } } else { rsc->setError(RS_ERROR_BAD_VALUE, "Unsupported bitmap format"); } } RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h, RsElement _dst, RsElement _src, bool genMips, const void *data) { const Element *src = static_cast<const Element *>(_src); Loading Loading
graphics/java/android/renderscript/Allocation.java +12 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,18 @@ public class Allocation extends BaseObj { subData1D(0, mType.getElementCount(), d); } public void updateFromBitmap(Bitmap b) throws IllegalArgumentException { mRS.validate(); if(mType.getX() != b.getWidth() || mType.getY() != b.getHeight()) { throw new IllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch"); } mRS.nAllocationUpdateFromBitmap(mID, b); } public void subData(int xoff, FieldPacker fp) { int eSize = mType.mElement.getSizeBytes(); final byte[] data = fp.getData(); Loading
graphics/java/android/renderscript/RenderScript.java +4 −0 Original line number Diff line number Diff line Loading @@ -186,6 +186,10 @@ public class RenderScript { synchronized int nAllocationCreateTyped(int type) { return rsnAllocationCreateTyped(mContext, type); } native void rsnAllocationUpdateFromBitmap(int con, int alloc, Bitmap bmp); synchronized void nAllocationUpdateFromBitmap(int alloc, Bitmap bmp) { rsnAllocationUpdateFromBitmap(mContext, alloc, bmp); } native int rsnAllocationCreateFromBitmap(int con, int dstFmt, boolean genMips, Bitmap bmp); synchronized int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp) { return rsnAllocationCreateFromBitmap(mContext, dstFmt, genMips, bmp); Loading
graphics/jni/android_renderscript_RenderScript.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -423,6 +423,23 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint dst return 0; } static void nAllocationUpdateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap) { SkBitmap const * nativeBitmap = (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); const SkBitmap& bitmap(*nativeBitmap); SkBitmap::Config config = bitmap.getConfig(); RsElement e = SkBitmapToPredefined(config); if (e) { bitmap.lockPixels(); const void* ptr = bitmap.getPixels(); rsAllocationUpdateFromBitmap(con, (RsAllocation)alloc, e, ptr); bitmap.unlockPixels(); } } static void ReleaseBitmapCallback(void *bmp) { SkBitmap const * nativeBitmap = (SkBitmap const *)bmp; Loading Loading @@ -1234,6 +1251,7 @@ static JNINativeMethod methods[] = { {"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData }, {"rsnAllocationCreateTyped", "(II)I", (void*)nAllocationCreateTyped }, {"rsnAllocationUpdateFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationUpdateFromBitmap }, {"rsnAllocationCreateFromBitmap", "(IIZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap }, {"rsnAllocationCreateBitmapRef", "(IILandroid/graphics/Bitmap;)I", (void*)nAllocationCreateBitmapRef }, {"rsnAllocationCreateFromAssetStream","(IIZI)I", (void*)nAllocationCreateFromAssetStream }, Loading
libs/rs/rs.spec +6 −0 Original line number Diff line number Diff line Loading @@ -127,6 +127,12 @@ AllocationCreateSized { ret RsAllocation } AllocationUpdateFromBitmap { param RsAllocation alloc param RsElement srcFmt param const void * data } AllocationCreateBitmapRef { param RsType type param void * bmpPtr Loading
libs/rs/rsAllocation.cpp +40 −3 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ #include <OpenGl/glext.h> #endif #include "utils/StopWatch.h" using namespace android; using namespace android::renderscript; Loading Loading @@ -150,6 +152,8 @@ void Allocation::uploadToTexture(const Context *rsc) return; } bool isFirstUpload = false; if (!mTextureID) { glGenTextures(1, &mTextureID); Loading @@ -162,6 +166,7 @@ void Allocation::uploadToTexture(const Context *rsc) mUploadDefered = true; return; } isFirstUpload = true; } glBindTexture(GL_TEXTURE_2D, mTextureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); Loading @@ -171,9 +176,15 @@ void Allocation::uploadToTexture(const Context *rsc) adapt.setLOD(lod+mTextureLOD); uint16_t * ptr = static_cast<uint16_t *>(adapt.getElement(0,0)); if(isFirstUpload) { glTexImage2D(GL_TEXTURE_2D, lod, format, adapt.getDimX(), adapt.getDimY(), 0, format, type, ptr); } else { glTexSubImage2D(GL_TEXTURE_2D, lod, 0, 0, adapt.getDimX(), adapt.getDimY(), format, type, ptr); } } if (mTextureGenMipmap) { #ifndef ANDROID_RS_BUILD_FOR_HOST Loading Loading @@ -751,6 +762,32 @@ RsAllocation rsi_AllocationCreateBitmapRef(Context *rsc, RsType vtype, return alloc; } void rsi_AllocationUpdateFromBitmap(Context *rsc, RsAllocation va, RsElement _src, const void *data) { Allocation *texAlloc = static_cast<Allocation *>(va); const Element *src = static_cast<const Element *>(_src); const Element *dst = texAlloc->getType()->getElement(); uint32_t w = texAlloc->getType()->getDimX(); uint32_t h = texAlloc->getType()->getDimY(); bool genMips = texAlloc->getType()->getDimLOD(); ElementConverter_t cvt = pickConverter(dst, src); if (cvt) { cvt(texAlloc->getPtr(), data, w * h); if (genMips) { Adapter2D adapt(rsc, texAlloc); Adapter2D adapt2(rsc, texAlloc); for(uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) { adapt.setLOD(lod); adapt2.setLOD(lod + 1); mip(adapt2, adapt); } } } else { rsc->setError(RS_ERROR_BAD_VALUE, "Unsupported bitmap format"); } } RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h, RsElement _dst, RsElement _src, bool genMips, const void *data) { const Element *src = static_cast<const Element *>(_src); Loading