blob: 10b9a13645d0ddefd49b55689a239eab59929dba [file] [log] [blame]
Jason Sams326e0dd2009-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>
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// ---------------------------------------------------------------------------
42namespace android {
43namespace renderscript {
44
Jason Sams326e0dd2009-05-22 14:03:28 -070045class Context
46{
47public:
48 Context(Device *, Surface *);
49 ~Context();
50
51
52 //StructuredAllocationContext mStateAllocation;
53 ElementState mStateElement;
54 TypeState mStateType;
55 SamplerState mStateSampler;
56 ProgramFragmentState mStateFragment;
57 ProgramFragmentStoreState mStateFragmentStore;
58 ProgramVertexState mStateVertex;
59
60 TriangleMeshContext mStateTriangleMesh;
61
62 ScriptCState mScriptC;
63
64 static Context * getContext() {return gCon;}
65
66 void swapBuffers();
67 void setRootScript(Script *);
68 void setVertex(ProgramVertex *);
69 void setFragment(ProgramFragment *);
70 void setFragmentStore(ProgramFragmentStore *);
71
72 void updateSurface(void *sur);
73
74 const ProgramFragment * getFragment() {return mFragment.get();}
75 const ProgramFragmentStore * getFragmentStore() {return mFragmentStore.get();}
76
77 void setupCheck();
78
Jason Samsa4a54e42009-06-10 18:39:40 -070079 void assignName(ObjectBase *obj, const char *name, uint32_t len);
Jason Samsa0a1b6f2009-06-10 15:04:38 -070080 void removeName(ObjectBase *obj);
81 ObjectBase * lookupName(const char *name) const;
Jason Samsa4a54e42009-06-10 18:39:40 -070082 void appendNameDefines(String8 *str) const;
Jason Samsa0a1b6f2009-06-10 15:04:38 -070083
Jason Sams8ce125b2009-06-17 16:52:59 -070084
85 ProgramFragment * getDefaultProgramFragment() const {
86 return mStateFragment.mDefault.get();
87 }
88 ProgramVertex * getDefaultProgramVertex() const {
89 return mStateVertex.mDefault.get();
90 }
91 ProgramFragmentStore * getDefaultProgramFragmentStore() const {
92 return mStateFragmentStore.mDefault.get();
93 }
94
Jason Sams326e0dd2009-05-22 14:03:28 -070095protected:
96 Device *mDev;
97
98 EGLint mNumConfigs;
99 EGLint mMajorVersion;
100 EGLint mMinorVersion;
101 EGLConfig mConfig;
102 EGLContext mContext;
103 EGLSurface mSurface;
104 EGLint mWidth;
105 EGLint mHeight;
106 EGLDisplay mDisplay;
107
108 bool mRunning;
109 bool mExit;
110
111 LocklessCommandFifo mServerCommands;
112 LocklessCommandFifo mServerReturns;
113
114 pthread_t mThreadId;
115
116 ObjectBaseRef<Script> mRootScript;
117 ObjectBaseRef<ProgramFragment> mFragment;
118 ObjectBaseRef<ProgramVertex> mVertex;
119 ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
120
121private:
122 Context();
123
124 void initEGL();
125
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700126 bool runScript(Script *s, uint32_t launchID);
Jason Samsa44cb292009-06-04 17:58:03 -0700127 bool runRootScript();
Jason Sams326e0dd2009-05-22 14:03:28 -0700128
129 static void * threadProc(void *);
130
131 // todo: put in TLS
132 static Context *gCon;
133 Surface *mWndSurface;
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700134
135 Vector<ObjectBase *> mNames;
Jason Sams326e0dd2009-05-22 14:03:28 -0700136};
137
138
139}
140}
141#endif