Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2222aa90 authored by Jason Sams's avatar Jason Sams
Browse files

Cleanup error message for null binding address.

Only print the debug if script debugging is enabled.

Change-Id: I72b9c2a73d49987a73b354442e9defec02b93bc6

Implement inner utiliy class to specify surface formats.
Remove boxed bitmap upload functions.

Change-Id: I3ff5ca59e53d02b9d75277afa947ea3d218459eb
parent 7499a1ca
Loading
Loading
Loading
Loading
+0 −29
Original line number Original line Diff line number Diff line
@@ -372,17 +372,6 @@ public class Allocation extends BaseObj {
        return a;
        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)
    static public Allocation createFromBitmapResource(RenderScript rs, Resources res, int id, Element dstFmt, boolean genMips)
        throws IllegalArgumentException {
        throws IllegalArgumentException {


@@ -415,24 +404,6 @@ public class Allocation extends BaseObj {
        return null;
        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)
    static public Allocation createFromString(RenderScript rs, String str)
        throws IllegalArgumentException {
        throws IllegalArgumentException {
        byte[] allocArray = null;
        byte[] allocArray = null;
+3 −8
Original line number Original line Diff line number Diff line
@@ -25,7 +25,6 @@ import android.os.Handler;
import android.os.Message;
import android.os.Message;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Log;
import android.util.Log;
import android.view.Surface;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.SurfaceView;
@@ -146,16 +145,12 @@ 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");
        Log.v(RenderScript.LOG_TAG, "createRenderScript");
        mRS = new RenderScriptGL(useDepth, forceSW);
        mRS = new RenderScriptGL(sc);
        return mRS;
        return mRS;
    }
    }


    public RenderScriptGL createRenderScript(boolean useDepth) {
        return createRenderScript(useDepth, false);
    }

    public void destroyRenderScript() {
    public void destroyRenderScript() {
        Log.v(RenderScript.LOG_TAG, "destroyRenderScript");
        Log.v(RenderScript.LOG_TAG, "destroyRenderScript");
        mRS.destroy();
        mRS.destroy();
+0 −4
Original line number Original line Diff line number Diff line
@@ -194,10 +194,6 @@ public class RenderScript {
    synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) {
    synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) {
        return rsnAllocationCreateBitmapRef(mContext, type, 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);
    native int  rsnAllocationCreateFromAssetStream(int con, int dstFmt, boolean genMips, int assetStream);
    synchronized int nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream) {
    synchronized int nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream) {
        return rsnAllocationCreateFromAssetStream(mContext, dstFmt, genMips, assetStream);
        return rsnAllocationCreateFromAssetStream(mContext, dstFmt, genMips, assetStream);
+81 −6
Original line number Original line Diff line number Diff line
@@ -23,7 +23,8 @@ import android.graphics.BitmapFactory;
import android.util.Config;
import android.util.Config;
import android.util.Log;
import android.util.Log;
import android.view.Surface;
import android.view.Surface;

import android.view.SurfaceHolder;
import android.view.SurfaceView;


/**
/**
 * @hide
 * @hide
@@ -34,16 +35,90 @@ public class RenderScriptGL extends RenderScript {
    int mWidth;
    int mWidth;
    int mHeight;
    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;
        mSurface = null;
        mWidth = 0;
        mWidth = 0;
        mHeight = 0;
        mHeight = 0;
        mDev = nDeviceCreate();
        mDev = nDeviceCreate();
        if(forceSW) {
        mContext = nContextCreateGL(mDev, 0, mSurfaceConfig.mDepthMin > 0);
            nDeviceSetConfig(mDev, 0, 1);
        }
        mContext = nContextCreateGL(mDev, 0, useDepth);
        mMessageThread = new MessageThread(this);
        mMessageThread = new MessageThread(this);
        mMessageThread.start();
        mMessageThread.start();
        Element.initPredefined(this);
        Element.initPredefined(this);
+0 −24
Original line number Original line Diff line number Diff line
@@ -466,29 +466,6 @@ nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jin
    return 0;
    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
static void
nAllocationSubData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint count, jintArray data, int sizeBytes)
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 },
{"rsnAllocationCreateTyped",         "(II)I",                                 (void*)nAllocationCreateTyped },
{"rsnAllocationCreateFromBitmap",    "(IIZLandroid/graphics/Bitmap;)I",       (void*)nAllocationCreateFromBitmap },
{"rsnAllocationCreateFromBitmap",    "(IIZLandroid/graphics/Bitmap;)I",       (void*)nAllocationCreateFromBitmap },
{"rsnAllocationCreateBitmapRef",     "(IILandroid/graphics/Bitmap;)I",        (void*)nAllocationCreateBitmapRef },
{"rsnAllocationCreateBitmapRef",     "(IILandroid/graphics/Bitmap;)I",        (void*)nAllocationCreateBitmapRef },
{"rsnAllocationCreateFromBitmapBoxed","(IIZLandroid/graphics/Bitmap;)I",      (void*)nAllocationCreateFromBitmapBoxed },
{"rsnAllocationCreateFromAssetStream","(IIZI)I",                              (void*)nAllocationCreateFromAssetStream },
{"rsnAllocationCreateFromAssetStream","(IIZI)I",                              (void*)nAllocationCreateFromAssetStream },
{"rsnAllocationUploadToTexture",     "(IIZI)V",                               (void*)nAllocationUploadToTexture },
{"rsnAllocationUploadToTexture",     "(IIZI)V",                               (void*)nAllocationUploadToTexture },
{"rsnAllocationUploadToBufferObject","(II)V",                                 (void*)nAllocationUploadToBufferObject },
{"rsnAllocationUploadToBufferObject","(II)V",                                 (void*)nAllocationUploadToBufferObject },
Loading