summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2010-12-10 16:03:15 -0800
committerJason Sams <rjsams@android.com>2010-12-10 16:03:15 -0800
commit4ef6650bd05a39a09958ea1db92f120ea4949cb1 (patch)
tree19e72e8c62fe8239d453826f4610feb7491dbcba /libs
parent16bb80af66012cee1625dd4e926c1fbdf87b8670 (diff)
downloadframeworks_base-4ef6650bd05a39a09958ea1db92f120ea4949cb1.zip
frameworks_base-4ef6650bd05a39a09958ea1db92f120ea4949cb1.tar.gz
frameworks_base-4ef6650bd05a39a09958ea1db92f120ea4949cb1.tar.bz2
Remove CreateFromBitmapRef and add
CopyTo(bitmap) replacement. Change-Id: Ib73fb9f4bfe5f468eaf0f8f1bf68a93759eef00d
Diffstat (limited to 'libs')
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java16
-rw-r--r--libs/rs/rs.spec10
-rw-r--r--libs/rs/rsAllocation.cpp54
3 files changed, 51 insertions, 29 deletions
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
index e935fa9..09654ab 100644
--- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
@@ -283,7 +283,7 @@ public class ImageProcessingActivity extends Activity
long t = java.lang.System.currentTimeMillis();
if (true) {
mScript.invoke_filter();
- mRS.finish();
+ mOutPixelsAllocation.copyTo(mBitmapOut);
} else {
javaFilter();
mDisplayView.invalidate();
@@ -352,7 +352,7 @@ public class ImageProcessingActivity extends Activity
public void surfaceCreated(SurfaceHolder holder) {
createScript();
mScript.invoke_filter();
- mRS.finish();
+ mOutPixelsAllocation.copyTo(mBitmapOut);
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
@@ -365,8 +365,12 @@ public class ImageProcessingActivity extends Activity
mRS = RenderScript.create();
mRS.setMessageHandler(new FilterCallback());
- mInPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapIn);
- mOutPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapOut);
+ mInPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
+ Allocation.MipmapControl.MIPMAP_NONE,
+ Allocation.USAGE_SCRIPT);
+ mOutPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapOut,
+ Allocation.MipmapControl.MIPMAP_NONE,
+ Allocation.USAGE_SCRIPT);
Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS));
tb.setX(mBitmapIn.getWidth());
@@ -419,7 +423,7 @@ public class ImageProcessingActivity extends Activity
long t = java.lang.System.currentTimeMillis();
mScript.invoke_filter();
- mRS.finish();
+ mOutPixelsAllocation.copyTo(mBitmapOut);
t = java.lang.System.currentTimeMillis() - t;
android.util.Log.v("Img", "Renderscript frame time core ms " + t);
@@ -432,6 +436,6 @@ public class ImageProcessingActivity extends Activity
mScript.set_radius(mRadius);
mScript.invoke_filter();
- mRS.finish();
+ mOutPixelsAllocation.copyTo(mBitmapOut);
}
}
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 97ecca0..14094c4 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -77,10 +77,16 @@ ElementCreate2 {
ret RsElement
}
-AllocationUpdateFromBitmap {
+AllocationCopyFromBitmap {
param RsAllocation alloc
- param RsElement srcFmt
param const void * data
+ param size_t dataLen
+ }
+
+AllocationCopyToBitmap {
+ param RsAllocation alloc
+ param void * data
+ param size_t dataLen
}
AllocationCreateBitmapRef {
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index f42be0e..10a5caf 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -763,32 +763,44 @@ RsAllocation rsi_AllocationCreateBitmapRef(Context *rsc, RsType vtype,
return alloc;
}
-void rsi_AllocationUpdateFromBitmap(Context *rsc, RsAllocation va,
- RsElement _src, const void *data) {
+void rsi_AllocationCopyFromBitmap(Context *rsc, RsAllocation va, const void *data, size_t dataLen) {
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);
- }
+ 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;
+ }
+
+ memcpy(texAlloc->getPtr(), data, s);
+ 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");
}
}
+void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t dataLen) {
+ Allocation *texAlloc = static_cast<Allocation *>(va);
+ const Type * t = texAlloc->getType();
+
+ size_t s = t->getDimX() * t->getDimY() * t->getElementSizeBytes();
+ if (s != dataLen) {
+ rsc->setError(RS_ERROR_BAD_VALUE, "Bitmap size didn't match allocation size");
+ return;
+ }
+
+ memcpy(data, texAlloc->getPtr(), s);
+}
+
void rsi_AllocationData(Context *rsc, RsAllocation va, const void *data, uint32_t sizeBytes) {
Allocation *a = static_cast<Allocation *>(va);
a->data(rsc, data, sizeBytes);