rsContext.h revision a89371c6f144b9049efe7689105feee2c4a38384
1/*
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 "rsType.h"
21#include "rsMatrix.h"
22#include "rsAllocation.h"
23#include "rsTriangleMesh.h"
24#include "rsMesh.h"
25#include "rsDevice.h"
26#include "rsScriptC.h"
27#include "rsAllocation.h"
28#include "rsAdapter.h"
29#include "rsSampler.h"
30#include "rsProgramFragment.h"
31#include "rsProgramFragmentStore.h"
32#include "rsProgramVertex.h"
33#include "rsLight.h"
34
35#include "rsgApiStructs.h"
36#include "rsLocklessFifo.h"
37
38#include <ui/EGLNativeWindowSurface.h>
39#include <ui/Surface.h>
40
41
42
43// ---------------------------------------------------------------------------
44namespace android {
45namespace renderscript {
46
47class Context
48{
49public:
50    Context(Device *, Surface *);
51    ~Context();
52
53    static pthread_key_t gThreadTLSKey;
54    struct ScriptTLSStruct {
55        Context * mContext;
56        Script * mScript;
57    };
58
59
60    //StructuredAllocationContext mStateAllocation;
61    ElementState mStateElement;
62    TypeState mStateType;
63    SamplerState mStateSampler;
64    ProgramFragmentState mStateFragment;
65    ProgramFragmentStoreState mStateFragmentStore;
66    ProgramVertexState mStateVertex;
67    LightState mStateLight;
68
69    TriangleMeshContext mStateTriangleMesh;
70
71    ScriptCState mScriptC;
72
73    static Context * getContext() {return gCon;}
74
75    void swapBuffers();
76    void setRootScript(Script *);
77    void setVertex(ProgramVertex *);
78    void setFragment(ProgramFragment *);
79    void setFragmentStore(ProgramFragmentStore *);
80
81    void updateSurface(void *sur);
82
83    const ProgramFragment * getFragment() {return mFragment.get();}
84    const ProgramFragmentStore * getFragmentStore() {return mFragmentStore.get();}
85
86    void setupCheck();
87
88    void assignName(ObjectBase *obj, const char *name, uint32_t len);
89    void removeName(ObjectBase *obj);
90    ObjectBase * lookupName(const char *name) const;
91    void appendNameDefines(String8 *str) const;
92
93
94    ProgramFragment * getDefaultProgramFragment() const {
95        return mStateFragment.mDefault.get();
96    }
97    ProgramVertex * getDefaultProgramVertex() const {
98        return mStateVertex.mDefault.get();
99    }
100    ProgramFragmentStore * getDefaultProgramFragmentStore() const {
101        return mStateFragmentStore.mDefault.get();
102    }
103
104protected:
105    Device *mDev;
106
107    EGLint mNumConfigs;
108    EGLint mMajorVersion;
109    EGLint mMinorVersion;
110    EGLConfig mConfig;
111    EGLContext mContext;
112    EGLSurface mSurface;
113    EGLint mWidth;
114    EGLint mHeight;
115    EGLDisplay mDisplay;
116
117    bool mRunning;
118    bool mExit;
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
132    bool runScript(Script *s, uint32_t launchID);
133    bool runRootScript();
134
135    static void * threadProc(void *);
136
137    // todo: put in TLS
138    static Context *gCon;
139    Surface *mWndSurface;
140
141    Vector<ObjectBase *> mNames;
142};
143
144
145}
146}
147#endif
148