• 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 #include "rsdAllocation.h"
21 #include "rsdBcc.h"
22 #ifndef RS_COMPATIBILITY_LIB
23     #include "rsdGL.h"
24     #include "rsdPath.h"
25     #include "rsdProgramStore.h"
26     #include "rsdProgramRaster.h"
27     #include "rsdProgramVertex.h"
28     #include "rsdProgramFragment.h"
29     #include "rsdMesh.h"
30     #include "rsdFrameBuffer.h"
31 #endif
32 #include "rsdSampler.h"
33 #include "rsdScriptGroup.h"
34 
35 #include <malloc.h>
36 #include "rsContext.h"
37 
38 #include <sys/types.h>
39 #include <sys/resource.h>
40 #include <sched.h>
41 #include <sys/syscall.h>
42 #include <string.h>
43 
44 #ifndef RS_SERVER
45 #include <cutils/properties.h>
46 #endif
47 
48 using namespace android;
49 using namespace android::renderscript;
50 
51 static void Shutdown(Context *rsc);
52 static void SetPriority(const Context *rsc, int32_t priority);
53 
54 #ifndef RS_COMPATIBILITY_LIB
55     #define NATIVE_FUNC(a) a
56 #else
57     #define NATIVE_FUNC(a) NULL
58 #endif
59 
60 
61 static RsdHalFunctions FunctionTable = {
62     NATIVE_FUNC(rsdGLInit),
63     NATIVE_FUNC(rsdGLShutdown),
64     NATIVE_FUNC(rsdGLSetSurface),
65     NATIVE_FUNC(rsdGLSwap),
66 
67     Shutdown,
68     NULL,
69     SetPriority,
70     rsdAllocRuntimeMem,
71     rsdFreeRuntimeMem,
72     {
73         rsdScriptInit,
74         rsdInitIntrinsic,
75         rsdScriptInvokeFunction,
76         rsdScriptInvokeRoot,
77         rsdScriptInvokeForEach,
78         rsdScriptInvokeInit,
79         rsdScriptInvokeFreeChildren,
80         rsdScriptSetGlobalVar,
81         rsdScriptGetGlobalVar,
82         rsdScriptSetGlobalVarWithElemDims,
83         rsdScriptSetGlobalBind,
84         rsdScriptSetGlobalObj,
85         rsdScriptDestroy
86     },
87 
88     {
89         rsdAllocationInit,
90         rsdAllocationDestroy,
91         rsdAllocationResize,
92         rsdAllocationSyncAll,
93         rsdAllocationMarkDirty,
94         NATIVE_FUNC(rsdAllocationGetSurface),
95         NATIVE_FUNC(rsdAllocationSetSurface),
96         NATIVE_FUNC(rsdAllocationIoSend),
97         NATIVE_FUNC(rsdAllocationIoReceive),
98         rsdAllocationData1D,
99         rsdAllocationData2D,
100         rsdAllocationData3D,
101         rsdAllocationRead1D,
102         rsdAllocationRead2D,
103         rsdAllocationRead3D,
104         rsdAllocationLock1D,
105         rsdAllocationUnlock1D,
106         rsdAllocationData1D_alloc,
107         rsdAllocationData2D_alloc,
108         rsdAllocationData3D_alloc,
109         rsdAllocationElementData1D,
110         rsdAllocationElementData2D,
111         rsdAllocationGenerateMipmaps
112     },
113 
114 
115     {
116         NATIVE_FUNC(rsdProgramStoreInit),
117         NATIVE_FUNC(rsdProgramStoreSetActive),
118         NATIVE_FUNC(rsdProgramStoreDestroy)
119     },
120 
121     {
122         NATIVE_FUNC(rsdProgramRasterInit),
123         NATIVE_FUNC(rsdProgramRasterSetActive),
124         NATIVE_FUNC(rsdProgramRasterDestroy)
125     },
126 
127     {
128         NATIVE_FUNC(rsdProgramVertexInit),
129         NATIVE_FUNC(rsdProgramVertexSetActive),
130         NATIVE_FUNC(rsdProgramVertexDestroy)
131     },
132 
133     {
134         NATIVE_FUNC(rsdProgramFragmentInit),
135         NATIVE_FUNC(rsdProgramFragmentSetActive),
136         NATIVE_FUNC(rsdProgramFragmentDestroy)
137     },
138 
139     {
140         NATIVE_FUNC(rsdMeshInit),
141         NATIVE_FUNC(rsdMeshDraw),
142         NATIVE_FUNC(rsdMeshDestroy)
143     },
144 
145     {
146         NATIVE_FUNC(rsdPathInitStatic),
147         NATIVE_FUNC(rsdPathInitDynamic),
148         NATIVE_FUNC(rsdPathDraw),
149         NATIVE_FUNC(rsdPathDestroy)
150     },
151 
152     {
153         rsdSamplerInit,
154         rsdSamplerDestroy
155     },
156 
157     {
158         NATIVE_FUNC(rsdFrameBufferInit),
159         NATIVE_FUNC(rsdFrameBufferSetActive),
160         NATIVE_FUNC(rsdFrameBufferDestroy)
161     },
162 
163     {
164         rsdScriptGroupInit,
165         rsdScriptGroupSetInput,
166         rsdScriptGroupSetOutput,
167         rsdScriptGroupExecute,
168         rsdScriptGroupDestroy
169     }
170 
171 
172 };
173 
174 extern const RsdCpuReference::CpuSymbol * rsdLookupRuntimeStub(Context * pContext, char const* name);
175 
LookupScript(Context *,const Script * s)176 static RsdCpuReference::CpuScript * LookupScript(Context *, const Script *s) {
177     return (RsdCpuReference::CpuScript *)s->mHal.drv;
178 }
179 
rsdHalInit(RsContext c,uint32_t version_major,uint32_t version_minor)180 extern "C" bool rsdHalInit(RsContext c, uint32_t version_major,
181                            uint32_t version_minor) {
182     Context *rsc = (Context*) c;
183     rsc->mHal.funcs = FunctionTable;
184 
185     RsdHal *dc = (RsdHal *)calloc(1, sizeof(RsdHal));
186     if (!dc) {
187         ALOGE("Calloc for driver hal failed.");
188         return false;
189     }
190     rsc->mHal.drv = dc;
191 
192     dc->mCpuRef = RsdCpuReference::create((Context *)c, version_major, version_minor,
193                                           &rsdLookupRuntimeStub, &LookupScript);
194     if (!dc->mCpuRef) {
195         ALOGE("RsdCpuReference::create for driver hal failed.");
196         free(dc);
197         return false;
198     }
199 
200     return true;
201 }
202 
203 
SetPriority(const Context * rsc,int32_t priority)204 void SetPriority(const Context *rsc, int32_t priority) {
205     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
206 
207     dc->mCpuRef->setPriority(priority);
208 
209 #ifndef RS_COMPATIBILITY_LIB
210     if (dc->mHasGraphics) {
211         rsdGLSetPriority(rsc, priority);
212     }
213 #endif
214 }
215 
Shutdown(Context * rsc)216 void Shutdown(Context *rsc) {
217     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
218     delete dc->mCpuRef;
219     rsc->mHal.drv = NULL;
220 }
221 
rsdAllocRuntimeMem(size_t size,uint32_t flags)222 void* rsdAllocRuntimeMem(size_t size, uint32_t flags) {
223     void* buffer = calloc(size, sizeof(char));
224     return buffer;
225 }
226 
rsdFreeRuntimeMem(void * ptr)227 void rsdFreeRuntimeMem(void* ptr) {
228     free(ptr);
229 }
230