15bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond/*
25bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* Copyright (C) 2016 The Android Open Source Project
35bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond*
45bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* Licensed under the Apache License, Version 2.0 (the "License");
55bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* you may not use this file except in compliance with the License.
65bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* You may obtain a copy of the License at
75bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond*
85bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond*      http://www.apache.org/licenses/LICENSE-2.0
95bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond*
105bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* Unless required by applicable law or agreed to in writing, software
115bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* distributed under the License is distributed on an "AS IS" BASIS,
125bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* See the License for the specific language governing permissions and
145bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond* limitations under the License.
155bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond*/
165bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond
17dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo#include <thread>
18dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo#include <chrono>
19dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
20dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo#include <RenderScript.h>
21dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
22a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond#include "ScriptC_infiniteloop.h"
23dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
24dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leoint main()
25dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo{
26dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    static const int size = 64;
27dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    sp<RS> rs = new RS();
28dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
29dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    rs->init("/data/rscache", RS_INIT_LOW_LATENCY);
30dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
31dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    auto e = Element::RGBA_8888(rs);
32dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    Type::Builder tb(rs, e);
33dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    tb.setX(size);
34dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    tb.setY(size);
35dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    auto t = tb.create();
36dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
37dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    auto a = Allocation::createTyped(rs, t);
38dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    auto b = Allocation::createTyped(rs, t);
39dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
40a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond    sp<ScriptC_infiniteloop> s = new ScriptC_infiniteloop(rs);
41dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
42dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    // Test is designed to loop forever, waits for two seconds
43dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    // between each invocation of the kernel
44dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    bool forever = true;
45dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    while(forever)
46dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    {
47dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        s->forEach_simple_kernel(a, b);
48dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo        std::this_thread::sleep_for(std::chrono::seconds(2));
49dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    }
50dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
51dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    uint32_t * output = new uint32_t[size*size];
52dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    b->copy2DRangeTo(0, 0, size, size, output);
53dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    delete [] output;
54dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
55dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo    return 0;
56dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo}
57dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo
58