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