rsContext.h revision 62bc1db27ba17f7eed0a6dfb639da7326753b268
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 <utils/Vector.h> 21#include <ui/EGLNativeWindowSurface.h> 22#include <ui/Surface.h> 23 24#include "rsType.h" 25#include "rsMatrix.h" 26#include "rsAllocation.h" 27#include "rsTriangleMesh.h" 28#include "rsDevice.h" 29#include "rsScriptC.h" 30#include "rsAllocation.h" 31#include "rsAdapter.h" 32#include "rsSampler.h" 33#include "rsProgramFragment.h" 34#include "rsProgramFragmentStore.h" 35#include "rsProgramVertex.h" 36#include "rsLight.h" 37 38#include "rsgApiStructs.h" 39#include "rsLocklessFifo.h" 40 41 42// --------------------------------------------------------------------------- 43namespace android { 44namespace renderscript { 45 46class Context 47{ 48public: 49 Context(Device *, Surface *); 50 ~Context(); 51 52 static pthread_key_t gThreadTLSKey; 53 struct ScriptTLSStruct { 54 Context * mContext; 55 Script * mScript; 56 }; 57 58 59 //StructuredAllocationContext mStateAllocation; 60 ElementState mStateElement; 61 TypeState mStateType; 62 SamplerState mStateSampler; 63 ProgramFragmentState mStateFragment; 64 ProgramFragmentStoreState mStateFragmentStore; 65 ProgramVertexState mStateVertex; 66 LightState mStateLight; 67 68 TriangleMeshContext mStateTriangleMesh; 69 70 ScriptCState mScriptC; 71 72 static Context * getContext() {return gCon;} 73 74 void swapBuffers(); 75 void setRootScript(Script *); 76 void setVertex(ProgramVertex *); 77 void setFragment(ProgramFragment *); 78 void setFragmentStore(ProgramFragmentStore *); 79 80 void updateSurface(void *sur); 81 82 const ProgramFragment * getFragment() {return mFragment.get();} 83 const ProgramFragmentStore * getFragmentStore() {return mFragmentStore.get();} 84 85 void setupCheck(); 86 87 void assignName(ObjectBase *obj, const char *name, uint32_t len); 88 void removeName(ObjectBase *obj); 89 ObjectBase * lookupName(const char *name) const; 90 void appendNameDefines(String8 *str) const; 91 92 93 ProgramFragment * getDefaultProgramFragment() const { 94 return mStateFragment.mDefault.get(); 95 } 96 ProgramVertex * getDefaultProgramVertex() const { 97 return mStateVertex.mDefault.get(); 98 } 99 ProgramFragmentStore * getDefaultProgramFragmentStore() const { 100 return mStateFragmentStore.mDefault.get(); 101 } 102 103protected: 104 Device *mDev; 105 106 EGLint mNumConfigs; 107 EGLint mMajorVersion; 108 EGLint mMinorVersion; 109 EGLConfig mConfig; 110 EGLContext mContext; 111 EGLSurface mSurface; 112 EGLint mWidth; 113 EGLint mHeight; 114 EGLDisplay mDisplay; 115 116 bool mRunning; 117 bool mExit; 118 119 LocklessCommandFifo mServerCommands; 120 LocklessCommandFifo mServerReturns; 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