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:
@@ -17,7 +17,6 @@
|
|||||||
#include "EglOsApi.h"
|
#include "EglOsApi.h"
|
||||||
#include <GLcommon/GLutils.h>
|
#include <GLcommon/GLutils.h>
|
||||||
#include <utils/threads.h>
|
#include <utils/threads.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
EglDisplay::EglDisplay(EGLNativeInternalDisplayType dpy,bool isDefault) :
|
EglDisplay::EglDisplay(EGLNativeInternalDisplayType dpy,bool isDefault) :
|
||||||
m_dpy(dpy),
|
m_dpy(dpy),
|
||||||
@@ -142,11 +141,8 @@ EglConfig* EglDisplay::getConfig(EGLConfig conf) {
|
|||||||
|
|
||||||
SurfacePtr EglDisplay::getSurface(EGLSurface surface) {
|
SurfacePtr EglDisplay::getSurface(EGLSurface surface) {
|
||||||
android::Mutex::Autolock mutex(m_lock);
|
android::Mutex::Autolock mutex(m_lock);
|
||||||
/* surface is "key" in map<unsigned int, SurfacePtr>.
|
/* surface is "key" in map<unsigned int, SurfacePtr>. */
|
||||||
In 64-bit the upper 32-bit should be all zero. Assert for that. */
|
unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)surface);
|
||||||
uintptr_t hndlptr = (uintptr_t)surface;
|
|
||||||
unsigned int hndl = (unsigned int)hndlptr;
|
|
||||||
assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);
|
|
||||||
SurfacesHndlMap::iterator it = m_surfaces.find(hndl);
|
SurfacesHndlMap::iterator it = m_surfaces.find(hndl);
|
||||||
return it != m_surfaces.end() ?
|
return it != m_surfaces.end() ?
|
||||||
(*it).second :
|
(*it).second :
|
||||||
@@ -155,11 +151,8 @@ SurfacePtr EglDisplay::getSurface(EGLSurface surface) {
|
|||||||
|
|
||||||
ContextPtr EglDisplay::getContext(EGLContext ctx) {
|
ContextPtr EglDisplay::getContext(EGLContext ctx) {
|
||||||
android::Mutex::Autolock mutex(m_lock);
|
android::Mutex::Autolock mutex(m_lock);
|
||||||
/* ctx is "key" in map<unsigned int, ContextPtr>.
|
/* ctx is "key" in map<unsigned int, ContextPtr>. */
|
||||||
In 64-bit the upper 32-bit should be all zero. Assert for that. */
|
unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)ctx);
|
||||||
uintptr_t hndlptr = (uintptr_t)ctx;
|
|
||||||
unsigned int hndl = (unsigned int)hndlptr;
|
|
||||||
assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);
|
|
||||||
ContextsHndlMap::iterator it = m_contexts.find(hndl);
|
ContextsHndlMap::iterator it = m_contexts.find(hndl);
|
||||||
return it != m_contexts.end() ?
|
return it != m_contexts.end() ?
|
||||||
(*it).second :
|
(*it).second :
|
||||||
@@ -168,11 +161,8 @@ ContextPtr EglDisplay::getContext(EGLContext ctx) {
|
|||||||
|
|
||||||
bool EglDisplay::removeSurface(EGLSurface s) {
|
bool EglDisplay::removeSurface(EGLSurface s) {
|
||||||
android::Mutex::Autolock mutex(m_lock);
|
android::Mutex::Autolock mutex(m_lock);
|
||||||
/* s is "key" in map<unsigned int, SurfacePtr>.
|
/* s is "key" in map<unsigned int, SurfacePtr>. */
|
||||||
In 64-bit the upper 32-bit should be all zero. Assert for that. */
|
unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)s);
|
||||||
uintptr_t hndlptr = (uintptr_t)s;
|
|
||||||
unsigned int hndl = (unsigned int)hndlptr;
|
|
||||||
assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);
|
|
||||||
SurfacesHndlMap::iterator it = m_surfaces.find(hndl);
|
SurfacesHndlMap::iterator it = m_surfaces.find(hndl);
|
||||||
if(it != m_surfaces.end()) {
|
if(it != m_surfaces.end()) {
|
||||||
m_surfaces.erase(it);
|
m_surfaces.erase(it);
|
||||||
@@ -200,11 +190,8 @@ bool EglDisplay::removeSurface(SurfacePtr s) {
|
|||||||
|
|
||||||
bool EglDisplay::removeContext(EGLContext ctx) {
|
bool EglDisplay::removeContext(EGLContext ctx) {
|
||||||
android::Mutex::Autolock mutex(m_lock);
|
android::Mutex::Autolock mutex(m_lock);
|
||||||
/* ctx is "key" in map<unsigned int, ContextPtr>.
|
/* ctx is "key" in map<unsigned int, ContextPtr>. */
|
||||||
In 64-bit the upper 32-bit should be all zero. Assert for that. */
|
unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)ctx);
|
||||||
uintptr_t hndlptr = (uintptr_t)ctx;
|
|
||||||
unsigned int hndl = (unsigned int)hndlptr;
|
|
||||||
assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);
|
|
||||||
ContextsHndlMap::iterator it = m_contexts.find(hndl);
|
ContextsHndlMap::iterator it = m_contexts.find(hndl);
|
||||||
if(it != m_contexts.end()) {
|
if(it != m_contexts.end()) {
|
||||||
m_contexts.erase(it);
|
m_contexts.erase(it);
|
||||||
@@ -307,22 +294,16 @@ EGLImageKHR EglDisplay::addImageKHR(ImagePtr img) {
|
|||||||
|
|
||||||
ImagePtr EglDisplay::getImage(EGLImageKHR img) {
|
ImagePtr EglDisplay::getImage(EGLImageKHR img) {
|
||||||
android::Mutex::Autolock mutex(m_lock);
|
android::Mutex::Autolock mutex(m_lock);
|
||||||
/* img is "key" in map<unsigned int, ImagePtr>.
|
/* img is "key" in map<unsigned int, ImagePtr>. */
|
||||||
In 64-bit the upper 32-bit should be all zero. Assert for that. */
|
unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)img);
|
||||||
uintptr_t hndlptr = (uintptr_t)img;
|
|
||||||
unsigned int hndl = (unsigned int)hndlptr;
|
|
||||||
assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);
|
|
||||||
ImagesHndlMap::iterator i( m_eglImages.find(hndl) );
|
ImagesHndlMap::iterator i( m_eglImages.find(hndl) );
|
||||||
return (i != m_eglImages.end()) ? (*i).second :ImagePtr(NULL);
|
return (i != m_eglImages.end()) ? (*i).second :ImagePtr(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EglDisplay:: destroyImageKHR(EGLImageKHR img) {
|
bool EglDisplay:: destroyImageKHR(EGLImageKHR img) {
|
||||||
android::Mutex::Autolock mutex(m_lock);
|
android::Mutex::Autolock mutex(m_lock);
|
||||||
/* img is "key" in map<unsigned int, ImagePtr>.
|
/* img is "key" in map<unsigned int, ImagePtr>. */
|
||||||
In 64-bit the upper 32-bit should be all zero. Assert for that. */
|
unsigned int hndl = ToTargetCompatibleHandle((uintptr_t)img);
|
||||||
uintptr_t hndlptr = (uintptr_t)img;
|
|
||||||
unsigned int hndl = (unsigned int)hndlptr;
|
|
||||||
assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr);
|
|
||||||
ImagesHndlMap::iterator i( m_eglImages.find(hndl) );
|
ImagesHndlMap::iterator i( m_eglImages.find(hndl) );
|
||||||
if (i != m_eglImages.end())
|
if (i != m_eglImages.end())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <GLES/glext.h>
|
#include <GLES/glext.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
@@ -1656,9 +1655,7 @@ GL_API void GL_APIENTRY glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOE
|
|||||||
{
|
{
|
||||||
GET_CTX();
|
GET_CTX();
|
||||||
SET_ERROR_IF(!GLEScmValidate::textureTargetLimited(target),GL_INVALID_ENUM);
|
SET_ERROR_IF(!GLEScmValidate::textureTargetLimited(target),GL_INVALID_ENUM);
|
||||||
uintptr_t imagehndlptr = (uintptr_t)image;
|
unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image);
|
||||||
unsigned int imagehndl = (unsigned int)imagehndlptr;
|
|
||||||
assert(sizeof(imagehndl) == sizeof(imagehndlptr) || imagehndl == imagehndlptr);
|
|
||||||
EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
|
EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
|
||||||
if (img) {
|
if (img) {
|
||||||
// Create the texture object in the underlying EGL implementation,
|
// Create the texture object in the underlying EGL implementation,
|
||||||
@@ -1694,9 +1691,7 @@ GL_API void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES(GLenum target, GL
|
|||||||
{
|
{
|
||||||
GET_CTX();
|
GET_CTX();
|
||||||
SET_ERROR_IF(target != GL_RENDERBUFFER_OES,GL_INVALID_ENUM);
|
SET_ERROR_IF(target != GL_RENDERBUFFER_OES,GL_INVALID_ENUM);
|
||||||
uintptr_t imagehndlptr = (uintptr_t)image;
|
unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image);
|
||||||
unsigned int imagehndl = (unsigned int)imagehndlptr;
|
|
||||||
assert(sizeof(imagehndl) == sizeof(imagehndlptr) || imagehndl == imagehndlptr);
|
|
||||||
EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
|
EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
|
||||||
SET_ERROR_IF(!img,GL_INVALID_VALUE);
|
SET_ERROR_IF(!img,GL_INVALID_VALUE);
|
||||||
SET_ERROR_IF(!ctx->shareGroup().Ptr(),GL_INVALID_OPERATION);
|
SET_ERROR_IF(!ctx->shareGroup().Ptr(),GL_INVALID_OPERATION);
|
||||||
|
|||||||
@@ -32,7 +32,6 @@
|
|||||||
#include "ProgramData.h"
|
#include "ProgramData.h"
|
||||||
#include <GLcommon/TextureUtils.h>
|
#include <GLcommon/TextureUtils.h>
|
||||||
#include <GLcommon/FramebufferData.h>
|
#include <GLcommon/FramebufferData.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
@@ -2009,9 +2008,7 @@ GL_APICALL void GL_APIENTRY glEGLImageTargetTexture2DOES(GLenum target, GLeglIma
|
|||||||
{
|
{
|
||||||
GET_CTX();
|
GET_CTX();
|
||||||
SET_ERROR_IF(!GLESv2Validate::textureTargetLimited(target),GL_INVALID_ENUM);
|
SET_ERROR_IF(!GLESv2Validate::textureTargetLimited(target),GL_INVALID_ENUM);
|
||||||
uintptr_t imagehndlptr = (uintptr_t)image;
|
unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image);
|
||||||
unsigned int imagehndl = (unsigned int)imagehndlptr;
|
|
||||||
assert(sizeof(imagehndl) == sizeof(imagehndlptr) || imagehndl == imagehndlptr);
|
|
||||||
EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
|
EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
|
||||||
if (img) {
|
if (img) {
|
||||||
// Create the texture object in the underlying EGL implementation,
|
// Create the texture object in the underlying EGL implementation,
|
||||||
@@ -2047,9 +2044,7 @@ GL_APICALL void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES(GLenum target
|
|||||||
{
|
{
|
||||||
GET_CTX();
|
GET_CTX();
|
||||||
SET_ERROR_IF(target != GL_RENDERBUFFER_OES,GL_INVALID_ENUM);
|
SET_ERROR_IF(target != GL_RENDERBUFFER_OES,GL_INVALID_ENUM);
|
||||||
uintptr_t imagehndlptr = (uintptr_t)image;
|
unsigned int imagehndl = ToTargetCompatibleHandle((uintptr_t)image);
|
||||||
unsigned int imagehndl = (unsigned int)imagehndlptr;
|
|
||||||
assert(sizeof(imagehndl) == sizeof(imagehndlptr) || imagehndl == imagehndlptr);
|
|
||||||
EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
|
EglImage *img = s_eglIface->eglAttachEGLImage(imagehndl);
|
||||||
SET_ERROR_IF(!img,GL_INVALID_VALUE);
|
SET_ERROR_IF(!img,GL_INVALID_VALUE);
|
||||||
SET_ERROR_IF(!ctx->shareGroup().Ptr(),GL_INVALID_OPERATION);
|
SET_ERROR_IF(!ctx->shareGroup().Ptr(),GL_INVALID_OPERATION);
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
#include <GLcommon/TextureUtils.h>
|
#include <GLcommon/TextureUtils.h>
|
||||||
#include <GLcommon/FramebufferData.h>
|
#include <GLcommon/FramebufferData.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
//decleration
|
//decleration
|
||||||
static void convertFixedDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize);
|
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) {
|
const GLvoid* GLEScontext::setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize) {
|
||||||
GLuint bufferName = m_arrayBuffer;
|
GLuint bufferName = m_arrayBuffer;
|
||||||
if(bufferName) {
|
if(bufferName) {
|
||||||
uintptr_t offsetptr = (uintptr_t)data;
|
unsigned int offset = ToTargetCompatibleHandle((uintptr_t)data);
|
||||||
unsigned int offset = offsetptr;
|
|
||||||
assert(sizeof(offset) == sizeof(offsetptr) || offset == offsetptr);
|
|
||||||
GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
|
GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
|
||||||
m_map[arrType]->setBuffer(size,type,stride,vbo,bufferName,offset,normalize);
|
m_map[arrType]->setBuffer(size,type,stride,vbo,bufferName,offset,normalize);
|
||||||
return static_cast<const unsigned char*>(vbo->getData()) + offset;
|
return static_cast<const unsigned char*>(vbo->getData()) + offset;
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
#ifndef GL_UTILS_H
|
#ifndef GL_UTILS_H
|
||||||
#define GL_UTILS_H
|
#define GL_UTILS_H
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
typedef enum{
|
typedef enum{
|
||||||
GLES_1_1 = 1,
|
GLES_1_1 = 1,
|
||||||
GLES_2_0 = 2,
|
GLES_2_0 = 2,
|
||||||
@@ -32,4 +35,17 @@ void swap(T& x,T& y) {
|
|||||||
|
|
||||||
bool isPowerOf2(int num);
|
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
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user