summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/current.xml56
-rw-r--r--graphics/java/android/renderscript/Allocation.java67
-rw-r--r--libs/rs/rsAllocation.cpp49
3 files changed, 143 insertions, 29 deletions
diff --git a/api/current.xml b/api/current.xml
index f80701b..7fa3d26 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -166384,6 +166384,60 @@
<parameter name="b" type="android.graphics.Bitmap">
</parameter>
</method>
+<method name="createCubemapFromCubeFaces"
+ return="android.renderscript.Allocation"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="rs" type="android.renderscript.RenderScript">
+</parameter>
+<parameter name="xpos" type="android.graphics.Bitmap">
+</parameter>
+<parameter name="xneg" type="android.graphics.Bitmap">
+</parameter>
+<parameter name="ypos" type="android.graphics.Bitmap">
+</parameter>
+<parameter name="yneg" type="android.graphics.Bitmap">
+</parameter>
+<parameter name="zpos" type="android.graphics.Bitmap">
+</parameter>
+<parameter name="zneg" type="android.graphics.Bitmap">
+</parameter>
+<parameter name="mips" type="android.renderscript.Allocation.MipmapControl">
+</parameter>
+<parameter name="usage" type="int">
+</parameter>
+</method>
+<method name="createCubemapFromCubeFaces"
+ return="android.renderscript.Allocation"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="rs" type="android.renderscript.RenderScript">
+</parameter>
+<parameter name="xpos" type="android.graphics.Bitmap">
+</parameter>
+<parameter name="xneg" type="android.graphics.Bitmap">
+</parameter>
+<parameter name="ypos" type="android.graphics.Bitmap">
+</parameter>
+<parameter name="yneg" type="android.graphics.Bitmap">
+</parameter>
+<parameter name="zpos" type="android.graphics.Bitmap">
+</parameter>
+<parameter name="zneg" type="android.graphics.Bitmap">
+</parameter>
+</method>
<method name="createFromBitmap"
return="android.renderscript.Allocation"
abstract="false"
@@ -258033,7 +258087,7 @@
deprecated="not deprecated"
visibility="public"
>
-<parameter name="t" type="T">
+<parameter name="arg0" type="T">
</parameter>
</method>
</interface>
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 7a47c3b..7a76685 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -18,7 +18,6 @@ package android.renderscript;
import java.io.IOException;
import java.io.InputStream;
-
import android.content.res.Resources;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
@@ -427,7 +426,7 @@ public class Allocation extends BaseObj {
throw new RSIllegalArgumentException("Cubemap height must be multiple of 6");
}
if (width / 6 != height) {
- throw new RSIllegalArgumentException("Only square cobe map faces supported");
+ throw new RSIllegalArgumentException("Only square cube map faces supported");
}
boolean isPow2 = (height & (height - 1)) == 0;
if (!isPow2) {
@@ -449,11 +448,73 @@ public class Allocation extends BaseObj {
return new Allocation(id, rs, t, usage);
}
- static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b) {
+ static public Allocation createCubemapFromBitmap(RenderScript rs,
+ Bitmap b) {
return createCubemapFromBitmap(rs, b, MipmapControl.MIPMAP_NONE,
USAGE_GRAPHICS_TEXTURE);
}
+ static public Allocation createCubemapFromCubeFaces(RenderScript rs,
+ Bitmap xpos,
+ Bitmap xneg,
+ Bitmap ypos,
+ Bitmap yneg,
+ Bitmap zpos,
+ Bitmap zneg,
+ MipmapControl mips,
+ int usage) {
+ int height = xpos.getHeight();
+ if (xpos.getWidth() != height ||
+ xneg.getWidth() != height || xneg.getHeight() != height ||
+ ypos.getWidth() != height || ypos.getHeight() != height ||
+ yneg.getWidth() != height || yneg.getHeight() != height ||
+ zpos.getWidth() != height || zpos.getHeight() != height ||
+ zneg.getWidth() != height || zneg.getHeight() != height) {
+ throw new RSIllegalArgumentException("Only square cube map faces supported");
+ }
+ boolean isPow2 = (height & (height - 1)) == 0;
+ if (!isPow2) {
+ throw new RSIllegalArgumentException("Only power of 2 cube faces supported");
+ }
+
+ Element e = elementFromBitmap(rs, xpos);
+ Type.Builder tb = new Type.Builder(rs, e);
+ tb.setX(height);
+ tb.setY(height);
+ tb.setFaces(true);
+ tb.setMipmaps(mips == MipmapControl.MIPMAP_FULL);
+ Type t = tb.create();
+ Allocation cubemap = Allocation.createTyped(rs, t, mips, usage);
+
+ AllocationAdapter adapter = AllocationAdapter.create2D(rs, cubemap);
+ adapter.setFace(Type.CubemapFace.POSITVE_X);
+ adapter.copyFrom(xpos);
+ adapter.setFace(Type.CubemapFace.NEGATIVE_X);
+ adapter.copyFrom(xneg);
+ adapter.setFace(Type.CubemapFace.POSITVE_Y);
+ adapter.copyFrom(ypos);
+ adapter.setFace(Type.CubemapFace.NEGATIVE_Y);
+ adapter.copyFrom(yneg);
+ adapter.setFace(Type.CubemapFace.POSITVE_Z);
+ adapter.copyFrom(zpos);
+ adapter.setFace(Type.CubemapFace.NEGATIVE_Z);
+ adapter.copyFrom(zneg);
+
+ return cubemap;
+ }
+
+ static public Allocation createCubemapFromCubeFaces(RenderScript rs,
+ Bitmap xpos,
+ Bitmap xneg,
+ Bitmap ypos,
+ Bitmap yneg,
+ Bitmap zpos,
+ Bitmap zneg) {
+ return createCubemapFromCubeFaces(rs, xpos, xneg, ypos, yneg,
+ zpos, zneg, MipmapControl.MIPMAP_NONE,
+ USAGE_GRAPHICS_TEXTURE);
+ }
+
static public Allocation createFromBitmapResource(RenderScript rs,
Resources res,
int id,
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index 673ade2..d6b90e6 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -28,6 +28,8 @@
#include "utils/StopWatch.h"
+static void rsaAllocationGenerateScriptMips(RsContext con, RsAllocation va);
+
using namespace android;
using namespace android::renderscript;
@@ -699,13 +701,7 @@ void rsi_AllocationCopyFromBitmap(Context *rsc, RsAllocation va, const void *dat
if (texAlloc->getIsScript()) {
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);
- }
+ rsaAllocationGenerateScriptMips(rsc, texAlloc);
}
} else {
texAlloc->upload2DTexture(false, data);
@@ -770,6 +766,23 @@ void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32
}
}
+static void rsaAllocationGenerateScriptMips(RsContext con, RsAllocation va) {
+ Context *rsc = static_cast<Context *>(con);
+ Allocation *texAlloc = static_cast<Allocation *>(va);
+ uint32_t numFaces = texAlloc->getType()->getDimFaces() ? 6 : 1;
+ for (uint32_t face = 0; face < numFaces; face ++) {
+ Adapter2D adapt(rsc, texAlloc);
+ Adapter2D adapt2(rsc, texAlloc);
+ adapt.setFace(face);
+ adapt2.setFace(face);
+ for (uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) {
+ adapt.setLOD(lod);
+ adapt2.setLOD(lod + 1);
+ mip(adapt2, adapt);
+ }
+ }
+}
+
const void * rsaAllocationGetType(RsContext con, RsAllocation va) {
Allocation *a = static_cast<Allocation *>(va);
a->getType()->incUserRef();
@@ -802,13 +815,7 @@ RsAllocation rsaAllocationCreateFromBitmap(RsContext con, RsType vtype,
memcpy(texAlloc->getPtr(), data, t->getDimX() * t->getDimY() * t->getElementSizeBytes());
if (mips == RS_ALLOCATION_MIPMAP_FULL) {
- 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);
- }
+ rsaAllocationGenerateScriptMips(rsc, texAlloc);
}
texAlloc->deferedUploadToTexture(rsc);
@@ -846,18 +853,10 @@ RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype,
// Move the data pointer to the next cube face
sourcePtr += copySize;
+ }
- if (mips == RS_ALLOCATION_MIPMAP_FULL) {
- Adapter2D adapt(rsc, texAlloc);
- Adapter2D adapt2(rsc, texAlloc);
- adapt.setFace(face);
- adapt2.setFace(face);
- for (uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) {
- adapt.setLOD(lod);
- adapt2.setLOD(lod + 1);
- mip(adapt2, adapt);
- }
- }
+ if (mips == RS_ALLOCATION_MIPMAP_FULL) {
+ rsaAllocationGenerateScriptMips(rsc, texAlloc);
}
texAlloc->deferedUploadToTexture(rsc);