1// Copyright (C) 2011 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15#pragma version(1) 16#pragma rs java_package_name(com.example.android.rs.computeperf) 17 18const int gMaxIteration = 500; 19const int gDimX = 1024; 20const int gDimY = 1024; 21 22void root(uchar4 *v_out, uint32_t x, uint32_t y) { 23 float2 p; 24 p.x = -2.5f + ((float)x / gDimX) * 3.5f; 25 p.y = -1.f + ((float)y / gDimY) * 2.f; 26 27 float2 t = 0; 28 float2 t2 = t * t; 29 int iteration = 0; 30 while((t2.x + t2.y < 4.f) && (iteration < gMaxIteration)) { 31 float xtemp = t2.x - t2.y + p.x; 32 t.y = 2 * t.x * t.y + p.y; 33 t.x = xtemp; 34 iteration++; 35 t2 = t * t; 36 } 37 38 if(iteration >= gMaxIteration) { 39 *v_out = 0; 40 } else { 41 *v_out = (uchar4){iteration & 0xff, (iteration >> 6) & 0xff, 0x8f, 0xff}; 42 } 43} 44