MultipleRSFiles.cpp revision 5bbcc3861c44435f89481f80946ef5c9c49968f2
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 <RenderScript.h>
18
19#include "ScriptC_first.h"
20#include "ScriptC_second.h"
21
22using namespace android;
23using namespace RSC;
24
25int main()
26{
27    static const int size = 64;
28    sp<RS> rs = new RS();
29
30    rs->init("/data/rscache", RS_INIT_LOW_LATENCY | RS_INIT_WAIT_FOR_ATTACH);
31
32    auto e = Element::RGBA_8888(rs);
33    Type::Builder tb(rs, e);
34    tb.setX(size);
35    tb.setY(size);
36    auto t = tb.create();
37
38    auto a = Allocation::createTyped(rs, t);
39    auto b = Allocation::createTyped(rs, t);
40
41    // Script is executed once, then the data is copied back when finished
42    sp<ScriptC_first> s1 = new ScriptC_first(rs);
43    sp<ScriptC_second> s2 = new ScriptC_second(rs);
44
45    s1->forEach_first_kernel(a, b);
46    uint32_t * output = new uint32_t[size*size];
47    b->copy2DRangeTo(0, 0, size, size, output);
48    delete [] output;
49
50    s2->forEach_second_kernel(a, b);
51
52    rs->finish();
53    return 0;
54}
55