rsContext.h revision a4a54e42fc710a62b47cbcb9d64c34a190429d9e
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 <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
45class 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
79    void assignName(ObjectBase *obj, const char *name, uint32_t len);
80    void removeName(ObjectBase *obj);
81    ObjectBase * lookupName(const char *name) const;
82    void appendNameDefines(String8 *str) const;
83
84protected:
85    Device *mDev;
86
87    EGLint mNumConfigs;
88    EGLint mMajorVersion;
89    EGLint mMinorVersion;
90    EGLConfig mConfig;
91    EGLContext mContext;
92    EGLSurface mSurface;
93    EGLint mWidth;
94    EGLint mHeight;
95    EGLDisplay mDisplay;
96
97    bool mRunning;
98    bool mExit;
99
100    LocklessCommandFifo mServerCommands;
101    LocklessCommandFifo mServerReturns;
102
103    pthread_t mThreadId;
104
105    ObjectBaseRef<Script> mRootScript;
106    ObjectBaseRef<ProgramFragment> mFragment;
107    ObjectBaseRef<ProgramVertex> mVertex;
108    ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
109
110    ProgramFragment * mDefaultFragment;
111    ProgramVertex * mDefaultVertex;
112    ProgramFragmentStore * mDefaultFragmentStore;
113
114private:
115    Context();
116
117    void initEGL();
118
119    bool runScript(Script *s, uint32_t launchID);
120    bool runRootScript();
121
122    static void * threadProc(void *);
123
124    // todo: put in TLS
125    static Context *gCon;
126    Surface *mWndSurface;
127
128    Vector<ObjectBase *> mNames;
129};
130
131
132}
133}
134#endif
135