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