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"
|
|
|
|
|
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-08-09 17:01:55 -07:00
|
|
|
#include "rsSimpleMesh.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"
|
2009-07-21 12:20:54 -07:00
|
|
|
#include "rsLight.h"
|
2009-05-22 14:03:28 -07:00
|
|
|
#include "rsProgramFragment.h"
|
|
|
|
#include "rsProgramFragmentStore.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"
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
namespace android {
|
2010-02-09 17:46:37 -08:00
|
|
|
|
2010-02-12 18:21:26 +08:00
|
|
|
class Surface;
|
|
|
|
|
2009-05-22 14:03:28 -07:00
|
|
|
namespace renderscript {
|
|
|
|
|
2009-08-05 13:57:03 -07:00
|
|
|
class Context
|
2009-05-22 14:03:28 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-02-09 16:05:07 -08:00
|
|
|
Context(Device *, bool isGraphics, bool useDepth);
|
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;
|
|
|
|
};
|
|
|
|
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
//StructuredAllocationContext mStateAllocation;
|
|
|
|
ElementState mStateElement;
|
|
|
|
TypeState mStateType;
|
|
|
|
SamplerState mStateSampler;
|
|
|
|
ProgramFragmentState mStateFragment;
|
|
|
|
ProgramFragmentStoreState mStateFragmentStore;
|
2009-09-23 13:57:02 -07:00
|
|
|
ProgramRasterState mStateRaster;
|
2009-05-22 14:03:28 -07:00
|
|
|
ProgramVertexState mStateVertex;
|
2009-06-22 15:49:21 -07:00
|
|
|
LightState mStateLight;
|
2009-11-25 13:22:07 -08:00
|
|
|
VertexArrayState mStateVertexArray;
|
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 *);
|
|
|
|
void setFragmentStore(ProgramFragmentStore *);
|
|
|
|
|
|
|
|
void updateSurface(void *sur);
|
|
|
|
|
|
|
|
const ProgramFragment * getFragment() {return mFragment.get();}
|
|
|
|
const ProgramFragmentStore * 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();}
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
void setupCheck();
|
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-02-12 18:21:26 +08:00
|
|
|
void setSurface(uint32_t w, uint32_t h, Surface *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);
|
|
|
|
ObjectBase * lookupName(const char *name) const;
|
2009-06-10 18:39:40 -07:00
|
|
|
void appendNameDefines(String8 *str) const;
|
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);
|
2009-12-09 11:05:45 -08:00
|
|
|
uint32_t runScript(Script *s, uint32_t launchID);
|
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();
|
|
|
|
}
|
|
|
|
ProgramFragmentStore * getDefaultProgramFragmentStore() const {
|
|
|
|
return mStateFragmentStore.mDefault.get();
|
|
|
|
}
|
2009-09-23 13:57:02 -07:00
|
|
|
ProgramRaster * getDefaultProgramRaster() const {
|
|
|
|
return mStateRaster.mDefault.get();
|
|
|
|
}
|
2009-06-17 16:52:59 -07:00
|
|
|
|
2009-08-25 11:34:49 -07:00
|
|
|
uint32_t getWidth() const {return mEGL.mWidth;}
|
|
|
|
uint32_t getHeight() const {return mEGL.mHeight;}
|
2009-08-10 14:55:26 -07:00
|
|
|
|
2009-08-17 18:35:48 -07:00
|
|
|
|
|
|
|
ThreadIO mIO;
|
2009-08-18 17:07:09 -07:00
|
|
|
void objDestroyAdd(ObjectBase *);
|
2009-08-17 18:35:48 -07:00
|
|
|
|
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-08-25 11:34:49 -07:00
|
|
|
bool checkVersion1_1() const {return (mGL.mMajorVersion > 1) || (mGL.mMinorVersion >= 1); }
|
|
|
|
bool checkVersion2_0() const {return mGL.mMajorVersion >= 2; }
|
|
|
|
|
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;
|
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;
|
2009-11-24 12:26:35 -08:00
|
|
|
|
2009-09-25 14:51:22 -07:00
|
|
|
mutable const ObjectBase * mObjHead;
|
|
|
|
|
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;
|
|
|
|
EGLint mWidth;
|
|
|
|
EGLint mHeight;
|
|
|
|
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;
|
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-08-25 11:34:49 -07:00
|
|
|
bool mUseDepth;
|
2009-09-24 17:38:20 -07:00
|
|
|
bool mPaused;
|
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
|
|
|
|
|
|
|
ObjectBaseRef<Script> mRootScript;
|
|
|
|
ObjectBaseRef<ProgramFragment> mFragment;
|
|
|
|
ObjectBaseRef<ProgramVertex> mVertex;
|
|
|
|
ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
|
2009-09-23 13:57:02 -07:00
|
|
|
ObjectBaseRef<ProgramRaster> mRaster;
|
2009-05-22 14:03:28 -07:00
|
|
|
|
2009-08-18 17:07:09 -07:00
|
|
|
|
|
|
|
struct ObjDestroyOOB {
|
|
|
|
pthread_mutex_t mMutex;
|
|
|
|
Vector<ObjectBase *> mDestroyList;
|
|
|
|
bool mNeedToEmpty;
|
|
|
|
};
|
|
|
|
ObjDestroyOOB mObjDestroy;
|
|
|
|
bool objDestroyOOBInit();
|
|
|
|
void objDestroyOOBRun();
|
|
|
|
void objDestroyOOBDestroy();
|
|
|
|
|
2009-05-22 14:03:28 -07:00
|
|
|
private:
|
|
|
|
Context();
|
|
|
|
|
2009-11-25 13:22:07 -08:00
|
|
|
void initEGL(bool useGL2);
|
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-02-12 18:21:26 +08:00
|
|
|
Surface *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;
|
2009-05-22 14:03:28 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|