diff options
Diffstat (limited to 'graphics')
5 files changed, 84 insertions, 71 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 2c076b3..06bfbcf 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -372,17 +372,6 @@ public class Allocation extends BaseObj { return a; } - static Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) - throws IllegalArgumentException { - - rs.validate(); - int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mID, genMips, b); - if(id == 0) { - throw new IllegalStateException("Load failed."); - } - return new Allocation(id, rs, null); - } - static public Allocation createFromBitmapResource(RenderScript rs, Resources res, int id, Element dstFmt, boolean genMips) throws IllegalArgumentException { @@ -415,24 +404,6 @@ public class Allocation extends BaseObj { return null; } - static public Allocation createFromBitmapResourceBoxed(RenderScript rs, Resources res, int id, Element dstFmt, boolean genMips) - throws IllegalArgumentException { - - mBitmapOptions.inPreferredConfig = null; - if (dstFmt == rs.mElement_RGBA_8888) { - mBitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; - } else if (dstFmt == rs.mElement_RGB_888) { - mBitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; - } else if (dstFmt == rs.mElement_RGBA_4444) { - mBitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_4444; - } else if (dstFmt == rs.mElement_RGB_565) { - mBitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565; - } - - Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); - return createFromBitmapBoxed(rs, b, dstFmt, genMips); - } - static public Allocation createFromString(RenderScript rs, String str) throws IllegalArgumentException { byte[] allocArray = null; diff --git a/graphics/java/android/renderscript/RSSurfaceView.java b/graphics/java/android/renderscript/RSSurfaceView.java index f05e84c..2540d01 100644 --- a/graphics/java/android/renderscript/RSSurfaceView.java +++ b/graphics/java/android/renderscript/RSSurfaceView.java @@ -25,7 +25,6 @@ import android.os.Handler; import android.os.Message; import android.util.AttributeSet; import android.util.Log; -import android.util.Log; import android.view.Surface; import android.view.SurfaceHolder; import android.view.SurfaceView; @@ -146,22 +145,18 @@ public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback // ---------------------------------------------------------------------- - public RenderScriptGL createRenderScript(boolean useDepth, boolean forceSW) { + public RenderScriptGL createRenderScript(RenderScriptGL.SurfaceConfig sc) { Log.v(RenderScript.LOG_TAG, "createRenderScript"); - mRS = new RenderScriptGL(useDepth, forceSW); + mRS = new RenderScriptGL(sc); return mRS; } - public RenderScriptGL createRenderScript(boolean useDepth) { - return createRenderScript(useDepth, false); - } - public void destroyRenderScript() { Log.v(RenderScript.LOG_TAG, "destroyRenderScript"); mRS.destroy(); mRS = null; } - + public void createRenderScript(RenderScriptGL rs) { mRS = rs; } diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 0088373..27c40fa 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -194,10 +194,6 @@ public class RenderScript { synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) { return rsnAllocationCreateBitmapRef(mContext, type, bmp); } - native int rsnAllocationCreateFromBitmapBoxed(int con, int dstFmt, boolean genMips, Bitmap bmp); - synchronized int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp) { - return rsnAllocationCreateFromBitmapBoxed(mContext, dstFmt, genMips, bmp); - } native int rsnAllocationCreateFromAssetStream(int con, int dstFmt, boolean genMips, int assetStream); synchronized int nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream) { return rsnAllocationCreateFromAssetStream(mContext, dstFmt, genMips, assetStream); diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java index 61ecc8d..b60c689 100644 --- a/graphics/java/android/renderscript/RenderScriptGL.java +++ b/graphics/java/android/renderscript/RenderScriptGL.java @@ -23,7 +23,8 @@ import android.graphics.BitmapFactory; import android.util.Config; import android.util.Log; import android.view.Surface; - +import android.view.SurfaceHolder; +import android.view.SurfaceView; /** * @hide @@ -34,16 +35,90 @@ public class RenderScriptGL extends RenderScript { int mWidth; int mHeight; + public static class SurfaceConfig { + int mDepthMin = 0; + int mDepthPref = 0; + int mStencilMin = 0; + int mStencilPref = 0; + int mColorMin = 8; + int mColorPref = 8; + int mAlphaMin = 0; + int mAlphaPref = 0; + int mSamplesMin = 1; + int mSamplesPref = 1; + float mSamplesQ = 1.f; + + public SurfaceConfig() { + } + + public SurfaceConfig(SurfaceConfig sc) { + mDepthMin = sc.mDepthMin; + mDepthPref = sc.mDepthPref; + mStencilMin = sc.mStencilMin; + mStencilPref = sc.mStencilPref; + mColorMin = sc.mColorMin; + mColorPref = sc.mColorPref; + mAlphaMin = sc.mAlphaMin; + mAlphaPref = sc.mAlphaPref; + mSamplesMin = sc.mSamplesMin; + mSamplesPref = sc.mSamplesPref; + mSamplesQ = sc.mSamplesQ; + } + + private void validateRange(int umin, int upref, int rmin, int rmax) { + if (umin < rmin || umin > rmax) { + throw new IllegalArgumentException("Minimum value provided out of range."); + } + if (upref < umin) { + throw new IllegalArgumentException("Prefered must be >= Minimum."); + } + } + + public void setColor(int minimum, int prefered) { + validateRange(minimum, prefered, 5, 8); + mColorMin = minimum; + mColorPref = prefered; + } + public void setAlpha(int minimum, int prefered) { + validateRange(minimum, prefered, 0, 8); + mAlphaMin = minimum; + mAlphaPref = prefered; + } + public void setDepth(int minimum, int prefered) { + validateRange(minimum, prefered, 0, 24); + mDepthMin = minimum; + mDepthPref = prefered; + } + public void setSamples(int minimum, int prefered, float Q) { + validateRange(minimum, prefered, 0, 24); + if (Q < 0.0f || Q > 1.0f) { + throw new IllegalArgumentException("Quality out of 0-1 range."); + } + mSamplesMin = minimum; + mSamplesPref = prefered; + mSamplesQ = Q; + } + }; + + SurfaceConfig mSurfaceConfig; + + public void configureSurface(SurfaceHolder sh) { + //getHolder().setFormat(PixelFormat.TRANSLUCENT); + } + + public void checkSurface(SurfaceHolder sh) { + } + + public RenderScriptGL(SurfaceConfig sc) { + mSurfaceConfig = new SurfaceConfig(sc); + + - public RenderScriptGL(boolean useDepth, boolean forceSW) { mSurface = null; mWidth = 0; mHeight = 0; mDev = nDeviceCreate(); - if(forceSW) { - nDeviceSetConfig(mDev, 0, 1); - } - mContext = nContextCreateGL(mDev, 0, useDepth); + mContext = nContextCreateGL(mDev, 0, mSurfaceConfig.mDepthMin > 0); mMessageThread = new MessageThread(this); mMessageThread.start(); Element.initPredefined(this); diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index 8f1e93c..3e52fef 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -466,29 +466,6 @@ nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jin return 0; } -static int -nAllocationCreateFromBitmapBoxed(JNIEnv *_env, jobject _this, RsContext con, jint dstFmt, jboolean genMips, jobject jbitmap) -{ - SkBitmap const * nativeBitmap = - (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); - const SkBitmap& bitmap(*nativeBitmap); - SkBitmap::Config config = bitmap.getConfig(); - - RsElement e = SkBitmapToPredefined(config); - - if (e) { - bitmap.lockPixels(); - const int w = bitmap.width(); - const int h = bitmap.height(); - const void* ptr = bitmap.getPixels(); - jint id = (jint)rsAllocationCreateFromBitmapBoxed(con, w, h, (RsElement)dstFmt, e, genMips, ptr); - bitmap.unlockPixels(); - return id; - } - return 0; -} - - static void nAllocationSubData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint count, jintArray data, int sizeBytes) { @@ -1252,7 +1229,6 @@ static JNINativeMethod methods[] = { {"rsnAllocationCreateTyped", "(II)I", (void*)nAllocationCreateTyped }, {"rsnAllocationCreateFromBitmap", "(IIZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap }, {"rsnAllocationCreateBitmapRef", "(IILandroid/graphics/Bitmap;)I", (void*)nAllocationCreateBitmapRef }, -{"rsnAllocationCreateFromBitmapBoxed","(IIZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed }, {"rsnAllocationCreateFromAssetStream","(IIZI)I", (void*)nAllocationCreateFromAssetStream }, {"rsnAllocationUploadToTexture", "(IIZI)V", (void*)nAllocationUploadToTexture }, {"rsnAllocationUploadToBufferObject","(II)V", (void*)nAllocationUploadToBufferObject }, |
