Java 类android.renderscript.Sampler 实例源码

项目:live-mandelbox    文件:Render.java   
public Render(Context context, float scale, int dim) {
    rs = RenderScript.create(context);
    rs.setMessageHandler(new Ready());

    render = new ScriptC_render(rs);
    render.set_seed(RANDOM.nextInt());
    render.set_invDim(1.0f / dim);
    Log.i(TAG, String.format("Render seed: %d", render.get_seed()));

    fxaa = new ScriptC_fxaa(rs);
    fxaa.set_sampler(Sampler.CLAMP_LINEAR(rs));
    fxaa.set_dim(dim);
    fxaa.set_pixWidth(1.0f / dim);

       if (scale != 0) {
           render.set_scale(scale);
       } else {
           float randomScale = RANDOM.nextFloat() * 5 + (1.5f * 1.5f);
           randomScale = (float) Math.sqrt(randomScale);
           randomScale *= RANDOM.nextBoolean() ? -1 : 1;
           Log.i(TAG, String.format("Random scale value: %.3f", randomScale));
           render.set_scale(randomScale);
       }
    long time1 = System.currentTimeMillis();
    render.invoke_randomize_position();
    rs.finish();
    long time2 = System.currentTimeMillis();
    render.invoke_collect_exposure();
    rs.finish();
    long time3 = System.currentTimeMillis();

    Log.i(TAG, String.format("Starting position in %d ms, exposure in %d ms", time2 - time1, time3 - time2));

       bm2 = Bitmap.createBitmap(dim, dim, Bitmap.Config.ARGB_8888);
    abm1 = Allocation.createFromBitmap(rs, bm2);
       abm2 = Allocation.createFromBitmap(rs, bm2);
}