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