rsContext.h revision 992a0b70d8fd7a14f0c57bc3c7e16c1f269a6609
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 "rsType.h" 21#include "rsMatrix.h" 22#include "rsAllocation.h" 23#include "rsTriangleMesh.h" 24#include "rsDevice.h" 25#include "rsScriptC.h" 26#include "rsAllocation.h" 27#include "rsAdapter.h" 28#include "rsSampler.h" 29#include "rsProgramFragment.h" 30#include "rsProgramFragmentStore.h" 31#include "rsProgramVertex.h" 32#include "rsLight.h" 33 34#include "rsgApiStructs.h" 35#include "rsLocklessFifo.h" 36 37#include <ui/EGLNativeWindowSurface.h> 38#include <ui/Surface.h> 39 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 pthread_t mThreadId; 120 121 ObjectBaseRef<Script> mRootScript; 122 ObjectBaseRef<ProgramFragment> mFragment; 123 ObjectBaseRef<ProgramVertex> mVertex; 124 ObjectBaseRef<ProgramFragmentStore> mFragmentStore; 125 126private: 127 Context(); 128 129 void initEGL(); 130 131 bool runScript(Script *s, uint32_t launchID); 132 bool runRootScript(); 133 134 static void * threadProc(void *); 135 136 // todo: put in TLS 137 static Context *gCon; 138 Surface *mWndSurface; 139 140 Vector<ObjectBase *> mNames; 141}; 142 143 144} 145} 146#endif 147