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 | |
| 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 | |
| 37 | #include "rsgApiStructs.h" |
| 38 | #include "rsLocklessFifo.h" |
| 39 | |
| 40 | |
| 41 | // --------------------------------------------------------------------------- |
| 42 | namespace android { |
| 43 | namespace renderscript { |
| 44 | |
| 45 | |
| 46 | class Context |
| 47 | { |
| 48 | public: |
| 49 | Context(Device *, Surface *); |
| 50 | ~Context(); |
| 51 | |
| 52 | |
| 53 | //StructuredAllocationContext mStateAllocation; |
| 54 | ElementState mStateElement; |
| 55 | TypeState mStateType; |
| 56 | SamplerState mStateSampler; |
| 57 | ProgramFragmentState mStateFragment; |
| 58 | ProgramFragmentStoreState mStateFragmentStore; |
| 59 | ProgramVertexState mStateVertex; |
| 60 | |
| 61 | TriangleMeshContext mStateTriangleMesh; |
| 62 | |
| 63 | ScriptCState mScriptC; |
| 64 | |
| 65 | static Context * getContext() {return gCon;} |
| 66 | |
| 67 | void swapBuffers(); |
| 68 | void setRootScript(Script *); |
| 69 | void setVertex(ProgramVertex *); |
| 70 | void setFragment(ProgramFragment *); |
| 71 | void setFragmentStore(ProgramFragmentStore *); |
| 72 | |
| 73 | void updateSurface(void *sur); |
| 74 | |
| 75 | const ProgramFragment * getFragment() {return mFragment.get();} |
| 76 | const ProgramFragmentStore * getFragmentStore() {return mFragmentStore.get();} |
| 77 | |
| 78 | void setupCheck(); |
| 79 | |
| 80 | protected: |
| 81 | Device *mDev; |
| 82 | |
| 83 | EGLint mNumConfigs; |
| 84 | EGLint mMajorVersion; |
| 85 | EGLint mMinorVersion; |
| 86 | EGLConfig mConfig; |
| 87 | EGLContext mContext; |
| 88 | EGLSurface mSurface; |
| 89 | EGLint mWidth; |
| 90 | EGLint mHeight; |
| 91 | EGLDisplay mDisplay; |
| 92 | |
| 93 | bool mRunning; |
| 94 | bool mExit; |
| 95 | |
| 96 | LocklessCommandFifo mServerCommands; |
| 97 | LocklessCommandFifo mServerReturns; |
| 98 | |
| 99 | pthread_t mThreadId; |
| 100 | |
| 101 | ObjectBaseRef<Script> mRootScript; |
| 102 | ObjectBaseRef<ProgramFragment> mFragment; |
| 103 | ObjectBaseRef<ProgramVertex> mVertex; |
| 104 | ObjectBaseRef<ProgramFragmentStore> mFragmentStore; |
| 105 | |
| 106 | private: |
| 107 | Context(); |
| 108 | |
| 109 | void initEGL(); |
| 110 | |
Jason Sams | a09f11d | 2009-06-04 17:58:03 -0700 | [diff] [blame^] | 111 | bool runRootScript(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 112 | |
| 113 | static void * threadProc(void *); |
| 114 | |
| 115 | // todo: put in TLS |
| 116 | static Context *gCon; |
| 117 | Surface *mWndSurface; |
| 118 | }; |
| 119 | |
| 120 | |
| 121 | } |
| 122 | } |
| 123 | #endif |