diff options
Diffstat (limited to 'distrib/android-emugl/host/libs/Translator/GLcommon')
13 files changed, 0 insertions, 3016 deletions
diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/Android.mk b/distrib/android-emugl/host/libs/Translator/GLcommon/Android.mk deleted file mode 100644 index d58d44dca..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/Android.mk +++ /dev/null @@ -1,44 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -host_common_SRC_FILES := \ - GLDispatch.cpp \ - GLutils.cpp \ - GLEScontext.cpp \ - GLESvalidate.cpp \ - GLESpointer.cpp \ - GLESbuffer.cpp \ - RangeManip.cpp \ - TextureUtils.cpp \ - PaletteTexture.cpp \ - etc1.cpp \ - objectNameManager.cpp \ - FramebufferData.cpp - -host_GL_COMMON_LINKER_FLAGS := -host_common_LDLIBS := -host_common_LDFLAGS := - -ifeq ($(HOST_OS),linux) -# host_common_LDFLAGS += -Wl,--whole-archive - host_common_LDLIBS += -lGL -ldl - host_common_LDFLAGS += -Wl,-Bsymbolic -endif - -ifeq ($(HOST_OS),windows) - host_common_LDLIBS += -lopengl32 -lgdi32 - host_common_LDFLAGS += -Wl,--add-stdcall-alias -endif - - -### EGL host implementation ######################## - -$(call emugl-begin-static-library,libGLcommon) - -LOCAL_SRC_FILES := $(host_common_SRC_FILES) -$(call emugl-export,LDLIBS,$(host_common_LDLIBS)) -$(call emugl-export,LDFLAGS,$(host_common_LDFLAGS)) -$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)/../include $(EMUGL_PATH)/shared) -$(call emugl-export,STATIC_LIBRARIES, libemugl_common) - -$(call emugl-end-module) - diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/FramebufferData.cpp b/distrib/android-emugl/host/libs/Translator/GLcommon/FramebufferData.cpp deleted file mode 100644 index 50b068a3b..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/FramebufferData.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* -* 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 <GLES/gl.h> -#include <GLES/glext.h> -#include <GLcommon/FramebufferData.h> -#include <GLcommon/GLEScontext.h> - -RenderbufferData::~RenderbufferData() { - if (sourceEGLImage && eglImageDetach) (*eglImageDetach)(sourceEGLImage); -} - -FramebufferData::FramebufferData(GLuint name) : m_fbName(name) {} - -FramebufferData::~FramebufferData() { - for (int i=0; i<MAX_ATTACH_POINTS; i++) { - detachObject(i); - } -} - -void FramebufferData::setAttachment(GLenum attachment, - GLenum target, - GLuint name, - ObjectDataPtr obj, - bool takeOwnership) { -int idx = attachmentPointIndex(attachment); - if (!name) { - detachObject(idx); - return; - } - if (m_attachPoints[idx].target != target || - m_attachPoints[idx].name != name || - m_attachPoints[idx].obj.get() != obj.get() || - m_attachPoints[idx].owned != takeOwnership) { - - detachObject(idx); - - m_attachPoints[idx].target = target; - m_attachPoints[idx].name = name; - m_attachPoints[idx].obj = obj; - m_attachPoints[idx].owned = takeOwnership; - - if (target == GL_RENDERBUFFER_OES && obj.get() != NULL) { - RenderbufferData *rbData = (RenderbufferData *)obj.get(); - rbData->attachedFB = m_fbName; - rbData->attachedPoint = attachment; - } - - m_dirty = true; - } -} - -GLuint FramebufferData::getAttachment(GLenum attachment, - GLenum *outTarget, - ObjectDataPtr *outObj) { - int idx = attachmentPointIndex(attachment); - if (outTarget) *outTarget = m_attachPoints[idx].target; - if (outObj) *outObj = m_attachPoints[idx].obj; - return m_attachPoints[idx].name; -} - -int FramebufferData::attachmentPointIndex(GLenum attachment) -{ - switch(attachment) { - case GL_COLOR_ATTACHMENT0_OES: - return 0; - case GL_DEPTH_ATTACHMENT_OES: - return 1; - case GL_STENCIL_ATTACHMENT_OES: - return 2; - default: - return MAX_ATTACH_POINTS; - } -} - -void FramebufferData::detachObject(int idx) { - if (m_attachPoints[idx].target == GL_RENDERBUFFER_OES && m_attachPoints[idx].obj.get() != NULL) { - RenderbufferData *rbData = (RenderbufferData *)m_attachPoints[idx].obj.get(); - rbData->attachedFB = 0; - rbData->attachedPoint = 0; - } - - if(m_attachPoints[idx].owned) - { - switch(m_attachPoints[idx].target) - { - case GL_RENDERBUFFER_OES: - GLEScontext::dispatcher().glDeleteRenderbuffersEXT(1, &(m_attachPoints[idx].name)); - break; - case GL_TEXTURE_2D: - GLEScontext::dispatcher().glDeleteTextures(1, &(m_attachPoints[idx].name)); - break; - } - } - - m_attachPoints[idx] = {}; -} - -void FramebufferData::validate(GLEScontext* ctx) -{ - if(!getAttachment(GL_COLOR_ATTACHMENT0_OES, NULL, NULL)) - { - // GLES does not require the framebuffer to have a color attachment. - // OpenGL does. Therefore, if no color is attached, create a dummy - // color texture and attach it. - // This dummy color texture will is owned by the FramebufferObject, - // and will be released by it when its object is detached. - - GLint type = GL_NONE; - GLint name = 0; - - ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT_OES, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type); - if(type != GL_NONE) - { - ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT_OES, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &name); - } - else - { - ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT_OES, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type); - if(type != GL_NONE) - { - ctx->dispatcher().glGetFramebufferAttachmentParameterivEXT(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT_OES, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &name); - } - else - { - // No color, depth or stencil attachments - do nothing - return; - } - } - - // Find the existing attachment(s) dimensions - GLint width = 0; - GLint height = 0; - - if(type == GL_RENDERBUFFER) - { - GLint prev; - ctx->dispatcher().glGetIntegerv(GL_RENDERBUFFER_BINDING, &prev); - ctx->dispatcher().glBindRenderbufferEXT(GL_RENDERBUFFER, name); - ctx->dispatcher().glGetRenderbufferParameterivEXT(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width); - ctx->dispatcher().glGetRenderbufferParameterivEXT(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height); - ctx->dispatcher().glBindRenderbufferEXT(GL_RENDERBUFFER, prev); - } - else if(type == GL_TEXTURE) - { - GLint prev; - ctx->dispatcher().glGetIntegerv(GL_TEXTURE_BINDING_2D, &prev); - ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, name); - ctx->dispatcher().glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); - ctx->dispatcher().glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); - ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, prev); - } - - // Create the color attachment and attch it - unsigned int tex = ctx->shareGroup()->genGlobalName(TEXTURE); - GLint prev; - ctx->dispatcher().glGetIntegerv(GL_TEXTURE_BINDING_2D, &prev); - ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, tex); - - ctx->dispatcher().glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); - ctx->dispatcher().glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); - ctx->dispatcher().glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - ctx->dispatcher().glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); - ctx->dispatcher().glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - - ctx->dispatcher().glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tex, 0); - setAttachment(GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tex, ObjectDataPtr(), true); - - ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, prev); - } - - if(m_dirty) - { - // This is a workaround for a bug found in several OpenGL - // drivers (e.g. ATI's) - after the framebuffer attachments - // have changed, and before the next draw, unbind and rebind - // the framebuffer to sort things out. - ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER,0); - ctx->dispatcher().glBindFramebufferEXT(GL_FRAMEBUFFER,ctx->shareGroup()->getGlobalName(FRAMEBUFFER,m_fbName)); - - m_dirty = false; - } -} - diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/GLDispatch.cpp b/distrib/android-emugl/host/libs/Translator/GLcommon/GLDispatch.cpp deleted file mode 100644 index 4eca59a50..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/GLDispatch.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* -* 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/GLDispatch.h" -#include "GLcommon/GLLibrary.h" - -#include "emugl/common/lazy_instance.h" -#include "emugl/common/shared_library.h" - -#include "OpenglCodecCommon/ErrorLog.h" - -#ifdef __linux__ -#include <GL/glx.h> -#elif defined(WIN32) -#include <windows.h> -#endif - -#include <stdio.h> - -typedef GlLibrary::GlFunctionPointer GL_FUNC_PTR; - -static GL_FUNC_PTR getGLFuncAddress(const char *funcName) { - return GlLibrary::getHostInstance()->findSymbol(funcName); -} - -#define LOAD_GL_FUNC(return_type, func_name, signature) do { \ - if (!func_name) { \ - void* address = (void *)getGLFuncAddress(#func_name); \ - if (address) { \ - func_name = (__typeof__(func_name))(address); \ - } else { \ - fprintf(stderr, "Could not load func %s\n", #func_name); \ - func_name = (__typeof__(func_name))(dummy_##func_name); \ - } \ - } \ - } while (0); - -#define LOAD_GLEXT_FUNC(return_type, func_name, signature) do { \ - if (!func_name) { \ - void* address = (void *)getGLFuncAddress(#func_name); \ - if (address) { \ - func_name = (__typeof__(func_name))(address); \ - } \ - } \ - } while (0); - - -// Define dummy functions, only for non-extensions. - -#define RETURN_void return -#define RETURN_GLboolean return GL_FALSE -#define RETURN_GLint return 0 -#define RETURN_GLuint return 0U -#define RETURN_GLenum return 0 -#define RETURN_int return 0 -#define RETURN_GLconstubyteptr return NULL - -#define RETURN_(x) RETURN_ ## x - -#define DEFINE_DUMMY_FUNCTION(return_type, func_name, signature) \ -static return_type dummy_##func_name signature { \ - RETURN_(return_type); \ -} - -#define DEFINE_DUMMY_EXTENSION_FUNCTION(return_type, func_name, signature) \ - // nothing here - -LIST_GLES_FUNCTIONS(DEFINE_DUMMY_FUNCTION, DEFINE_DUMMY_EXTENSION_FUNCTION) - -// Initializing static GLDispatch members*/ - -emugl::Mutex GLDispatch::s_lock; - -#define GL_DISPATCH_DEFINE_POINTER(return_type, function_name, signature) \ - GL_APICALL return_type (GL_APIENTRY *GLDispatch::function_name) signature = NULL; - -LIST_GLES_FUNCTIONS(GL_DISPATCH_DEFINE_POINTER, GL_DISPATCH_DEFINE_POINTER) - -// Constructor. -GLDispatch::GLDispatch() : m_isLoaded(false) {} - -void GLDispatch::dispatchFuncs(GLESVersion version) { - emugl::Mutex::AutoLock mutex(s_lock); - if(m_isLoaded) - return; - - /* Loading OpenGL functions which are needed for implementing BOTH GLES 1.1 & GLES 2.0*/ - LIST_GLES_COMMON_FUNCTIONS(LOAD_GL_FUNC) - LIST_GLES_EXTENSIONS_FUNCTIONS(LOAD_GLEXT_FUNC) - - /* Loading OpenGL functions which are needed ONLY for implementing GLES 1.1*/ - if(version == GLES_1_1){ - LIST_GLES1_ONLY_FUNCTIONS(LOAD_GL_FUNC) - LIST_GLES1_EXTENSIONS_FUNCTIONS(LOAD_GLEXT_FUNC) - } else if (version == GLES_2_0){ - LIST_GLES2_ONLY_FUNCTIONS(LOAD_GL_FUNC) - LIST_GLES2_EXTENSIONS_FUNCTIONS(LOAD_GLEXT_FUNC) - } - - /* Load glGetStringi() if it is available, so use LOAD_GLEXT_FUNC */ - LIST_GLES3_ONLY_FUNCTIONS(LOAD_GLEXT_FUNC) - - m_isLoaded = true; -} diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/GLESbuffer.cpp b/distrib/android-emugl/host/libs/Translator/GLcommon/GLESbuffer.cpp deleted file mode 100644 index 5dcdd6564..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/GLESbuffer.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* -* 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/GLESbuffer.h> -#include <string.h> - -bool GLESbuffer::setBuffer(GLuint size,GLuint usage,const GLvoid* data) { - m_size = size; - m_usage = usage; - if(m_data) { - delete [] m_data; - m_data = NULL; - } - m_data = new unsigned char[size]; - if(m_data) { - if(data) { - memcpy(m_data,data,size); - } - m_conversionManager.clear(); - m_conversionManager.addRange(Range(0,m_size)); - return true; - } - return false; -} - -bool GLESbuffer::setSubBuffer(GLint offset,GLuint size,const GLvoid* data) { - if(offset + size > m_size) return false; - memcpy(m_data+offset,data,size); - m_conversionManager.addRange(Range(offset,size)); - m_conversionManager.merge(); - return true; -} - -void GLESbuffer::getConversions(const RangeList& rIn,RangeList& rOut) { - m_conversionManager.delRanges(rIn,rOut); - rOut.merge(); -} - -GLESbuffer::~GLESbuffer() { - if(m_data) { - delete [] m_data; - } -} diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/GLEScontext.cpp b/distrib/android-emugl/host/libs/Translator/GLcommon/GLEScontext.cpp deleted file mode 100644 index bbd077efb..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/GLEScontext.cpp +++ /dev/null @@ -1,826 +0,0 @@ -/* -* Copyright 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/GLEScontext.h> -#include <GLcommon/GLconversion_macros.h> -#include <GLcommon/GLESmacros.h> -#include <GLES/gl.h> -#include <GLES/glext.h> -#include <OpenglCodecCommon/ErrorLog.h> -#include <GLcommon/GLESvalidate.h> -#include <GLcommon/TextureUtils.h> -#include <GLcommon/FramebufferData.h> -#include <strings.h> -#include <string.h> - -//decleration -static void convertFixedDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize); -static void convertFixedIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize); -static void convertByteDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize); -static void convertByteIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize); - -GLESConversionArrays::~GLESConversionArrays() { - for(std::map<GLenum,ArrayData>::iterator it = m_arrays.begin(); it != m_arrays.end();it++) { - if((*it).second.allocated){ - if((*it).second.type == GL_FLOAT){ - GLfloat* p = (GLfloat *)((*it).second.data); - if(p) delete[] p; - } else if((*it).second.type == GL_SHORT){ - GLshort* p = (GLshort *)((*it).second.data); - if(p) delete[] p; - } - } - } -} - -void GLESConversionArrays::allocArr(unsigned int size,GLenum type){ - if(type == GL_FIXED){ - m_arrays[m_current].data = new GLfloat[size]; - m_arrays[m_current].type = GL_FLOAT; - } else if(type == GL_BYTE){ - m_arrays[m_current].data = new GLshort[size]; - m_arrays[m_current].type = GL_SHORT; - } - m_arrays[m_current].stride = 0; - m_arrays[m_current].allocated = true; -} - -void GLESConversionArrays::setArr(void* data,unsigned int stride,GLenum type){ - m_arrays[m_current].type = type; - m_arrays[m_current].data = data; - m_arrays[m_current].stride = stride; - m_arrays[m_current].allocated = false; -} - -void* GLESConversionArrays::getCurrentData(){ - return m_arrays[m_current].data; -} - -ArrayData& GLESConversionArrays::getCurrentArray(){ - return m_arrays[m_current]; -} - -unsigned int GLESConversionArrays::getCurrentIndex(){ - return m_current; -} - -ArrayData& GLESConversionArrays::operator[](int i){ - return m_arrays[i]; -} - -void GLESConversionArrays::operator++(){ - m_current++; -} - -GLDispatch GLEScontext::s_glDispatch; -emugl::Mutex GLEScontext::s_lock; -std::string* GLEScontext::s_glExtensions= NULL; -std::string GLEScontext::s_glVendor; -std::string GLEScontext::s_glRenderer; -std::string GLEScontext::s_glVersion; -GLSupport GLEScontext::s_glSupport; - -Version::Version(int major,int minor,int release):m_major(major), - m_minor(minor), - m_release(release){}; - -Version::Version(const Version& ver):m_major(ver.m_major), - m_minor(ver.m_minor), - m_release(ver.m_release){} - -Version::Version(const char* versionString){ - m_release = 0; - if((!versionString) || - ((!(sscanf(versionString,"%d.%d" ,&m_major,&m_minor) == 2)) && - (!(sscanf(versionString,"%d.%d.%d",&m_major,&m_minor,&m_release) == 3)))){ - m_major = m_minor = 0; // the version is not in the right format - } -} - -Version& Version::operator=(const Version& ver){ - m_major = ver.m_major; - m_minor = ver.m_minor; - m_release = ver.m_release; - return *this; -} - -bool Version::operator<(const Version& ver) const{ - if(m_major < ver.m_major) return true; - if(m_major == ver.m_major){ - if(m_minor < ver.m_minor) return true; - if(m_minor == ver.m_minor){ - return m_release < ver.m_release; - } - } - return false; -} - -static std::string getHostExtensionsString(GLDispatch* dispatch) { - // glGetString(GL_EXTENSIONS) is deprecated in GL 3.0, one has to use - // glGetStringi(GL_EXTENSIONS, index) instead to get individual extension - // names. Recent desktop drivers implement glGetStringi() but have a - // version of glGetString() that returns NULL, so deal with this by - // doing the following: - // - // - If glGetStringi() is available, use it to build the extensions - // string, using simple spaces to separate the names. - // - // - Otherwise, fallback to getGetString(). If it returns NULL, return - // an empty string. - // - std::string result; - if (dispatch->glGetStringi != nullptr) { - int count = 0; - dispatch->glGetIntegerv(GL_NUM_EXTENSIONS, &count); - for (int n = 0; n < count; n++) { - const char* ext = reinterpret_cast<const char*>( - dispatch->glGetStringi(GL_EXTENSIONS, n)); - if (ext != NULL) { - if (!result.empty()) { - result += " "; - } - result += ext; - } - } - } else { - const char* extensions = reinterpret_cast<const char*>( - dispatch->glGetString(GL_EXTENSIONS)); - if (extensions) { - result = extensions; - } - } - // For the sake of initCapsLocked() add a starting and trailing space. - if (!result.empty()) { - if (result[0] != ' ') { - result.insert(0, 1, ' '); - } - if (result[result.size() - 1U] != ' ') { - result += ' '; - } - } - return result; -} - -void GLEScontext::init(GlLibrary* glLib) { - - if (!s_glExtensions) { - initCapsLocked(reinterpret_cast<const GLubyte*>( - getHostExtensionsString(&s_glDispatch).c_str())); - // NOTE: the string below corresponds to the extensions reported - // by this context, which is initialized in each GLESv1 or GLESv2 - // context implementation, based on the parsing of the host - // extensions string performed by initCapsLocked(). I.e. it will - // be populated after calling this ::init() method. - s_glExtensions = new std::string(""); - } - - if (!m_initialized) { - initExtensionString(); - - int maxTexUnits = getMaxTexUnits(); - m_texState = new textureUnitState[maxTexUnits]; - for (int i=0;i<maxTexUnits;++i) { - for (int j=0;j<NUM_TEXTURE_TARGETS;++j) - { - m_texState[i][j].texture = 0; - m_texState[i][j].enabled = GL_FALSE; - } - } - } -} - -GLenum GLEScontext::getGLerror() { - return m_glError; -} - -void GLEScontext::setGLerror(GLenum err) { - m_glError = err; -} - -void GLEScontext::setActiveTexture(GLenum tex) { - m_activeTexture = tex - GL_TEXTURE0; -} - -GLEScontext::~GLEScontext() { - for(ArraysMap::iterator it = m_map.begin(); it != m_map.end();it++) { - GLESpointer* p = (*it).second; - if(p) { - delete p; - } - } - delete[] m_texState; - m_texState = NULL; -} - -const GLvoid* GLEScontext::setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize) { - GLuint bufferName = m_arrayBuffer; - if(bufferName) { - unsigned int offset = SafeUIntFromPointer(data); - GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).get()); - m_map[arrType]->setBuffer(size,type,stride,vbo,bufferName,offset,normalize); - return static_cast<const unsigned char*>(vbo->getData()) + offset; - } - m_map[arrType]->setArray(size,type,stride,data,normalize); - return data; -} - -void GLEScontext::enableArr(GLenum arr,bool enable) { - m_map[arr]->enable(enable); -} - -bool GLEScontext::isArrEnabled(GLenum arr) { - return m_map[arr]->isEnable(); -} - -const GLESpointer* GLEScontext::getPointer(GLenum arrType) { - if (m_map.find(arrType) != m_map.end()) return m_map[arrType]; - return NULL; -} - -static void convertFixedDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize) { - - for(unsigned int i = 0; i < nBytes;i+=strideOut) { - const GLfixed* fixed_data = (const GLfixed *)dataIn; - //filling attrib - for(int j=0;j<attribSize;j++) { - reinterpret_cast<GLfloat*>(&static_cast<unsigned char*>(dataOut)[i])[j] = X2F(fixed_data[j]); - } - dataIn += strideIn; - } -} - -static void convertFixedIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize) { - for(int i = 0 ;i < count ;i++) { - unsigned short index = indices_type == GL_UNSIGNED_BYTE? ((GLubyte *)indices)[i]: - ((GLushort *)indices)[i]; - const GLfixed* fixed_data = (GLfixed *)(dataIn + index*strideIn); - GLfloat* float_data = reinterpret_cast<GLfloat*>(static_cast<unsigned char*>(dataOut) + index*strideOut); - - for(int j=0;j<attribSize;j++) { - float_data[j] = X2F(fixed_data[j]); - } - } -} - -static void convertByteDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize) { - - for(unsigned int i = 0; i < nBytes;i+=strideOut) { - const GLbyte* byte_data = (const GLbyte *)dataIn; - //filling attrib - for(int j=0;j<attribSize;j++) { - reinterpret_cast<GLshort*>(&static_cast<unsigned char*>(dataOut)[i])[j] = B2S(byte_data[j]); - } - dataIn += strideIn; - } -} - -static void convertByteIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize) { - for(int i = 0 ;i < count ;i++) { - unsigned short index = indices_type == GL_UNSIGNED_BYTE? ((GLubyte *)indices)[i]: - ((GLushort *)indices)[i]; - const GLbyte* bytes_data = (GLbyte *)(dataIn + index*strideIn); - GLshort* short_data = reinterpret_cast<GLshort*>(static_cast<unsigned char*>(dataOut) + index*strideOut); - - for(int j=0;j<attribSize;j++) { - short_data[j] = B2S(bytes_data[j]); - } - } -} -static void directToBytesRanges(GLint first,GLsizei count,GLESpointer* p,RangeList& list) { - - int attribSize = p->getSize()*4; //4 is the sizeof GLfixed or GLfloat in bytes - int stride = p->getStride()?p->getStride():attribSize; - int start = p->getBufferOffset()+first*attribSize; - if(!p->getStride()) { - list.addRange(Range(start,count*attribSize)); - } else { - for(int i = 0 ;i < count; i++,start+=stride) { - list.addRange(Range(start,attribSize)); - } - } -} - -static void indirectToBytesRanges(const GLvoid* indices,GLenum indices_type,GLsizei count,GLESpointer* p,RangeList& list) { - - int attribSize = p->getSize() * 4; //4 is the sizeof GLfixed or GLfloat in bytes - int stride = p->getStride()?p->getStride():attribSize; - int start = p->getBufferOffset(); - for(int i=0 ; i < count; i++) { - GLushort index = (indices_type == GL_UNSIGNED_SHORT? - static_cast<const GLushort*>(indices)[i]: - static_cast<const GLubyte*>(indices)[i]); - list.addRange(Range(start+index*stride,attribSize)); - - } -} - -int bytesRangesToIndices(RangeList& ranges,GLESpointer* p,GLushort* indices) { - - int attribSize = p->getSize() * 4; //4 is the sizeof GLfixed or GLfloat in bytes - int stride = p->getStride()?p->getStride():attribSize; - int offset = p->getBufferOffset(); - - int n = 0; - for(int i=0;i<ranges.size();i++) { - int startIndex = (ranges[i].getStart() - offset) / stride; - int nElements = ranges[i].getSize()/attribSize; - for(int j=0;j<nElements;j++) { - indices[n++] = startIndex+j; - } - } - return n; -} - -void GLEScontext::convertDirect(GLESConversionArrays& cArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p) { - - GLenum type = p->getType(); - int attribSize = p->getSize(); - unsigned int size = attribSize*count + first; - unsigned int bytes = type == GL_FIXED ? sizeof(GLfixed):sizeof(GLbyte); - cArrs.allocArr(size,type); - int stride = p->getStride()?p->getStride():bytes*attribSize; - const char* data = (const char*)p->getArrayData() + (first*stride); - - if(type == GL_FIXED) { - convertFixedDirectLoop(data,stride,cArrs.getCurrentData(),size*sizeof(GLfloat),attribSize*sizeof(GLfloat),attribSize); - } else if(type == GL_BYTE) { - convertByteDirectLoop(data,stride,cArrs.getCurrentData(),size*sizeof(GLshort),attribSize*sizeof(GLshort),attribSize); - } -} - -void GLEScontext::convertDirectVBO(GLESConversionArrays& cArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p) { - - RangeList ranges; - RangeList conversions; - GLushort* indices = NULL; - int attribSize = p->getSize(); - int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize; - char* data = (char*)p->getBufferData() + (first*stride); - - if(p->bufferNeedConversion()) { - directToBytesRanges(first,count,p,ranges); //converting indices range to buffer bytes ranges by offset - p->getBufferConversions(ranges,conversions); // getting from the buffer the relevant ranges that still needs to be converted - - if(conversions.size()) { // there are some elements to convert - indices = new GLushort[count]; - int nIndices = bytesRangesToIndices(conversions,p,indices); //converting bytes ranges by offset to indices in this array - convertFixedIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,indices,stride,attribSize); - } - } - if(indices) delete[] indices; - cArrs.setArr(data,p->getStride(),GL_FLOAT); -} - -int GLEScontext::findMaxIndex(GLsizei count,GLenum type,const GLvoid* indices) { - //finding max index - int max = 0; - if(type == GL_UNSIGNED_BYTE) { - GLubyte* b_indices =(GLubyte *)indices; - for(int i=0;i<count;i++) { - if(b_indices[i] > max) max = b_indices[i]; - } - } else { - GLushort* us_indices =(GLushort *)indices; - for(int i=0;i<count;i++) { - if(us_indices[i] > max) max = us_indices[i]; - } - } - return max; -} - -void GLEScontext::convertIndirect(GLESConversionArrays& cArrs,GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p) { - GLenum type = p->getType(); - int maxElements = findMaxIndex(count,type,indices) + 1; - - int attribSize = p->getSize(); - int size = attribSize * maxElements; - unsigned int bytes = type == GL_FIXED ? sizeof(GLfixed):sizeof(GLbyte); - cArrs.allocArr(size,type); - int stride = p->getStride()?p->getStride():bytes*attribSize; - - const char* data = (const char*)p->getArrayData(); - if(type == GL_FIXED) { - convertFixedIndirectLoop(data,stride,cArrs.getCurrentData(),count,indices_type,indices,attribSize*sizeof(GLfloat),attribSize); - } else if(type == GL_BYTE){ - convertByteIndirectLoop(data,stride,cArrs.getCurrentData(),count,indices_type,indices,attribSize*sizeof(GLshort),attribSize); - } -} - -void GLEScontext::convertIndirectVBO(GLESConversionArrays& cArrs,GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p) { - RangeList ranges; - RangeList conversions; - GLushort* conversionIndices = NULL; - int attribSize = p->getSize(); - int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize; - char* data = static_cast<char*>(p->getBufferData()); - if(p->bufferNeedConversion()) { - indirectToBytesRanges(indices,indices_type,count,p,ranges); //converting indices range to buffer bytes ranges by offset - p->getBufferConversions(ranges,conversions); // getting from the buffer the relevant ranges that still needs to be converted - if(conversions.size()) { // there are some elements to convert - conversionIndices = new GLushort[count]; - int nIndices = bytesRangesToIndices(conversions,p,conversionIndices); //converting bytes ranges by offset to indices in this array - convertFixedIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,conversionIndices,stride,attribSize); - } - } - if(conversionIndices) delete[] conversionIndices; - cArrs.setArr(data,p->getStride(),GL_FLOAT); -} - - - -void GLEScontext::bindBuffer(GLenum target,GLuint buffer) { - if(target == GL_ARRAY_BUFFER) { - m_arrayBuffer = buffer; - } else { - m_elementBuffer = buffer; - } -} - -void GLEScontext::unbindBuffer(GLuint buffer) { - if(m_arrayBuffer == buffer) - { - m_arrayBuffer = 0; - } - if(m_elementBuffer == buffer) - { - m_elementBuffer = 0; - } -} - -//checks if any buffer is binded to target -bool GLEScontext::isBindedBuffer(GLenum target) { - if(target == GL_ARRAY_BUFFER) { - return m_arrayBuffer != 0; - } else { - return m_elementBuffer != 0; - } -} - -GLuint GLEScontext::getBuffer(GLenum target) { - return target == GL_ARRAY_BUFFER ? m_arrayBuffer:m_elementBuffer; -} - -GLvoid* GLEScontext::getBindedBuffer(GLenum target) { - GLuint bufferName = getBuffer(target); - if(!bufferName) return NULL; - - GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).get()); - return vbo->getData(); -} - -void GLEScontext::getBufferSize(GLenum target,GLint* param) { - GLuint bufferName = getBuffer(target); - GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).get()); - *param = vbo->getSize(); -} - -void GLEScontext::getBufferUsage(GLenum target,GLint* param) { - GLuint bufferName = getBuffer(target); - GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).get()); - *param = vbo->getUsage(); -} - -bool GLEScontext::setBufferData(GLenum target,GLsizeiptr size,const GLvoid* data,GLenum usage) { - GLuint bufferName = getBuffer(target); - if(!bufferName) return false; - GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).get()); - return vbo->setBuffer(size,usage,data); -} - -bool GLEScontext::setBufferSubData(GLenum target,GLintptr offset,GLsizeiptr size,const GLvoid* data) { - - GLuint bufferName = getBuffer(target); - if(!bufferName) return false; - GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).get()); - return vbo->setSubBuffer(offset,size,data); -} - -const char * GLEScontext::getExtensionString() { - const char * ret; - s_lock.lock(); - if (s_glExtensions) - ret = s_glExtensions->c_str(); - else - ret=""; - s_lock.unlock(); - return ret; -} - -const char * GLEScontext::getVendorString() const { - return s_glVendor.c_str(); -} - -const char * GLEScontext::getRendererString() const { - return s_glRenderer.c_str(); -} - -const char * GLEScontext::getVersionString() const { - return s_glVersion.c_str(); -} - -void GLEScontext::getGlobalLock() { - s_lock.lock(); -} - -void GLEScontext::releaseGlobalLock() { - s_lock.unlock(); -} - - -void GLEScontext::initCapsLocked(const GLubyte * extensionString) -{ - const char* cstring = (const char*)extensionString; - - s_glDispatch.glGetIntegerv(GL_MAX_VERTEX_ATTRIBS,&s_glSupport.maxVertexAttribs); - s_glDispatch.glGetIntegerv(GL_MAX_CLIP_PLANES,&s_glSupport.maxClipPlane); - s_glDispatch.glGetIntegerv(GL_MAX_LIGHTS,&s_glSupport.maxLights); - s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_SIZE,&s_glSupport.maxTexSize); - s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_UNITS,&s_glSupport.maxTexUnits); - s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,&s_glSupport.maxTexImageUnits); - s_glDispatch.glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &s_glSupport.maxCombinedTexImageUnits); - const GLubyte* glslVersion = s_glDispatch.glGetString(GL_SHADING_LANGUAGE_VERSION); - s_glSupport.glslVersion = Version((const char*)(glslVersion)); - const GLubyte* glVersion = s_glDispatch.glGetString(GL_VERSION); - - if (strstr(cstring,"GL_EXT_bgra ")!=NULL) - s_glSupport.GL_EXT_TEXTURE_FORMAT_BGRA8888 = true; - - if (strstr(cstring,"GL_EXT_framebuffer_object ")!=NULL) - s_glSupport.GL_EXT_FRAMEBUFFER_OBJECT = true; - - if (strstr(cstring,"GL_ARB_vertex_blend ")!=NULL) - s_glSupport.GL_ARB_VERTEX_BLEND = true; - - if (strstr(cstring,"GL_ARB_matrix_palette ")!=NULL) - s_glSupport.GL_ARB_MATRIX_PALETTE = true; - - if (strstr(cstring,"GL_EXT_packed_depth_stencil ")!=NULL ) - s_glSupport.GL_EXT_PACKED_DEPTH_STENCIL = true; - - if (strstr(cstring,"GL_OES_read_format ")!=NULL) - s_glSupport.GL_OES_READ_FORMAT = true; - - if (strstr(cstring,"GL_ARB_half_float_pixel ")!=NULL) - s_glSupport.GL_ARB_HALF_FLOAT_PIXEL = true; - - if (strstr(cstring,"GL_NV_half_float ")!=NULL) - s_glSupport.GL_NV_HALF_FLOAT = true; - - if (strstr(cstring,"GL_ARB_half_float_vertex ")!=NULL) - s_glSupport.GL_ARB_HALF_FLOAT_VERTEX = true; - - if (strstr(cstring,"GL_SGIS_generate_mipmap ")!=NULL) - s_glSupport.GL_SGIS_GENERATE_MIPMAP = true; - - if (strstr(cstring,"GL_ARB_ES2_compatibility ")!=NULL) - s_glSupport.GL_ARB_ES2_COMPATIBILITY = true; - - if (strstr(cstring,"GL_OES_standard_derivatives ")!=NULL) - s_glSupport.GL_OES_STANDARD_DERIVATIVES = true; - - if (strstr(cstring,"GL_ARB_texture_non_power_of_two")!=NULL) - s_glSupport.GL_OES_TEXTURE_NPOT = true; - - if (!(Version((const char*)glVersion) < Version("3.0")) || strstr(cstring,"GL_OES_rgb8_rgba8")!=NULL) - s_glSupport.GL_OES_RGB8_RGBA8 = true; - - // Check for anisotropic filtering support. - // We should be able to count on this being in most desktop OpenGL implementations, - // but display a message if it is in fact not supported (e.g., Mesa) - if (strstr(cstring,"GL_EXT_texture_filter_anisotropic") == NULL) { - ERR("OpenGL warning: Anisotropic filtering not supported in underlying system OpenGL\n"); - } -} - -void GLEScontext::buildStrings(const char* baseVendor, - const char* baseRenderer, const char* baseVersion, const char* version) -{ - static const char VENDOR[] = {"Google ("}; - static const char RENDERER[] = {"Android Emulator OpenGL ES Translator ("}; - const size_t VENDOR_LEN = sizeof(VENDOR) - 1; - const size_t RENDERER_LEN = sizeof(RENDERER) - 1; - - // Sanitize the strings as some OpenGL implementations return NULL - // when asked the basic questions (this happened at least once on a client - // machine) - if (!baseVendor) { - baseVendor = "N/A"; - } - if (!baseRenderer) { - baseRenderer = "N/A"; - } - if (!baseVersion) { - baseVersion = "N/A"; - } - if (!version) { - version = "N/A"; - } - - size_t baseVendorLen = strlen(baseVendor); - s_glVendor.clear(); - s_glVendor.reserve(baseVendorLen + VENDOR_LEN + 1); - s_glVendor.append(VENDOR, VENDOR_LEN); - s_glVendor.append(baseVendor, baseVendorLen); - s_glVendor.append(")", 1); - - size_t baseRendererLen = strlen(baseRenderer); - s_glRenderer.clear(); - s_glRenderer.reserve(baseRendererLen + RENDERER_LEN + 1); - s_glRenderer.append(RENDERER, RENDERER_LEN); - s_glRenderer.append(baseRenderer, baseRendererLen); - s_glRenderer.append(")", 1); - - size_t baseVersionLen = strlen(baseVersion); - size_t versionLen = strlen(version); - s_glVersion.clear(); - s_glVersion.reserve(baseVersionLen + versionLen + 3); - s_glVersion.append(version, versionLen); - s_glVersion.append(" (", 2); - s_glVersion.append(baseVersion, baseVersionLen); - s_glVersion.append(")", 1); -} - -bool GLEScontext::isTextureUnitEnabled(GLenum unit) { - for (int i=0;i<NUM_TEXTURE_TARGETS;++i) { - if (m_texState[unit-GL_TEXTURE0][i].enabled) - return true; - } - return false; -} - -bool GLEScontext::glGetBooleanv(GLenum pname, GLboolean *params) -{ - GLint iParam; - - if(glGetIntegerv(pname, &iParam)) - { - *params = (iParam != 0); - return true; - } - - return false; -} - -bool GLEScontext::glGetFixedv(GLenum pname, GLfixed *params) -{ - bool result = false; - GLint numParams = 1; - - GLint* iParams = new GLint[numParams]; - if (numParams>0 && glGetIntegerv(pname,iParams)) { - while(numParams >= 0) - { - params[numParams] = I2X(iParams[numParams]); - numParams--; - } - result = true; - } - delete [] iParams; - - return result; -} - -bool GLEScontext::glGetFloatv(GLenum pname, GLfloat *params) -{ - bool result = false; - GLint numParams = 1; - - GLint* iParams = new GLint[numParams]; - if (numParams>0 && glGetIntegerv(pname,iParams)) { - while(numParams >= 0) - { - params[numParams] = (GLfloat)iParams[numParams]; - numParams--; - } - result = true; - } - delete [] iParams; - - return result; -} - -bool GLEScontext::glGetIntegerv(GLenum pname, GLint *params) -{ - switch(pname) - { - case GL_ARRAY_BUFFER_BINDING: - *params = m_arrayBuffer; - break; - - case GL_ELEMENT_ARRAY_BUFFER_BINDING: - *params = m_elementBuffer; - break; - - case GL_TEXTURE_BINDING_CUBE_MAP: - *params = m_texState[m_activeTexture][TEXTURE_CUBE_MAP].texture; - break; - - case GL_TEXTURE_BINDING_2D: - *params = m_texState[m_activeTexture][TEXTURE_2D].texture; - break; - - case GL_ACTIVE_TEXTURE: - *params = m_activeTexture+GL_TEXTURE0; - break; - - case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES: - *params = GL_UNSIGNED_BYTE; - break; - - case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES: - *params = GL_RGBA; - break; - - case GL_MAX_TEXTURE_SIZE: - *params = getMaxTexSize(); - break; - default: - return false; - } - - return true; -} - -TextureTarget GLEScontext::GLTextureTargetToLocal(GLenum target) { - TextureTarget value=TEXTURE_2D; - switch (target) { - case GL_TEXTURE_CUBE_MAP: - case GL_TEXTURE_CUBE_MAP_POSITIVE_X: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: - value = TEXTURE_CUBE_MAP; - break; - case GL_TEXTURE_2D: - value = TEXTURE_2D; - break; - } - return value; -} - -unsigned int GLEScontext::getBindedTexture(GLenum target) { - TextureTarget pos = GLTextureTargetToLocal(target); - return m_texState[m_activeTexture][pos].texture; -} - -unsigned int GLEScontext::getBindedTexture(GLenum unit, GLenum target) { - TextureTarget pos = GLTextureTargetToLocal(target); - return m_texState[unit-GL_TEXTURE0][pos].texture; -} - -void GLEScontext::setBindedTexture(GLenum target, unsigned int tex) { - TextureTarget pos = GLTextureTargetToLocal(target); - m_texState[m_activeTexture][pos].texture = tex; -} - -void GLEScontext::setTextureEnabled(GLenum target, GLenum enable) { - TextureTarget pos = GLTextureTargetToLocal(target); - m_texState[m_activeTexture][pos].enabled = enable; -} - -#define INTERNAL_NAME(x) (x +0x100000000ll); - -ObjectLocalName GLEScontext::getDefaultTextureName(GLenum target) { - ObjectLocalName name = 0; - switch (GLTextureTargetToLocal(target)) { - case TEXTURE_2D: - name = INTERNAL_NAME(0); - break; - case TEXTURE_CUBE_MAP: - name = INTERNAL_NAME(1); - break; - default: - name = 0; - break; - } - return name; -} - -void GLEScontext::drawValidate(void) -{ - if(m_framebuffer == 0) - return; - - ObjectDataPtr fbObj = m_shareGroup->getObjectData(FRAMEBUFFER,m_framebuffer); - if (fbObj.get() == NULL) - return; - - FramebufferData *fbData = (FramebufferData *)fbObj.get(); - - fbData->validate(this); -} diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/GLESpointer.cpp b/distrib/android-emugl/host/libs/Translator/GLcommon/GLESpointer.cpp deleted file mode 100644 index e861a9b5f..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/GLESpointer.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/GLESpointer.h> -#include <stdlib.h> - -GLESpointer::GLESpointer():m_size(4), - m_type(GL_FLOAT), - m_stride(0), - m_enabled(false), - m_normalize(false), - m_data(), - m_buffer(), - m_bufferName(0), - m_buffOffset(0), - m_isVBO(false){}; - - -GLenum GLESpointer:: getType() const { - return m_type; -} - -GLint GLESpointer::getSize() const { - return m_size; -} - -GLsizei GLESpointer::getStride() const { - return m_stride; -} - -const GLvoid* GLESpointer::getArrayData() const { - return m_data; -} - -GLvoid* GLESpointer::getBufferData() const { - return m_buffer ? static_cast<unsigned char*>(m_buffer->getData()) + m_buffOffset : NULL; -} - -const GLvoid* GLESpointer::getData() const{ - return m_isVBO ? getBufferData():getArrayData(); -} - -void GLESpointer::redirectPointerData(){ - m_data = getBufferData(); -} - -GLuint GLESpointer::getBufferName() const { - return m_bufferName; -} - -unsigned int GLESpointer::getBufferOffset() const { - - return m_buffOffset; -} - -bool GLESpointer::isEnable() const { - return m_enabled; -} - -bool GLESpointer::isNormalize() const { - return m_normalize; -} - -bool GLESpointer::isVBO() const { - return m_isVBO; -} - -void GLESpointer::enable(bool b) { - m_enabled = b; -} - -void GLESpointer::setArray(GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize) { - m_size = size; - m_type = type; - m_stride = stride; - m_data = data; - m_buffer = NULL; - m_bufferName = 0; - m_normalize = normalize; - m_isVBO = false; -} - -void GLESpointer::setBuffer(GLint size,GLenum type,GLsizei stride,GLESbuffer* buf,GLuint bufferName,int offset,bool normalize) { - m_size = size; - m_type = type; - m_stride = stride; - m_data = NULL; - m_buffer = buf; - m_bufferName = bufferName; - m_buffOffset = offset; - m_normalize = normalize; - m_isVBO = true; -} - -void GLESpointer::getBufferConversions(const RangeList& rl,RangeList& rlOut) { - m_buffer->getConversions(rl,rlOut); -} diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/GLESvalidate.cpp b/distrib/android-emugl/host/libs/Translator/GLcommon/GLESvalidate.cpp deleted file mode 100644 index 8e35978a6..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/GLESvalidate.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* -* Copyright 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/GLESvalidate.h> -#include <GLES/gl.h> -#include <GLES/glext.h> -#include <GLES2/gl2.h> -#include <GLES2/gl2ext.h> -#include <OpenglCodecCommon/ErrorLog.h> - - -bool GLESvalidate::textureEnum(GLenum e,unsigned int maxTex) { - return e >= GL_TEXTURE0 && e <= (GL_TEXTURE0 + maxTex); -} - -bool GLESvalidate::pixelType(GLEScontext * ctx, GLenum type) { - if ((ctx && ctx->getCaps()->GL_EXT_PACKED_DEPTH_STENCIL) && - (type == GL_UNSIGNED_INT_24_8_OES) ) - return true; - - if (ctx && - (ctx->getCaps()->GL_ARB_HALF_FLOAT_PIXEL || ctx->getCaps()->GL_NV_HALF_FLOAT) && - (type == GL_HALF_FLOAT_OES)) - return true; - - switch(type) { - case GL_UNSIGNED_BYTE: - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_FLOAT: - return true; - } - return false; -} - -bool GLESvalidate::pixelOp(GLenum format,GLenum type) { - switch(type) { - case GL_UNSIGNED_SHORT_4_4_4_4: - case GL_UNSIGNED_SHORT_5_5_5_1: - return format == GL_RGBA; - case GL_UNSIGNED_SHORT_5_6_5: - return format == GL_RGB; - } - return true; -} - -bool GLESvalidate::pixelFrmt(GLEScontext* ctx ,GLenum format) { - if (ctx && ctx->getCaps()->GL_EXT_TEXTURE_FORMAT_BGRA8888 && format == GL_BGRA_EXT) - return true; - if (ctx && ctx->getCaps()->GL_EXT_PACKED_DEPTH_STENCIL && format == GL_DEPTH_STENCIL_OES) - return true; - switch(format) { - case GL_ALPHA: - case GL_RGB: - case GL_RGBA: - case GL_LUMINANCE: - case GL_LUMINANCE_ALPHA: - return true; - } - return false; -} - -bool GLESvalidate::bufferTarget(GLenum target) { - return target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER; -} - -bool GLESvalidate::bufferUsage(GLenum usage) { - switch(usage) { - case GL_STREAM_DRAW: - case GL_STATIC_DRAW: - case GL_DYNAMIC_DRAW: - return true; - } - return false; -} - -bool GLESvalidate::bufferParam(GLenum param) { - return (param == GL_BUFFER_SIZE) || (param == GL_BUFFER_USAGE); -} - -bool GLESvalidate::drawMode(GLenum mode) { - switch(mode) { - case GL_POINTS: - case GL_LINE_STRIP: - case GL_LINE_LOOP: - case GL_LINES: - case GL_TRIANGLE_STRIP: - case GL_TRIANGLE_FAN: - case GL_TRIANGLES: - return true; - } - return false; -} - -bool GLESvalidate::drawType(GLenum mode) { - return mode == GL_UNSIGNED_BYTE || - mode == GL_UNSIGNED_SHORT || - mode == GL_UNSIGNED_INT; -} - -bool GLESvalidate::textureTarget(GLenum target) { - return target==GL_TEXTURE_2D || target==GL_TEXTURE_CUBE_MAP; -} - -bool GLESvalidate::textureTargetLimited(GLenum target) { - return target==GL_TEXTURE_2D; -} - -bool GLESvalidate::textureTargetEx(GLenum target) { - switch(target) { - case GL_TEXTURE_CUBE_MAP_POSITIVE_X_OES: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_OES: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_OES: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_OES: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_OES: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_OES: - case GL_TEXTURE_2D: - return true; - } - return false; -} - -bool GLESvalidate::blendEquationMode(GLenum mode){ - return mode == GL_FUNC_ADD || - mode == GL_FUNC_SUBTRACT || - mode == GL_FUNC_REVERSE_SUBTRACT; -} - -bool GLESvalidate::framebufferTarget(GLenum target){ - return target == GL_FRAMEBUFFER; -} - -bool GLESvalidate::framebufferAttachment(GLenum attachment){ - switch(attachment){ - case GL_COLOR_ATTACHMENT0: - case GL_DEPTH_ATTACHMENT: - case GL_STENCIL_ATTACHMENT: - return true; - } - return false; -} - -bool GLESvalidate::framebufferAttachmentParams(GLenum pname){ - switch(pname){ - case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: - case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: - case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: - case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: - return true; - } - return false; -} - -bool GLESvalidate::renderbufferTarget(GLenum target){ - return target == GL_RENDERBUFFER; -} - -bool GLESvalidate::renderbufferParams(GLenum pname){ - switch(pname){ - case GL_RENDERBUFFER_WIDTH: - case GL_RENDERBUFFER_HEIGHT: - case GL_RENDERBUFFER_INTERNAL_FORMAT: - case GL_RENDERBUFFER_RED_SIZE: - case GL_RENDERBUFFER_GREEN_SIZE: - case GL_RENDERBUFFER_BLUE_SIZE: - case GL_RENDERBUFFER_ALPHA_SIZE: - case GL_RENDERBUFFER_DEPTH_SIZE: - case GL_RENDERBUFFER_STENCIL_SIZE: - return true; - } - return false; -} - -bool GLESvalidate::texImgDim(GLsizei width,GLsizei height,int maxTexSize) { - - if( width < 0 || height < 0 || width > maxTexSize || height > maxTexSize) - return false; - return isPowerOf2(width) && isPowerOf2(height); -} - diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/GLutils.cpp b/distrib/android-emugl/host/libs/Translator/GLcommon/GLutils.cpp deleted file mode 100644 index 46e292c23..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/GLutils.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* -* 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; -} diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/PaletteTexture.cpp b/distrib/android-emugl/host/libs/Translator/GLcommon/PaletteTexture.cpp deleted file mode 100644 index c99ed072d..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/PaletteTexture.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* -* 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/PaletteTexture.h" -#include <stdio.h> - - - -struct Color -{ - Color(unsigned char r, unsigned char g,unsigned char b, unsigned char a):red(r),green(g),blue(b),alpha(a){}; - unsigned char red; - unsigned char green; - unsigned char blue; - unsigned char alpha; -}; - -void getPaletteInfo(GLenum internalFormat,unsigned int& indexSizeBits,unsigned int& colorSizeBytes,GLenum& colorFrmt) { - - colorFrmt = GL_RGB; - switch(internalFormat) - { - case GL_PALETTE4_RGB8_OES: - indexSizeBits = 4; - colorSizeBytes = 3; - break; - - case GL_PALETTE4_RGBA8_OES: - indexSizeBits = 4; - colorSizeBytes = 4; - colorFrmt = GL_RGBA; - break; - - case GL_PALETTE4_RGBA4_OES: - case GL_PALETTE4_RGB5_A1_OES: - colorFrmt = GL_RGBA; - /* fall-through */ - case GL_PALETTE4_R5_G6_B5_OES: - indexSizeBits = 4; - colorSizeBytes = 2; - break; - - case GL_PALETTE8_RGB8_OES: - indexSizeBits = 8; - colorSizeBytes = 3; - break; - - case GL_PALETTE8_RGBA8_OES: - indexSizeBits = 8; - colorSizeBytes = 4; - colorFrmt = GL_RGBA; - break; - - case GL_PALETTE8_RGBA4_OES: - case GL_PALETTE8_RGB5_A1_OES: - colorFrmt = GL_RGBA; - /* fall-through */ - case GL_PALETTE8_R5_G6_B5_OES: - indexSizeBits = 8; - colorSizeBytes = 2; - break; - } -} - - -Color paletteColor(const unsigned char* pallete,unsigned int index,GLenum format) -{ - short s; - switch(format) { - //RGB - case GL_PALETTE4_RGB8_OES: - case GL_PALETTE8_RGB8_OES: - return Color(pallete[index],pallete[index+1],pallete[index+2],0); - case GL_PALETTE8_R5_G6_B5_OES: - case GL_PALETTE4_R5_G6_B5_OES: - s = *((short *)(pallete+index)); - return Color((s >> 11)*255/31,((s >> 5) & 0x3f)*255/63 ,(s & 0x1f)*255/31,0); - - //RGBA - case GL_PALETTE4_RGBA8_OES: - case GL_PALETTE8_RGBA8_OES: - return Color(pallete[index],pallete[index+1],pallete[index+2],pallete[index+3]); - case GL_PALETTE4_RGBA4_OES: - case GL_PALETTE8_RGBA4_OES: - s = *((short *)(pallete+index)); - return Color(((s >> 12) & 0xf)*255/15,((s >> 8) & 0xf)*255/15,((s >> 4) & 0xf)*255/15 ,(s & 0xf)*255/15); - case GL_PALETTE4_RGB5_A1_OES: - case GL_PALETTE8_RGB5_A1_OES: - s = *((short *)(pallete+index)); - return Color(((s >> 11) & 0x1f)*255/31,((s >> 6) & 0x1f)*255/31,((s >> 1) & 0x1f)*255/31 ,(s & 0x1) * 255); - default: - return Color(255,255,255,255); - } -} - -unsigned char* uncompressTexture(GLenum internalformat,GLenum& formatOut,GLsizei width,GLsizei height,GLsizei imageSize, const GLvoid* data,GLint level) { - - unsigned int indexSizeBits; //the size of the color index in the pallete - unsigned int colorSizeBytes; //the size of each color cell in the pallete - - getPaletteInfo(internalformat,indexSizeBits,colorSizeBytes,formatOut); - if(!data) - { - return NULL; - } - - const unsigned char* palette = static_cast<const unsigned char *>(data); - - //the pallete positioned in the begininng of the data - // so we jump over it to get to the colos indices in the palette - - int nColors = 2 << (indexSizeBits -1); //2^indexSizeBits - int paletteSizeBytes = nColors*colorSizeBytes; - const unsigned char* imageIndices = palette + paletteSizeBytes; - - //jumping to the the correct mipmap level - for(int i=0;i<level;i++) { - imageIndices+= (width*height*indexSizeBits)/8; - width = width >> 1; - height = height >> 1; - } - - int colorSizeOut = (formatOut == GL_RGB? 3:4); - int nPixels = width*height; - unsigned char* pixelsOut = new unsigned char[nPixels*colorSizeOut]; - if(!pixelsOut) return NULL; - - int leftBytes = ((palette + imageSize) /* the end of data pointer*/ - - imageIndices); - int leftPixels = (leftBytes * 8 )/indexSizeBits; - - int maxIndices = (leftPixels < nPixels) ? leftPixels:nPixels; - - //filling the pixels array - for(int i =0 ; i < maxIndices ; i++) { - int paletteIndex = 0; - int indexOut = i*colorSizeOut; - if(indexSizeBits == 4) { - paletteIndex = (i%2) == 0 ? - imageIndices[i/2] >> 4: //upper bits - imageIndices[i/2] & 0xf; //lower bits - } else { - paletteIndex = imageIndices[i]; - } - - paletteIndex*=colorSizeBytes; - Color c = paletteColor(palette,paletteIndex,internalformat); - - pixelsOut[indexOut] = c.red; - pixelsOut[indexOut+1] = c.green; - pixelsOut[indexOut+2] = c.blue; - if(formatOut == GL_RGBA) { - pixelsOut[indexOut+3] = c.alpha; - } - } - return pixelsOut; -} - diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/RangeManip.cpp b/distrib/android-emugl/host/libs/Translator/GLcommon/RangeManip.cpp deleted file mode 100644 index 2d6f11932..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/RangeManip.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* -* 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/RangeManip.h> - - -bool Range::rangeIntersection(const Range& r,Range& rOut) const { - if(m_start > r.getEnd() || r.getStart() > m_end) return false; - int max_start = (m_start > r.getStart())? m_start:r.getStart(); - int min_end = (m_end < r.getEnd())?m_end:r.getEnd(); - int size = min_end - max_start; - if(size) { - rOut.setRange(max_start,min_end-max_start); - return true; - } - return false; -} - -bool Range::rangeUnion(const Range& r,Range& rOut) const { - if(m_start > r.getEnd() || r.getStart() > m_end) return false; - int min_start = (m_start < r.getStart())?m_start:r.getStart(); - int max_end = (m_end > r.getEnd())?m_end:r.getEnd(); - int size = max_end - min_start; - if(size) { - rOut.setRange(min_start,max_end-min_start); - return true; - } - return false; -} - -void RangeList::addRange(const Range& r) { - if(r.getSize()) - list.push_back(r); -} - -void RangeList::addRanges(const RangeList& rl) { - for(int i =0; i< rl.size();i++) { - addRange(rl.list[i]); - } -} - -void RangeList::delRanges(const RangeList& rl,RangeList& deleted) { - for(int i =0; i< rl.size();i++) { - delRange(rl.list[i],deleted); - } -} - -bool RangeList::empty() const{ - return list.empty(); -} - -int RangeList::size() const{ - return list.size(); -} -void RangeList::clear() { - return list.clear(); -} - -void RangeList::erase(unsigned int i) { - if(i > list.size()) return; - list.erase(list.begin() +i); -} - -void RangeList::delRange(const Range& r,RangeList& deleted) { - if(r.getSize() == 0) return; - - Range intersection; - Range temp; - // compare new rect to each and any of the rects on the list - for (int i=0;i<(int)list.size();i++) { // i must be signed for i-- below - // if there is intersection - if (r.rangeIntersection(list[i],intersection)) { - Range old=list[i]; - // remove old as it is about to be split - erase(i); - i--; - if (intersection!=old) { // otherwise split: - //intersection on right side - if(old.getStart() != intersection.getStart()) { - list.insert(list.begin(),Range(old.getStart(),intersection.getStart() - old.getStart())); - } - - //intersection on left side - if(old.getEnd() != intersection.getEnd()) { - list.insert(list.begin(),Range(intersection.getEnd(),old.getEnd() - intersection.getEnd())); - } - } - deleted.addRange(intersection); - } - } -} - -void RangeList::merge() { - if(list.empty()) return; - - Range temp; - bool changed; - - do { // re-run if changed in last run - changed=0; - // run for each combinations of two rects in the list - for (int i=0;i<(((int)list.size())-1) && !changed ;i++) - { - for (int j=i+1;j<(int)list.size() && !changed ;j++) - { - if (list[i].rangeUnion(list[j],temp)) { - // are them exactly one on left of the other - list[i] = temp; - erase(j); - changed=1; - } - } - } - } while (changed); -} diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/TextureUtils.cpp b/distrib/android-emugl/host/libs/Translator/GLcommon/TextureUtils.cpp deleted file mode 100644 index 81152f6a3..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/TextureUtils.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* -* 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/TextureUtils.h> -#include <GLcommon/GLESmacros.h> -#include <GLcommon/GLDispatch.h> -#include <GLcommon/GLESvalidate.h> -#include <stdio.h> -#include <cmath> - -int getCompressedFormats(int* formats){ - if(formats){ - //Palette - formats[0] = GL_PALETTE4_RGBA8_OES; - formats[1] = GL_PALETTE4_RGBA4_OES; - formats[2] = GL_PALETTE8_RGBA8_OES; - formats[3] = GL_PALETTE8_RGBA4_OES; - formats[4] = GL_PALETTE4_RGB8_OES; - formats[5] = GL_PALETTE8_RGB8_OES; - formats[6] = GL_PALETTE4_RGB5_A1_OES; - formats[7] = GL_PALETTE8_RGB5_A1_OES; - formats[8] = GL_PALETTE4_R5_G6_B5_OES; - formats[9] = GL_PALETTE8_R5_G6_B5_OES; - //ETC - formats[MAX_SUPPORTED_PALETTE] = GL_ETC1_RGB8_OES; - } - return MAX_SUPPORTED_PALETTE + MAX_ETC_SUPPORTED; -} - -void doCompressedTexImage2D(GLEScontext * ctx, GLenum target, GLint level, - GLenum internalformat, GLsizei width, - GLsizei height, GLint border, - GLsizei imageSize, const GLvoid* data, void * funcPtr) -{ - /* XXX: This is just a hack to fix the resolve of glTexImage2D problem - It will be removed when we'll no longer link against ligGL */ - typedef void (GLAPIENTRY *glTexImage2DPtr_t ) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); - glTexImage2DPtr_t glTexImage2DPtr; - glTexImage2DPtr = (glTexImage2DPtr_t)funcPtr; - - switch (internalformat) { - case GL_ETC1_RGB8_OES: - { - GLint format = GL_RGB; - GLint type = GL_UNSIGNED_BYTE; - - GLsizei compressedSize = etc1_get_encoded_data_size(width, height); - SET_ERROR_IF((compressedSize > imageSize), GL_INVALID_VALUE); - - const int32_t align = ctx->getUnpackAlignment()-1; - const int32_t bpr = ((width * 3) + align) & ~align; - const size_t size = bpr * height; - - etc1_byte* pOut = new etc1_byte[size]; - int res = etc1_decode_image((const etc1_byte*)data, pOut, width, height, 3, bpr); - SET_ERROR_IF(res!=0, GL_INVALID_VALUE); - glTexImage2DPtr(target,level,format,width,height,border,format,type,pOut); - delete [] pOut; - } - break; - - case GL_PALETTE4_RGB8_OES: - case GL_PALETTE4_RGBA8_OES: - case GL_PALETTE4_R5_G6_B5_OES: - case GL_PALETTE4_RGBA4_OES: - case GL_PALETTE4_RGB5_A1_OES: - case GL_PALETTE8_RGB8_OES: - case GL_PALETTE8_RGBA8_OES: - case GL_PALETTE8_R5_G6_B5_OES: - case GL_PALETTE8_RGBA4_OES: - case GL_PALETTE8_RGB5_A1_OES: - { - SET_ERROR_IF(level > log2(ctx->getMaxTexSize()) || - border !=0 || level > 0 || - !GLESvalidate::texImgDim(width,height,ctx->getMaxTexSize()+2),GL_INVALID_VALUE) - - int nMipmaps = -level + 1; - GLsizei tmpWidth = width; - GLsizei tmpHeight = height; - - for(int i = 0; i < nMipmaps ; i++) - { - GLenum uncompressedFrmt; - unsigned char* uncompressed = uncompressTexture(internalformat,uncompressedFrmt,width,height,imageSize,data,i); - glTexImage2DPtr(target,i,uncompressedFrmt,tmpWidth,tmpHeight,border,uncompressedFrmt,GL_UNSIGNED_BYTE,uncompressed); - tmpWidth/=2; - tmpHeight/=2; - delete[] uncompressed; - } - } - break; - - default: - SET_ERROR_IF(1, GL_INVALID_ENUM); - break; - } -} diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/etc1.cpp b/distrib/android-emugl/host/libs/Translator/GLcommon/etc1.cpp deleted file mode 100644 index 97d10851d..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/etc1.cpp +++ /dev/null @@ -1,670 +0,0 @@ -// Copyright 2009 Google Inc. -// -// 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 <ETC1/etc1.h> - -#include <string.h> - -/* From http://www.khronos.org/registry/gles/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt - - The number of bits that represent a 4x4 texel block is 64 bits if - <internalformat> is given by ETC1_RGB8_OES. - - The data for a block is a number of bytes, - - {q0, q1, q2, q3, q4, q5, q6, q7} - - where byte q0 is located at the lowest memory address and q7 at - the highest. The 64 bits specifying the block is then represented - by the following 64 bit integer: - - int64bit = 256*(256*(256*(256*(256*(256*(256*q0+q1)+q2)+q3)+q4)+q5)+q6)+q7; - - ETC1_RGB8_OES: - - a) bit layout in bits 63 through 32 if diffbit = 0 - - 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 - ----------------------------------------------- - | base col1 | base col2 | base col1 | base col2 | - | R1 (4bits)| R2 (4bits)| G1 (4bits)| G2 (4bits)| - ----------------------------------------------- - - 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 - --------------------------------------------------- - | base col1 | base col2 | table | table |diff|flip| - | B1 (4bits)| B2 (4bits)| cw 1 | cw 2 |bit |bit | - --------------------------------------------------- - - - b) bit layout in bits 63 through 32 if diffbit = 1 - - 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 - ----------------------------------------------- - | base col1 | dcol 2 | base col1 | dcol 2 | - | R1' (5 bits) | dR2 | G1' (5 bits) | dG2 | - ----------------------------------------------- - - 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 - --------------------------------------------------- - | base col 1 | dcol 2 | table | table |diff|flip| - | B1' (5 bits) | dB2 | cw 1 | cw 2 |bit |bit | - --------------------------------------------------- - - - c) bit layout in bits 31 through 0 (in both cases) - - 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 - ----------------------------------------------- - | most significant pixel index bits | - | p| o| n| m| l| k| j| i| h| g| f| e| d| c| b| a| - ----------------------------------------------- - - 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - -------------------------------------------------- - | least significant pixel index bits | - | p| o| n| m| l| k| j| i| h| g| f| e| d| c | b | a | - -------------------------------------------------- - - - Add table 3.17.2: Intensity modifier sets for ETC1 compressed textures: - - table codeword modifier table - ------------------ ---------------------- - 0 -8 -2 2 8 - 1 -17 -5 5 17 - 2 -29 -9 9 29 - 3 -42 -13 13 42 - 4 -60 -18 18 60 - 5 -80 -24 24 80 - 6 -106 -33 33 106 - 7 -183 -47 47 183 - - - Add table 3.17.3 Mapping from pixel index values to modifier values for - ETC1 compressed textures: - - pixel index value - --------------- - msb lsb resulting modifier value - ----- ----- ------------------------- - 1 1 -b (large negative value) - 1 0 -a (small negative value) - 0 0 a (small positive value) - 0 1 b (large positive value) - - - */ - -static const int kModifierTable[] = { -/* 0 */2, 8, -2, -8, -/* 1 */5, 17, -5, -17, -/* 2 */9, 29, -9, -29, -/* 3 */13, 42, -13, -42, -/* 4 */18, 60, -18, -60, -/* 5 */24, 80, -24, -80, -/* 6 */33, 106, -33, -106, -/* 7 */47, 183, -47, -183 }; - -static const int kLookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 }; - -static inline etc1_byte clamp(int x) { - return (etc1_byte) (x >= 0 ? (x < 255 ? x : 255) : 0); -} - -static -inline int convert4To8(int b) { - int c = b & 0xf; - return (c << 4) | c; -} - -static -inline int convert5To8(int b) { - int c = b & 0x1f; - return (c << 3) | (c >> 2); -} - -static -inline int convert6To8(int b) { - int c = b & 0x3f; - return (c << 2) | (c >> 4); -} - -static -inline int divideBy255(int d) { - return (d + 128 + (d >> 8)) >> 8; -} - -static -inline int convert8To4(int b) { - int c = b & 0xff; - return divideBy255(c * 15); -} - -static -inline int convert8To5(int b) { - int c = b & 0xff; - return divideBy255(c * 31); -} - -static -inline int convertDiff(int base, int diff) { - return convert5To8((0x1f & base) + kLookup[0x7 & diff]); -} - -static -void decode_subblock(etc1_byte* pOut, int r, int g, int b, const int* table, - etc1_uint32 low, bool second, bool flipped) { - int baseX = 0; - int baseY = 0; - if (second) { - if (flipped) { - baseY = 2; - } else { - baseX = 2; - } - } - for (int i = 0; i < 8; i++) { - int x, y; - if (flipped) { - x = baseX + (i >> 1); - y = baseY + (i & 1); - } else { - x = baseX + (i >> 2); - y = baseY + (i & 3); - } - int k = y + (x * 4); - int offset = ((low >> k) & 1) | ((low >> (k + 15)) & 2); - int delta = table[offset]; - etc1_byte* q = pOut + 3 * (x + 4 * y); - *q++ = clamp(r + delta); - *q++ = clamp(g + delta); - *q++ = clamp(b + delta); - } -} - -// Input is an ETC1 compressed version of the data. -// Output is a 4 x 4 square of 3-byte pixels in form R, G, B - -void etc1_decode_block(const etc1_byte* pIn, etc1_byte* pOut) { - etc1_uint32 high = (pIn[0] << 24) | (pIn[1] << 16) | (pIn[2] << 8) | pIn[3]; - etc1_uint32 low = (pIn[4] << 24) | (pIn[5] << 16) | (pIn[6] << 8) | pIn[7]; - int r1, r2, g1, g2, b1, b2; - if (high & 2) { - // differential - int rBase = high >> 27; - int gBase = high >> 19; - int bBase = high >> 11; - r1 = convert5To8(rBase); - r2 = convertDiff(rBase, high >> 24); - g1 = convert5To8(gBase); - g2 = convertDiff(gBase, high >> 16); - b1 = convert5To8(bBase); - b2 = convertDiff(bBase, high >> 8); - } else { - // not differential - r1 = convert4To8(high >> 28); - r2 = convert4To8(high >> 24); - g1 = convert4To8(high >> 20); - g2 = convert4To8(high >> 16); - b1 = convert4To8(high >> 12); - b2 = convert4To8(high >> 8); - } - int tableIndexA = 7 & (high >> 5); - int tableIndexB = 7 & (high >> 2); - const int* tableA = kModifierTable + tableIndexA * 4; - const int* tableB = kModifierTable + tableIndexB * 4; - bool flipped = (high & 1) != 0; - decode_subblock(pOut, r1, g1, b1, tableA, low, false, flipped); - decode_subblock(pOut, r2, g2, b2, tableB, low, true, flipped); -} - -typedef struct { - etc1_uint32 high; - etc1_uint32 low; - etc1_uint32 score; // Lower is more accurate -} etc_compressed; - -static -inline void take_best(etc_compressed* a, const etc_compressed* b) { - if (a->score > b->score) { - *a = *b; - } -} - -static -void etc_average_colors_subblock(const etc1_byte* pIn, etc1_uint32 inMask, - etc1_byte* pColors, bool flipped, bool second) { - int r = 0; - int g = 0; - int b = 0; - - if (flipped) { - int by = 0; - if (second) { - by = 2; - } - for (int y = 0; y < 2; y++) { - int yy = by + y; - for (int x = 0; x < 4; x++) { - int i = x + 4 * yy; - if (inMask & (1 << i)) { - const etc1_byte* p = pIn + i * 3; - r += *(p++); - g += *(p++); - b += *(p++); - } - } - } - } else { - int bx = 0; - if (second) { - bx = 2; - } - for (int y = 0; y < 4; y++) { - for (int x = 0; x < 2; x++) { - int xx = bx + x; - int i = xx + 4 * y; - if (inMask & (1 << i)) { - const etc1_byte* p = pIn + i * 3; - r += *(p++); - g += *(p++); - b += *(p++); - } - } - } - } - pColors[0] = (etc1_byte)((r + 4) >> 3); - pColors[1] = (etc1_byte)((g + 4) >> 3); - pColors[2] = (etc1_byte)((b + 4) >> 3); -} - -static -inline int square(int x) { - return x * x; -} - -static etc1_uint32 chooseModifier(const etc1_byte* pBaseColors, - const etc1_byte* pIn, etc1_uint32 *pLow, int bitIndex, - const int* pModifierTable) { - etc1_uint32 bestScore = ~0; - int bestIndex = 0; - int pixelR = pIn[0]; - int pixelG = pIn[1]; - int pixelB = pIn[2]; - int r = pBaseColors[0]; - int g = pBaseColors[1]; - int b = pBaseColors[2]; - for (int i = 0; i < 4; i++) { - int modifier = pModifierTable[i]; - int decodedG = clamp(g + modifier); - etc1_uint32 score = (etc1_uint32) (6 * square(decodedG - pixelG)); - if (score >= bestScore) { - continue; - } - int decodedR = clamp(r + modifier); - score += (etc1_uint32) (3 * square(decodedR - pixelR)); - if (score >= bestScore) { - continue; - } - int decodedB = clamp(b + modifier); - score += (etc1_uint32) square(decodedB - pixelB); - if (score < bestScore) { - bestScore = score; - bestIndex = i; - } - } - etc1_uint32 lowMask = (((bestIndex >> 1) << 16) | (bestIndex & 1)) - << bitIndex; - *pLow |= lowMask; - return bestScore; -} - -static -void etc_encode_subblock_helper(const etc1_byte* pIn, etc1_uint32 inMask, - etc_compressed* pCompressed, bool flipped, bool second, - const etc1_byte* pBaseColors, const int* pModifierTable) { - int score = pCompressed->score; - if (flipped) { - int by = 0; - if (second) { - by = 2; - } - for (int y = 0; y < 2; y++) { - int yy = by + y; - for (int x = 0; x < 4; x++) { - int i = x + 4 * yy; - if (inMask & (1 << i)) { - score += chooseModifier(pBaseColors, pIn + i * 3, - &pCompressed->low, yy + x * 4, pModifierTable); - } - } - } - } else { - int bx = 0; - if (second) { - bx = 2; - } - for (int y = 0; y < 4; y++) { - for (int x = 0; x < 2; x++) { - int xx = bx + x; - int i = xx + 4 * y; - if (inMask & (1 << i)) { - score += chooseModifier(pBaseColors, pIn + i * 3, - &pCompressed->low, y + xx * 4, pModifierTable); - } - } - } - } - pCompressed->score = score; -} - -static bool inRange4bitSigned(int color) { - return color >= -4 && color <= 3; -} - -static void etc_encodeBaseColors(etc1_byte* pBaseColors, - const etc1_byte* pColors, etc_compressed* pCompressed) { - int r1, g1, b1, r2, g2, b2; // 8 bit base colors for sub-blocks - bool differential; - { - int r51 = convert8To5(pColors[0]); - int g51 = convert8To5(pColors[1]); - int b51 = convert8To5(pColors[2]); - int r52 = convert8To5(pColors[3]); - int g52 = convert8To5(pColors[4]); - int b52 = convert8To5(pColors[5]); - - r1 = convert5To8(r51); - g1 = convert5To8(g51); - b1 = convert5To8(b51); - - int dr = r52 - r51; - int dg = g52 - g51; - int db = b52 - b51; - - differential = inRange4bitSigned(dr) && inRange4bitSigned(dg) - && inRange4bitSigned(db); - if (differential) { - r2 = convert5To8(r51 + dr); - g2 = convert5To8(g51 + dg); - b2 = convert5To8(b51 + db); - pCompressed->high |= (r51 << 27) | ((7 & dr) << 24) | (g51 << 19) - | ((7 & dg) << 16) | (b51 << 11) | ((7 & db) << 8) | 2; - } - } - - if (!differential) { - int r41 = convert8To4(pColors[0]); - int g41 = convert8To4(pColors[1]); - int b41 = convert8To4(pColors[2]); - int r42 = convert8To4(pColors[3]); - int g42 = convert8To4(pColors[4]); - int b42 = convert8To4(pColors[5]); - r1 = convert4To8(r41); - g1 = convert4To8(g41); - b1 = convert4To8(b41); - r2 = convert4To8(r42); - g2 = convert4To8(g42); - b2 = convert4To8(b42); - pCompressed->high |= (r41 << 28) | (r42 << 24) | (g41 << 20) | (g42 - << 16) | (b41 << 12) | (b42 << 8); - } - pBaseColors[0] = r1; - pBaseColors[1] = g1; - pBaseColors[2] = b1; - pBaseColors[3] = r2; - pBaseColors[4] = g2; - pBaseColors[5] = b2; -} - -static -void etc_encode_block_helper(const etc1_byte* pIn, etc1_uint32 inMask, - const etc1_byte* pColors, etc_compressed* pCompressed, bool flipped) { - pCompressed->score = ~0; - pCompressed->high = (flipped ? 1 : 0); - pCompressed->low = 0; - - etc1_byte pBaseColors[6]; - - etc_encodeBaseColors(pBaseColors, pColors, pCompressed); - - int originalHigh = pCompressed->high; - - const int* pModifierTable = kModifierTable; - for (int i = 0; i < 8; i++, pModifierTable += 4) { - etc_compressed temp; - temp.score = 0; - temp.high = originalHigh | (i << 5); - temp.low = 0; - etc_encode_subblock_helper(pIn, inMask, &temp, flipped, false, - pBaseColors, pModifierTable); - take_best(pCompressed, &temp); - } - pModifierTable = kModifierTable; - etc_compressed firstHalf = *pCompressed; - for (int i = 0; i < 8; i++, pModifierTable += 4) { - etc_compressed temp; - temp.score = firstHalf.score; - temp.high = firstHalf.high | (i << 2); - temp.low = firstHalf.low; - etc_encode_subblock_helper(pIn, inMask, &temp, flipped, true, - pBaseColors + 3, pModifierTable); - if (i == 0) { - *pCompressed = temp; - } else { - take_best(pCompressed, &temp); - } - } -} - -static void writeBigEndian(etc1_byte* pOut, etc1_uint32 d) { - pOut[0] = (etc1_byte)(d >> 24); - pOut[1] = (etc1_byte)(d >> 16); - pOut[2] = (etc1_byte)(d >> 8); - pOut[3] = (etc1_byte) d; -} - -// Input is a 4 x 4 square of 3-byte pixels in form R, G, B -// inmask is a 16-bit mask where bit (1 << (x + y * 4)) tells whether the corresponding (x,y) -// pixel is valid or not. Invalid pixel color values are ignored when compressing. -// Output is an ETC1 compressed version of the data. - -void etc1_encode_block(const etc1_byte* pIn, etc1_uint32 inMask, - etc1_byte* pOut) { - etc1_byte colors[6]; - etc1_byte flippedColors[6]; - etc_average_colors_subblock(pIn, inMask, colors, false, false); - etc_average_colors_subblock(pIn, inMask, colors + 3, false, true); - etc_average_colors_subblock(pIn, inMask, flippedColors, true, false); - etc_average_colors_subblock(pIn, inMask, flippedColors + 3, true, true); - - etc_compressed a, b; - etc_encode_block_helper(pIn, inMask, colors, &a, false); - etc_encode_block_helper(pIn, inMask, flippedColors, &b, true); - take_best(&a, &b); - writeBigEndian(pOut, a.high); - writeBigEndian(pOut + 4, a.low); -} - -// Return the size of the encoded image data (does not include size of PKM header). - -etc1_uint32 etc1_get_encoded_data_size(etc1_uint32 width, etc1_uint32 height) { - return (((width + 3) & ~3) * ((height + 3) & ~3)) >> 1; -} - -// Encode an entire image. -// pIn - pointer to the image data. Formatted such that the Red component of -// pixel (x,y) is at pIn + pixelSize * x + stride * y + redOffset; -// pOut - pointer to encoded data. Must be large enough to store entire encoded image. - -int etc1_encode_image(const etc1_byte* pIn, etc1_uint32 width, etc1_uint32 height, - etc1_uint32 pixelSize, etc1_uint32 stride, etc1_byte* pOut) { - if (pixelSize < 2 || pixelSize > 3) { - return -1; - } - static const unsigned short kYMask[] = { 0x0, 0xf, 0xff, 0xfff, 0xffff }; - static const unsigned short kXMask[] = { 0x0, 0x1111, 0x3333, 0x7777, - 0xffff }; - etc1_byte block[ETC1_DECODED_BLOCK_SIZE]; - etc1_byte encoded[ETC1_ENCODED_BLOCK_SIZE]; - - etc1_uint32 encodedWidth = (width + 3) & ~3; - etc1_uint32 encodedHeight = (height + 3) & ~3; - - for (etc1_uint32 y = 0; y < encodedHeight; y += 4) { - etc1_uint32 yEnd = height - y; - if (yEnd > 4) { - yEnd = 4; - } - int ymask = kYMask[yEnd]; - for (etc1_uint32 x = 0; x < encodedWidth; x += 4) { - etc1_uint32 xEnd = width - x; - if (xEnd > 4) { - xEnd = 4; - } - int mask = ymask & kXMask[xEnd]; - for (etc1_uint32 cy = 0; cy < yEnd; cy++) { - etc1_byte* q = block + (cy * 4) * 3; - const etc1_byte* p = pIn + pixelSize * x + stride * (y + cy); - if (pixelSize == 3) { - memcpy(q, p, xEnd * 3); - } else { - for (etc1_uint32 cx = 0; cx < xEnd; cx++) { - int pixel = (p[1] << 8) | p[0]; - *q++ = convert5To8(pixel >> 11); - *q++ = convert6To8(pixel >> 5); - *q++ = convert5To8(pixel); - p += pixelSize; - } - } - } - etc1_encode_block(block, mask, encoded); - memcpy(pOut, encoded, sizeof(encoded)); - pOut += sizeof(encoded); - } - } - return 0; -} - -// Decode an entire image. -// pIn - pointer to encoded data. -// pOut - pointer to the image data. Will be written such that the Red component of -// pixel (x,y) is at pIn + pixelSize * x + stride * y + redOffset. Must be -// large enough to store entire image. - - -int etc1_decode_image(const etc1_byte* pIn, etc1_byte* pOut, - etc1_uint32 width, etc1_uint32 height, - etc1_uint32 pixelSize, etc1_uint32 stride) { - if (pixelSize < 2 || pixelSize > 3) { - return -1; - } - etc1_byte block[ETC1_DECODED_BLOCK_SIZE]; - - etc1_uint32 encodedWidth = (width + 3) & ~3; - etc1_uint32 encodedHeight = (height + 3) & ~3; - - for (etc1_uint32 y = 0; y < encodedHeight; y += 4) { - etc1_uint32 yEnd = height - y; - if (yEnd > 4) { - yEnd = 4; - } - for (etc1_uint32 x = 0; x < encodedWidth; x += 4) { - etc1_uint32 xEnd = width - x; - if (xEnd > 4) { - xEnd = 4; - } - etc1_decode_block(pIn, block); - pIn += ETC1_ENCODED_BLOCK_SIZE; - for (etc1_uint32 cy = 0; cy < yEnd; cy++) { - const etc1_byte* q = block + (cy * 4) * 3; - etc1_byte* p = pOut + pixelSize * x + stride * (y + cy); - if (pixelSize == 3) { - memcpy(p, q, xEnd * 3); - } else { - for (etc1_uint32 cx = 0; cx < xEnd; cx++) { - etc1_byte r = *q++; - etc1_byte g = *q++; - etc1_byte b = *q++; - etc1_uint32 pixel = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3); - *p++ = (etc1_byte) pixel; - *p++ = (etc1_byte) (pixel >> 8); - } - } - } - } - } - return 0; -} - -static const char kMagic[] = { 'P', 'K', 'M', ' ', '1', '0' }; - -static const etc1_uint32 ETC1_PKM_FORMAT_OFFSET = 6; -static const etc1_uint32 ETC1_PKM_ENCODED_WIDTH_OFFSET = 8; -static const etc1_uint32 ETC1_PKM_ENCODED_HEIGHT_OFFSET = 10; -static const etc1_uint32 ETC1_PKM_WIDTH_OFFSET = 12; -static const etc1_uint32 ETC1_PKM_HEIGHT_OFFSET = 14; - -static const etc1_uint32 ETC1_RGB_NO_MIPMAPS = 0; - -static void writeBEUint16(etc1_byte* pOut, etc1_uint32 data) { - pOut[0] = (etc1_byte) (data >> 8); - pOut[1] = (etc1_byte) data; -} - -static etc1_uint32 readBEUint16(const etc1_byte* pIn) { - return (pIn[0] << 8) | pIn[1]; -} - -// Format a PKM header - -void etc1_pkm_format_header(etc1_byte* pHeader, etc1_uint32 width, etc1_uint32 height) { - memcpy(pHeader, kMagic, sizeof(kMagic)); - etc1_uint32 encodedWidth = (width + 3) & ~3; - etc1_uint32 encodedHeight = (height + 3) & ~3; - writeBEUint16(pHeader + ETC1_PKM_FORMAT_OFFSET, ETC1_RGB_NO_MIPMAPS); - writeBEUint16(pHeader + ETC1_PKM_ENCODED_WIDTH_OFFSET, encodedWidth); - writeBEUint16(pHeader + ETC1_PKM_ENCODED_HEIGHT_OFFSET, encodedHeight); - writeBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET, width); - writeBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET, height); -} - -// Check if a PKM header is correctly formatted. - -etc1_bool etc1_pkm_is_valid(const etc1_byte* pHeader) { - if (memcmp(pHeader, kMagic, sizeof(kMagic))) { - return false; - } - etc1_uint32 format = readBEUint16(pHeader + ETC1_PKM_FORMAT_OFFSET); - etc1_uint32 encodedWidth = readBEUint16(pHeader + ETC1_PKM_ENCODED_WIDTH_OFFSET); - etc1_uint32 encodedHeight = readBEUint16(pHeader + ETC1_PKM_ENCODED_HEIGHT_OFFSET); - etc1_uint32 width = readBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET); - etc1_uint32 height = readBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET); - return format == ETC1_RGB_NO_MIPMAPS && - encodedWidth >= width && encodedWidth - width < 4 && - encodedHeight >= height && encodedHeight - height < 4; -} - -// Read the image width from a PKM header - -etc1_uint32 etc1_pkm_get_width(const etc1_byte* pHeader) { - return readBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET); -} - -// Read the image height from a PKM header - -etc1_uint32 etc1_pkm_get_height(const etc1_byte* pHeader){ - return readBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET); -} diff --git a/distrib/android-emugl/host/libs/Translator/GLcommon/objectNameManager.cpp b/distrib/android-emugl/host/libs/Translator/GLcommon/objectNameManager.cpp deleted file mode 100644 index 0f67a420a..000000000 --- a/distrib/android-emugl/host/libs/Translator/GLcommon/objectNameManager.cpp +++ /dev/null @@ -1,379 +0,0 @@ -/* -* 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/objectNameManager.h> -#include <GLcommon/GLEScontext.h> - -#include <utility> - -namespace { -// A struct serving as a key in a hash table, represents an object name with -// object type together. -struct TypedObjectName { - ObjectLocalName name; - NamedObjectType type; - - TypedObjectName(NamedObjectType type, ObjectLocalName name) - : name(name), type(type) {} - - bool operator==(const TypedObjectName& other) const noexcept { - return name == other.name && type == other.type; - } -}; -} // namespace - -namespace std { -template <> -struct hash<TypedObjectName> { - size_t operator()(const TypedObjectName& tn) const noexcept { - return hash<int>()(tn.name) ^ - hash<ObjectLocalName>()(tn.type); - } -}; -} // namespace std - -using ObjectDataMap = std::unordered_map<TypedObjectName, ObjectDataPtr>; - -NameSpace::NameSpace(NamedObjectType p_type, - GlobalNameSpace *globalNameSpace) : - m_type(p_type), - m_globalNameSpace(globalNameSpace) {} - -NameSpace::~NameSpace() -{ - for (NamesMap::iterator n = m_localToGlobalMap.begin(); - n != m_localToGlobalMap.end(); - ++n) { - m_globalNameSpace->deleteName(m_type, (*n).second); - } -} - -ObjectLocalName -NameSpace::genName(ObjectLocalName p_localName, - bool genGlobal, bool genLocal) -{ - ObjectLocalName localName = p_localName; - if (genLocal) { - do { - localName = ++m_nextName; - } while(localName == 0 || - m_localToGlobalMap.find(localName) != - m_localToGlobalMap.end() ); - } - - if (genGlobal) { - unsigned int globalName = m_globalNameSpace->genName(m_type); - m_localToGlobalMap[localName] = globalName; - m_globalToLocalMap[globalName] = localName; - } - - return localName; -} - - -unsigned int -NameSpace::genGlobalName(void) -{ - return m_globalNameSpace->genName(m_type); -} - -unsigned int -NameSpace::getGlobalName(ObjectLocalName 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; -} - -ObjectLocalName -NameSpace::getLocalName(unsigned int p_globalName) -{ - const auto it = m_globalToLocalMap.find(p_globalName); - if (it != m_globalToLocalMap.end()) { - return it->second; - } - - return 0; -} - -void -NameSpace::deleteName(ObjectLocalName p_localName) -{ - NamesMap::iterator n( m_localToGlobalMap.find(p_localName) ); - if (n != m_localToGlobalMap.end()) { - m_globalNameSpace->deleteName(m_type, (*n).second); - m_globalToLocalMap.erase(n->second); - m_localToGlobalMap.erase(n); - } -} - -bool -NameSpace::isObject(ObjectLocalName p_localName) -{ - return (m_localToGlobalMap.find(p_localName) != m_localToGlobalMap.end() ); -} - -void -NameSpace::replaceGlobalName(ObjectLocalName p_localName, unsigned int p_globalName) -{ - NamesMap::iterator n( m_localToGlobalMap.find(p_localName) ); - if (n != m_localToGlobalMap.end()) { - m_globalNameSpace->deleteName(m_type, (*n).second); - m_globalToLocalMap.erase(n->second); - (*n).second = p_globalName; - m_globalToLocalMap.emplace(p_globalName, p_localName); - } -} - -unsigned int -GlobalNameSpace::genName(NamedObjectType p_type) -{ - if ( p_type >= NUM_OBJECT_TYPES ) return 0; - unsigned int name = 0; - - emugl::Mutex::AutoLock _lock(m_lock); - switch (p_type) { - case VERTEXBUFFER: - GLEScontext::dispatcher().glGenBuffers(1,&name); - break; - case TEXTURE: - GLEScontext::dispatcher().glGenTextures(1,&name); - break; - case RENDERBUFFER: - GLEScontext::dispatcher().glGenRenderbuffersEXT(1,&name); - break; - case FRAMEBUFFER: - GLEScontext::dispatcher().glGenFramebuffersEXT(1,&name); - break; - case SHADER: //objects in shader namepace are not handled - default: - name = 0; - } - return name; -} - -void -GlobalNameSpace::deleteName(NamedObjectType p_type, unsigned int p_name) -{ -} - -ShareGroup::ShareGroup(GlobalNameSpace *globalNameSpace) { - for (int i=0; i < NUM_OBJECT_TYPES; i++) { - m_nameSpace[i] = new NameSpace((NamedObjectType)i, globalNameSpace); - } -} - -ShareGroup::~ShareGroup() -{ - emugl::Mutex::AutoLock _lock(m_lock); - for (int t = 0; t < NUM_OBJECT_TYPES; t++) { - delete m_nameSpace[t]; - } - - delete (ObjectDataMap *)m_objectsData; -} - -ObjectLocalName -ShareGroup::genName(NamedObjectType p_type, - ObjectLocalName p_localName, - bool genLocal) -{ - if (p_type >= NUM_OBJECT_TYPES) return 0; - - emugl::Mutex::AutoLock _lock(m_lock); - ObjectLocalName localName = - m_nameSpace[p_type]->genName(p_localName, true, genLocal); - return localName; -} - -unsigned int -ShareGroup::genGlobalName(NamedObjectType p_type) -{ - if (p_type >= NUM_OBJECT_TYPES) return 0; - - emugl::Mutex::AutoLock _lock(m_lock); - return m_nameSpace[p_type]->genGlobalName(); -} - -unsigned int -ShareGroup::getGlobalName(NamedObjectType p_type, - ObjectLocalName p_localName) -{ - if (p_type >= NUM_OBJECT_TYPES) return 0; - - emugl::Mutex::AutoLock _lock(m_lock); - return m_nameSpace[p_type]->getGlobalName(p_localName); -} - -ObjectLocalName -ShareGroup::getLocalName(NamedObjectType p_type, - unsigned int p_globalName) -{ - if (p_type >= NUM_OBJECT_TYPES) return 0; - - emugl::Mutex::AutoLock _lock(m_lock); - return m_nameSpace[p_type]->getLocalName(p_globalName); -} - -void -ShareGroup::deleteName(NamedObjectType p_type, ObjectLocalName p_localName) -{ - if (p_type >= NUM_OBJECT_TYPES) return; - - emugl::Mutex::AutoLock _lock(m_lock); - m_nameSpace[p_type]->deleteName(p_localName); - ObjectDataMap *map = (ObjectDataMap *)m_objectsData; - if (map) { - map->erase(TypedObjectName(p_type, p_localName)); - } -} - -bool -ShareGroup::isObject(NamedObjectType p_type, ObjectLocalName p_localName) -{ - if (p_type >= NUM_OBJECT_TYPES) return 0; - - emugl::Mutex::AutoLock _lock(m_lock); - return m_nameSpace[p_type]->isObject(p_localName); -} - -void -ShareGroup::replaceGlobalName(NamedObjectType p_type, - ObjectLocalName p_localName, - unsigned int p_globalName) -{ - if (p_type >= NUM_OBJECT_TYPES) return; - - emugl::Mutex::AutoLock _lock(m_lock); - m_nameSpace[p_type]->replaceGlobalName(p_localName, p_globalName); -} - -void -ShareGroup::setObjectData(NamedObjectType p_type, - ObjectLocalName p_localName, - ObjectDataPtr data) -{ - if (p_type >= NUM_OBJECT_TYPES) return; - - emugl::Mutex::AutoLock _lock(m_lock); - - ObjectDataMap *map = (ObjectDataMap *)m_objectsData; - if (!map) { - map = new ObjectDataMap(); - m_objectsData = map; - } - - TypedObjectName id(p_type, p_localName); - map->emplace(id, std::move(data)); -} - -ObjectDataPtr -ShareGroup::getObjectData(NamedObjectType p_type, - ObjectLocalName p_localName) -{ - ObjectDataPtr ret; - - if (p_type >= NUM_OBJECT_TYPES) return ret; - - emugl::Mutex::AutoLock _lock(m_lock); - - ObjectDataMap *map = (ObjectDataMap *)m_objectsData; - if (map) { - ObjectDataMap::iterator i = - map->find(TypedObjectName(p_type, p_localName)); - if (i != map->end()) ret = (*i).second; - } - return ret; -} - -ObjectNameManager::ObjectNameManager(GlobalNameSpace *globalNameSpace) : - m_globalNameSpace(globalNameSpace) {} - -ShareGroupPtr -ObjectNameManager::createShareGroup(void *p_groupName) -{ - emugl::Mutex::AutoLock _lock(m_lock); - - 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_globalNameSpace)); - m_groups.emplace(p_groupName, shareGroupReturn); - } - - return shareGroupReturn; -} - -ShareGroupPtr -ObjectNameManager::getShareGroup(void *p_groupName) -{ - emugl::Mutex::AutoLock _lock(m_lock); - - ShareGroupPtr shareGroupReturn; - - ShareGroupsMap::iterator s( m_groups.find(p_groupName) ); - if (s != m_groups.end()) { - shareGroupReturn = (*s).second; - } - - return shareGroupReturn; -} - -ShareGroupPtr -ObjectNameManager::attachShareGroup(void *p_groupName, - void *p_existingGroupName) -{ - emugl::Mutex::AutoLock _lock(m_lock); - - ShareGroupsMap::iterator s( m_groups.find(p_existingGroupName) ); - if (s == m_groups.end()) { - // ShareGroup is not found !!! - return ShareGroupPtr(); - } - - ShareGroupPtr shareGroupReturn((*s).second); - if (m_groups.find(p_groupName) == m_groups.end()) { - m_groups.emplace(p_groupName, shareGroupReturn); - } - return shareGroupReturn; -} - -void -ObjectNameManager::deleteShareGroup(void *p_groupName) -{ - emugl::Mutex::AutoLock _lock(m_lock); - - ShareGroupsMap::iterator s( m_groups.find(p_groupName) ); - if (s != m_groups.end()) { - m_groups.erase(s); - } -} - -void *ObjectNameManager::getGlobalContext() -{ - emugl::Mutex::AutoLock _lock(m_lock); - return m_groups.empty() ? nullptr : m_groups.begin()->first; -} |