This is a common library for the EGL/GLES/GLES2 translator libraries.
It includes code that is shared with all three components:
ThreadInfo.h - defines a structure of information stored in the TLS.
TranslatorIfaces - defines the interface between EGL and its client APIs (GLES and GLESv2)
objectrNameManager - manages the set of OpenGL objects in share groups name space.
Change-Id: Idb1bd1e2c3dcbb5dac7ba4ea85f78da856b897d9
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
LOCAL_PATH := $(call my-dir)
|
||||||
|
|
||||||
|
### EGL host implementation ########################
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
translator_path := $(LOCAL_PATH)/..
|
||||||
|
|
||||||
|
LOCAL_SRC_FILES := \
|
||||||
|
GLutils.cpp \
|
||||||
|
objectNameManager.cpp
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL_C_INCLUDES += \
|
||||||
|
$(translator_path)/include
|
||||||
|
|
||||||
|
LOCAL_CFLAGS := -g -O0
|
||||||
|
LOCAL_MODULE_TAGS := debug
|
||||||
|
LOCAL_MODULE := libGLcommon
|
||||||
|
|
||||||
|
include $(BUILD_HOST_STATIC_LIBRARY)
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011 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.
|
||||||
|
*/
|
||||||
|
#include <GLcommon/GLutils.h>
|
||||||
|
|
||||||
|
bool isPowerOf2(int num) {
|
||||||
|
return (num & (num -1)) == 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,376 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011 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.
|
||||||
|
*/
|
||||||
|
#include <map>
|
||||||
|
#include <GLcommon/objectNameManager.h>
|
||||||
|
|
||||||
|
class GlobalNameSpace
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GlobalNameSpace()
|
||||||
|
{
|
||||||
|
mutex_init(&m_lock);
|
||||||
|
|
||||||
|
for (int i=0; i<NUM_OBJECT_TYPES; i++) {
|
||||||
|
m_nameSpace[i] = new NameSpace((NamedObjectType)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
~GlobalNameSpace()
|
||||||
|
{
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
for (int i=0; i<NUM_OBJECT_TYPES; i++) {
|
||||||
|
delete m_nameSpace[i];
|
||||||
|
}
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
mutex_destroy(&m_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int genName(NamedObjectType p_type)
|
||||||
|
{
|
||||||
|
if ( p_type >= NUM_OBJECT_TYPES ) return 0;
|
||||||
|
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
unsigned int name = m_nameSpace[p_type]->genName(0, false);
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteName(NamedObjectType p_type, unsigned int p_name)
|
||||||
|
{
|
||||||
|
if ( p_type >= NUM_OBJECT_TYPES ) return;
|
||||||
|
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
m_nameSpace[p_type]->deleteName(p_name);
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutex_t m_lock;
|
||||||
|
NameSpace *m_nameSpace[NUM_OBJECT_TYPES];
|
||||||
|
};
|
||||||
|
|
||||||
|
static GlobalNameSpace *s_globalNameSpace = NULL;
|
||||||
|
|
||||||
|
NameSpace::NameSpace(NamedObjectType p_type) :
|
||||||
|
m_nextName(0),
|
||||||
|
m_type(p_type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NameSpace::~NameSpace()
|
||||||
|
{
|
||||||
|
for (NamesMap::iterator n = m_localToGlobalMap.begin();
|
||||||
|
n != m_localToGlobalMap.end();
|
||||||
|
n++) {
|
||||||
|
s_globalNameSpace->deleteName(m_type, (*n).second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
NameSpace::genName(unsigned int p_localName, bool genGlobal)
|
||||||
|
{
|
||||||
|
|
||||||
|
unsigned int localName = p_localName;
|
||||||
|
if (localName == 0) {
|
||||||
|
do {
|
||||||
|
localName = ++m_nextName;
|
||||||
|
} while( localName == 0 || m_localToGlobalMap.find(localName) != m_localToGlobalMap.end() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (genGlobal) {
|
||||||
|
unsigned int globalName = s_globalNameSpace->genName(m_type);
|
||||||
|
m_localToGlobalMap[localName] = globalName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return localName;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
NameSpace::getGlobalName(unsigned int p_localName)
|
||||||
|
{
|
||||||
|
NamesMap::iterator n( m_localToGlobalMap.find(p_localName) );
|
||||||
|
if (n != m_localToGlobalMap.end()) {
|
||||||
|
// object found - return its global name map
|
||||||
|
return (*n).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// object does not exist;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NameSpace::deleteName(unsigned int p_localName)
|
||||||
|
{
|
||||||
|
NamesMap::iterator n( m_localToGlobalMap.find(p_localName) );
|
||||||
|
if (n != m_localToGlobalMap.end()) {
|
||||||
|
s_globalNameSpace->deleteName(m_type, (*n).second);
|
||||||
|
m_localToGlobalMap.erase(p_localName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
NameSpace::isObject(unsigned int p_localName)
|
||||||
|
{
|
||||||
|
return (m_localToGlobalMap.find(p_localName) != m_localToGlobalMap.end() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NameSpace::replaceGlobalName(unsigned int p_localName, unsigned int p_globalName)
|
||||||
|
{
|
||||||
|
NamesMap::iterator n( m_localToGlobalMap.find(p_localName) );
|
||||||
|
if (n != m_localToGlobalMap.end()) {
|
||||||
|
s_globalNameSpace->deleteName(m_type, (*n).second);
|
||||||
|
(*n).second = p_globalName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef std::pair<NamedObjectType, unsigned int> ObjectIDPair;
|
||||||
|
typedef std::map<ObjectIDPair, ObjectDataPtr> ObjectDataMap;
|
||||||
|
|
||||||
|
ShareGroup::ShareGroup()
|
||||||
|
{
|
||||||
|
mutex_init(&m_lock);
|
||||||
|
|
||||||
|
for (int i=0; i<NUM_OBJECT_TYPES; i++) {
|
||||||
|
m_nameSpace[i] = new NameSpace((NamedObjectType)i);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_objectsData = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShareGroup::~ShareGroup()
|
||||||
|
{
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
for (int t = 0; t < NUM_OBJECT_TYPES; t++) {
|
||||||
|
delete m_nameSpace[t];
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectDataMap *map = (ObjectDataMap *)m_objectsData;
|
||||||
|
if (map) delete map;
|
||||||
|
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
mutex_destroy(&m_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
ShareGroup::genName(NamedObjectType p_type, unsigned int p_localName)
|
||||||
|
{
|
||||||
|
if (p_type >= NUM_OBJECT_TYPES) return 0;
|
||||||
|
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
unsigned int localName = m_nameSpace[p_type]->genName(p_localName);
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
|
||||||
|
return localName;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
ShareGroup::getGlobalName(NamedObjectType p_type, unsigned int p_localName)
|
||||||
|
{
|
||||||
|
if (p_type >= NUM_OBJECT_TYPES) return 0;
|
||||||
|
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
unsigned int globalName = m_nameSpace[p_type]->getGlobalName(p_localName);
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
|
||||||
|
return globalName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShareGroup::deleteName(NamedObjectType p_type, unsigned int p_localName)
|
||||||
|
{
|
||||||
|
if (p_type >= NUM_OBJECT_TYPES) return;
|
||||||
|
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
m_nameSpace[p_type]->deleteName(p_localName);
|
||||||
|
ObjectDataMap *map = (ObjectDataMap *)m_objectsData;
|
||||||
|
if (map) {
|
||||||
|
map->erase( ObjectIDPair(p_type, p_localName) );
|
||||||
|
}
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ShareGroup::isObject(NamedObjectType p_type, unsigned int p_localName)
|
||||||
|
{
|
||||||
|
if (p_type >= NUM_OBJECT_TYPES) return 0;
|
||||||
|
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
bool exist = m_nameSpace[p_type]->isObject(p_localName);
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
|
||||||
|
return exist;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShareGroup::replaceGlobalName(NamedObjectType p_type, unsigned int p_localName, unsigned int p_globalName)
|
||||||
|
{
|
||||||
|
if (p_type >= NUM_OBJECT_TYPES) return;
|
||||||
|
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
m_nameSpace[p_type]->replaceGlobalName(p_localName, p_globalName);
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShareGroup::setObjectData(NamedObjectType p_type, unsigned int p_localName, ObjectDataPtr data)
|
||||||
|
{
|
||||||
|
if (p_type >= NUM_OBJECT_TYPES) return;
|
||||||
|
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
|
||||||
|
ObjectDataMap *map = (ObjectDataMap *)m_objectsData;
|
||||||
|
if (!map) {
|
||||||
|
map = new ObjectDataMap();
|
||||||
|
m_objectsData = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectIDPair id( p_type, p_localName );
|
||||||
|
map->insert( std::pair<ObjectIDPair, ObjectDataPtr>(id, data) );
|
||||||
|
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectDataPtr
|
||||||
|
ShareGroup::getObjectData(NamedObjectType p_type, unsigned int p_localName)
|
||||||
|
{
|
||||||
|
ObjectDataPtr ret;
|
||||||
|
|
||||||
|
if (p_type >= NUM_OBJECT_TYPES) return ret;
|
||||||
|
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
|
||||||
|
ObjectDataMap *map = (ObjectDataMap *)m_objectsData;
|
||||||
|
if (map) {
|
||||||
|
ObjectDataMap::iterator i = map->find( ObjectIDPair(p_type, p_localName) );
|
||||||
|
if (i != map->end()) ret = (*i).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectNameManager::ObjectNameManager()
|
||||||
|
{
|
||||||
|
mutex_init(&m_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectNameManager::~ObjectNameManager()
|
||||||
|
{
|
||||||
|
mutex_destroy(&m_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
ShareGroupPtr
|
||||||
|
ObjectNameManager::createShareGroup(void *p_groupName)
|
||||||
|
{
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
|
||||||
|
if (!s_globalNameSpace) s_globalNameSpace = new GlobalNameSpace();
|
||||||
|
|
||||||
|
ShareGroupPtr shareGroupReturn;
|
||||||
|
|
||||||
|
ShareGroupsMap::iterator s( m_groups.find(p_groupName) );
|
||||||
|
if (s != m_groups.end()) {
|
||||||
|
shareGroupReturn = (*s).second;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//
|
||||||
|
// Group does not exist, create new group
|
||||||
|
//
|
||||||
|
shareGroupReturn = ShareGroupPtr( new ShareGroup() );
|
||||||
|
m_groups.insert( std::pair<void *, ShareGroupPtr>(p_groupName, shareGroupReturn) );
|
||||||
|
}
|
||||||
|
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
|
||||||
|
return shareGroupReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShareGroupPtr
|
||||||
|
ObjectNameManager::getShareGroup(void *p_groupName)
|
||||||
|
{
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
|
||||||
|
if (!s_globalNameSpace) s_globalNameSpace = new GlobalNameSpace();
|
||||||
|
|
||||||
|
ShareGroupPtr shareGroupReturn(NULL);
|
||||||
|
|
||||||
|
ShareGroupsMap::iterator s( m_groups.find(p_groupName) );
|
||||||
|
if (s != m_groups.end()) {
|
||||||
|
shareGroupReturn = (*s).second;
|
||||||
|
}
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
|
||||||
|
return shareGroupReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShareGroupPtr
|
||||||
|
ObjectNameManager::attachShareGroup(void *p_groupName, void *p_existingGroupName)
|
||||||
|
{
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
|
||||||
|
if (!s_globalNameSpace) s_globalNameSpace = new GlobalNameSpace();
|
||||||
|
|
||||||
|
ShareGroupPtr shareGroupReturn;
|
||||||
|
|
||||||
|
ShareGroupsMap::iterator s( m_groups.find(p_existingGroupName) );
|
||||||
|
if (s == m_groups.end()) {
|
||||||
|
// ShareGroup did not found !!!
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
return ShareGroupPtr(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
shareGroupReturn = (*s).second;
|
||||||
|
|
||||||
|
if (m_groups.find(p_groupName) == m_groups.end())
|
||||||
|
{
|
||||||
|
m_groups.insert( std::pair<void *, ShareGroupPtr>(p_groupName, shareGroupReturn) );
|
||||||
|
}
|
||||||
|
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
|
||||||
|
return shareGroupReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ObjectNameManager::deleteShareGroup(void *p_groupName)
|
||||||
|
{
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
|
||||||
|
ShareGroupsMap::iterator s( m_groups.find(p_groupName) );
|
||||||
|
if (s != m_groups.end()) {
|
||||||
|
m_groups.erase(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_groups.size() == 0 && s_globalNameSpace) {
|
||||||
|
delete s_globalNameSpace;
|
||||||
|
s_globalNameSpace = NULL;
|
||||||
|
}
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ObjectNameManager::getGlobalContext()
|
||||||
|
{
|
||||||
|
void *ret = NULL;
|
||||||
|
|
||||||
|
mutex_lock(&m_lock);
|
||||||
|
if (m_groups.size() > 0) ret = (*m_groups.begin()).first;
|
||||||
|
mutex_unlock(&m_lock);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011 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 GL_UTILS_H
|
||||||
|
#define GL_UTILS_H
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void swap(T& x,T& y) {
|
||||||
|
T temp;
|
||||||
|
temp=x;
|
||||||
|
x=y;
|
||||||
|
y=temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isPowerOf2(int num);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011 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 __SMART_PTR_H
|
||||||
|
#define __SMART_PTR_H
|
||||||
|
|
||||||
|
#include <cutils/threads.h>
|
||||||
|
#include <cutils/atomic.h>
|
||||||
|
|
||||||
|
template <class T, bool threadSafe = false>
|
||||||
|
class SmartPtr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit SmartPtr(T* ptr = (T*)NULL) {
|
||||||
|
if (threadSafe) {
|
||||||
|
m_lock = new mutex_t;
|
||||||
|
mutex_init(m_lock);
|
||||||
|
}
|
||||||
|
else m_lock = NULL;
|
||||||
|
|
||||||
|
m_ptr = ptr;
|
||||||
|
if (ptr)
|
||||||
|
m_pRefCount = new int32_t(1);
|
||||||
|
else
|
||||||
|
m_pRefCount = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SmartPtr<T,threadSafe>(const SmartPtr<T,false>& rhs) {
|
||||||
|
if (threadSafe) {
|
||||||
|
m_lock = new mutex_t;
|
||||||
|
mutex_init(m_lock);
|
||||||
|
}
|
||||||
|
else m_lock = NULL;
|
||||||
|
|
||||||
|
m_pRefCount = rhs.m_pRefCount;
|
||||||
|
m_ptr = rhs.m_ptr;
|
||||||
|
use();
|
||||||
|
}
|
||||||
|
|
||||||
|
SmartPtr<T,threadSafe>(SmartPtr<T,true>& rhs) {
|
||||||
|
if (threadSafe) {
|
||||||
|
m_lock = new mutex_t;
|
||||||
|
mutex_init(m_lock);
|
||||||
|
}
|
||||||
|
else m_lock = NULL;
|
||||||
|
|
||||||
|
if (rhs.m_lock) mutex_lock(rhs.m_lock);
|
||||||
|
m_pRefCount = rhs.m_pRefCount;
|
||||||
|
m_ptr = rhs.m_ptr;
|
||||||
|
use();
|
||||||
|
if (rhs.m_lock) mutex_unlock(rhs.m_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
~SmartPtr() {
|
||||||
|
if (m_lock) mutex_lock(m_lock);
|
||||||
|
release();
|
||||||
|
if (m_lock)
|
||||||
|
{
|
||||||
|
mutex_unlock(m_lock);
|
||||||
|
mutex_destroy(m_lock);
|
||||||
|
delete m_lock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
T* Ptr() const {
|
||||||
|
return m_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const T* constPtr() const
|
||||||
|
{
|
||||||
|
return m_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
T* operator->() const {
|
||||||
|
return m_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
T& operator*() const {
|
||||||
|
return *m_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator void*() const {
|
||||||
|
return (void *)m_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This gives STL lists something to compare.
|
||||||
|
bool operator <(const SmartPtr<T>& t1) const {
|
||||||
|
return m_ptr < t1.m_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
SmartPtr<T,threadSafe>& operator=(const SmartPtr<T,false>& rhs)
|
||||||
|
{
|
||||||
|
if (m_ptr == rhs.m_ptr)
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
if (m_lock) mutex_lock(m_lock);
|
||||||
|
release();
|
||||||
|
m_pRefCount = rhs.m_pRefCount;
|
||||||
|
m_ptr = rhs.m_ptr;
|
||||||
|
use();
|
||||||
|
if (m_lock) mutex_unlock(m_lock);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
SmartPtr<T,threadSafe>& operator=(SmartPtr<T,true>& rhs)
|
||||||
|
{
|
||||||
|
if (m_ptr == rhs.m_ptr)
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
if (m_lock) mutex_lock(m_lock);
|
||||||
|
release();
|
||||||
|
if (rhs.m_lock) mutex_lock(rhs.m_lock);
|
||||||
|
m_pRefCount = rhs.m_pRefCount;
|
||||||
|
m_ptr = rhs.m_ptr;
|
||||||
|
use();
|
||||||
|
if (rhs.m_lock) mutex_unlock(rhs.m_lock);
|
||||||
|
if (m_lock) mutex_unlock(m_lock);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int32_t *m_pRefCount;
|
||||||
|
mutex_t *m_lock;
|
||||||
|
T* m_ptr;
|
||||||
|
|
||||||
|
// Increment the reference count on this pointer by 1.
|
||||||
|
int use() {
|
||||||
|
if (!m_pRefCount) return 0;
|
||||||
|
return android_atomic_inc(m_pRefCount) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decrement the reference count on the pointer by 1.
|
||||||
|
// If the reference count goes to (or below) 0, the pointer is deleted.
|
||||||
|
int release() {
|
||||||
|
if (!m_pRefCount) return 0;
|
||||||
|
|
||||||
|
int iVal = android_atomic_dec(m_pRefCount);
|
||||||
|
if (iVal > 1)
|
||||||
|
return iVal - 1;
|
||||||
|
|
||||||
|
delete m_pRefCount;
|
||||||
|
m_pRefCount = NULL;
|
||||||
|
|
||||||
|
if (m_ptr) {
|
||||||
|
delete m_ptr;
|
||||||
|
m_ptr = NULL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // of __SMART_PTR_H
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011 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 THREAD_INFO_H
|
||||||
|
#define THREAD_INFO_H
|
||||||
|
|
||||||
|
#include "objectNameManager.h"
|
||||||
|
|
||||||
|
struct ThreadInfo {
|
||||||
|
ThreadInfo():eglContext(NULL),glesContext(NULL),objManager(NULL){}
|
||||||
|
void updateInfo(void* eglctx,void* dpy,void* glesCtx,ShareGroupPtr share,ObjectNameManager* manager);
|
||||||
|
void* eglContext;
|
||||||
|
void* eglDisplay;
|
||||||
|
void* glesContext;
|
||||||
|
ShareGroupPtr shareGroup;
|
||||||
|
ObjectNameManager* objManager;
|
||||||
|
};
|
||||||
|
|
||||||
|
ThreadInfo* getThreadInfo();
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011 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 TRANSLATOR_IFACES_H
|
||||||
|
#define TRANSLATOR_IFACES_H
|
||||||
|
#include <GLcommon/ThreadInfo.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
class GLEScontext;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GLEScontext* (*createGLESContext)();
|
||||||
|
void (*initContext)(GLEScontext*);
|
||||||
|
void (*deleteGLESContext)(GLEScontext*);
|
||||||
|
void (*flush)();
|
||||||
|
void (*finish)();
|
||||||
|
}GLESiface;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ThreadInfo* (*getThreadInfo)();
|
||||||
|
}EGLiface;
|
||||||
|
|
||||||
|
typedef GLESiface* (*__translator_getGLESIfaceFunc)(EGLiface*);
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011 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 _OBJECT_NAME_MANAGER_H
|
||||||
|
#define _OBJECT_NAME_MANAGER_H
|
||||||
|
|
||||||
|
#include <cutils/threads.h>
|
||||||
|
#include <map>
|
||||||
|
#include "SmartPtr.h"
|
||||||
|
|
||||||
|
typedef std::map<unsigned int, unsigned int> NamesMap;
|
||||||
|
|
||||||
|
enum NamedObjectType {
|
||||||
|
VERTEXBUFFER = 0,
|
||||||
|
TEXTURE = 1,
|
||||||
|
RENDERBUFFER = 2,
|
||||||
|
FRAMEBUFFER = 3,
|
||||||
|
SHADER = 4,
|
||||||
|
PROGRAM = 5,
|
||||||
|
NUM_OBJECT_TYPES = 6 // Must be last
|
||||||
|
};
|
||||||
|
|
||||||
|
class ObjectData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~ObjectData() {}
|
||||||
|
};
|
||||||
|
typedef SmartPtr<ObjectData> ObjectDataPtr;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Class NameSpace - this class manages allocations and deletions of objects
|
||||||
|
// from a single "local" namespace (private to context group).
|
||||||
|
// For each allocated object name, a "global" name is
|
||||||
|
// generated as well to be used in the space where all
|
||||||
|
// contexts are shared.
|
||||||
|
//
|
||||||
|
// NOTE: this class does not used by the EGL/GLES layer directly,
|
||||||
|
// the EGL/GLES layer creates objects using the ShareGroup class
|
||||||
|
// interface (see below).
|
||||||
|
class NameSpace
|
||||||
|
{
|
||||||
|
friend class ShareGroup;
|
||||||
|
friend class GlobalNameSpace;
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit NameSpace(NamedObjectType p_type);
|
||||||
|
~NameSpace();
|
||||||
|
|
||||||
|
//
|
||||||
|
// genName - creates new object in the namespace and returns its name.
|
||||||
|
// if p_localName is specified this name will be used.
|
||||||
|
// This function also generate a global name for the object,
|
||||||
|
// the value of the global name can be retrieved using the
|
||||||
|
// getGlobalName function.
|
||||||
|
//
|
||||||
|
unsigned int genName(unsigned int p_localName = 0, bool genGlobal = true);
|
||||||
|
|
||||||
|
//
|
||||||
|
// getGlobalName - returns the global name of an object or 0 if the object
|
||||||
|
// does not exist.
|
||||||
|
//
|
||||||
|
unsigned int getGlobalName(unsigned int p_localName);
|
||||||
|
|
||||||
|
//
|
||||||
|
// deleteName - deletes and object from the namespace as well as its
|
||||||
|
// global name from the global name space.
|
||||||
|
//
|
||||||
|
void deleteName(unsigned int p_localName);
|
||||||
|
|
||||||
|
//
|
||||||
|
// isObject - returns true if the named object exist.
|
||||||
|
//
|
||||||
|
bool isObject(unsigned int p_localName);
|
||||||
|
|
||||||
|
//
|
||||||
|
// replaces an object to map to an existing global object
|
||||||
|
//
|
||||||
|
void replaceGlobalName(unsigned int p_localName, unsigned int p_globalName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned int m_nextName;
|
||||||
|
NamesMap m_localToGlobalMap;
|
||||||
|
const NamedObjectType m_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// class ShareGroup -
|
||||||
|
// That class manages objects of one "local" context share group, typically
|
||||||
|
// there will be one inctance of ShareGroup for each user OpenGL context
|
||||||
|
// unless the user context share with another user context. In that case they
|
||||||
|
// both will share the same ShareGroup instance.
|
||||||
|
// calls into that class gets serialized through a lock so it is thread safe.
|
||||||
|
//
|
||||||
|
class ShareGroup
|
||||||
|
{
|
||||||
|
friend class ObjectNameManager;
|
||||||
|
friend class SmartPtr<ShareGroup>; // to allow destructing when ShareGroupPtr refcount reaches zero
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//
|
||||||
|
// genName - generates new object name and returns its name value.
|
||||||
|
// if p_localName is specified this name will be used.
|
||||||
|
// This function also generates a "global" name for the object
|
||||||
|
// which can be queried using the getGlobalName function.
|
||||||
|
//
|
||||||
|
unsigned int genName(NamedObjectType p_type, unsigned int p_localName = 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// getGlobalName - retrieves the "global" name of an object or 0 if the
|
||||||
|
// object does not exist.
|
||||||
|
//
|
||||||
|
unsigned int getGlobalName(NamedObjectType p_type, unsigned int p_localName);
|
||||||
|
|
||||||
|
//
|
||||||
|
// deleteName - deletes and object from the namespace as well as its
|
||||||
|
// global name from the global name space.
|
||||||
|
//
|
||||||
|
void deleteName(NamedObjectType p_type, unsigned int p_localName);
|
||||||
|
|
||||||
|
//
|
||||||
|
// replaceGlobalName - replaces an object to map to an existing global
|
||||||
|
// named object. (used when creating EGLImage siblings)
|
||||||
|
//
|
||||||
|
void replaceGlobalName(NamedObjectType p_type, unsigned int p_localName, unsigned int p_globalName);
|
||||||
|
|
||||||
|
//
|
||||||
|
// isObject - returns true if the named object exist.
|
||||||
|
//
|
||||||
|
bool isObject(NamedObjectType p_type, unsigned int p_localName);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assign object global data to a names object
|
||||||
|
//
|
||||||
|
void setObjectData(NamedObjectType p_type, unsigned int p_localName, ObjectDataPtr data);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve object global data
|
||||||
|
//
|
||||||
|
ObjectDataPtr getObjectData(NamedObjectType p_type, unsigned int p_localName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ShareGroup();
|
||||||
|
~ShareGroup();
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutex_t m_lock;
|
||||||
|
NameSpace *m_nameSpace[NUM_OBJECT_TYPES];
|
||||||
|
void *m_objectsData;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef SmartPtr<ShareGroup> ShareGroupPtr;
|
||||||
|
typedef std::multimap<void *, ShareGroupPtr> ShareGroupsMap;
|
||||||
|
|
||||||
|
//
|
||||||
|
// ObjectNameManager -
|
||||||
|
// This class manages the set of all ShareGroups instances,
|
||||||
|
// each ShareGroup instance can be accessed through one or more 'groupName'
|
||||||
|
// values. the type of 'groupName' is void *, the intent is that the EGL
|
||||||
|
// layer will use the user context handle as the name for its ShareGroup
|
||||||
|
// object. Multiple names can be attached to a ShareGroup object to support
|
||||||
|
// user context sharing.
|
||||||
|
//
|
||||||
|
class ObjectNameManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ObjectNameManager();
|
||||||
|
~ObjectNameManager();
|
||||||
|
|
||||||
|
//
|
||||||
|
// createShareGroup - create a new ShareGroup object and attach it with
|
||||||
|
// the "name" specified by p_groupName.
|
||||||
|
//
|
||||||
|
ShareGroupPtr createShareGroup(void *p_groupName);
|
||||||
|
|
||||||
|
//
|
||||||
|
// attachShareGroup - find the ShareGroup object attached to the name
|
||||||
|
// specified in p_existingGroupName and attach p_groupName to the same
|
||||||
|
// ShareGroup instance.
|
||||||
|
//
|
||||||
|
ShareGroupPtr attachShareGroup(void *p_groupName, void *p_existingGroupName);
|
||||||
|
|
||||||
|
//
|
||||||
|
// getShareGroup - retreive a ShareGroup object based on its "name"
|
||||||
|
//
|
||||||
|
ShareGroupPtr getShareGroup(void *p_groupName);
|
||||||
|
|
||||||
|
//
|
||||||
|
// deleteShareGroup - deletes the attachment of the p_groupName to its
|
||||||
|
// attached ShareGroup. When the last name of ShareGroup is
|
||||||
|
// deleted the ShareGroup object is destroyed.
|
||||||
|
//
|
||||||
|
void deleteShareGroup(void *p_groupName);
|
||||||
|
|
||||||
|
//
|
||||||
|
// getGlobalContext() - this function returns a name of an existing
|
||||||
|
// ShareGroup. The intent is that the EGL layer will
|
||||||
|
// use that function to get the GL context which each
|
||||||
|
// new context needs to share with.
|
||||||
|
//
|
||||||
|
void *getGlobalContext();
|
||||||
|
|
||||||
|
private:
|
||||||
|
ShareGroupsMap m_groups;
|
||||||
|
mutex_t m_lock;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user