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