1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.rs.imagejb; 18 19import java.lang.Math; 20 21import android.renderscript.Allocation; 22import android.renderscript.Element; 23import android.renderscript.RenderScript; 24import android.renderscript.Script; 25import android.renderscript.ScriptC; 26import android.renderscript.Type; 27import android.util.Log; 28import android.widget.SeekBar; 29import android.widget.TextView; 30 31public class Mandelbrot extends TestBase { 32 private ScriptC_mandelbrot mScript; 33 34 public boolean onBar1Setup(SeekBar b, TextView t) { 35 t.setText("Iterations"); 36 b.setProgress(0); 37 return true; 38 } 39 40 public void onBar1Changed(int progress) { 41 int iters = progress * 3 + 50; 42 mScript.set_gMaxIteration(iters); 43 } 44 45 public boolean onBar2Setup(SeekBar b, TextView t) { 46 t.setText("Lower Bound: X"); 47 b.setProgress(0); 48 return true; 49 } 50 51 public void onBar2Changed(int progress) { 52 float scaleFactor = mScript.get_scaleFactor(); 53 // allow viewport to be moved by 2x scale factor 54 float lowerBoundX = -2.f + ((progress / scaleFactor) / 50.f); 55 mScript.set_lowerBoundX(lowerBoundX); 56 } 57 58 public boolean onBar3Setup(SeekBar b, TextView t) { 59 t.setText("Lower Bound: Y"); 60 b.setProgress(0); 61 return true; 62 } 63 64 public void onBar3Changed(int progress) { 65 float scaleFactor = mScript.get_scaleFactor(); 66 // allow viewport to be moved by 2x scale factor 67 float lowerBoundY = -2.f + ((progress / scaleFactor) / 50.f); 68 mScript.set_lowerBoundY(lowerBoundY); 69 } 70 71 public boolean onBar4Setup(SeekBar b, TextView t) { 72 t.setText("Scale Factor"); 73 b.setProgress(0); 74 return true; 75 } 76 77 public void onBar4Changed(int progress) { 78 float scaleFactor = 4.f - (3.96f * (progress / 100.f)); 79 mScript.set_scaleFactor(scaleFactor); 80 } 81 82 public void createTest(android.content.res.Resources res) { 83 int width = mOutPixelsAllocation.getType().getX(); 84 int height = mOutPixelsAllocation.getType().getY(); 85 86 mScript = new ScriptC_mandelbrot(mRS, res, R.raw.mandelbrot); 87 mScript.set_gDimX(width); 88 mScript.set_gDimY(height); 89 mScript.set_gMaxIteration(50); 90 } 91 92 public void runTest() { 93 mScript.forEach_root(mOutPixelsAllocation); 94 mRS.finish(); 95 } 96 97} 98 99