blob: d98bfd9045b50599e8ec1f13b528be3c7fe8464c [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 Samsd19f10d2009-05-22 14:03:28 -070020#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 Samsbba134c2009-06-22 15:49:21 -070032#include "rsLight.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070033
34#include "rsgApiStructs.h"
35#include "rsLocklessFifo.h"
36
Jason Sams4b962e52009-06-22 17:15:15 -070037#include <ui/EGLNativeWindowSurface.h>
38#include <ui/Surface.h>
39
40
Jason Samsd19f10d2009-05-22 14:03:28 -070041
42// ---------------------------------------------------------------------------
43namespace android {
44namespace renderscript {
45
Jason Samsd19f10d2009-05-22 14:03:28 -070046class Context
47{
48public:
49 Context(Device *, Surface *);
50 ~Context();
51
Jason Sams462d11b2009-06-19 16:03:18 -070052 static pthread_key_t gThreadTLSKey;
53 struct ScriptTLSStruct {
54 Context * mContext;
55 Script * mScript;
56 };
57
Jason Samsd19f10d2009-05-22 14:03:28 -070058
59 //StructuredAllocationContext mStateAllocation;
60 ElementState mStateElement;
61 TypeState mStateType;
62 SamplerState mStateSampler;
63 ProgramFragmentState mStateFragment;
64 ProgramFragmentStoreState mStateFragmentStore;
65 ProgramVertexState mStateVertex;
Jason Samsbba134c2009-06-22 15:49:21 -070066 LightState mStateLight;
Jason Samsd19f10d2009-05-22 14:03:28 -070067
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 Samsd5680f92009-06-10 18:39:40 -070087 void assignName(ObjectBase *obj, const char *name, uint32_t len);
Jason Sams3eaa3382009-06-10 15:04:38 -070088 void removeName(ObjectBase *obj);
89 ObjectBase * lookupName(const char *name) const;
Jason Samsd5680f92009-06-10 18:39:40 -070090 void appendNameDefines(String8 *str) const;
Jason Sams3eaa3382009-06-10 15:04:38 -070091
Jason Sams9c54bdb2009-06-17 16:52:59 -070092
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 Samsd19f10d2009-05-22 14:03:28 -0700103protected:
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 Samsd19f10d2009-05-22 14:03:28 -0700119 pthread_t mThreadId;
120
121 ObjectBaseRef<Script> mRootScript;
122 ObjectBaseRef<ProgramFragment> mFragment;
123 ObjectBaseRef<ProgramVertex> mVertex;
124 ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
125
126private:
127 Context();
128
129 void initEGL();
130
Jason Sams3eaa3382009-06-10 15:04:38 -0700131 bool runScript(Script *s, uint32_t launchID);
Jason Samsa09f11d2009-06-04 17:58:03 -0700132 bool runRootScript();
Jason Samsd19f10d2009-05-22 14:03:28 -0700133
134 static void * threadProc(void *);
135
136 // todo: put in TLS
137 static Context *gCon;
138 Surface *mWndSurface;
Jason Sams3eaa3382009-06-10 15:04:38 -0700139
140 Vector<ObjectBase *> mNames;
Jason Samsd19f10d2009-05-22 14:03:28 -0700141};
142
143
144}
145}
146#endif