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-05-22 14:03:28 -07:00
|
|
|
#include <ui/Surface.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"
|
|
|
|
#include "rsTriangleMesh.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"
|
|
|
|
#include "rsProgramVertex.h"
|
|
|
|
|
|
|
|
#include "rsgApiStructs.h"
|
|
|
|
#include "rsLocklessFifo.h"
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
namespace android {
|
|
|
|
namespace renderscript {
|
|
|
|
|
2009-08-05 13:57:03 -07:00
|
|
|
class Context
|
2009-05-22 14:03:28 -07:00
|
|
|
{
|
|
|
|
public:
|
2009-08-25 11:34:49 -07:00
|
|
|
Context(Device *, Surface *, bool useDepth);
|
2009-05-22 14:03:28 -07:00
|
|
|
~Context();
|
|
|
|
|
2009-06-19 16:03:18 -07:00
|
|
|
static pthread_key_t gThreadTLSKey;
|
|
|
|
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;
|
|
|
|
ProgramVertexState mStateVertex;
|
2009-06-22 15:49:21 -07:00
|
|
|
LightState mStateLight;
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
TriangleMeshContext mStateTriangleMesh;
|
|
|
|
|
|
|
|
ScriptCState mScriptC;
|
|
|
|
|
|
|
|
void swapBuffers();
|
|
|
|
void setRootScript(Script *);
|
|
|
|
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-07-28 12:02:16 -07:00
|
|
|
const ProgramVertex * getVertex() {return mVertex.get();}
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
void setupCheck();
|
2009-08-05 13:57:03 -07:00
|
|
|
void allocationCheck(const Allocation *);
|
2009-05-22 14:03:28 -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-08-09 22:57:44 -07:00
|
|
|
void appendVarDefines(String8 *str) const;
|
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-08-09 22:57:44 -07:00
|
|
|
void addInt32Define(const char* name, int32_t value) {
|
|
|
|
mInt32Defines.add(String8(name), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addFloatDefine(const char* name, float value) {
|
|
|
|
mFloatDefines.add(String8(name), value);
|
|
|
|
}
|
|
|
|
|
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-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-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;
|
|
|
|
|
|
|
|
} mGL;
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
bool mRunning;
|
|
|
|
bool mExit;
|
2009-08-25 11:34:49 -07:00
|
|
|
bool mUseDepth;
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
pthread_t mThreadId;
|
|
|
|
|
|
|
|
ObjectBaseRef<Script> mRootScript;
|
|
|
|
ObjectBaseRef<ProgramFragment> mFragment;
|
|
|
|
ObjectBaseRef<ProgramVertex> mVertex;
|
|
|
|
ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
void initEGL();
|
|
|
|
|
2009-06-10 15:04:38 -07:00
|
|
|
bool runScript(Script *s, uint32_t launchID);
|
2009-06-04 17:58:03 -07:00
|
|
|
bool runRootScript();
|
2009-05-22 14:03:28 -07:00
|
|
|
|
|
|
|
static void * threadProc(void *);
|
|
|
|
|
|
|
|
Surface *mWndSurface;
|
2009-06-10 15:04:38 -07:00
|
|
|
|
|
|
|
Vector<ObjectBase *> mNames;
|
2009-08-09 22:57:44 -07:00
|
|
|
KeyedVector<String8,int> mInt32Defines;
|
|
|
|
KeyedVector<String8,float> mFloatDefines;
|
2009-08-19 12:17:14 -07:00
|
|
|
|
|
|
|
uint64_t mTimers[_RS_TIMER_TOTAL];
|
|
|
|
Timers mTimerActive;
|
|
|
|
uint64_t mTimeLast;
|
2009-05-22 14:03:28 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|