rsContext.h revision 57b79ceb1126e3797fa42367b97dd7bcfcda1ed9
1/* 2 * Copyright (C) 2009 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#ifndef ANDROID_RS_CONTEXT_H 18#define ANDROID_RS_CONTEXT_H 19 20#include "rsUtils.h" 21 22#include <utils/KeyedVector.h> 23#include <utils/String8.h> 24#include <utils/Vector.h> 25#include <ui/Surface.h> 26 27#include "rsType.h" 28#include "rsMatrix.h" 29#include "rsAllocation.h" 30#include "rsTriangleMesh.h" 31#include "rsSimpleMesh.h" 32#include "rsMesh.h" 33#include "rsDevice.h" 34#include "rsScriptC.h" 35#include "rsAllocation.h" 36#include "rsAdapter.h" 37#include "rsSampler.h" 38#include "rsLight.h" 39#include "rsProgramFragment.h" 40#include "rsProgramFragmentStore.h" 41#include "rsProgramVertex.h" 42 43#include "rsgApiStructs.h" 44#include "rsLocklessFifo.h" 45 46 47// --------------------------------------------------------------------------- 48namespace android { 49namespace renderscript { 50 51class Context 52{ 53public: 54 Context(Device *, Surface *); 55 ~Context(); 56 57 static pthread_key_t gThreadTLSKey; 58 struct ScriptTLSStruct { 59 Context * mContext; 60 Script * mScript; 61 }; 62 63 64 //StructuredAllocationContext mStateAllocation; 65 ElementState mStateElement; 66 TypeState mStateType; 67 SamplerState mStateSampler; 68 ProgramFragmentState mStateFragment; 69 ProgramFragmentStoreState mStateFragmentStore; 70 ProgramVertexState mStateVertex; 71 LightState mStateLight; 72 73 TriangleMeshContext mStateTriangleMesh; 74 75 ScriptCState mScriptC; 76 77 static Context * getContext() {return gCon;} 78 79 void swapBuffers(); 80 void setRootScript(Script *); 81 void setVertex(ProgramVertex *); 82 void setFragment(ProgramFragment *); 83 void setFragmentStore(ProgramFragmentStore *); 84 85 void updateSurface(void *sur); 86 87 const ProgramFragment * getFragment() {return mFragment.get();} 88 const ProgramFragmentStore * getFragmentStore() {return mFragmentStore.get();} 89 const ProgramVertex * getVertex() {return mVertex.get();} 90 91 void setupCheck(); 92 void allocationCheck(const Allocation *); 93 94 void assignName(ObjectBase *obj, const char *name, uint32_t len); 95 void removeName(ObjectBase *obj); 96 ObjectBase * lookupName(const char *name) const; 97 void appendNameDefines(String8 *str) const; 98 void appendVarDefines(String8 *str) const; 99 100 ProgramFragment * getDefaultProgramFragment() const { 101 return mStateFragment.mDefault.get(); 102 } 103 ProgramVertex * getDefaultProgramVertex() const { 104 return mStateVertex.mDefault.get(); 105 } 106 ProgramFragmentStore * getDefaultProgramFragmentStore() const { 107 return mStateFragmentStore.mDefault.get(); 108 } 109 110 void addInt32Define(const char* name, int32_t value) { 111 mInt32Defines.add(String8(name), value); 112 } 113 114 void addFloatDefine(const char* name, float value) { 115 mFloatDefines.add(String8(name), value); 116 } 117 118protected: 119 Device *mDev; 120 121 EGLint mNumConfigs; 122 EGLint mMajorVersion; 123 EGLint mMinorVersion; 124 EGLConfig mConfig; 125 EGLContext mContext; 126 EGLSurface mSurface; 127 EGLint mWidth; 128 EGLint mHeight; 129 EGLDisplay mDisplay; 130 131 bool mRunning; 132 bool mExit; 133 134 pthread_t mThreadId; 135 136 ObjectBaseRef<Script> mRootScript; 137 ObjectBaseRef<ProgramFragment> mFragment; 138 ObjectBaseRef<ProgramVertex> mVertex; 139 ObjectBaseRef<ProgramFragmentStore> mFragmentStore; 140 141private: 142 Context(); 143 144 void initEGL(); 145 146 bool runScript(Script *s, uint32_t launchID); 147 bool runRootScript(); 148 149 static void * threadProc(void *); 150 151 // todo: put in TLS 152 static Context *gCon; 153 Surface *mWndSurface; 154 155 Vector<ObjectBase *> mNames; 156 KeyedVector<String8,int> mInt32Defines; 157 KeyedVector<String8,float> mFloatDefines; 158}; 159 160 161} 162} 163#endif 164