FileDocCategorySizeDatePackage
SampleRSActivity.javaAPI DocAndroid 5.1 API6630Thu Mar 12 22:22:54 GMT 2015com.android.rs.sample

SampleRSActivity

public class SampleRSActivity extends android.app.Activity

Fields Summary
private final String
TAG
private android.graphics.Bitmap
mBitmapTwoByTwo
private android.graphics.Bitmap
mBitmapCity
private android.widget.TextView
mBenchmarkResult
private android.renderscript.RenderScript
mRS
private android.renderscript.Allocation
mTwoByTwoAlloc
private android.renderscript.Allocation
mCityAlloc
private ScriptC_sample
mScript
Constructors Summary
Methods Summary
public voidbenchmark(android.view.View v)

        /*filterAlloc();
        long t = java.lang.System.currentTimeMillis();
        filterAlloc();
        t = java.lang.System.currentTimeMillis() - t;
        mDisplayView.invalidate();
        mBenchmarkResult.setText("Result: " + t + " ms");*/
    
private synchronized voidfilterAlloc(android.renderscript.Allocation alloc, android.renderscript.Sampler sampler)

        long t = java.lang.System.currentTimeMillis();
        mScript.invoke_setSampleData(alloc, mTwoByTwoAlloc, sampler);
        mScript.forEach_root(alloc);
        alloc.ioSend();
        mRS.finish();
        t = java.lang.System.currentTimeMillis() - t;
        Log.i(TAG, "Filter time is: " + t + " ms");
    
private android.graphics.BitmaploadBitmap(int resource)

        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap b = BitmapFactory.decodeResource(getResources(), resource, options);
        Bitmap b2 = Bitmap.createBitmap(b.getWidth(), b.getHeight(), b.getConfig());
        Canvas c = new Canvas(b2);
        c.drawBitmap(b, 0, 0, null);
        b.recycle();
        return b2;
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);
        setContentView(R.layout.rs);

        mBitmapTwoByTwo = loadBitmap(R.drawable.twobytwo);
        mBitmapCity = loadBitmap(R.drawable.city);

        mBenchmarkResult = (TextView) findViewById(R.id.benchmarkText);
        mBenchmarkResult.setText("Result: not run");

        mRS = RenderScript.create(this);
        mTwoByTwoAlloc = Allocation.createFromBitmap(mRS, mBitmapTwoByTwo,
                                                          Allocation.MipmapControl.MIPMAP_NONE,
                                                          Allocation.USAGE_SCRIPT | Allocation.USAGE_GRAPHICS_TEXTURE);

        mCityAlloc = Allocation.createFromBitmap(mRS, mBitmapCity,
                                                          Allocation.MipmapControl.MIPMAP_NONE,
                                                          Allocation.USAGE_SCRIPT | Allocation.USAGE_GRAPHICS_TEXTURE);

        Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS));

        int usage = Allocation.USAGE_SCRIPT | Allocation.USAGE_IO_OUTPUT;

        int outX = 256;
        int outY = 256;

        // Wrap Linear
        Allocation outAlloc = Allocation.createTyped(mRS, b.setX(outX).setY(outY).create(), usage);
        TextureViewUpdater updater = new TextureViewUpdater(outAlloc, Sampler.WRAP_LINEAR(mRS));
        TextureView displayView = (TextureView) findViewById(R.id.display);
        displayView.setSurfaceTextureListener(updater);

        // Clamp Linear
        outAlloc = Allocation.createTyped(mRS, b.setX(outX).setY(outY).create(), usage);
        updater = new TextureViewUpdater(outAlloc, Sampler.CLAMP_LINEAR(mRS));
        displayView = (TextureView) findViewById(R.id.display2);
        displayView.setSurfaceTextureListener(updater);

        // Wrap Nearest
        outAlloc = Allocation.createTyped(mRS, b.setX(outX).setY(outY).create(), usage);
        updater = new TextureViewUpdater(outAlloc, Sampler.WRAP_NEAREST(mRS));
        displayView = (TextureView) findViewById(R.id.display3);
        displayView.setSurfaceTextureListener(updater);

        // Clamp Nearest
        outAlloc = Allocation.createTyped(mRS, b.setX(outX).setY(outY).create(), usage);
        updater = new TextureViewUpdater(outAlloc, Sampler.CLAMP_NEAREST(mRS));
        displayView = (TextureView) findViewById(R.id.display4);
        displayView.setSurfaceTextureListener(updater);

        mScript = new ScriptC_sample(mRS);
    
public voidonStartTrackingTouch(android.widget.SeekBar seekBar)


        
    
public voidonStopTrackingTouch(android.widget.SeekBar seekBar)