1 /*
2 * Copyright (C) 2016 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 
17 #include <thread>
18 #include <chrono>
19 
20 #include <RenderScript.h>
21 
22 #include "ScriptC_infiniteloop.h"
23 
main()24 int main()
25 {
26     static const int size = 64;
27     sp<RS> rs = new RS();
28 
29     rs->init("/data/rscache", RS_INIT_LOW_LATENCY);
30 
31     auto e = Element::RGBA_8888(rs);
32     Type::Builder tb(rs, e);
33     tb.setX(size);
34     tb.setY(size);
35     auto t = tb.create();
36 
37     auto a = Allocation::createTyped(rs, t);
38     auto b = Allocation::createTyped(rs, t);
39 
40     sp<ScriptC_infiniteloop> s = new ScriptC_infiniteloop(rs);
41 
42     // Test is designed to loop forever, waits for two seconds
43     // between each invocation of the kernel
44     bool forever = true;
45     while(forever)
46     {
47         s->forEach_simple_kernel(a, b);
48         std::this_thread::sleep_for(std::chrono::seconds(2));
49     }
50 
51     uint32_t * output = new uint32_t[size*size];
52     b->copy2DRangeTo(0, 0, size, size, output);
53     delete [] output;
54 
55     return 0;
56 }
57 
58