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