2009-05-22 14:03:28 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANDROID_RS_CONTEXT_H
|
|
|
|
#define ANDROID_RS_CONTEXT_H
|
|
|
|
|
2009-07-13 12:20:31 -07:00
|
|
|
#include "rsUtils.h"
|
2010-03-18 11:39:44 -07:00
|
|
|
#include "rsMutex.h"
|
2009-07-13 12:20:31 -07:00
|
|
|
|
2009-08-17 18:35:48 -07:00
|
|
|
#include "rsThreadIO.h"
|
2009-05-22 14:03:28 -07:00
|
|
|
#include "rsType.h"
|
|
|
|
#include "rsMatrix.h"
|
|
|
|
#include "rsAllocation.h"
|
2009-06-30 14:13:04 -07:00
|
|
|
#include "rsMesh.h"
|
2009-05-22 14:03:28 -07:00
|
|
|
#include "rsDevice.h"
|
|
|
|
#include "rsScriptC.h"
|
|
|
|
#include "rsAllocation.h"
|
|
|
|
#include "rsAdapter.h"
|
|
|
|
#include "rsSampler.h"
|
2010-06-24 17:15:34 -07:00
|
|
|
#include "rsFont.h"
|
2009-05-22 14:03:28 -07:00
|
|
|
#include "rsProgramFragment.h"
|
2010-05-13 18:30:11 -07:00
|
|
|
#include "rsProgramStore.h"
|
2009-09-23 13:57:02 -07:00
|
|
|
#include "rsProgramRaster.h"
|
2009-05-22 14:03:28 -07:00
|
|
|
#include "rsProgramVertex.h"
|
2009-11-25 13:22:07 -08:00
|
|
|
#include "rsShaderCache.h"
|
|
|
|
#include "rsVertexArray.h"
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
#include "rsgApiStructs.h"
|
|
|
|
#include "rsLocklessFifo.h"
|
|
|
|
|
2010-02-12 12:00:38 -08:00
|
|
|
#include <ui/egl/android_natives.h>
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
namespace android {
|
2010-02-09 17:46:37 -08:00
|
|
|
|
2009-05-22 14:03:28 -07:00
|
|
|
namespace renderscript {
|
|
|
|
|
2010-09-30 18:15:52 -07:00
|
|
|
#if 0
|
|
|
|
#define CHECK_OBJ(o) { \
|
|
|
|
GET_TLS(); \
|
|
|
|
if(!ObjectBase::isValid(rsc, (const ObjectBase *)o)) { \
|
|
|
|
LOGE("Bad object %p at %s, %i", o, __FILE__, __LINE__); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define CHECK_OBJ_OR_NULL(o) { \
|
|
|
|
GET_TLS(); \
|
|
|
|
if(o && !ObjectBase::isValid(rsc, (const ObjectBase *)o)) { \
|
|
|
|
LOGE("Bad object %p at %s, %i", o, __FILE__, __LINE__); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define CHECK_OBJ(o)
|
|
|
|
#define CHECK_OBJ_OR_NULL(o)
|
|
|
|
#endif
|
|
|
|
|
2009-08-05 13:57:03 -07:00
|
|
|
class Context
|
2009-05-22 14:03:28 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-11-03 14:27:11 -07:00
|
|
|
static Context * createContext(Device *, const RsSurfaceConfig *sc);
|
2009-05-22 14:03:28 -07:00
|
|
|
~Context();
|
|
|
|
|
2009-06-19 16:03:18 -07:00
|
|
|
static pthread_key_t gThreadTLSKey;
|
2009-10-15 16:47:31 -07:00
|
|
|
static uint32_t gThreadTLSKeyCount;
|
2009-10-27 14:44:31 -07:00
|
|
|
static uint32_t gGLContextCount;
|
2009-10-15 16:47:31 -07:00
|
|
|
static pthread_mutex_t gInitMutex;
|
|
|
|
|
2009-06-19 16:03:18 -07:00
|
|
|
struct ScriptTLSStruct {
|
|
|
|
Context * mContext;
|
|
|
|
Script * mScript;
|
|
|
|
};
|
2010-09-30 18:15:52 -07:00
|
|
|
ScriptTLSStruct *mTlsStruct;
|
2010-10-13 15:31:10 -07:00
|
|
|
RsSurfaceConfig mUserSurfaceConfig;
|
2009-06-19 16:03:18 -07:00
|
|
|
|
2010-07-19 15:38:19 -07:00
|
|
|
typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
//StructuredAllocationContext mStateAllocation;
|
|
|
|
ElementState mStateElement;
|
|
|
|
TypeState mStateType;
|
|
|
|
SamplerState mStateSampler;
|
|
|
|
ProgramFragmentState mStateFragment;
|
2010-05-13 18:30:11 -07:00
|
|
|
ProgramStoreState mStateFragmentStore;
|
2009-09-23 13:57:02 -07:00
|
|
|
ProgramRasterState mStateRaster;
|
2009-05-22 14:03:28 -07:00
|
|
|
ProgramVertexState mStateVertex;
|
2009-11-25 13:22:07 -08:00
|
|
|
VertexArrayState mStateVertexArray;
|
2010-06-24 17:15:34 -07:00
|
|
|
FontState mStateFont;
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
ScriptCState mScriptC;
|
2009-11-25 13:22:07 -08:00
|
|
|
ShaderCache mShaderCache;
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
void swapBuffers();
|
|
|
|
void setRootScript(Script *);
|
2009-09-23 13:57:02 -07:00
|
|
|
void setRaster(ProgramRaster *);
|
2009-05-22 14:03:28 -07:00
|
|
|
void setVertex(ProgramVertex *);
|
|
|
|
void setFragment(ProgramFragment *);
|
2010-05-13 18:30:11 -07:00
|
|
|
void setFragmentStore(ProgramStore *);
|
2010-06-24 17:15:34 -07:00
|
|
|
void setFont(Font *);
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
void updateSurface(void *sur);
|
|
|
|
|
|
|
|
const ProgramFragment * getFragment() {return mFragment.get();}
|
2010-05-13 18:30:11 -07:00
|
|
|
const ProgramStore * getFragmentStore() {return mFragmentStore.get();}
|
2009-09-23 13:57:02 -07:00
|
|
|
const ProgramRaster * getRaster() {return mRaster.get();}
|
2009-07-28 12:02:16 -07:00
|
|
|
const ProgramVertex * getVertex() {return mVertex.get();}
|
2010-06-24 17:15:34 -07:00
|
|
|
Font * getFont() {return mFont.get();}
|
2009-05-22 14:03:28 -07:00
|
|
|
|
2010-03-03 13:03:18 -08:00
|
|
|
bool setupCheck();
|
2010-10-01 10:54:06 -07:00
|
|
|
void setupProgramStore();
|
2009-12-14 12:57:40 -08:00
|
|
|
bool checkDriver() const {return mEGL.mSurface != 0;}
|
2009-05-22 14:03:28 -07:00
|
|
|
|
2009-09-24 17:38:20 -07:00
|
|
|
void pause();
|
|
|
|
void resume();
|
2010-06-30 13:56:17 -07:00
|
|
|
void setSurface(uint32_t w, uint32_t h, ANativeWindow *sur);
|
2009-11-15 12:14:26 -08:00
|
|
|
void setPriority(int32_t p);
|
2009-09-24 17:38:20 -07:00
|
|
|
|
2009-06-10 18:39:40 -07:00
|
|
|
void assignName(ObjectBase *obj, const char *name, uint32_t len);
|
2009-06-10 15:04:38 -07:00
|
|
|
void removeName(ObjectBase *obj);
|
2009-06-17 16:52:59 -07:00
|
|
|
|
2009-10-06 13:58:47 -07:00
|
|
|
uint32_t getMessageToClient(void *data, size_t *receiveLen, size_t bufferLen, bool wait);
|
|
|
|
bool sendMessageToClient(void *data, uint32_t cmdID, size_t len, bool waitForSpace);
|
2010-05-28 18:23:22 -07:00
|
|
|
uint32_t runScript(Script *s);
|
2009-10-06 13:58:47 -07:00
|
|
|
|
|
|
|
void initToClient();
|
|
|
|
void deinitToClient();
|
|
|
|
|
2009-06-17 16:52:59 -07:00
|
|
|
ProgramFragment * getDefaultProgramFragment() const {
|
|
|
|
return mStateFragment.mDefault.get();
|
|
|
|
}
|
|
|
|
ProgramVertex * getDefaultProgramVertex() const {
|
|
|
|
return mStateVertex.mDefault.get();
|
|
|
|
}
|
2010-05-13 18:30:11 -07:00
|
|
|
ProgramStore * getDefaultProgramStore() const {
|
2009-06-17 16:52:59 -07:00
|
|
|
return mStateFragmentStore.mDefault.get();
|
|
|
|
}
|
2009-09-23 13:57:02 -07:00
|
|
|
ProgramRaster * getDefaultProgramRaster() const {
|
|
|
|
return mStateRaster.mDefault.get();
|
|
|
|
}
|
2010-06-24 17:15:34 -07:00
|
|
|
Font* getDefaultFont() const {
|
|
|
|
return mStateFont.mDefault.get();
|
|
|
|
}
|
2009-06-17 16:52:59 -07:00
|
|
|
|
2010-05-14 15:30:29 -07:00
|
|
|
uint32_t getWidth() const {return mWidth;}
|
|
|
|
uint32_t getHeight() const {return mHeight;}
|
2009-08-10 14:55:26 -07:00
|
|
|
|
2009-08-17 18:35:48 -07:00
|
|
|
|
|
|
|
ThreadIO mIO;
|
|
|
|
|
2009-08-19 12:17:14 -07:00
|
|
|
// Timers
|
|
|
|
enum Timers {
|
|
|
|
RS_TIMER_IDLE,
|
|
|
|
RS_TIMER_INTERNAL,
|
|
|
|
RS_TIMER_SCRIPT,
|
|
|
|
RS_TIMER_CLEAR_SWAP,
|
|
|
|
_RS_TIMER_TOTAL
|
|
|
|
};
|
|
|
|
uint64_t getTime() const;
|
|
|
|
void timerInit();
|
|
|
|
void timerReset();
|
|
|
|
void timerSet(Timers);
|
|
|
|
void timerPrint();
|
2009-09-03 15:43:13 -07:00
|
|
|
void timerFrame();
|
2009-08-19 12:17:14 -07:00
|
|
|
|
2009-09-25 15:25:00 -07:00
|
|
|
struct {
|
|
|
|
bool mLogTimes;
|
|
|
|
bool mLogScripts;
|
|
|
|
bool mLogObjects;
|
2009-12-15 19:10:11 -08:00
|
|
|
bool mLogShaders;
|
2010-09-29 09:49:13 -07:00
|
|
|
bool mLogShadersAttr;
|
|
|
|
bool mLogShadersUniforms;
|
2010-08-03 12:03:16 -07:00
|
|
|
bool mLogVisual;
|
2009-09-25 15:25:00 -07:00
|
|
|
} props;
|
2009-09-23 16:37:36 -07:00
|
|
|
|
2009-11-24 12:26:35 -08:00
|
|
|
void dumpDebug() const;
|
2009-12-23 14:35:29 -08:00
|
|
|
void checkError(const char *) const;
|
2010-03-03 13:03:18 -08:00
|
|
|
const char * getError(RsError *);
|
2010-03-10 17:30:41 -08:00
|
|
|
void setError(RsError e, const char *msg = NULL);
|
2009-11-24 12:26:35 -08:00
|
|
|
|
2009-09-25 14:51:22 -07:00
|
|
|
mutable const ObjectBase * mObjHead;
|
|
|
|
|
2010-02-22 15:37:51 -08:00
|
|
|
bool ext_OES_texture_npot() const {return mGL.OES_texture_npot;}
|
2010-10-27 14:10:07 -07:00
|
|
|
bool ext_GL_NV_texture_npot_2D_mipmap() const {return mGL.GL_NV_texture_npot_2D_mipmap;}
|
2010-09-29 09:49:13 -07:00
|
|
|
float ext_texture_max_aniso() const {return mGL.EXT_texture_max_aniso; }
|
2010-09-23 16:16:33 -07:00
|
|
|
uint32_t getMaxFragmentTextures() const {return mGL.mMaxFragmentTextureImageUnits;}
|
|
|
|
uint32_t getMaxFragmentUniformVectors() const {return mGL.mMaxFragmentUniformVectors;}
|
|
|
|
uint32_t getMaxVertexUniformVectors() const {return mGL.mMaxVertexUniformVectors;}
|
2010-02-22 15:37:51 -08:00
|
|
|
|
2010-07-19 15:38:19 -07:00
|
|
|
void launchThreads(WorkerCallback_t cbk, void *data);
|
2010-09-28 14:41:22 -07:00
|
|
|
uint32_t getWorkerPoolSize() const {return (uint32_t)mWorkers.mCount;}
|
2010-07-19 15:38:19 -07:00
|
|
|
|
2009-05-22 14:03:28 -07:00
|
|
|
protected:
|
|
|
|
Device *mDev;
|
|
|
|
|
2009-08-25 11:34:49 -07:00
|
|
|
struct {
|
|
|
|
EGLint mNumConfigs;
|
|
|
|
EGLint mMajorVersion;
|
|
|
|
EGLint mMinorVersion;
|
|
|
|
EGLConfig mConfig;
|
|
|
|
EGLContext mContext;
|
|
|
|
EGLSurface mSurface;
|
2010-10-13 15:31:10 -07:00
|
|
|
EGLSurface mSurfaceDefault;
|
2009-08-25 11:34:49 -07:00
|
|
|
EGLDisplay mDisplay;
|
|
|
|
} mEGL;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
const uint8_t * mVendor;
|
|
|
|
const uint8_t * mRenderer;
|
|
|
|
const uint8_t * mVersion;
|
|
|
|
const uint8_t * mExtensions;
|
|
|
|
|
|
|
|
uint32_t mMajorVersion;
|
|
|
|
uint32_t mMinorVersion;
|
|
|
|
|
2009-12-15 12:58:36 -08:00
|
|
|
int32_t mMaxVaryingVectors;
|
|
|
|
int32_t mMaxTextureImageUnits;
|
|
|
|
|
|
|
|
int32_t mMaxFragmentTextureImageUnits;
|
|
|
|
int32_t mMaxFragmentUniformVectors;
|
|
|
|
|
|
|
|
int32_t mMaxVertexAttribs;
|
|
|
|
int32_t mMaxVertexUniformVectors;
|
|
|
|
int32_t mMaxVertexTextureUnits;
|
2010-02-22 15:37:51 -08:00
|
|
|
|
|
|
|
bool OES_texture_npot;
|
2010-10-27 14:10:07 -07:00
|
|
|
bool GL_NV_texture_npot_2D_mipmap;
|
2010-09-29 09:49:13 -07:00
|
|
|
float EXT_texture_max_aniso;
|
2009-08-25 11:34:49 -07:00
|
|
|
} mGL;
|
2009-05-22 14:03:28 -07:00
|
|
|
|
2009-11-12 15:10:25 -08:00
|
|
|
uint32_t mWidth;
|
|
|
|
uint32_t mHeight;
|
2009-12-09 11:05:45 -08:00
|
|
|
int32_t mThreadPriority;
|
2010-02-09 16:05:07 -08:00
|
|
|
bool mIsGraphicsContext;
|
2009-11-12 15:10:25 -08:00
|
|
|
|
2009-05-22 14:03:28 -07:00
|
|
|
bool mRunning;
|
|
|
|
bool mExit;
|
2009-09-24 17:38:20 -07:00
|
|
|
bool mPaused;
|
2010-03-03 13:03:18 -08:00
|
|
|
RsError mError;
|
|
|
|
const char *mErrorMsg;
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
pthread_t mThreadId;
|
2009-11-15 12:14:26 -08:00
|
|
|
pid_t mNativeThreadId;
|
2009-05-22 14:03:28 -07:00
|
|
|
|
2010-07-19 15:38:19 -07:00
|
|
|
struct Workers {
|
|
|
|
volatile int mRunningCount;
|
|
|
|
volatile int mLaunchCount;
|
|
|
|
uint32_t mCount;
|
|
|
|
pthread_t *mThreadId;
|
|
|
|
pid_t *mNativeThreadId;
|
|
|
|
Signal mCompleteSignal;
|
|
|
|
|
|
|
|
Signal *mLaunchSignals;
|
|
|
|
WorkerCallback_t mLaunchCallback;
|
|
|
|
void *mLaunchData;
|
|
|
|
};
|
|
|
|
Workers mWorkers;
|
|
|
|
|
2009-05-22 14:03:28 -07:00
|
|
|
ObjectBaseRef<Script> mRootScript;
|
|
|
|
ObjectBaseRef<ProgramFragment> mFragment;
|
|
|
|
ObjectBaseRef<ProgramVertex> mVertex;
|
2010-05-13 18:30:11 -07:00
|
|
|
ObjectBaseRef<ProgramStore> mFragmentStore;
|
2009-09-23 13:57:02 -07:00
|
|
|
ObjectBaseRef<ProgramRaster> mRaster;
|
2010-06-24 17:15:34 -07:00
|
|
|
ObjectBaseRef<Font> mFont;
|
2009-08-18 17:07:09 -07:00
|
|
|
|
2010-08-03 12:03:16 -07:00
|
|
|
void displayDebugStats();
|
|
|
|
|
2009-05-22 14:03:28 -07:00
|
|
|
private:
|
|
|
|
Context();
|
2010-11-03 14:27:11 -07:00
|
|
|
bool initContext(Device *, const RsSurfaceConfig *sc);
|
2009-05-22 14:03:28 -07:00
|
|
|
|
2010-11-03 14:27:11 -07:00
|
|
|
|
|
|
|
bool initGLThread();
|
2009-10-27 14:44:31 -07:00
|
|
|
void deinitEGL();
|
2009-05-22 14:03:28 -07:00
|
|
|
|
2009-12-09 11:05:45 -08:00
|
|
|
uint32_t runRootScript();
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
static void * threadProc(void *);
|
2010-07-19 15:38:19 -07:00
|
|
|
static void * helperThreadProc(void *);
|
2009-05-22 14:03:28 -07:00
|
|
|
|
2010-06-30 13:56:17 -07:00
|
|
|
ANativeWindow *mWndSurface;
|
2009-06-10 15:04:38 -07:00
|
|
|
|
|
|
|
Vector<ObjectBase *> mNames;
|
2009-08-19 12:17:14 -07:00
|
|
|
|
|
|
|
uint64_t mTimers[_RS_TIMER_TOTAL];
|
|
|
|
Timers mTimerActive;
|
|
|
|
uint64_t mTimeLast;
|
2009-09-03 15:43:13 -07:00
|
|
|
uint64_t mTimeFrame;
|
|
|
|
uint64_t mTimeLastFrame;
|
2009-12-09 11:05:45 -08:00
|
|
|
uint32_t mTimeMSLastFrame;
|
|
|
|
uint32_t mTimeMSLastScript;
|
|
|
|
uint32_t mTimeMSLastSwap;
|
2010-10-05 13:23:55 -07:00
|
|
|
uint32_t mAverageFPSFrameCount;
|
|
|
|
uint64_t mAverageFPSStartTime;
|
|
|
|
uint32_t mAverageFPS;
|
2009-05-22 14:03:28 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|