blob: 334ef3c475b304e237ed6afe3cf0a625a374738f [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
Jason Samse5769102009-06-19 16:03:18 -070051 static pthread_key_t gThreadTLSKey;
52 struct ScriptTLSStruct {
53 Context * mContext;
54 Script * mScript;
55 };
56
Jason Sams326e0dd2009-05-22 14:03:28 -070057
58 //StructuredAllocationContext mStateAllocation;
59 ElementState mStateElement;
60 TypeState mStateType;
61 SamplerState mStateSampler;
62 ProgramFragmentState mStateFragment;
63 ProgramFragmentStoreState mStateFragmentStore;
64 ProgramVertexState mStateVertex;
65
66 TriangleMeshContext mStateTriangleMesh;
67
68 ScriptCState mScriptC;
69
70 static Context * getContext() {return gCon;}
71
72 void swapBuffers();
73 void setRootScript(Script *);
74 void setVertex(ProgramVertex *);
75 void setFragment(ProgramFragment *);
76 void setFragmentStore(ProgramFragmentStore *);
77
78 void updateSurface(void *sur);
79
80 const ProgramFragment * getFragment() {return mFragment.get();}
81 const ProgramFragmentStore * getFragmentStore() {return mFragmentStore.get();}
82
83 void setupCheck();
84
Jason Samsa4a54e42009-06-10 18:39:40 -070085 void assignName(ObjectBase *obj, const char *name, uint32_t len);
Jason Samsa0a1b6f2009-06-10 15:04:38 -070086 void removeName(ObjectBase *obj);
87 ObjectBase * lookupName(const char *name) const;
Jason Samsa4a54e42009-06-10 18:39:40 -070088 void appendNameDefines(String8 *str) const;
Jason Samsa0a1b6f2009-06-10 15:04:38 -070089
Jason Sams8ce125b2009-06-17 16:52:59 -070090
91 ProgramFragment * getDefaultProgramFragment() const {
92 return mStateFragment.mDefault.get();
93 }
94 ProgramVertex * getDefaultProgramVertex() const {
95 return mStateVertex.mDefault.get();
96 }
97 ProgramFragmentStore * getDefaultProgramFragmentStore() const {
98 return mStateFragmentStore.mDefault.get();
99 }
100
Jason Sams326e0dd2009-05-22 14:03:28 -0700101protected:
102 Device *mDev;
103
104 EGLint mNumConfigs;
105 EGLint mMajorVersion;
106 EGLint mMinorVersion;
107 EGLConfig mConfig;
108 EGLContext mContext;
109 EGLSurface mSurface;
110 EGLint mWidth;
111 EGLint mHeight;
112 EGLDisplay mDisplay;
113
114 bool mRunning;
115 bool mExit;
116
117 LocklessCommandFifo mServerCommands;
118 LocklessCommandFifo mServerReturns;
119
120 pthread_t mThreadId;
121
122 ObjectBaseRef<Script> mRootScript;
123 ObjectBaseRef<ProgramFragment> mFragment;
124 ObjectBaseRef<ProgramVertex> mVertex;
125 ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
126
127private:
128 Context();
129
130 void initEGL();
131
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700132 bool runScript(Script *s, uint32_t launchID);
Jason Samsa44cb292009-06-04 17:58:03 -0700133 bool runRootScript();
Jason Sams326e0dd2009-05-22 14:03:28 -0700134
135 static void * threadProc(void *);
136
137 // todo: put in TLS
138 static Context *gCon;
139 Surface *mWndSurface;
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700140
141 Vector<ObjectBase *> mNames;
Jason Sams326e0dd2009-05-22 14:03:28 -0700142};
143
144
145}
146}
147#endif