blob: 442a920fbbd70adf0e390f74d5cc3ebf2793de06 [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
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 Sams399bfce2009-07-13 12:20:31 -070020#include "rsUtils.h"
21
Jason Samsd19f10d2009-05-22 14:03:28 -070022#include <utils/Vector.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070023#include <ui/Surface.h>
24
25#include "rsType.h"
26#include "rsMatrix.h"
27#include "rsAllocation.h"
28#include "rsTriangleMesh.h"
Jason Sams7c878f32009-06-30 14:13:04 -070029#include "rsMesh.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070030#include "rsDevice.h"
31#include "rsScriptC.h"
32#include "rsAllocation.h"
33#include "rsAdapter.h"
34#include "rsSampler.h"
35#include "rsProgramFragment.h"
36#include "rsProgramFragmentStore.h"
37#include "rsProgramVertex.h"
Jason Samsbba134c2009-06-22 15:49:21 -070038#include "rsLight.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070039
40#include "rsgApiStructs.h"
41#include "rsLocklessFifo.h"
42
43
44// ---------------------------------------------------------------------------
45namespace android {
46namespace renderscript {
47
Jason Samsd19f10d2009-05-22 14:03:28 -070048class Context
49{
50public:
51 Context(Device *, Surface *);
52 ~Context();
53
Jason Sams462d11b2009-06-19 16:03:18 -070054 static pthread_key_t gThreadTLSKey;
55 struct ScriptTLSStruct {
56 Context * mContext;
57 Script * mScript;
58 };
59
Jason Samsd19f10d2009-05-22 14:03:28 -070060
61 //StructuredAllocationContext mStateAllocation;
62 ElementState mStateElement;
63 TypeState mStateType;
64 SamplerState mStateSampler;
65 ProgramFragmentState mStateFragment;
66 ProgramFragmentStoreState mStateFragmentStore;
67 ProgramVertexState mStateVertex;
Jason Samsbba134c2009-06-22 15:49:21 -070068 LightState mStateLight;
Jason Samsd19f10d2009-05-22 14:03:28 -070069
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();}
86
87 void setupCheck();
88
Jason Samsd5680f92009-06-10 18:39:40 -070089 void assignName(ObjectBase *obj, const char *name, uint32_t len);
Jason Sams3eaa3382009-06-10 15:04:38 -070090 void removeName(ObjectBase *obj);
91 ObjectBase * lookupName(const char *name) const;
Jason Samsd5680f92009-06-10 18:39:40 -070092 void appendNameDefines(String8 *str) const;
Jason Sams3eaa3382009-06-10 15:04:38 -070093
Jason Sams9c54bdb2009-06-17 16:52:59 -070094
95 ProgramFragment * getDefaultProgramFragment() const {
96 return mStateFragment.mDefault.get();
97 }
98 ProgramVertex * getDefaultProgramVertex() const {
99 return mStateVertex.mDefault.get();
100 }
101 ProgramFragmentStore * getDefaultProgramFragmentStore() const {
102 return mStateFragmentStore.mDefault.get();
103 }
104
Jason Samsd19f10d2009-05-22 14:03:28 -0700105protected:
106 Device *mDev;
107
108 EGLint mNumConfigs;
109 EGLint mMajorVersion;
110 EGLint mMinorVersion;
111 EGLConfig mConfig;
112 EGLContext mContext;
113 EGLSurface mSurface;
114 EGLint mWidth;
115 EGLint mHeight;
116 EGLDisplay mDisplay;
117
118 bool mRunning;
119 bool mExit;
120
Jason Samsd19f10d2009-05-22 14:03:28 -0700121 pthread_t mThreadId;
122
123 ObjectBaseRef<Script> mRootScript;
124 ObjectBaseRef<ProgramFragment> mFragment;
125 ObjectBaseRef<ProgramVertex> mVertex;
126 ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
127
128private:
129 Context();
130
131 void initEGL();
132
Jason Sams3eaa3382009-06-10 15:04:38 -0700133 bool runScript(Script *s, uint32_t launchID);
Jason Samsa09f11d2009-06-04 17:58:03 -0700134 bool runRootScript();
Jason Samsd19f10d2009-05-22 14:03:28 -0700135
136 static void * threadProc(void *);
137
138 // todo: put in TLS
139 static Context *gCon;
140 Surface *mWndSurface;
Jason Sams3eaa3382009-06-10 15:04:38 -0700141
142 Vector<ObjectBase *> mNames;
Jason Samsd19f10d2009-05-22 14:03:28 -0700143};
144
145
146}
147}
148#endif