1326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams/*
2a04e30dbb5ab11592b03666bb3d102070759c58eAlex Sakhartchouk * Copyright (C) 2011 The Android Open Source Project
3326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
4326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * you may not use this file except in compliance with the License.
6326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * You may obtain a copy of the License at
7326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
8326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
10326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Unless required by applicable law or agreed to in writing, software
11326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * See the License for the specific language governing permissions and
14326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * limitations under the License.
15326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams */
16326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
17326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#ifndef ANDROID_RS_CONTEXT_H
18326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#define ANDROID_RS_CONTEXT_H
19326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
20a5577808737a394bdb156fbeb80018d0a4d8438dJason Sams#include "rsUtils.h"
21bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams#include "rs_hal.h"
2293eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#include <string.h>
23bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams
2477d9f4bd05b2d2a161f30c12a2248f9c97eaac42Alex Sakhartchouk#include "rsThreadIO.h"
25326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#include "rsScriptC.h"
26dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams#include "rsScriptGroup.h"
27326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#include "rsSampler.h"
2893eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams
29574854bcb2eb25a85b9b52faf2fb3e743fa7aa14Stephen Hines#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
30fa85e9143c6f6a227c67bab5f08ff86194abdf2aTim Murray#define ATRACE_TAG ATRACE_TAG_RS
31fa85e9143c6f6a227c67bab5f08ff86194abdf2aTim Murray#include "utils/Trace.h"
32574854bcb2eb25a85b9b52faf2fb3e743fa7aa14Stephen Hines#else
33574854bcb2eb25a85b9b52faf2fb3e743fa7aa14Stephen Hines#define ATRACE_ENABLED(...) false
34574854bcb2eb25a85b9b52faf2fb3e743fa7aa14Stephen Hines#define ATRACE_NAME(...)
35574854bcb2eb25a85b9b52faf2fb3e743fa7aa14Stephen Hines#define ATRACE_CALL(...)
36fa85e9143c6f6a227c67bab5f08ff86194abdf2aTim Murray#endif
37fa85e9143c6f6a227c67bab5f08ff86194abdf2aTim Murray
3893eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#ifndef RS_COMPATIBILITY_LIB
39d3e0ad43dc758c409fc23d1893dab67b18520c24Alex Sakhartchouk#include "rsFont.h"
409e0afb5a2b3e476c42a373e7cd89cef4a34f8195Jason Sams#include "rsPath.h"
41326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#include "rsProgramFragment.h"
42ccc010bb7c0f89e162bf60033968a20be90a903aJason Sams#include "rsProgramStore.h"
435fd09d847586f9680b4f495413b6ca5fbb69af6eJason Sams#include "rsProgramRaster.h"
44326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#include "rsProgramVertex.h"
457d9c5ffccb7a5e682860f752403e5a03aed587beAlex Sakhartchouk#include "rsFBOCache.h"
46fa85e9143c6f6a227c67bab5f08ff86194abdf2aTim Murray
4793eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#endif
4893eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams
49326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
50326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams// ---------------------------------------------------------------------------
51326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace android {
52d4c25e3c197bc79c8508b76b20611b67ef883138Mathias Agopian
53326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace renderscript {
54326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
554edf030cbb7c6ac08dc563335c2af73c20f6e2e5Alex Sakhartchoukclass Device;
564edf030cbb7c6ac08dc563335c2af73c20f6e2e5Alex Sakhartchouk
57605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams#if 0
58605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams#define CHECK_OBJ(o) { \
59605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams    GET_TLS(); \
60afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchouk    if (!ObjectBase::isValid(rsc, (const ObjectBase *)o)) {  \
61af12ac6a08651464f8d823add667c706f993b587Steve Block        ALOGE("Bad object %p at %s, %i", o, __FILE__, __LINE__);  \
62605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams    } \
63605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams}
64605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams#define CHECK_OBJ_OR_NULL(o) { \
65605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams    GET_TLS(); \
66afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchouk    if (o && !ObjectBase::isValid(rsc, (const ObjectBase *)o)) {  \
67af12ac6a08651464f8d823add667c706f993b587Steve Block        ALOGE("Bad object %p at %s, %i", o, __FILE__, __LINE__);  \
68605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams    } \
69605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams}
70605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams#else
71605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams#define CHECK_OBJ(o)
72605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams#define CHECK_OBJ_OR_NULL(o)
73605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams#endif
74605048a9f9af925782f6c90bc1cdc5af59e337d8Jason Sams
75fa85e9143c6f6a227c67bab5f08ff86194abdf2aTim Murray
76fa85e9143c6f6a227c67bab5f08ff86194abdf2aTim Murray
77afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukclass Context {
78326e0ddf89e8df2837752fbfd7a014814b32082cJason Samspublic:
79bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams    struct Hal {
80bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        void * drv;
81bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams
82bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        RsdHalFunctions funcs;
83416f4b6d3ee6f30b747e7cd556b28d84b0226cf3Jason Sams        uint32_t flags;
84bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams    };
85bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams    Hal mHal;
86bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams
87cca3d6ca444bef3b6d75431ec19bd07bfe40a733Stephen Hines    static Context * createContext(Device *, const RsSurfaceConfig *sc,
88cca3d6ca444bef3b6d75431ec19bd07bfe40a733Stephen Hines            RsContextType ct = RS_CONTEXT_TYPE_NORMAL,
8984e3dea053bea25c1cec44ffb298f8b5b9b9141aTim Murray            uint32_t flags = 0);
90b81a0eb8180791e4eaab1253b59fa8bd562b046bAlex Sakhartchouk    static Context * createContextLite();
91326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    ~Context();
92326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
934961cceab2b71bf0ab59e1b66a7559f67ed28781Jason Sams    static pthread_mutex_t gMessageMutex;
94fb03a22ad2adadc1ff50a8b50d43ad7fcc3fa6edJason Sams    static pthread_mutex_t gInitMutex;
95ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines    // Library mutex (for providing thread-safe calls from the runtime)
96ca3f09c0924e9515901dfd47fa5f95385d53cf80Stephen Hines    static pthread_mutex_t gLibMutex;
97fb03a22ad2adadc1ff50a8b50d43ad7fcc3fa6edJason Sams
9860709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams    class PushState {
9960709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams    public:
10060709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams        PushState(Context *);
10160709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams        ~PushState();
10260709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams
10360709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams    private:
10493eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#ifndef RS_COMPATIBILITY_LIB
10560709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams        ObjectBaseRef<ProgramFragment> mFragment;
10660709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams        ObjectBaseRef<ProgramVertex> mVertex;
10760709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams        ObjectBaseRef<ProgramStore> mStore;
10860709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams        ObjectBaseRef<ProgramRaster> mRaster;
10960709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams        ObjectBaseRef<Font> mFont;
11093eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#endif
11160709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams        Context *mRsc;
11260709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams    };
11360709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams
1146b8552a4f6a44848255d77222e66aa92dd21b1b5Jason Sams    RsSurfaceConfig mUserSurfaceConfig;
115e57691037aea219562ac686429b4b98202aab7bcJason Sams
116326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    ElementState mStateElement;
117326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    TypeState mStateType;
118326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    SamplerState mStateSampler;
11993eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams
12093eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams    bool isSynchronous() {return mSynchronous;}
12193eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams    bool setupCheck();
12293eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams
12393eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#ifndef RS_COMPATIBILITY_LIB
12493eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams    FBOCache mFBOCache;
125326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    ProgramFragmentState mStateFragment;
126ccc010bb7c0f89e162bf60033968a20be90a903aJason Sams    ProgramStoreState mStateFragmentStore;
1275fd09d847586f9680b4f495413b6ca5fbb69af6eJason Sams    ProgramRasterState mStateRaster;
128326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    ProgramVertexState mStateVertex;
129d3e0ad43dc758c409fc23d1893dab67b18520c24Alex Sakhartchouk    FontState mStateFont;
130326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
1314d252d6e807b89764dad123ac845df298c52ca97Tim Murray
132326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    void swapBuffers();
133326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    void setRootScript(Script *);
13460709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams    void setProgramRaster(ProgramRaster *);
13560709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams    void setProgramVertex(ProgramVertex *);
13660709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams    void setProgramFragment(ProgramFragment *);
13760709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams    void setProgramStore(ProgramStore *);
138d3e0ad43dc758c409fc23d1893dab67b18520c24Alex Sakhartchouk    void setFont(Font *);
139326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
140326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    void updateSurface(void *sur);
141326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
14260709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams    ProgramFragment * getProgramFragment() {return mFragment.get();}
14360709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams    ProgramStore * getProgramStore() {return mFragmentStore.get();}
14460709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams    ProgramRaster * getProgramRaster() {return mRaster.get();}
14560709257bbdeb0c50f39b9c8969dc76264d6e142Jason Sams    ProgramVertex * getProgramVertex() {return mVertex.get();}
146d3e0ad43dc758c409fc23d1893dab67b18520c24Alex Sakhartchouk    Font * getFont() {return mFont.get();}
147326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
148889fe50e7aaebed8cb8284b16a0e51e64e8a3a9cAlex Sakhartchouk    void setupProgramStore();
149326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
15086f1b23aaaf9b8822a009d8c3e585e46768abb6aJason Sams    void pause();
15186f1b23aaaf9b8822a009d8c3e585e46768abb6aJason Sams    void resume();
1527257c7ee4b66f00c43d9235f3ac600061ae79968Alex Sakhartchouk    void setSurface(uint32_t w, uint32_t h, RsNativeWindow sur);
15393eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#endif
154f2748276ea84bed83728e38a6661946b5fb3bc5cJason Sams    void finish();
15593eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams
156158324456b8dbf40f684dd0a4af3493b9549f3f5Jason Sams    void setPriority(int32_t p);
157741aac95b777b2e6cb90f484a05e489a79a6ef05Jason Sams    void destroyWorkerThreadResources();
15886f1b23aaaf9b8822a009d8c3e585e46768abb6aJason Sams
159a4a54e42fc710a62b47cbcb9d64c34a190429d9eJason Sams    void assignName(ObjectBase *obj, const char *name, uint32_t len);
160a0a1b6fbece2eb8d72d788422ab3e5f58d5a9216Jason Sams    void removeName(ObjectBase *obj);
1618ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams
1621a4efa363916977ef9aeab756725b3bdc880a15bJason Sams    RsMessageToClientType peekMessageToClient(size_t *receiveLen, uint32_t *subID);
1631a4efa363916977ef9aeab756725b3bdc880a15bJason Sams    RsMessageToClientType getMessageToClient(void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen);
16487319de2b16a185cf360827c96a42cf1fcaae744Jason Sams    bool sendMessageToClient(const void *data, RsMessageToClientType cmdID, uint32_t subID, size_t len, bool waitForSpace) const;
165c61346b91434307c5003029017b54ce9c49112beJason Sams    uint32_t runScript(Script *s);
1668c401effb0837155fc39ca0364f57a882d127d38Jason Sams
1678c401effb0837155fc39ca0364f57a882d127d38Jason Sams    void initToClient();
1688c401effb0837155fc39ca0364f57a882d127d38Jason Sams    void deinitToClient();
1698c401effb0837155fc39ca0364f57a882d127d38Jason Sams
17093eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#ifndef RS_COMPATIBILITY_LIB
1718ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams    ProgramFragment * getDefaultProgramFragment() const {
1728ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams        return mStateFragment.mDefault.get();
1738ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams    }
1748ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams    ProgramVertex * getDefaultProgramVertex() const {
1758ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams        return mStateVertex.mDefault.get();
1768ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams    }
177ccc010bb7c0f89e162bf60033968a20be90a903aJason Sams    ProgramStore * getDefaultProgramStore() const {
1788ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams        return mStateFragmentStore.mDefault.get();
1798ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams    }
1805fd09d847586f9680b4f495413b6ca5fbb69af6eJason Sams    ProgramRaster * getDefaultProgramRaster() const {
1815fd09d847586f9680b4f495413b6ca5fbb69af6eJason Sams        return mStateRaster.mDefault.get();
1825fd09d847586f9680b4f495413b6ca5fbb69af6eJason Sams    }
183d3e0ad43dc758c409fc23d1893dab67b18520c24Alex Sakhartchouk    Font* getDefaultFont() const {
184d3e0ad43dc758c409fc23d1893dab67b18520c24Alex Sakhartchouk        return mStateFont.mDefault.get();
185d3e0ad43dc758c409fc23d1893dab67b18520c24Alex Sakhartchouk    }
1868ce125be69531dbf3a7e856d5e59d1b8e2789db0Jason Sams
187771565f47fc44608444c00aa8fa3bda769ceaeceJason Sams    uint32_t getWidth() const {return mWidth;}
188771565f47fc44608444c00aa8fa3bda769ceaeceJason Sams    uint32_t getHeight() const {return mHeight;}
189e579df42e85d9e00f53c42ef1b78dbd209dba989Jason Sams
190a74a8f635ce4fae0a9d4b9c79e9fa412787bf6a2Alex Sakhartchouk    uint32_t getCurrentSurfaceWidth() const;
191a74a8f635ce4fae0a9d4b9c79e9fa412787bf6a2Alex Sakhartchouk    uint32_t getCurrentSurfaceHeight() const;
192a74a8f635ce4fae0a9d4b9c79e9fa412787bf6a2Alex Sakhartchouk
19393eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams    void setWatchdogGL(const char *cmd, uint32_t line, const char *file) const {
19493eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams        watchdog.command = cmd;
19593eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams        watchdog.file = file;
19693eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams        watchdog.line = line;
19793eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams    }
19893eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#endif
19993eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams
20087319de2b16a185cf360827c96a42cf1fcaae744Jason Sams    mutable ThreadIO mIO;
201fcd3192ebff8ab58d841836b7e94361d0998338cJason Sams
20224371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams    // Timers
20324371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams    enum Timers {
20424371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams        RS_TIMER_IDLE,
20524371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams        RS_TIMER_INTERNAL,
20624371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams        RS_TIMER_SCRIPT,
20724371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams        RS_TIMER_CLEAR_SWAP,
20824371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams        _RS_TIMER_TOTAL
20924371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams    };
21024371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams    uint64_t getTime() const;
21124371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams    void timerInit();
21224371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams    void timerReset();
21324371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams    void timerSet(Timers);
21424371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams    void timerPrint();
2151d54f10f3c23e0d7ec57e52ec3b0701a2a5ed24eJason Sams    void timerFrame();
21624371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams
2171fddd90849deaae89b546ff492c345d485bbce42Jason Sams    struct {
2181fddd90849deaae89b546ff492c345d485bbce42Jason Sams        bool mLogTimes;
2191fddd90849deaae89b546ff492c345d485bbce42Jason Sams        bool mLogScripts;
2201fddd90849deaae89b546ff492c345d485bbce42Jason Sams        bool mLogObjects;
221cd50653f99c960e1a47c2c30e53b369b8805344aJason Sams        bool mLogShaders;
222886f11ade9dde05485cb11c0d67d87f76a428f6cAlex Sakhartchouk        bool mLogShadersAttr;
223886f11ade9dde05485cb11c0d67d87f76a428f6cAlex Sakhartchouk        bool mLogShadersUniforms;
2240cae59f7d8dd63d1bf0ca4abedecb4cfa3ab1921Alex Sakhartchouk        bool mLogVisual;
225d1f7da6803a1bfc0bf8129a66316cfb8994e7110Jason Sams        uint32_t mDebugMaxThreads;
2261fddd90849deaae89b546ff492c345d485bbce42Jason Sams    } props;
22776371fff76412fd020e24ddb8bf1ddb5c75f0ed1Joe Onorato
2282382aba4a55c6ae74789c478eead8fbd96593321Jason Sams    mutable struct {
2292382aba4a55c6ae74789c478eead8fbd96593321Jason Sams        bool inRoot;
2302382aba4a55c6ae74789c478eead8fbd96593321Jason Sams        const char *command;
2312382aba4a55c6ae74789c478eead8fbd96593321Jason Sams        const char *file;
2322382aba4a55c6ae74789c478eead8fbd96593321Jason Sams        uint32_t line;
2332382aba4a55c6ae74789c478eead8fbd96593321Jason Sams    } watchdog;
2342382aba4a55c6ae74789c478eead8fbd96593321Jason Sams    static void printWatchdogInfo(void *ctx);
2352382aba4a55c6ae74789c478eead8fbd96593321Jason Sams
23613e2634a71a30d289ed8d821aef61c7d1687460eJason Sams    void dumpDebug() const;
23787319de2b16a185cf360827c96a42cf1fcaae744Jason Sams    void setError(RsError e, const char *msg = NULL) const;
23813e2634a71a30d289ed8d821aef61c7d1687460eJason Sams
239e514b45de8561fbc6ef6770845102ca10b0a69d7Jason Sams    mutable const ObjectBase * mObjHead;
240e514b45de8561fbc6ef6770845102ca10b0a69d7Jason Sams
2417b3e9bd825901e33661e3c385e3e7c6f40ca6000Alex Sakhartchouk    uint32_t getDPI() const {return mDPI;}
2427b3e9bd825901e33661e3c385e3e7c6f40ca6000Alex Sakhartchouk    void setDPI(uint32_t dpi) {mDPI = dpi;}
2437bf29ddc35450d8064541c42c99a1f48be6cf0ddJason Sams
244cbb0b8aceedb9146ba901cba1fbd6d1e9ca88f51Stephen Hines    uint32_t getTargetSdkVersion() const {return mTargetSdkVersion;}
245cbb0b8aceedb9146ba901cba1fbd6d1e9ca88f51Stephen Hines    void setTargetSdkVersion(uint32_t sdkVer) {mTargetSdkVersion = sdkVer;}
246cbb0b8aceedb9146ba901cba1fbd6d1e9ca88f51Stephen Hines
247cca3d6ca444bef3b6d75431ec19bd07bfe40a733Stephen Hines    RsContextType getContextType() const { return mContextType; }
248cca3d6ca444bef3b6d75431ec19bd07bfe40a733Stephen Hines    void setContextType(RsContextType ct) { mContextType = ct; }
249cca3d6ca444bef3b6d75431ec19bd07bfe40a733Stephen Hines
250326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    Device *mDev;
2514b3de47071d875faaa7d419d050a464b09538797Jason Samsprotected:
252326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
253cbb0b8aceedb9146ba901cba1fbd6d1e9ca88f51Stephen Hines    uint32_t mTargetSdkVersion;
2547b3e9bd825901e33661e3c385e3e7c6f40ca6000Alex Sakhartchouk    uint32_t mDPI;
255613cad1702dbb76eb2a6ba0cfcb43b9fe207cebcJason Sams    uint32_t mWidth;
256613cad1702dbb76eb2a6ba0cfcb43b9fe207cebcJason Sams    uint32_t mHeight;
2572dca84dd6c07992f78ad050177975f16486dd77eJason Sams    int32_t mThreadPriority;
2584820e8bb83b1f78e6232ebe853221f737da2a1eaJason Sams    bool mIsGraphicsContext;
259613cad1702dbb76eb2a6ba0cfcb43b9fe207cebcJason Sams
2600e92fa3775b3537c29a7a0ca603d892548936038Tim Murray    bool mForceCpu;
2610e92fa3775b3537c29a7a0ca603d892548936038Tim Murray
262cca3d6ca444bef3b6d75431ec19bd07bfe40a733Stephen Hines    RsContextType mContextType;
263cca3d6ca444bef3b6d75431ec19bd07bfe40a733Stephen Hines
264326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    bool mRunning;
265326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    bool mExit;
26686f1b23aaaf9b8822a009d8c3e585e46768abb6aJason Sams    bool mPaused;
26787319de2b16a185cf360827c96a42cf1fcaae744Jason Sams    mutable RsError mError;
268326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
269326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    pthread_t mThreadId;
270158324456b8dbf40f684dd0a4af3493b9549f3f5Jason Sams    pid_t mNativeThreadId;
271326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
272326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    ObjectBaseRef<Script> mRootScript;
27393eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#ifndef RS_COMPATIBILITY_LIB
274326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    ObjectBaseRef<ProgramFragment> mFragment;
275326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    ObjectBaseRef<ProgramVertex> mVertex;
276ccc010bb7c0f89e162bf60033968a20be90a903aJason Sams    ObjectBaseRef<ProgramStore> mFragmentStore;
2775fd09d847586f9680b4f495413b6ca5fbb69af6eJason Sams    ObjectBaseRef<ProgramRaster> mRaster;
278d3e0ad43dc758c409fc23d1893dab67b18520c24Alex Sakhartchouk    ObjectBaseRef<Font> mFont;
27993eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#endif
2805086938044e0a9b6b1138f915d0d252fe046e102Jason Sams
2810cae59f7d8dd63d1bf0ca4abedecb4cfa3ab1921Alex Sakhartchouk    void displayDebugStats();
2820cae59f7d8dd63d1bf0ca4abedecb4cfa3ab1921Alex Sakhartchouk
283326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsprivate:
284326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    Context();
2855c1c79a54c63b9de8c391f7ed890c02f280ec17fJason Sams    bool initContext(Device *, const RsSurfaceConfig *sc);
286326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
2874d252d6e807b89764dad123ac845df298c52ca97Tim Murray    bool mSynchronous;
2885c1c79a54c63b9de8c391f7ed890c02f280ec17fJason Sams    bool initGLThread();
28933b6e3b91329080e5cdd0b8fdbcd3e6a906032aeJason Sams    void deinitEGL();
290326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
2912dca84dd6c07992f78ad050177975f16486dd77eJason Sams    uint32_t runRootScript();
292326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
2930c66f0795ad0b45934502820df6d718b9096edfaTim Murray    static bool loadRuntime(const char* filename, Context* rsc);
294326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    static void * threadProc(void *);
2957bf29ddc35450d8064541c42c99a1f48be6cf0ddJason Sams    static void * helperThreadProc(void *);
296326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
2977257c7ee4b66f00c43d9235f3ac600061ae79968Alex Sakhartchouk    bool mHasSurface;
298b81a0eb8180791e4eaab1253b59fa8bd562b046bAlex Sakhartchouk    bool mIsContextLite;
299a0a1b6fbece2eb8d72d788422ab3e5f58d5a9216Jason Sams
300a0a1b6fbece2eb8d72d788422ab3e5f58d5a9216Jason Sams    Vector<ObjectBase *> mNames;
30124371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams
30224371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams    uint64_t mTimers[_RS_TIMER_TOTAL];
30324371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams    Timers mTimerActive;
30424371d93cdb6999971c4058f78974da3c3d5fc64Jason Sams    uint64_t mTimeLast;
3051d54f10f3c23e0d7ec57e52ec3b0701a2a5ed24eJason Sams    uint64_t mTimeFrame;
3061d54f10f3c23e0d7ec57e52ec3b0701a2a5ed24eJason Sams    uint64_t mTimeLastFrame;
3072dca84dd6c07992f78ad050177975f16486dd77eJason Sams    uint32_t mTimeMSLastFrame;
3082dca84dd6c07992f78ad050177975f16486dd77eJason Sams    uint32_t mTimeMSLastScript;
3092dca84dd6c07992f78ad050177975f16486dd77eJason Sams    uint32_t mTimeMSLastSwap;
310c8fb69e4a3e01501a3d38a6d3ea185e583d3f493Alex Sakhartchouk    uint32_t mAverageFPSFrameCount;
311c8fb69e4a3e01501a3d38a6d3ea185e583d3f493Alex Sakhartchouk    uint64_t mAverageFPSStartTime;
312c8fb69e4a3e01501a3d38a6d3ea185e583d3f493Alex Sakhartchouk    uint32_t mAverageFPS;
313326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams};
314326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
315397b0b17fd26439eb82a76fea903952b88e5cc96Tim Murrayvoid LF_ObjDestroy_handcode(const Context *rsc, RsAsyncVoidPtr objPtr);
316397b0b17fd26439eb82a76fea903952b88e5cc96Tim Murray
31777d9f4bd05b2d2a161f30c12a2248f9c97eaac42Alex Sakhartchouk} // renderscript
31877d9f4bd05b2d2a161f30c12a2248f9c97eaac42Alex Sakhartchouk} // android
319326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#endif
320