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 | 399bfce | 2009-07-13 12:20:31 -0700 | [diff] [blame] | 20 | #include "rsUtils.h" |
| 21 | |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 22 | #include <utils/KeyedVector.h> |
| 23 | #include <utils/String8.h> |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 24 | #include <utils/Vector.h> |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 25 | #include <ui/Surface.h> |
| 26 | |
| 27 | #include "rsType.h" |
| 28 | #include "rsMatrix.h" |
| 29 | #include "rsAllocation.h" |
| 30 | #include "rsTriangleMesh.h" |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 31 | #include "rsSimpleMesh.h" |
Jason Sams | 7c878f3 | 2009-06-30 14:13:04 -0700 | [diff] [blame] | 32 | #include "rsMesh.h" |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 33 | #include "rsDevice.h" |
| 34 | #include "rsScriptC.h" |
| 35 | #include "rsAllocation.h" |
| 36 | #include "rsAdapter.h" |
| 37 | #include "rsSampler.h" |
Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 38 | #include "rsLight.h" |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 39 | #include "rsProgramFragment.h" |
| 40 | #include "rsProgramFragmentStore.h" |
| 41 | #include "rsProgramVertex.h" |
| 42 | |
| 43 | #include "rsgApiStructs.h" |
| 44 | #include "rsLocklessFifo.h" |
| 45 | |
| 46 | |
| 47 | // --------------------------------------------------------------------------- |
| 48 | namespace android { |
| 49 | namespace renderscript { |
| 50 | |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 51 | class Context |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 52 | { |
| 53 | public: |
| 54 | Context(Device *, Surface *); |
| 55 | ~Context(); |
| 56 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 57 | static pthread_key_t gThreadTLSKey; |
| 58 | struct ScriptTLSStruct { |
| 59 | Context * mContext; |
| 60 | Script * mScript; |
| 61 | }; |
| 62 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 63 | |
| 64 | //StructuredAllocationContext mStateAllocation; |
| 65 | ElementState mStateElement; |
| 66 | TypeState mStateType; |
| 67 | SamplerState mStateSampler; |
| 68 | ProgramFragmentState mStateFragment; |
| 69 | ProgramFragmentStoreState mStateFragmentStore; |
| 70 | ProgramVertexState mStateVertex; |
Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 71 | LightState mStateLight; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 72 | |
| 73 | TriangleMeshContext mStateTriangleMesh; |
| 74 | |
| 75 | ScriptCState mScriptC; |
| 76 | |
| 77 | static Context * getContext() {return gCon;} |
| 78 | |
| 79 | void swapBuffers(); |
| 80 | void setRootScript(Script *); |
| 81 | void setVertex(ProgramVertex *); |
| 82 | void setFragment(ProgramFragment *); |
| 83 | void setFragmentStore(ProgramFragmentStore *); |
| 84 | |
| 85 | void updateSurface(void *sur); |
| 86 | |
| 87 | const ProgramFragment * getFragment() {return mFragment.get();} |
| 88 | const ProgramFragmentStore * getFragmentStore() {return mFragmentStore.get();} |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 89 | const ProgramVertex * getVertex() {return mVertex.get();} |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 90 | |
| 91 | void setupCheck(); |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 92 | void allocationCheck(const Allocation *); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 93 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 94 | void assignName(ObjectBase *obj, const char *name, uint32_t len); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 95 | void removeName(ObjectBase *obj); |
| 96 | ObjectBase * lookupName(const char *name) const; |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 97 | void appendNameDefines(String8 *str) const; |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 98 | void appendVarDefines(String8 *str) const; |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 99 | |
| 100 | ProgramFragment * getDefaultProgramFragment() const { |
| 101 | return mStateFragment.mDefault.get(); |
| 102 | } |
| 103 | ProgramVertex * getDefaultProgramVertex() const { |
| 104 | return mStateVertex.mDefault.get(); |
| 105 | } |
| 106 | ProgramFragmentStore * getDefaultProgramFragmentStore() const { |
| 107 | return mStateFragmentStore.mDefault.get(); |
| 108 | } |
| 109 | |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 110 | void addInt32Define(const char* name, int32_t value) { |
| 111 | mInt32Defines.add(String8(name), value); |
| 112 | } |
| 113 | |
| 114 | void addFloatDefine(const char* name, float value) { |
| 115 | mFloatDefines.add(String8(name), value); |
| 116 | } |
| 117 | |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame^] | 118 | uint32_t getWidth() const {return mWidth;} |
| 119 | uint32_t getHeight() const {return mHeight;} |
| 120 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 121 | protected: |
| 122 | Device *mDev; |
| 123 | |
| 124 | EGLint mNumConfigs; |
| 125 | EGLint mMajorVersion; |
| 126 | EGLint mMinorVersion; |
| 127 | EGLConfig mConfig; |
| 128 | EGLContext mContext; |
| 129 | EGLSurface mSurface; |
| 130 | EGLint mWidth; |
| 131 | EGLint mHeight; |
| 132 | EGLDisplay mDisplay; |
| 133 | |
| 134 | bool mRunning; |
| 135 | bool mExit; |
| 136 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 137 | pthread_t mThreadId; |
| 138 | |
| 139 | ObjectBaseRef<Script> mRootScript; |
| 140 | ObjectBaseRef<ProgramFragment> mFragment; |
| 141 | ObjectBaseRef<ProgramVertex> mVertex; |
| 142 | ObjectBaseRef<ProgramFragmentStore> mFragmentStore; |
| 143 | |
| 144 | private: |
| 145 | Context(); |
| 146 | |
| 147 | void initEGL(); |
| 148 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 149 | bool runScript(Script *s, uint32_t launchID); |
Jason Sams | a09f11d | 2009-06-04 17:58:03 -0700 | [diff] [blame] | 150 | bool runRootScript(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 151 | |
| 152 | static void * threadProc(void *); |
| 153 | |
| 154 | // todo: put in TLS |
| 155 | static Context *gCon; |
| 156 | Surface *mWndSurface; |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 157 | |
| 158 | Vector<ObjectBase *> mNames; |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 159 | KeyedVector<String8,int> mInt32Defines; |
| 160 | KeyedVector<String8,float> mFloatDefines; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | |
| 164 | } |
| 165 | } |
| 166 | #endif |