blob: e9d75e09b534e42c44122fd5f9483f8c6f96546f [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
20#include <utils/Vector.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070021#include <ui/Surface.h>
22
23#include "rsType.h"
24#include "rsMatrix.h"
25#include "rsAllocation.h"
26#include "rsTriangleMesh.h"
27#include "rsDevice.h"
28#include "rsScriptC.h"
29#include "rsAllocation.h"
30#include "rsAdapter.h"
31#include "rsSampler.h"
32#include "rsProgramFragment.h"
33#include "rsProgramFragmentStore.h"
34#include "rsProgramVertex.h"
35
36#include "rsgApiStructs.h"
37#include "rsLocklessFifo.h"
38
39
40// ---------------------------------------------------------------------------
41namespace android {
42namespace renderscript {
43
Jason Samsd19f10d2009-05-22 14:03:28 -070044class Context
45{
46public:
47 Context(Device *, Surface *);
48 ~Context();
49
Jason Sams462d11b2009-06-19 16:03:18 -070050 static pthread_key_t gThreadTLSKey;
51 struct ScriptTLSStruct {
52 Context * mContext;
53 Script * mScript;
54 };
55
Jason Samsd19f10d2009-05-22 14:03:28 -070056
57 //StructuredAllocationContext mStateAllocation;
58 ElementState mStateElement;
59 TypeState mStateType;
60 SamplerState mStateSampler;
61 ProgramFragmentState mStateFragment;
62 ProgramFragmentStoreState mStateFragmentStore;
63 ProgramVertexState mStateVertex;
64
65 TriangleMeshContext mStateTriangleMesh;
66
67 ScriptCState mScriptC;
68
69 static Context * getContext() {return gCon;}
70
71 void swapBuffers();
72 void setRootScript(Script *);
73 void setVertex(ProgramVertex *);
74 void setFragment(ProgramFragment *);
75 void setFragmentStore(ProgramFragmentStore *);
76
77 void updateSurface(void *sur);
78
79 const ProgramFragment * getFragment() {return mFragment.get();}
80 const ProgramFragmentStore * getFragmentStore() {return mFragmentStore.get();}
81
82 void setupCheck();
83
Jason Samsd5680f92009-06-10 18:39:40 -070084 void assignName(ObjectBase *obj, const char *name, uint32_t len);
Jason Sams3eaa3382009-06-10 15:04:38 -070085 void removeName(ObjectBase *obj);
86 ObjectBase * lookupName(const char *name) const;
Jason Samsd5680f92009-06-10 18:39:40 -070087 void appendNameDefines(String8 *str) const;
Jason Sams3eaa3382009-06-10 15:04:38 -070088
Jason Sams9c54bdb2009-06-17 16:52:59 -070089
90 ProgramFragment * getDefaultProgramFragment() const {
91 return mStateFragment.mDefault.get();
92 }
93 ProgramVertex * getDefaultProgramVertex() const {
94 return mStateVertex.mDefault.get();
95 }
96 ProgramFragmentStore * getDefaultProgramFragmentStore() const {
97 return mStateFragmentStore.mDefault.get();
98 }
99
Jason Samsd19f10d2009-05-22 14:03:28 -0700100protected:
101 Device *mDev;
102
103 EGLint mNumConfigs;
104 EGLint mMajorVersion;
105 EGLint mMinorVersion;
106 EGLConfig mConfig;
107 EGLContext mContext;
108 EGLSurface mSurface;
109 EGLint mWidth;
110 EGLint mHeight;
111 EGLDisplay mDisplay;
112
113 bool mRunning;
114 bool mExit;
115
116 LocklessCommandFifo mServerCommands;
117 LocklessCommandFifo mServerReturns;
118
119 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