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