• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011-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 
17 #include "../cpu_ref/rsd_cpu.h"
18 
19 #include "rsdCore.h"
20 
21 #include "rsdBcc.h"
22 #include "rsdAllocation.h"
23 
24 #include "rsContext.h"
25 #include "rsElement.h"
26 #include "rsScriptC.h"
27 
28 #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
29 #include "utils/Vector.h"
30 #include "utils/Timers.h"
31 #include "utils/StopWatch.h"
32 #endif
33 
34 using namespace android;
35 using namespace android::renderscript;
36 
37 
rsdScriptInit(const Context * rsc,ScriptC * script,char const * resName,char const * cacheDir,uint8_t const * bitcode,size_t bitcodeSize,uint32_t flags)38 bool rsdScriptInit(const Context *rsc,
39                      ScriptC *script,
40                      char const *resName,
41                      char const *cacheDir,
42                      uint8_t const *bitcode,
43                      size_t bitcodeSize,
44                      uint32_t flags) {
45     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
46     RsdCpuReference::CpuScript * cs = dc->mCpuRef->createScript(script, resName, cacheDir,
47                                                                 bitcode, bitcodeSize, flags);
48     if (cs == NULL) {
49         return false;
50     }
51     script->mHal.drv = cs;
52     cs->populateScript(script);
53     return true;
54 }
55 
rsdInitIntrinsic(const Context * rsc,Script * s,RsScriptIntrinsicID iid,Element * e)56 bool rsdInitIntrinsic(const Context *rsc, Script *s, RsScriptIntrinsicID iid, Element *e) {
57     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
58     RsdCpuReference::CpuScript * cs = dc->mCpuRef->createIntrinsic(s, iid, e);
59     if (cs == NULL) {
60         return false;
61     }
62     s->mHal.drv = cs;
63     cs->populateScript(s);
64     return true;
65 }
66 
rsdScriptInvokeForEach(const Context * rsc,Script * s,uint32_t slot,const Allocation * ain,Allocation * aout,const void * usr,size_t usrLen,const RsScriptCall * sc)67 void rsdScriptInvokeForEach(const Context *rsc,
68                             Script *s,
69                             uint32_t slot,
70                             const Allocation * ain,
71                             Allocation * aout,
72                             const void * usr,
73                             size_t usrLen,
74                             const RsScriptCall *sc) {
75 
76     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
77     cs->invokeForEach(slot, ain, aout, usr, usrLen, sc);
78 }
79 
rsdScriptInvokeForEachMulti(const Context * rsc,Script * s,uint32_t slot,const Allocation ** ains,size_t inLen,Allocation * aout,const void * usr,size_t usrLen,const RsScriptCall * sc)80 void rsdScriptInvokeForEachMulti(const Context *rsc,
81                                  Script *s,
82                                  uint32_t slot,
83                                  const Allocation ** ains,
84                                  size_t inLen,
85                                  Allocation * aout,
86                                  const void * usr,
87                                  size_t usrLen,
88                                  const RsScriptCall *sc) {
89 
90     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
91     cs->invokeForEachMulti(slot, ains, inLen, aout, usr, usrLen, sc);
92 }
93 
94 
rsdScriptInvokeRoot(const Context * dc,Script * s)95 int rsdScriptInvokeRoot(const Context *dc, Script *s) {
96     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
97     return cs->invokeRoot();
98 }
99 
rsdScriptInvokeInit(const Context * dc,Script * s)100 void rsdScriptInvokeInit(const Context *dc, Script *s) {
101     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
102     cs->invokeInit();
103 }
104 
rsdScriptInvokeFreeChildren(const Context * dc,Script * s)105 void rsdScriptInvokeFreeChildren(const Context *dc, Script *s) {
106     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
107     cs->invokeFreeChildren();
108 }
109 
rsdScriptInvokeFunction(const Context * dc,Script * s,uint32_t slot,const void * params,size_t paramLength)110 void rsdScriptInvokeFunction(const Context *dc, Script *s,
111                             uint32_t slot,
112                             const void *params,
113                             size_t paramLength) {
114     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
115     cs->invokeFunction(slot, params, paramLength);
116 }
117 
rsdScriptSetGlobalVar(const Context * dc,const Script * s,uint32_t slot,void * data,size_t dataLength)118 void rsdScriptSetGlobalVar(const Context *dc, const Script *s,
119                            uint32_t slot, void *data, size_t dataLength) {
120     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
121     cs->setGlobalVar(slot, data, dataLength);
122 }
123 
rsdScriptGetGlobalVar(const Context * dc,const Script * s,uint32_t slot,void * data,size_t dataLength)124 void rsdScriptGetGlobalVar(const Context *dc, const Script *s,
125                            uint32_t slot, void *data, size_t dataLength) {
126     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
127     cs->getGlobalVar(slot, data, dataLength);
128 }
129 
130 
rsdScriptSetGlobalVarWithElemDims(const Context * dc,const Script * s,uint32_t slot,void * data,size_t dataLength,const android::renderscript::Element * elem,const uint32_t * dims,size_t dimLength)131 void rsdScriptSetGlobalVarWithElemDims(const Context *dc, const Script *s,
132                                        uint32_t slot, void *data, size_t dataLength,
133                                        const android::renderscript::Element *elem,
134                                        const uint32_t *dims, size_t dimLength) {
135     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
136     cs->setGlobalVarWithElemDims(slot, data, dataLength, elem, dims, dimLength);
137 }
138 
rsdScriptSetGlobalBind(const Context * dc,const Script * s,uint32_t slot,Allocation * data)139 void rsdScriptSetGlobalBind(const Context *dc, const Script *s, uint32_t slot, Allocation *data) {
140     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
141     cs->setGlobalBind(slot, data);
142 }
143 
rsdScriptSetGlobalObj(const Context * dc,const Script * s,uint32_t slot,ObjectBase * data)144 void rsdScriptSetGlobalObj(const Context *dc, const Script *s, uint32_t slot, ObjectBase *data) {
145     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
146     cs->setGlobalObj(slot, data);
147 }
148 
rsdScriptDestroy(const Context * dc,Script * s)149 void rsdScriptDestroy(const Context *dc, Script *s) {
150     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
151     delete cs;
152     s->mHal.drv = NULL;
153 }
154 
155 
rsdScriptGetAllocationForPointer(const android::renderscript::Context * dc,const android::renderscript::Script * sc,const void * ptr)156 Allocation * rsdScriptGetAllocationForPointer(const android::renderscript::Context *dc,
157                                               const android::renderscript::Script *sc,
158                                               const void *ptr) {
159     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)sc->mHal.drv;
160     return cs->getAllocationForPointer(ptr);
161 }
162 
rsdScriptUpdateCachedObject(const Context * rsc,const Script * script,rs_script * obj)163 void rsdScriptUpdateCachedObject(const Context *rsc,
164                                  const Script *script,
165                                  rs_script *obj)
166 {
167     obj->p = script;
168 #ifdef __LP64__
169     obj->r = NULL;
170     if (script != NULL) {
171         obj->v1 = script->mHal.drv;
172     } else {
173         obj->v1 = NULL;
174     }
175     obj->v2 = NULL;
176 #endif
177 }
178