summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/Bitmap.java7
-rw-r--r--graphics/java/android/graphics/SurfaceTexture.java27
-rw-r--r--graphics/java/android/graphics/drawable/NinePatchDrawable.java12
-rw-r--r--graphics/java/android/renderscript/Element.java87
-rw-r--r--graphics/java/android/renderscript/ProgramRaster.java28
-rw-r--r--graphics/java/android/renderscript/ProgramStore.java93
-rw-r--r--graphics/java/android/renderscript/RSSurfaceView.java22
-rw-r--r--graphics/java/android/renderscript/RenderScript.java7
-rw-r--r--graphics/java/android/renderscript/Sampler.java59
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp12
10 files changed, 319 insertions, 35 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index 79acd55..380b3d8 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -604,10 +604,13 @@ public final class Bitmap implements Parcelable {
}
Bitmap bm = nativeCreate(null, 0, width, width, height, config.nativeInt, true);
if (config == Config.ARGB_8888 && !hasAlpha) {
- bm.eraseColor(0xff000000);
+ nativeErase(bm.mNativeBitmap, 0xff000000);
nativeSetHasAlpha(bm.mNativeBitmap, hasAlpha);
} else {
- bm.eraseColor(0);
+ // No need to initialize it to zeroes; it is backed by a VM byte array
+ // which is by definition preinitialized to all zeroes.
+ //
+ //nativeErase(bm.mNativeBitmap, 0);
}
return bm;
}
diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java
index f3b62ec..0521e69 100644
--- a/graphics/java/android/graphics/SurfaceTexture.java
+++ b/graphics/java/android/graphics/SurfaceTexture.java
@@ -17,6 +17,7 @@
package android.graphics;
import java.lang.ref.WeakReference;
+
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -130,10 +131,23 @@ public class SurfaceTexture {
}
/**
- * Set the size of buffers returned by requestBuffers when a width and height
- * of zero is requested.
+ * Set the default size of the image buffers. The image producer may override the buffer size,
+ * in which case the producer-set buffer size will be used, not the default size set by this
+ * method. Both video and camera based image producers do override the size. This method may
+ * be used to set the image size when producing images with {@link android.graphics.Canvas} (via
+ * {@link android.view.Surface#lockCanvas}), or OpenGL ES (via an EGLSurface).
*
- * @hide Pending approval by API council.
+ * The new default buffer size will take effect the next time the image producer requests a
+ * buffer to fill. For {@link android.graphics.Canvas} this will be the next time {@link
+ * android.view.Surface#lockCanvas} is called. For OpenGL ES, the EGLSurface should be
+ * destroyed (via eglDestroySurface), made not-current (via eglMakeCurrent), and then recreated
+ * (via eglCreateWindowSurface) to ensure that the new default size has taken effect.
+ *
+ * The width and height parameters must be no greater than the minimum of
+ * GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see
+ * {@link javax.microedition.khronos.opengles.GL10#glGetIntegerv glGetIntegerv}).
+ * An error due to invalid dimensions might not be reported until
+ * updateTexImage() is called.
*/
public void setDefaultBufferSize(int width, int height) {
nativeSetDefaultBufferSize(width, height);
@@ -145,7 +159,10 @@ public class SurfaceTexture {
* implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target.
*/
public void updateTexImage() {
- nativeUpdateTexImage();
+ int err = nativeUpdateTexImage();
+ if (err != 0) {
+ throw new RuntimeException("Error during updateTexImage (see logs)");
+ }
}
/**
@@ -251,7 +268,7 @@ public class SurfaceTexture {
private native void nativeGetTransformMatrix(float[] mtx);
private native long nativeGetTimestamp();
private native void nativeSetDefaultBufferSize(int width, int height);
- private native void nativeUpdateTexImage();
+ private native int nativeUpdateTexImage();
private native int nativeGetQueuedCount();
private native void nativeRelease();
diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
index bc7e906..18b8bc7 100644
--- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java
+++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
@@ -202,18 +202,30 @@ public class NinePatchDrawable extends Drawable {
@Override
public void setAlpha(int alpha) {
+ if (mPaint == null && alpha == 0xFF) {
+ // Fast common case -- leave at normal alpha.
+ return;
+ }
getPaint().setAlpha(alpha);
invalidateSelf();
}
@Override
public void setColorFilter(ColorFilter cf) {
+ if (mPaint == null && cf == null) {
+ // Fast common case -- leave at no color filter.
+ return;
+ }
getPaint().setColorFilter(cf);
invalidateSelf();
}
@Override
public void setDither(boolean dither) {
+ if (mPaint == null && dither == DEFAULT_DITHER) {
+ // Fast common case -- leave at default dither.
+ return;
+ }
getPaint().setDither(dither);
invalidateSelf();
}
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index f844331..8a9ca85 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -46,13 +46,18 @@ public class Element extends BaseObj {
Element[] mElements;
String[] mElementNames;
int[] mArraySizes;
+ int[] mOffsetInBytes;
DataType mType;
DataKind mKind;
boolean mNormalized;
int mVectorSize;
- int getSizeBytes() {return mSize;}
+ /**
+ * @hide
+ * @return element size in bytes
+ */
+ public int getSizeBytes() {return mSize;}
/**
@@ -152,6 +157,77 @@ public class Element extends BaseObj {
}
/**
+ * @hide
+ * @return number of sub-elements in this element
+ */
+ public int getSubElementCount() {
+ if (mElements == null) {
+ return 0;
+ }
+ return mElements.length;
+ }
+
+ /**
+ * @hide
+ * @param index index of the sub-element to return
+ * @return sub-element in this element at given index
+ */
+ public Element getSubElement(int index) {
+ if (mElements == null) {
+ throw new RSIllegalArgumentException("Element contains no sub-elements");
+ }
+ if (index < 0 || index >= mElements.length) {
+ throw new RSIllegalArgumentException("Illegal sub-element index");
+ }
+ return mElements[index];
+ }
+
+ /**
+ * @hide
+ * @param index index of the sub-element
+ * @return sub-element in this element at given index
+ */
+ public String getSubElementName(int index) {
+ if (mElements == null) {
+ throw new RSIllegalArgumentException("Element contains no sub-elements");
+ }
+ if (index < 0 || index >= mElements.length) {
+ throw new RSIllegalArgumentException("Illegal sub-element index");
+ }
+ return mElementNames[index];
+ }
+
+ /**
+ * @hide
+ * @param index index of the sub-element
+ * @return array size of sub-element in this element at given index
+ */
+ public int getSubElementArraySize(int index) {
+ if (mElements == null) {
+ throw new RSIllegalArgumentException("Element contains no sub-elements");
+ }
+ if (index < 0 || index >= mElements.length) {
+ throw new RSIllegalArgumentException("Illegal sub-element index");
+ }
+ return mArraySizes[index];
+ }
+
+ /**
+ * @hide
+ * @param index index of the sub-element
+ * @return offset in bytes of sub-element in this element at given index
+ */
+ public int getSubElementOffsetBytes(int index) {
+ if (mElements == null) {
+ throw new RSIllegalArgumentException("Element contains no sub-elements");
+ }
+ if (index < 0 || index >= mElements.length) {
+ throw new RSIllegalArgumentException("Illegal sub-element index");
+ }
+ return mOffsetInBytes[index];
+ }
+
+ /**
* Utility function for returning an Element containing a single Boolean.
*
* @param rs Context to which the element will belong.
@@ -602,7 +678,9 @@ public class Element extends BaseObj {
mElements = e;
mElementNames = n;
mArraySizes = as;
+ mOffsetInBytes = new int[mElements.length];
for (int ct = 0; ct < mElements.length; ct++ ) {
+ mOffsetInBytes[ct] = mSize;
mSize += mElements[ct].mSize * mArraySizes[ct];
}
}
@@ -653,13 +731,16 @@ public class Element extends BaseObj {
if(numSubElements > 0) {
mElements = new Element[numSubElements];
mElementNames = new String[numSubElements];
+ mArraySizes = new int[numSubElements];
+ mOffsetInBytes = new int[numSubElements];
int[] subElementIds = new int[numSubElements];
- mRS.nElementGetSubElements(getID(), subElementIds, mElementNames);
+ mRS.nElementGetSubElements(getID(), subElementIds, mElementNames, mArraySizes);
for(int i = 0; i < numSubElements; i ++) {
mElements[i] = new Element(subElementIds[i], mRS);
mElements[i].updateFromNative();
- mSize += mElements[i].mSize;
+ mOffsetInBytes[i] = mSize;
+ mSize += mElements[i].mSize * mArraySizes[i];
}
}
diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java
index 60d9698..93ee0ce 100644
--- a/graphics/java/android/renderscript/ProgramRaster.java
+++ b/graphics/java/android/renderscript/ProgramRaster.java
@@ -37,23 +37,32 @@ public class ProgramRaster extends BaseObj {
}
}
- boolean mPointSmooth;
- boolean mLineSmooth;
boolean mPointSprite;
- float mLineWidth;
CullMode mCullMode;
ProgramRaster(int id, RenderScript rs) {
super(id, rs);
- mLineWidth = 1.0f;
- mPointSmooth = false;
- mLineSmooth = false;
mPointSprite = false;
-
mCullMode = CullMode.BACK;
}
+ /**
+ * @hide
+ * @return whether point sprites are enabled
+ */
+ public boolean getPointSpriteEnabled() {
+ return mPointSprite;
+ }
+
+ /**
+ * @hide
+ * @return cull mode
+ */
+ public CullMode getCullMode() {
+ return mCullMode;
+ }
+
public static ProgramRaster CULL_BACK(RenderScript rs) {
if(rs.mProgramRaster_CULL_BACK == null) {
ProgramRaster.Builder builder = new ProgramRaster.Builder(rs);
@@ -105,7 +114,10 @@ public class ProgramRaster extends BaseObj {
public ProgramRaster create() {
mRS.validate();
int id = mRS.nProgramRasterCreate(mPointSprite, mCullMode.mID);
- return new ProgramRaster(id, mRS);
+ ProgramRaster programRaster = new ProgramRaster(id, mRS);
+ programRaster.mPointSprite = mPointSprite;
+ programRaster.mCullMode = mCullMode;
+ return programRaster;
}
}
diff --git a/graphics/java/android/renderscript/ProgramStore.java b/graphics/java/android/renderscript/ProgramStore.java
index fb7c8ca..677dadd 100644
--- a/graphics/java/android/renderscript/ProgramStore.java
+++ b/graphics/java/android/renderscript/ProgramStore.java
@@ -135,12 +135,93 @@ public class ProgramStore extends BaseObj {
}
}
+ DepthFunc mDepthFunc;
+ boolean mDepthMask;
+ boolean mColorMaskR;
+ boolean mColorMaskG;
+ boolean mColorMaskB;
+ boolean mColorMaskA;
+ BlendSrcFunc mBlendSrc;
+ BlendDstFunc mBlendDst;
+ boolean mDither;
ProgramStore(int id, RenderScript rs) {
super(id, rs);
}
/**
+ * @hide
+ * @return depth function
+ */
+ public DepthFunc getDepthFunc() {
+ return mDepthFunc;
+ }
+
+ /**
+ * @hide
+ * @return whether depth writes are enabled
+ */
+ public boolean getDepthMaskEnabled() {
+ return mDepthMask;
+ }
+
+ /**
+ * @hide
+ * @return red color channel mask
+ */
+ public boolean getColorMaskREnabled() {
+ return mColorMaskR;
+ }
+
+ /**
+ * @hide
+ * @return green color channel mask
+ */
+ public boolean getColorMaskGEnabled() {
+ return mColorMaskG;
+ }
+
+ /**
+ * @hide
+ * @return blue color channel mask
+ */
+ public boolean getColorMaskBEnabled() {
+ return mColorMaskB;
+ }
+
+ /**
+ * @hide
+ * @return alpha channel mask
+ */
+ public boolean getColorMaskAEnabled() {
+ return mColorMaskA;
+ }
+
+ /**
+ * @hide
+ * @return source blend function
+ */
+ public BlendSrcFunc getBlendSrcFunc() {
+ return mBlendSrc;
+ }
+
+ /**
+ * @hide
+ * @return destination blend function
+ */
+ public BlendDstFunc getBlendDstFunc() {
+ return mBlendDst;
+ }
+
+ /**
+ * @hide
+ * @return whether dither is enabled
+ */
+ public boolean getDitherEnabled() {
+ return mDither;
+ }
+
+ /**
* Returns a pre-defined program store object with the following
* characteristics:
* - incoming pixels are drawn if their depth value is less than
@@ -340,7 +421,17 @@ public class ProgramStore extends BaseObj {
int id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA,
mDepthMask, mDither,
mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID);
- return new ProgramStore(id, mRS);
+ ProgramStore programStore = new ProgramStore(id, mRS);
+ programStore.mDepthFunc = mDepthFunc;
+ programStore.mDepthMask = mDepthMask;
+ programStore.mColorMaskR = mColorMaskR;
+ programStore.mColorMaskG = mColorMaskG;
+ programStore.mColorMaskB = mColorMaskB;
+ programStore.mColorMaskA = mColorMaskA;
+ programStore.mBlendSrc = mBlendSrc;
+ programStore.mBlendDst = mBlendDst;
+ programStore.mDither = mDither;
+ return programStore;
}
}
diff --git a/graphics/java/android/renderscript/RSSurfaceView.java b/graphics/java/android/renderscript/RSSurfaceView.java
index 199952c..a8e3107 100644
--- a/graphics/java/android/renderscript/RSSurfaceView.java
+++ b/graphics/java/android/renderscript/RSSurfaceView.java
@@ -30,7 +30,7 @@ import android.view.SurfaceHolder;
import android.view.SurfaceView;
/**
- * The Surface View for a graphics renderscript (RenderScriptGL) to draw on.
+ * The Surface View for a graphics renderscript (RenderScriptGL) to draw on.
*/
public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mSurfaceHolder;
@@ -78,9 +78,11 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
* not normally called or subclassed by clients of RSSurfaceView.
*/
public void surfaceDestroyed(SurfaceHolder holder) {
- // Surface will be destroyed when we return
- if (mRS != null) {
- mRS.setSurface(null, 0, 0);
+ synchronized (this) {
+ // Surface will be destroyed when we return
+ if (mRS != null) {
+ mRS.setSurface(null, 0, 0);
+ }
}
}
@@ -89,8 +91,10 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
* not normally called or subclassed by clients of RSSurfaceView.
*/
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
- if (mRS != null) {
- mRS.setSurface(holder, w, h);
+ synchronized (this) {
+ if (mRS != null) {
+ mRS.setSurface(holder, w, h);
+ }
}
}
@@ -126,8 +130,10 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback
}
public void destroyRenderScriptGL() {
- mRS.destroy();
- mRS = null;
+ synchronized (this) {
+ mRS.destroy();
+ mRS = null;
+ }
}
public void setRenderScriptGL(RenderScriptGL rs) {
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index d3d65a3..1305633 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -210,10 +210,11 @@ public class RenderScript {
validate();
rsnElementGetNativeData(mContext, id, elementData);
}
- native void rsnElementGetSubElements(int con, int id, int[] IDs, String[] names);
- synchronized void nElementGetSubElements(int id, int[] IDs, String[] names) {
+ native void rsnElementGetSubElements(int con, int id,
+ int[] IDs, String[] names, int[] arraySizes);
+ synchronized void nElementGetSubElements(int id, int[] IDs, String[] names, int[] arraySizes) {
validate();
- rsnElementGetSubElements(mContext, id, IDs, names);
+ rsnElementGetSubElements(mContext, id, IDs, names, arraySizes);
}
native int rsnTypeCreate(int con, int eid, int x, int y, int z, boolean mips, boolean faces);
diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java
index 98943a1..0a3c91d 100644
--- a/graphics/java/android/renderscript/Sampler.java
+++ b/graphics/java/android/renderscript/Sampler.java
@@ -47,11 +47,58 @@ public class Sampler extends BaseObj {
}
}
+ Value mMin;
+ Value mMag;
+ Value mWrapS;
+ Value mWrapT;
+ Value mWrapR;
+ float mAniso;
+
Sampler(int id, RenderScript rs) {
super(id, rs);
}
/**
+ * @hide
+ * @return minification setting for the sampler
+ */
+ public Value getMinification() {
+ return mMin;
+ }
+
+ /**
+ * @hide
+ * @return magnification setting for the sampler
+ */
+ public Value getMagnification() {
+ return mMag;
+ }
+
+ /**
+ * @hide
+ * @return S wrapping mode for the sampler
+ */
+ public Value getWrapS() {
+ return mWrapS;
+ }
+
+ /**
+ * @hide
+ * @return T wrapping mode for the sampler
+ */
+ public Value getWrapT() {
+ return mWrapT;
+ }
+
+ /**
+ * @hide
+ * @return anisotropy setting for the sampler
+ */
+ public float getAnisotropy() {
+ return mAniso;
+ }
+
+ /**
* Retrieve a sampler with min and mag set to nearest and wrap modes set to
* clamp.
*
@@ -241,8 +288,16 @@ public class Sampler extends BaseObj {
public Sampler create() {
mRS.validate();
- int id = mRS.nSamplerCreate(mMag.mID, mMin.mID, mWrapS.mID, mWrapT.mID, mWrapR.mID, mAniso);
- return new Sampler(id, mRS);
+ int id = mRS.nSamplerCreate(mMag.mID, mMin.mID,
+ mWrapS.mID, mWrapT.mID, mWrapR.mID, mAniso);
+ Sampler sampler = new Sampler(id, mRS);
+ sampler.mMin = mMin;
+ sampler.mMag = mMag;
+ sampler.mWrapS = mWrapS;
+ sampler.mWrapT = mWrapT;
+ sampler.mWrapR = mWrapR;
+ sampler.mAniso = mAniso;
+ return sampler;
}
}
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index ec1f8de..af03ee2 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -371,23 +371,29 @@ nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintA
static void
-nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _IDs, jobjectArray _names)
+nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
+ jintArray _IDs,
+ jobjectArray _names,
+ jintArray _arraySizes)
{
int dataSize = _env->GetArrayLength(_IDs);
LOG_API("nElementGetSubElements, con(%p)", con);
uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
+ uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
- rsaElementGetSubElements(con, (RsElement)id, ids, names, (uint32_t)dataSize);
+ rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
for(jint i = 0; i < dataSize; i++) {
_env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
_env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
+ _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
}
free(ids);
free(names);
+ free(arraySizes);
}
// -----------------------------------
@@ -1239,7 +1245,7 @@ static JNINativeMethod methods[] = {
{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
-{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;)V", (void*)nElementGetSubElements },
+{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
{"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate },
{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },