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.image; 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 private boolean mUseDouble = false; 34 35 public Mandelbrot(boolean useDouble) { 36 mUseDouble = useDouble; 37 } 38 39 public boolean onBar1Setup(SeekBar b, TextView t) { 40 t.setText("Iterations"); 41 b.setProgress(0); 42 return true; 43 } 44 45 public void onBar1Changed(int progress) { 46 int iters = progress * 3 + 50; 47 mScript.set_gMaxIteration(iters); 48 } 49 50 public boolean onBar2Setup(SeekBar b, TextView t) { 51 t.setText("Lower Bound: X"); 52 b.setProgress(0); 53 return true; 54 } 55 56 public void onBar2Changed(int progress) { 57 float scaleFactor = mScript.get_scaleFactor(); 58 // allow viewport to be moved by 2x scale factor 59 float lowerBoundX = -2.f + ((progress / scaleFactor) / 50.f); 60 mScript.set_lowerBoundX(lowerBoundX); 61 } 62 63 public boolean onBar3Setup(SeekBar b, TextView t) { 64 t.setText("Lower Bound: Y"); 65 b.setProgress(0); 66 return true; 67 } 68 69 public void onBar3Changed(int progress) { 70 float scaleFactor = mScript.get_scaleFactor(); 71 // allow viewport to be moved by 2x scale factor 72 float lowerBoundY = -2.f + ((progress / scaleFactor) / 50.f); 73 mScript.set_lowerBoundY(lowerBoundY); 74 } 75 76 public boolean onBar4Setup(SeekBar b, TextView t) { 77 t.setText("Scale Factor"); 78 b.setProgress(0); 79 return true; 80 } 81 82 public void onBar4Changed(int progress) { 83 float scaleFactor = 4.f - (3.96f * (progress / 100.f)); 84 mScript.set_scaleFactor(scaleFactor); 85 } 86 87 public void createTest(android.content.res.Resources res) { 88 int width = mOutPixelsAllocation.getType().getX(); 89 int height = mOutPixelsAllocation.getType().getY(); 90 91 mScript = new ScriptC_mandelbrot(mRS); 92 mScript.set_gDimX(width); 93 mScript.set_gDimY(height); 94 mScript.set_gMaxIteration(50); 95 } 96 97 public void runTest() { 98 if (mUseDouble) { 99 mScript.forEach_rootD(mOutPixelsAllocation); 100 } else { 101 mScript.forEach_root(mOutPixelsAllocation); 102 } 103 mRS.finish(); 104 } 105 106} 107 108