diff --git a/api/current.xml b/api/current.xml
index 53ab70c012764..3451402d8014d 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -166131,7 +166131,7 @@
-
+
-
+
-
+
-
+
-
+
+
+
0)|| (mType.getZ() > 0) || mType.hasFaces() || mType.hasMipmaps()) {
throw new RSInvalidStateException("Resize only support for 1D allocations at this time.");
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 4c9ad569262a6..28b32d5df69c2 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -223,6 +223,10 @@ public class RenderScript {
synchronized void nAllocationSyncAll(int alloc, int src) {
rsnAllocationSyncAll(mContext, alloc, src);
}
+ native void rsnAllocationGenerateMipmaps(int con, int alloc);
+ synchronized void nAllocationGenerateMipmaps(int alloc) {
+ rsnAllocationGenerateMipmaps(mContext, alloc);
+ }
native void rsnAllocationCopyFromBitmap(int con, int alloc, Bitmap bmp);
synchronized void nAllocationCopyFromBitmap(int alloc, Bitmap bmp) {
rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 1817a1b0d7ae3..a7913d7e08641 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -411,6 +411,13 @@ nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits
rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
}
+static void
+nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
+{
+ LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
+ rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
+}
+
static int
nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
{
@@ -445,10 +452,14 @@ nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc
SkBitmap const * nativeBitmap =
(SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
const SkBitmap& bitmap(*nativeBitmap);
+ int w = bitmap.width();
+ int h = bitmap.height();
bitmap.lockPixels();
const void* ptr = bitmap.getPixels();
- rsAllocationCopyFromBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
+ rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
+ 0, RS_ALLOCATION_CUBMAP_FACE_POSITVE_X,
+ w, h, ptr, bitmap.getSize());
bitmap.unlockPixels();
}
@@ -1211,6 +1222,7 @@ static JNINativeMethod methods[] = {
{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
{"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D },
+{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 33ac2f0b1de1e..7e23cec908050 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -77,12 +77,6 @@ ElementCreate2 {
ret RsElement
}
-AllocationCopyFromBitmap {
- param RsAllocation alloc
- param const void * data
- param size_t dataLen
- }
-
AllocationCopyToBitmap {
param RsAllocation alloc
param void * data
@@ -135,6 +129,10 @@ Allocation2DElementData {
param uint32_t bytes
}
+AllocationGenerateMipmaps {
+ param RsAllocation va
+}
+
AllocationRead {
param RsAllocation va
param void * data
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index d6b90e6d13bd8..cf394c0dc1c74 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -342,26 +342,34 @@ void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod,
uint32_t lineSize = eSize * w;
uint32_t destW = mType->getDimX();
- const uint8_t *src = static_cast(data);
- uint8_t *dst = static_cast(mPtr);
- dst += eSize * (xoff + yoff * destW);
+ //LOGE("data2d %p, %i %i %i %i %i %i %p %i", this, xoff, yoff, lod, face, w, h, data, sizeBytes);
- if ((lineSize * eSize * h) != sizeBytes) {
+ if ((lineSize * h) != sizeBytes) {
+ LOGE("Allocation size mismatch, expected %i, got %i", (lineSize * h), sizeBytes);
rsAssert(!"Allocation::subData called with mismatched size");
return;
}
- for (uint32_t line=yoff; line < (yoff+h); line++) {
- if (mType->getElement()->getHasReferences()) {
- incRefs(src, w);
- decRefs(dst, w);
+ if (mPtr) {
+ const uint8_t *src = static_cast(data);
+ uint8_t *dst = static_cast(mPtr);
+ dst += mType->getLODOffset(lod, xoff, yoff);
+
+ //LOGE(" %p %p %i ", dst, src, eSize);
+ for (uint32_t line=yoff; line < (yoff+h); line++) {
+ if (mType->getElement()->getHasReferences()) {
+ incRefs(src, w);
+ decRefs(dst, w);
+ }
+ memcpy(dst, src, lineSize);
+ src += lineSize;
+ dst += destW * eSize;
}
- memcpy(dst, src, lineSize);
- src += lineSize;
- dst += destW * eSize;
+ sendDirty();
+ mUploadDefered = true;
+ } else {
+ upload2DTexture(false, data);
}
- sendDirty();
- mUploadDefered = true;
}
void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, RsAllocationCubemapFace face,
@@ -685,28 +693,9 @@ void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType
a->syncAll(rsc, src);
}
-void rsi_AllocationCopyFromBitmap(Context *rsc, RsAllocation va, const void *data, size_t dataLen) {
+void rsi_AllocationGenerateMipmaps(Context *rsc, RsAllocation va) {
Allocation *texAlloc = static_cast(va);
- const Type * t = texAlloc->getType();
-
- uint32_t w = t->getDimX();
- uint32_t h = t->getDimY();
- bool genMips = t->getDimLOD();
- size_t s = w * h * t->getElementSizeBytes();
- if (s != dataLen) {
- rsc->setError(RS_ERROR_BAD_VALUE, "Bitmap size didn't match allocation size");
- return;
- }
-
- if (texAlloc->getIsScript()) {
- memcpy(texAlloc->getPtr(), data, s);
- if (genMips) {
- rsaAllocationGenerateScriptMips(rsc, texAlloc);
- }
- } else {
- texAlloc->upload2DTexture(false, data);
- }
-
+ rsaAllocationGenerateScriptMips(rsc, texAlloc);
}
void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t dataLen) {