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