Refactor with ToTargetCompatibleHandle()

Refactor statements doing host-to-target handle conversion, eg.

   uintptr_t hndlptr = (uintptr_t)hostHandle;
   unsigned int hndl = (unsigned int)hndlptr;
   assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);

into a call to ToTargetCompatibleHandle()

Change-Id: I0bcfb37f1b50679d29e7f21fe230ad433fbbef7c
This commit is contained in:
Andrew Hsieh
2012-03-22 01:27:44 +08:00
parent 8385e714a7
commit 206ea399b5
5 changed files with 33 additions and 49 deletions

View File

@@ -17,7 +17,6 @@
#include "EglOsApi.h"
#include <GLcommon/GLutils.h>
#include <utils/threads.h>
#include <assert.h>
EglDisplay::EglDisplay(EGLNativeInternalDisplayType dpy,bool isDefault) :
m_dpy(dpy),
@@ -142,11 +141,8 @@ EglConfig* EglDisplay::getConfig(EGLConfig conf) {
SurfacePtr EglDisplay::getSurface(EGLSurface surface) {
android::Mutex::Autolock mutex(m_lock);
/* surface is "key" in map<unsigned int, SurfacePtr>.
In 64-bit the upper 32-bit should be all zero. Assert for that. */
uintptr_t hndlptr = (uintptr_t)surface;
unsigned int hndl = (unsigned int)hndlptr;
assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);
/* surface is "key" in map<unsigned int, SurfacePtr>. */
unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)surface);
SurfacesHndlMap::iterator it = m_surfaces.find(hndl);
return it != m_surfaces.end() ?
(*it).second :
@@ -155,11 +151,8 @@ SurfacePtr EglDisplay::getSurface(EGLSurface surface) {
ContextPtr EglDisplay::getContext(EGLContext ctx) {
android::Mutex::Autolock mutex(m_lock);
/* ctx is "key" in map<unsigned int, ContextPtr>.
In 64-bit the upper 32-bit should be all zero. Assert for that. */
uintptr_t hndlptr = (uintptr_t)ctx;
unsigned int hndl = (unsigned int)hndlptr;
assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);
/* ctx is "key" in map<unsigned int, ContextPtr>. */
unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)ctx);
ContextsHndlMap::iterator it = m_contexts.find(hndl);
return it != m_contexts.end() ?
(*it).second :
@@ -168,11 +161,8 @@ ContextPtr EglDisplay::getContext(EGLContext ctx) {
bool EglDisplay::removeSurface(EGLSurface s) {
android::Mutex::Autolock mutex(m_lock);
/* s is "key" in map<unsigned int, SurfacePtr>.
In 64-bit the upper 32-bit should be all zero. Assert for that. */
uintptr_t hndlptr = (uintptr_t)s;
unsigned int hndl = (unsigned int)hndlptr;
assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);
/* s is "key" in map<unsigned int, SurfacePtr>. */
unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)s);
SurfacesHndlMap::iterator it = m_surfaces.find(hndl);
if(it != m_surfaces.end()) {
m_surfaces.erase(it);
@@ -200,11 +190,8 @@ bool EglDisplay::removeSurface(SurfacePtr s) {
bool EglDisplay::removeContext(EGLContext ctx) {
android::Mutex::Autolock mutex(m_lock);
/* ctx is "key" in map<unsigned int, ContextPtr>.
In 64-bit the upper 32-bit should be all zero. Assert for that. */
uintptr_t hndlptr = (uintptr_t)ctx;
unsigned int hndl = (unsigned int)hndlptr;
assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);
/* ctx is "key" in map<unsigned int, ContextPtr>. */
unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)ctx);
ContextsHndlMap::iterator it = m_contexts.find(hndl);
if(it != m_contexts.end()) {
m_contexts.erase(it);
@@ -307,22 +294,16 @@ EGLImageKHR EglDisplay::addImageKHR(ImagePtr img) {
ImagePtr EglDisplay::getImage(EGLImageKHR img) {
android::Mutex::Autolock mutex(m_lock);
/* img is "key" in map<unsigned int, ImagePtr>.
In 64-bit the upper 32-bit should be all zero. Assert for that. */
uintptr_t hndlptr = (uintptr_t)img;
unsigned int hndl = (unsigned int)hndlptr;
assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);
/* img is "key" in map<unsigned int, ImagePtr>. */
unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)img);
ImagesHndlMap::iterator i( m_eglImages.find(hndl) );
return (i != m_eglImages.end()) ? (*i).second :ImagePtr(NULL);
}
bool EglDisplay:: destroyImageKHR(EGLImageKHR img) {
android::Mutex::Autolock mutex(m_lock);
/* img is "key" in map<unsigned int, ImagePtr>.
In 64-bit the upper 32-bit should be all zero. Assert for that. */
uintptr_t hndlptr = (uintptr_t)img;
unsigned int hndl = (unsigned int)hndlptr;
assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);
/* img is "key" in map<unsigned int, ImagePtr>. */
unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)img);
ImagesHndlMap::iterator i( m_eglImages.find(hndl) );
if (i != m_eglImages.end())
{

View File

@@ -35,7 +35,6 @@
#include <GLES/glext.h>
#include <cmath>
#include <map>
#include <assert.h>
extern "C" {
@@ -1656,9 +1655,7 @@ GL_API void GL_APIENTRY glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOE
{
GET_CTX();
SET_ERROR_IF(!GLEScmValidate::textureTargetLimited(target),GL_INVALID_ENUM);
uintptr_t imagehndlptr = (uintptr_t)image;
unsigned int imagehndl = (unsigned int)imagehndlptr;
assert(sizeof(imagehndl) == sizeof(imagehndlptr) || imagehndl == imagehndlptr);
unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image);
EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
if (img) {
// Create the texture object in the underlying EGL implementation,
@@ -1694,9 +1691,7 @@ GL_API void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES(GLenum target, GL
{
GET_CTX();
SET_ERROR_IF(target != GL_RENDERBUFFER_OES,GL_INVALID_ENUM);
uintptr_t imagehndlptr = (uintptr_t)image;
unsigned int imagehndl = (unsigned int)imagehndlptr;
assert(sizeof(imagehndl) == sizeof(imagehndlptr) || imagehndl == imagehndlptr);
unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image);
EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
SET_ERROR_IF(!img,GL_INVALID_VALUE);
SET_ERROR_IF(!ctx->shareGroup().Ptr(),GL_INVALID_OPERATION);

View File

@@ -32,7 +32,6 @@
#include "ProgramData.h"
#include <GLcommon/TextureUtils.h>
#include <GLcommon/FramebufferData.h>
#include <assert.h>
extern "C" {
@@ -2009,9 +2008,7 @@ GL_APICALL void GL_APIENTRY glEGLImageTargetTexture2DOES(GLenum target, GLeglIma
{
GET_CTX();
SET_ERROR_IF(!GLESv2Validate::textureTargetLimited(target),GL_INVALID_ENUM);
uintptr_t imagehndlptr = (uintptr_t)image;
unsigned int imagehndl = (unsigned int)imagehndlptr;
assert(sizeof(imagehndl) == sizeof(imagehndlptr) || imagehndl == imagehndlptr);
unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image);
EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
if (img) {
// Create the texture object in the underlying EGL implementation,
@@ -2047,9 +2044,7 @@ GL_APICALL void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES(GLenum target
{
GET_CTX();
SET_ERROR_IF(target != GL_RENDERBUFFER_OES,GL_INVALID_ENUM);
uintptr_t imagehndlptr = (uintptr_t)image;
unsigned int imagehndl = (unsigned int)imagehndlptr;
assert(sizeof(imagehndl) == sizeof(imagehndlptr) || imagehndl == imagehndlptr);
unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image);
EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
SET_ERROR_IF(!img,GL_INVALID_VALUE);
SET_ERROR_IF(!ctx->shareGroup().Ptr(),GL_INVALID_OPERATION);

View File

@@ -23,7 +23,6 @@
#include <GLcommon/TextureUtils.h>
#include <GLcommon/FramebufferData.h>
#include <strings.h>
#include <assert.h>
//decleration
static void convertFixedDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize);
@@ -190,9 +189,7 @@ GLEScontext::~GLEScontext() {
const GLvoid* GLEScontext::setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize) {
GLuint bufferName = m_arrayBuffer;
if(bufferName) {
uintptr_t offsetptr = (uintptr_t)data;
unsigned int offset = offsetptr;
assert(sizeof(offset) == sizeof(offsetptr) || offset == offsetptr);
unsigned int offset = ToTargetCompatibleHandle((uintptr_t)data);
GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
m_map[arrType]->setBuffer(size,type,stride,vbo,bufferName,offset,normalize);
return static_cast<const unsigned char*>(vbo->getData()) + offset;

View File

@@ -16,6 +16,9 @@
#ifndef GL_UTILS_H
#define GL_UTILS_H
#include <inttypes.h>
#include <assert.h>
typedef enum{
GLES_1_1 = 1,
GLES_2_0 = 2,
@@ -32,4 +35,17 @@ void swap(T& x,T& y) {
bool isPowerOf2(int num);
inline
unsigned int ToTargetCompatibleHandle(uintptr_t hostHandle)
{
// The host and target handles can have different sizes (e.g. 32-bit
// target handle for ARM, and 64-bit host handle on x86_64).
// This function checks that the input host handle value can be
// converted into a target handle one without losing any bits.
//
unsigned int targetHandle = (unsigned int)hostHandle;
assert(sizeof(targetHandle) == sizeof(hostHandle) || targetHandle == hostHandle);
return targetHandle;
}
#endif