summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2011-01-12 13:28:37 -0800
committerJason Sams <rjsams@android.com>2011-01-12 13:28:37 -0800
commitf7086090cfc8d97b5bd3b4d7801a27af11f7c207 (patch)
tree44ac295d7ede32a76af74f20b80a95cb2a6d1e13 /graphics
parent1415bb7a948e0add9f6beb6dccbea70e9d2bedd0 (diff)
downloadframeworks_base-f7086090cfc8d97b5bd3b4d7801a27af11f7c207.zip
frameworks_base-f7086090cfc8d97b5bd3b4d7801a27af11f7c207.tar.gz
frameworks_base-f7086090cfc8d97b5bd3b4d7801a27af11f7c207.tar.bz2
Cleanup bitmap uploads
Implement standalone mipmap generation. Change-Id: Ie3a9781bbe50e2f58adca6f184d84fea50e40263
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/renderscript/Allocation.java113
-rw-r--r--graphics/java/android/renderscript/RenderScript.java4
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp14
3 files changed, 120 insertions, 11 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index abe66726..0c33a5f 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -46,15 +46,62 @@ public class Allocation extends BaseObj {
Bitmap mBitmap;
int mUsage;
+ /**
+ * The usage of the allocation. These signal to renderscript
+ * where to place the allocation in memory.
+ *
+ * SCRIPT The allocation will be bound to and accessed by
+ * scripts.
+ */
public static final int USAGE_SCRIPT = 0x0001;
+
+ /**
+ * GRAPHICS_TEXTURE The allcation will be used as a texture
+ * source by one or more graphcics programs.
+ *
+ */
public static final int USAGE_GRAPHICS_TEXTURE = 0x0002;
+
+ /**
+ * GRAPHICS_VERTEX The allocation will be used as a graphics
+ * mesh.
+ *
+ */
public static final int USAGE_GRAPHICS_VERTEX = 0x0004;
+
+
+ /**
+ * GRAPHICS_CONSTANTS The allocation will be used as the source
+ * of shader constants by one or more programs.
+ *
+ */
public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008;
+ /**
+ * Controls mipmap behavior when using the bitmap creation and
+ * update functions.
+ */
public enum MipmapControl {
+ /**
+ * No mipmaps will be generated and the type generated from the
+ * incoming bitmap will not contain additional LODs.
+ */
MIPMAP_NONE(0),
+
+ /**
+ * A Full mipmap chain will be created in script memory. The
+ * type of the allocation will contain a full mipmap chain. On
+ * upload to graphics the full chain will be transfered.
+ */
MIPMAP_FULL(1),
+
+ /**
+ * The type of the allocation will be the same as MIPMAP_NONE.
+ * It will not contain mipmaps. On upload to graphics the
+ * graphics copy of the allocation data will contain a full
+ * mipmap chain generated from the top level in script memory.
+ */
MIPMAP_ON_SYNC_TO_TEXTURE(2);
int mID;
@@ -256,6 +303,20 @@ public class Allocation extends BaseObj {
}
}
+ /**
+ * Generate a mipmap chain. Requires the type of the allocation
+ * include mipmaps.
+ *
+ * This function will generate a complete set of mipmaps from
+ * the top level lod and place them into the script memoryspace.
+ *
+ * If the allocation is also using other memory spaces a
+ * followup sync will be required.
+ */
+ public void generateMipmaps() {
+ mRS.nAllocationGenerateMipmaps(getID());
+ }
+
public void copy1DRangeFrom(int off, int count, int[] d) {
int dataSize = mType.mElement.getSizeBytes() * count;
data1DChecks(off, count, d.length * 4, dataSize);
@@ -278,29 +339,49 @@ public class Allocation extends BaseObj {
}
- public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] d) {
+ /**
+ * Copy a rectanglular region from the array into the
+ * allocation. The incoming array is assumed to be tightly
+ * packed.
+ *
+ * @param xoff X offset of the region to update
+ * @param yoff Y offset of the region to update
+ * @param w Width of the incoming region to update
+ * @param h Height of the incoming region to update
+ * @param data to be placed into the allocation
+ */
+ public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data) {
mRS.validate();
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, d, d.length);
+ mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length);
}
- public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] d) {
+ public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) {
mRS.validate();
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, d, d.length * 2);
+ mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length * 2);
}
- public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] d) {
+ public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data) {
mRS.validate();
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, d, d.length * 4);
+ mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length * 4);
}
- public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] d) {
+ public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data) {
mRS.validate();
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, d, d.length * 4);
+ mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length * 4);
}
- public void copy2DRangeFrom(int xoff, int yoff, Bitmap b) {
+ /**
+ * Copy a bitmap into an allocation. The height and width of
+ * the update will use the height and width of the incoming
+ * bitmap.
+ *
+ * @param xoff X offset of the region to update
+ * @param yoff Y offset of the region to update
+ * @param data the bitmap to be copied
+ */
+ public void copy2DRangeFrom(int xoff, int yoff, Bitmap data) {
mRS.validate();
- mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, b);
+ mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, data);
}
@@ -329,6 +410,18 @@ public class Allocation extends BaseObj {
mRS.nAllocationRead(getID(), d);
}
+ /**
+ * Resize a 1D allocation. The contents of the allocation are
+ * preserved. If new elements are allocated objects are created
+ * with null contents and the new region is otherwise undefined.
+ *
+ * If the new region is smaller the references of any objects
+ * outside the new region will be released.
+ *
+ * A new type will be created with the new dimension.
+ *
+ * @param dimX The new size of the allocation.
+ */
public synchronized void resize(int dimX) {
if ((mType.getY() > 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 4c9ad56..28b32d5 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 1817a1b..a7913d7 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 },