Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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" |
Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 32 | #include "rsLight.h" |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 33 | |
| 34 | #include "rsgApiStructs.h" |
| 35 | #include "rsLocklessFifo.h" |
| 36 | |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 37 | #include <ui/EGLNativeWindowSurface.h> |
| 38 | #include <ui/Surface.h> |
| 39 | |
| 40 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 41 | |
| 42 | // --------------------------------------------------------------------------- |
| 43 | namespace android { |
| 44 | namespace renderscript { |
| 45 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 46 | class Context |
| 47 | { |
| 48 | public: |
| 49 | Context(Device *, Surface *); |
| 50 | ~Context(); |
| 51 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 52 | static pthread_key_t gThreadTLSKey; |
| 53 | struct ScriptTLSStruct { |
| 54 | Context * mContext; |
| 55 | Script * mScript; |
| 56 | }; |
| 57 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 58 | |
| 59 | //StructuredAllocationContext mStateAllocation; |
| 60 | ElementState mStateElement; |
| 61 | TypeState mStateType; |
| 62 | SamplerState mStateSampler; |
| 63 | ProgramFragmentState mStateFragment; |
| 64 | ProgramFragmentStoreState mStateFragmentStore; |
| 65 | ProgramVertexState mStateVertex; |
Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 66 | LightState mStateLight; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 87 | void assignName(ObjectBase *obj, const char *name, uint32_t len); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 88 | void removeName(ObjectBase *obj); |
| 89 | ObjectBase * lookupName(const char *name) const; |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 90 | void appendNameDefines(String8 *str) const; |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 91 | |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 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 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 103 | protected: |
| 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 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 119 | pthread_t mThreadId; |
| 120 | |
| 121 | ObjectBaseRef<Script> mRootScript; |
| 122 | ObjectBaseRef<ProgramFragment> mFragment; |
| 123 | ObjectBaseRef<ProgramVertex> mVertex; |
| 124 | ObjectBaseRef<ProgramFragmentStore> mFragmentStore; |
| 125 | |
| 126 | private: |
| 127 | Context(); |
| 128 | |
| 129 | void initEGL(); |
| 130 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 131 | bool runScript(Script *s, uint32_t launchID); |
Jason Sams | a09f11d | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 132 | bool runRootScript(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 133 | |
| 134 | static void * threadProc(void *); |
| 135 | |
| 136 | // todo: put in TLS |
| 137 | static Context *gCon; |
| 138 | Surface *mWndSurface; |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 139 | |
| 140 | Vector<ObjectBase *> mNames; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | |
| 144 | } |
| 145 | } |
| 146 | #endif |