diff -r e70851cd9e5e -r a3f46bb01be2 holdingarea/libGLESv1/src/EGLInterface.cpp --- a/holdingarea/libGLESv1/src/EGLInterface.cpp Thu Sep 16 12:43:44 2010 +0100 +++ b/holdingarea/libGLESv1/src/EGLInterface.cpp Mon Sep 20 14:29:05 2010 +0100 @@ -1,148 +1,148 @@ -/* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and /or associated documentation files - * (the "Materials "), to deal in the Materials without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Materials, - * and to permit persons to whom the Materials are furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR - * THE USE OR OTHER DEALINGS IN THE MATERIALS. - * - * Initial Contributors: - * Nokia Corporation - initial contribution. - * - * Contributors: - * - * Description: - * - */ - -#include "EGLInterface.h" -#include -#include "glesInternal.h" -#include "GLESContext.h" -#include "SurfaceDescriptor.h" -#include "GLESTexture.h" - -#include -#include - -namespace -{ -EGLtoGLESInterface g_EGLtoGLESInterface; -} - -GLES_API_CALL IEGLtoGLESInterface* getGLESInterface(void) -{ - return &g_EGLtoGLESInterface; -} - -void glesReleaseTexImage(void* surface, int name, int level) -{ - EGLtoGLESInterface::GetEGLInterface()->ReleaseTexImage(surface, name, level); -} - -EGLtoGLESInterface::EGLtoGLESInterface() : - m_egl(NULL) -{ -} - -void EGLtoGLESInterface::SetEGLInterface( IGLEStoEGLInterface* egl ) -{ - m_egl = egl; -} - -void* EGLtoGLESInterface::CreateContext(void* nativeContext) -{ - GLESContext* newContext = NULL; - - newContext = GLES_NEW GLESContext(nativeContext); - if(newContext == NULL) - { - return NULL; - } - m_contexts.insert(newContext); - return newContext; -} - -bool EGLtoGLESInterface::ReleaseContext(void* context) -{ - GLES_ASSERT(context != NULL); - - GLESContext* ctx = static_cast(context); - if(m_contexts.find(ctx) == m_contexts.end()) - { - return false; - } - - delete ctx; - m_contexts.erase(ctx); - - return true; -} - -void* EGLtoGLESInterface::GetNativeContext(void* context) -{ - GLES_ASSERT(context != NULL); - - GLESContext* ctx = static_cast(context); - if(m_contexts.find(ctx) == m_contexts.end()) - { - return false; - } - - return ctx->NativeContext(); -} - -fpGLProc EGLtoGLESInterface::GetGLProcAddress( const char *procname ) -{ - if(strcmp(procname, "glPointSizePointerOES") == 0) - { - return (fpGLProc)glPointSizePointerOES; - } - else - { - return NULL; - } -} - -static SurfaceDescriptor createSurfaceDescriptor(int redBits, int redShift, int greenBits, int greenShift, int blueBits, int blueShift, int alphaBits, int alphaShift, int luminanceBits, int luminanceShift, CColorDescriptor::ColorFormat format, int bpp) -{ - SurfaceDescriptor desc; - desc.m_colorDescriptor.m_redSize = redBits; - desc.m_colorDescriptor.m_greenSize = greenBits; - desc.m_colorDescriptor.m_blueSize = blueBits; - desc.m_colorDescriptor.m_alphaSize = alphaBits; - desc.m_colorDescriptor.m_luminanceSize = luminanceBits; - desc.m_redShift = redShift; - desc.m_greenShift = greenShift; - desc.m_blueShift = blueShift; - desc.m_alphaShift = alphaShift; - desc.m_luminanceShift = luminanceShift; - desc.m_colorDescriptor.m_format = format; - desc.m_colorDescriptor.m_bpp = bpp; - return desc; -} - +/* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and /or associated documentation files + * (the "Materials "), to deal in the Materials without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Materials, + * and to permit persons to whom the Materials are furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR + * THE USE OR OTHER DEALINGS IN THE MATERIALS. + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + +#include "EGLInterface.h" +#include +#include "glesInternal.h" +#include "GLESContext.h" +#include "SurfaceDescriptor.h" +#include "GLESTexture.h" + +#include +#include + +namespace +{ +EGLtoGLESInterface g_EGLtoGLESInterface; +} + +GLES_API_CALL IEGLtoGLESInterface* getGLESInterface(void) +{ + return &g_EGLtoGLESInterface; +} + +void glesReleaseTexImage(void* surface, int name, int level) +{ + EGLtoGLESInterface::GetEGLInterface()->ReleaseTexImage(surface, name, level); +} + +EGLtoGLESInterface::EGLtoGLESInterface() : + m_egl(NULL) +{ +} + +void EGLtoGLESInterface::SetEGLInterface( IGLEStoEGLInterface* egl ) +{ + m_egl = egl; +} + +void* EGLtoGLESInterface::CreateContext(void* nativeContext) +{ + GLESContext* newContext = NULL; + + newContext = GLES_NEW GLESContext(nativeContext); + if(newContext == NULL) + { + return NULL; + } + m_contexts.insert(newContext); + return newContext; +} + +bool EGLtoGLESInterface::ReleaseContext(void* context) +{ + GLES_ASSERT(context != NULL); + + GLESContext* ctx = static_cast(context); + if(m_contexts.find(ctx) == m_contexts.end()) + { + return false; + } + + delete ctx; + m_contexts.erase(ctx); + + return true; +} + +void* EGLtoGLESInterface::GetNativeContext(void* context) +{ + GLES_ASSERT(context != NULL); + + GLESContext* ctx = static_cast(context); + if(m_contexts.find(ctx) == m_contexts.end()) + { + return false; + } + + return ctx->NativeContext(); +} + +fpGLProc EGLtoGLESInterface::GetGLProcAddress( const char *procname ) +{ + if(strcmp(procname, "glPointSizePointerOES") == 0) + { + return (fpGLProc)glPointSizePointerOES; + } + else + { + return NULL; + } +} + +static SurfaceDescriptor createSurfaceDescriptor(int redBits, int redShift, int greenBits, int greenShift, int blueBits, int blueShift, int alphaBits, int alphaShift, int luminanceBits, int luminanceShift, CColorDescriptor::ColorFormat format, int bpp) +{ + SurfaceDescriptor desc; + desc.m_colorDescriptor.m_redSize = redBits; + desc.m_colorDescriptor.m_greenSize = greenBits; + desc.m_colorDescriptor.m_blueSize = blueBits; + desc.m_colorDescriptor.m_alphaSize = alphaBits; + desc.m_colorDescriptor.m_luminanceSize = luminanceBits; + desc.m_redShift = redShift; + desc.m_greenShift = greenShift; + desc.m_blueShift = blueShift; + desc.m_alphaShift = alphaShift; + desc.m_luminanceShift = luminanceShift; + desc.m_colorDescriptor.m_format = format; + desc.m_colorDescriptor.m_bpp = bpp; + return desc; +} + typedef struct { SurfaceDescriptor desc; GLenum internal_format; GLenum data_format; GLenum data_type; -} DescToEnumMapping; - +} DescToEnumMapping; + static bool isDescEqualToMapping(const SurfaceDescriptor& desc, const DescToEnumMapping& mapping) { if ((desc.m_colorDescriptor.m_redSize == mapping.desc.m_colorDescriptor.m_redSize) && @@ -160,8 +160,8 @@ return true; return false; -} - +} + static void surfaceDescriptorToGLEnums(const SurfaceDescriptor& desc, GLenum& internal_format, GLenum& data_format, GLenum& data_type) { static const DescToEnumMapping map[] = { @@ -269,158 +269,158 @@ } GLES_ASSERT(false); return; -} - -int EGLtoGLESInterface::BindTexImage( void* surface, int level, bool generateMipmap, const SurfaceDescriptor* desc, void* buffer ) -{ - GLES_ENTER_RET(NULL); - - GLuint ret = 0; - - // Store the current error and clear the error flag. - ctx->GetHostError(); - - if(level < 0) - { - level = 0; - } - else if(level > (int)ctx->MaxTextureLevel()) - { - level = ctx->MaxTextureLevel(); - } - - GLint origGenMipmapParam; - ctx->DGL().glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, &origGenMipmapParam); - - if(!generateMipmap) - { - // Disable automatic mipmap generation. - ctx->DGL().glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); - } - - // Clear all mipmap levels. - for(unsigned int i = 0; i < ctx->MaxTextureLevel(); i++) - { - ctx->DGL().glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - } - - GLenum internalFormat, dataFormat, dataType; - surfaceDescriptorToGLEnums(*desc, internalFormat, dataFormat, dataType); - ctx->DGL().glTexImage2D(GL_TEXTURE_2D, level, internalFormat, desc->m_width, desc->m_height, 0, - dataFormat, dataType, buffer); - - if(!generateMipmap) - { - // Restore original state. - ctx->DGL().glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, origGenMipmapParam); - } - - // Clear any possible error flag. - if(ctx->DGL().glGetError() == GL_NO_ERROR) - { - GLESTexture* texture = ctx->Texture(ctx->TextureBinding()); - GLES_ASSERT(texture != NULL); - texture->SetLevel(level, GL_RGBA, desc->m_width, desc->m_height); - - if(generateMipmap && origGenMipmapParam && level == 0) - { - texture->GenerateMipmap(); - } - - if(texture->Level(level)->boundSurface != NULL) - { - glesReleaseTexImage(texture->Level(level)->boundSurface, texture->Name(), level); - } - texture->Level(level)->boundSurface = surface; - - ret = texture->Name(); - } - - GLES_LEAVE_NO_ERROR_CHECK_RET(ret); -} - -bool EGLtoGLESInterface::ReleaseTexImage( int name, int level ) -{ - GLES_ENTER_RET(false); - - ctx->GetHostError(); - - GLuint binding; - ctx->DGL().glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&binding); - ctx->DGL().glBindTexture(GL_TEXTURE_2D, (GLuint)name); - ctx->DGL().glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - ctx->DGL().glBindTexture(GL_TEXTURE_2D, binding); - - GLES_LEAVE_NO_ERROR_CHECK_RET(ctx->DGL().glGetError() == GL_NO_ERROR); -} - -bool EGLtoGLESInterface::CopyBuffers( void* buf, const SurfaceDescriptor* desc ) -{ - GLES_ENTER_RET(false); - - // Store the current error and clear the error flag. - ctx->GetHostError(); - - GLenum internal_format, data_format, data_type; - surfaceDescriptorToGLEnums(*desc, internal_format, data_format, data_type); - - GLint pack_alignment; - ctx->DGL().glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment); - ctx->DGL().glPixelStorei(GL_PACK_ALIGNMENT, 1); - ctx->DGL().glReadPixels(0, 0, desc->m_width, desc->m_height, data_format, data_type, buf); - ctx->DGL().glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment); - - GLES_LEAVE_NO_ERROR_CHECK_RET(ctx->DGL().glGetError() == GL_NO_ERROR); -} - -bool EGLtoGLESInterface::UpdateBuffers( void* buf, const SurfaceDescriptor* desc ) -{ - GLES_ENTER_RET(false); - - // Store the current error and clear the error flag. - ctx->GetHostError(); - - GLenum internal_format, data_format, data_type; - surfaceDescriptorToGLEnums(*desc, internal_format, data_format, data_type); - - GLint unpack_alignment; - ctx->DGL().glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_alignment); - ctx->DGL().glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - ctx->DGL().glDrawPixels( desc->m_width, desc->m_height, data_format, data_type, buf ); - ctx->DGL().glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment); - - GLES_LEAVE_NO_ERROR_CHECK_RET(ctx->DGL().glGetError() == GL_NO_ERROR); -} - -void EGLtoGLESInterface::Flush() -{ - GLES_ENTER(); - - // Store the current error and clear the error flag. - ctx->GetHostError(); - - ctx->DGL().glFlush(); - - ctx->DGL().glGetError(); - - GLES_LEAVE(); -} - -void EGLtoGLESInterface::Finish() -{ - GLES_ENTER(); - - // Store the current error and clear the error flag. - ctx->GetHostError(); - - ctx->DGL().glFinish(); - - ctx->DGL().glGetError(); - - GLES_LEAVE(); -} - -/*static*/ IGLEStoEGLInterface* EGLtoGLESInterface::GetEGLInterface() -{ - return g_EGLtoGLESInterface.m_egl; -} +} + +int EGLtoGLESInterface::BindTexImage( void* surface, int level, bool generateMipmap, const SurfaceDescriptor* desc, void* buffer ) +{ + GLES_ENTER_RET(NULL); + + GLuint ret = 0; + + // Store the current error and clear the error flag. + ctx->GetHostError(); + + if(level < 0) + { + level = 0; + } + else if(level > (int)ctx->MaxTextureLevel()) + { + level = ctx->MaxTextureLevel(); + } + + GLint origGenMipmapParam; + ctx->DGL().glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, &origGenMipmapParam); + + if(!generateMipmap) + { + // Disable automatic mipmap generation. + ctx->DGL().glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); + } + + // Clear all mipmap levels. + for(unsigned int i = 0; i < ctx->MaxTextureLevel(); i++) + { + ctx->DGL().glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + + GLenum internalFormat, dataFormat, dataType; + surfaceDescriptorToGLEnums(*desc, internalFormat, dataFormat, dataType); + ctx->DGL().glTexImage2D(GL_TEXTURE_2D, level, internalFormat, desc->m_width, desc->m_height, 0, + dataFormat, dataType, buffer); + + if(!generateMipmap) + { + // Restore original state. + ctx->DGL().glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, origGenMipmapParam); + } + + // Clear any possible error flag. + if(ctx->DGL().glGetError() == GL_NO_ERROR) + { + GLESTexture* texture = ctx->Texture(ctx->TextureBinding()); + GLES_ASSERT(texture != NULL); + texture->SetLevel(level, GL_RGBA, desc->m_width, desc->m_height); + + if(generateMipmap && origGenMipmapParam && level == 0) + { + texture->GenerateMipmap(); + } + + if(texture->Level(level)->boundSurface != NULL) + { + glesReleaseTexImage(texture->Level(level)->boundSurface, texture->Name(), level); + } + texture->Level(level)->boundSurface = surface; + + ret = texture->Name(); + } + + GLES_LEAVE_NO_ERROR_CHECK_RET(ret); +} + +bool EGLtoGLESInterface::ReleaseTexImage( int name, int level ) +{ + GLES_ENTER_RET(false); + + ctx->GetHostError(); + + GLuint binding; + ctx->DGL().glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&binding); + ctx->DGL().glBindTexture(GL_TEXTURE_2D, (GLuint)name); + ctx->DGL().glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + ctx->DGL().glBindTexture(GL_TEXTURE_2D, binding); + + GLES_LEAVE_NO_ERROR_CHECK_RET(ctx->DGL().glGetError() == GL_NO_ERROR); +} + +bool EGLtoGLESInterface::CopyBuffers( void* buf, const SurfaceDescriptor* desc ) +{ + GLES_ENTER_RET(false); + + // Store the current error and clear the error flag. + ctx->GetHostError(); + + GLenum internal_format, data_format, data_type; + surfaceDescriptorToGLEnums(*desc, internal_format, data_format, data_type); + + GLint pack_alignment; + ctx->DGL().glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment); + ctx->DGL().glPixelStorei(GL_PACK_ALIGNMENT, 1); + ctx->DGL().glReadPixels(0, 0, desc->m_width, desc->m_height, data_format, data_type, buf); + ctx->DGL().glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment); + + GLES_LEAVE_NO_ERROR_CHECK_RET(ctx->DGL().glGetError() == GL_NO_ERROR); +} + +bool EGLtoGLESInterface::UpdateBuffers( void* buf, const SurfaceDescriptor* desc ) +{ + GLES_ENTER_RET(false); + + // Store the current error and clear the error flag. + ctx->GetHostError(); + + GLenum internal_format, data_format, data_type; + surfaceDescriptorToGLEnums(*desc, internal_format, data_format, data_type); + + GLint unpack_alignment; + ctx->DGL().glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_alignment); + ctx->DGL().glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + ctx->DGL().glDrawPixels( desc->m_width, desc->m_height, data_format, data_type, buf ); + ctx->DGL().glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment); + + GLES_LEAVE_NO_ERROR_CHECK_RET(ctx->DGL().glGetError() == GL_NO_ERROR); +} + +void EGLtoGLESInterface::Flush() +{ + GLES_ENTER(); + + // Store the current error and clear the error flag. + ctx->GetHostError(); + + ctx->DGL().glFlush(); + + ctx->DGL().glGetError(); + + GLES_LEAVE(); +} + +void EGLtoGLESInterface::Finish() +{ + GLES_ENTER(); + + // Store the current error and clear the error flag. + ctx->GetHostError(); + + ctx->DGL().glFinish(); + + ctx->DGL().glGetError(); + + GLES_LEAVE(); +} + +/*static*/ IGLEStoEGLInterface* EGLtoGLESInterface::GetEGLInterface() +{ + return g_EGLtoGLESInterface.m_egl; +}