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