aboutsummaryrefslogtreecommitdiffstats
path: root/emulator/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'emulator/opengl')
-rw-r--r--emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp10
-rw-r--r--emulator/opengl/host/libs/Translator/EGL/MacNative.h1
-rw-r--r--emulator/opengl/host/libs/Translator/EGL/MacNative.m28
-rw-r--r--emulator/opengl/host/libs/Translator/GLcommon/RangeManip.cpp5
-rw-r--r--emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp23
-rw-r--r--emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp50
6 files changed, 92 insertions, 25 deletions
diff --git a/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp b/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp
index 31527af..eeaa25c 100644
--- a/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp
+++ b/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp
@@ -68,7 +68,15 @@ static EglConfig* pixelFormatToConfig(int index,int renderableType,EGLNativePixe
getPixelFormatAttrib(*frmt,MAC_SAMPLES_PER_PIXEL,&samples);
getPixelFormatAttrib(*frmt,MAC_COLOR_SIZE,&colorSize);
- getPixelFormatAttrib(*frmt,MAC_ALPHA_SIZE,&alpha);
+ /* All configs can end up having an alpha channel even if none was requested.
+ * The default config chooser in GLSurfaceView will therefore not find any
+ * matching config. Thus, make sure alpha is zero (or at least signalled as
+ * zero to the calling EGL layer) for the configs where it was intended to
+ * be zero. */
+ if (getPixelFormatDefinitionAlpha(index) == 0)
+ alpha = 0;
+ else
+ getPixelFormatAttrib(*frmt,MAC_ALPHA_SIZE,&alpha);
getPixelFormatAttrib(*frmt,MAC_DEPTH_SIZE,&depth);
getPixelFormatAttrib(*frmt,MAC_STENCIL_SIZE,&stencil);
diff --git a/emulator/opengl/host/libs/Translator/EGL/MacNative.h b/emulator/opengl/host/libs/Translator/EGL/MacNative.h
index 82ab667..c8a1df2 100644
--- a/emulator/opengl/host/libs/Translator/EGL/MacNative.h
+++ b/emulator/opengl/host/libs/Translator/EGL/MacNative.h
@@ -33,6 +33,7 @@ extern "C"{
int getNumPixelFormats();
void* getPixelFormat(int i);
+int getPixelFormatDefinitionAlpha(int i);
void getPixelFormatAttrib(void* pixelFormat,int attrib,int* val);
void* nsCreateContext(void* format,void* share);
void nsWindowMakeCurrent(void* context,void* nativeWin);
diff --git a/emulator/opengl/host/libs/Translator/EGL/MacNative.m b/emulator/opengl/host/libs/Translator/EGL/MacNative.m
index 6828655..a2cea93 100644
--- a/emulator/opengl/host/libs/Translator/EGL/MacNative.m
+++ b/emulator/opengl/host/libs/Translator/EGL/MacNative.m
@@ -75,6 +75,34 @@ void* getPixelFormat(int i){
return [[NSOpenGLPixelFormat alloc] initWithAttributes:attrib_lists[i]];
}
+int getPixelFormatDefinitionAlpha(int i) {
+ int size;
+ NSOpenGLPixelFormatAttribute** attrib_lists = getPixelFormatsAttributes(&size);
+ NSOpenGLPixelFormatAttribute* attribs = attrib_lists[i];
+ while (*attribs) {
+ switch (*attribs) {
+ // These are the ones that take a value, according to the current
+ // NSOpenGLPixelFormat docs
+ case NSOpenGLPFAAuxBuffers:
+ case NSOpenGLPFAColorSize:
+ case NSOpenGLPFADepthSize:
+ case NSOpenGLPFAStencilSize:
+ case NSOpenGLPFAAccumSize:
+ case NSOpenGLPFARendererID:
+ case NSOpenGLPFAScreenMask:
+ attribs += 2;
+ break;
+ case NSOpenGLPFAAlphaSize:
+ return attribs[1];
+ break;
+ // All other attributes are boolean attributes that don't take a value
+ default:
+ attribs++;
+ }
+ }
+ return 0;
+}
+
void getPixelFormatAttrib(void* pixelFormat,int attrib,int* val){
NSOpenGLPixelFormat *frmt = (NSOpenGLPixelFormat *)pixelFormat;
[frmt getValues:val forAttribute:attrib forVirtualScreen:0];
diff --git a/emulator/opengl/host/libs/Translator/GLcommon/RangeManip.cpp b/emulator/opengl/host/libs/Translator/GLcommon/RangeManip.cpp
index 5ba609b..2d6f119 100644
--- a/emulator/opengl/host/libs/Translator/GLcommon/RangeManip.cpp
+++ b/emulator/opengl/host/libs/Translator/GLcommon/RangeManip.cpp
@@ -35,13 +35,14 @@ bool Range::rangeUnion(const Range& r,Range& rOut) const {
int size = max_end - min_start;
if(size) {
rOut.setRange(min_start,max_end-min_start);
- return false;
+ return true;
}
return false;
}
void RangeList::addRange(const Range& r) {
- list.push_back(r);
+ if(r.getSize())
+ list.push_back(r);
}
void RangeList::addRanges(const RangeList& rl) {
diff --git a/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp b/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp
index 8609e09..cfadf12 100644
--- a/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp
+++ b/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
#include "FrameBuffer.h"
#include "NativeSubWindow.h"
#include "FBConfig.h"
@@ -20,14 +21,14 @@
#include "GLDispatch.h"
#include "GL2Dispatch.h"
#include "ThreadInfo.h"
-#include <stdio.h>
#include "TimeUtils.h"
+#include <stdio.h>
FrameBuffer *FrameBuffer::s_theFrameBuffer = NULL;
HandleType FrameBuffer::s_nextHandle = 0;
#ifdef WITH_GLES2
-static const char *getGLES2ExtensionString(EGLDisplay p_dpy)
+static char* getGLES2ExtensionString(EGLDisplay p_dpy)
{
EGLConfig config;
EGLSurface surface;
@@ -74,10 +75,9 @@ static const char *getGLES2ExtensionString(EGLDisplay p_dpy)
return NULL;
}
- const char *extString = (const char *)s_gl2.glGetString(GL_EXTENSIONS);
- if (!extString) {
- extString = "";
- }
+ // the string pointer may become invalid when the context is destroyed
+ const char* s = (const char*)s_gl2.glGetString(GL_EXTENSIONS);
+ char* extString = strdup(s ? s : "");
s_egl.eglMakeCurrent(p_dpy, NULL, NULL, NULL);
s_egl.eglDestroyContext(p_dpy, ctx);
@@ -153,7 +153,7 @@ bool FrameBuffer::initialize(int width, int height)
// if GLES2 plugin has loaded - try to make GLES2 context and
// get GLES2 extension string
//
- const char *gl2Extensions = NULL;
+ char* gl2Extensions = NULL;
#ifdef WITH_GLES2
if (fb->m_caps.hasGL2) {
gl2Extensions = getGLES2ExtensionString(fb->m_eglDisplay);
@@ -187,6 +187,7 @@ bool FrameBuffer::initialize(int width, int height)
if (!s_egl.eglChooseConfig(fb->m_eglDisplay, configAttribs,
&fb->m_eglConfig, 1, &n)) {
ERR("Failed on eglChooseConfig\n");
+ free(gl2Extensions);
delete fb;
return false;
}
@@ -201,6 +202,7 @@ bool FrameBuffer::initialize(int width, int height)
glContextAttribs);
if (fb->m_eglContext == EGL_NO_CONTEXT) {
printf("Failed to create Context 0x%x\n", s_egl.eglGetError());
+ free(gl2Extensions);
delete fb;
return false;
}
@@ -218,6 +220,7 @@ bool FrameBuffer::initialize(int width, int height)
glContextAttribs);
if (fb->m_pbufContext == EGL_NO_CONTEXT) {
printf("Failed to create Pbuffer Context 0x%x\n", s_egl.eglGetError());
+ free(gl2Extensions);
delete fb;
return false;
}
@@ -238,6 +241,7 @@ bool FrameBuffer::initialize(int width, int height)
pbufAttribs);
if (fb->m_pbufSurface == EGL_NO_SURFACE) {
printf("Failed to create pbuf surface for FB 0x%x\n", s_egl.eglGetError());
+ free(gl2Extensions);
delete fb;
return false;
}
@@ -245,6 +249,7 @@ bool FrameBuffer::initialize(int width, int height)
// Make the context current
if (!fb->bind_locked()) {
ERR("Failed to make current\n");
+ free(gl2Extensions);
delete fb;
return false;
}
@@ -259,8 +264,10 @@ bool FrameBuffer::initialize(int width, int height)
}
if (fb->m_caps.hasGL2 && has_gl_oes_image) {
- has_gl_oes_image &= (strstr(gl2Extensions, "GL_OES_EGL_image") != NULL);
+ has_gl_oes_image &= strstr(gl2Extensions, "GL_OES_EGL_image") != NULL;
}
+ free(gl2Extensions);
+ gl2Extensions = NULL;
const char *eglExtensions = s_egl.eglQueryString(fb->m_eglDisplay,
EGL_EXTENSIONS);
diff --git a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp
index 8504f7f..c7da37a 100644
--- a/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp
+++ b/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp
@@ -16,10 +16,19 @@
#include "GLSharedGroup.h"
+/**** KeyedVector utilities ****/
+
+template <typename T>
+static void clearObjectMap(android::DefaultKeyedVector<GLuint, T>& v) {
+ for (size_t i = 0; i < v.size(); i++)
+ delete v.valueAt(i);
+ v.clear();
+}
+
/**** BufferData ****/
BufferData::BufferData() : m_size(0) {};
-BufferData::BufferData(GLsizeiptr size, void * data) : m_size(size)
+BufferData::BufferData(GLsizeiptr size, void * data) : m_size(size)
{
void * buffer = NULL;
if (size>0) buffer = m_fixedBuffer.alloc(size);
@@ -55,7 +64,7 @@ ProgramData::~ProgramData()
}
void ProgramData::setIndexInfo(GLuint index, GLint base, GLint size, GLenum type)
-{
+{
if (index>=m_numIndexes)
return;
m_Indexes[index].base = base;
@@ -87,7 +96,7 @@ GLuint ProgramData::getIndexForLocation(GLint location)
for (GLuint i=0;i<m_numIndexes;++i)
{
GLint dist = location - m_Indexes[i].base;
- if (dist >= 0 &&
+ if (dist >= 0 &&
(minDist < 0 || dist < minDist)) {
index = i;
minDist = dist;
@@ -126,7 +135,7 @@ GLint ProgramData::locationWARHostToApp(GLint hostLoc, GLint arrIndex)
GLuint index = getIndexForLocation(hostLoc);
if (index<m_numIndexes) {
if (arrIndex > 0) {
- m_Indexes[index].hostLocsPerElement =
+ m_Indexes[index].hostLocsPerElement =
(hostLoc - m_Indexes[index].base) / arrIndex;
}
return m_Indexes[index].appBase + arrIndex;
@@ -226,12 +235,15 @@ GLSharedGroup::~GLSharedGroup()
{
m_buffers.clear();
m_programs.clear();
+ clearObjectMap(m_buffers);
+ clearObjectMap(m_programs);
+ clearObjectMap(m_shaders);
}
BufferData * GLSharedGroup::getBufferData(GLuint bufferId)
{
android::AutoMutex _lock(m_lock);
- return m_buffers.valueFor(bufferId);
+ return m_buffers.valueFor(bufferId);
}
void GLSharedGroup::addBufferData(GLuint bufferId, GLsizeiptr size, void * data)
@@ -243,32 +255,42 @@ void GLSharedGroup::addBufferData(GLuint bufferId, GLsizeiptr size, void * data)
void GLSharedGroup::updateBufferData(GLuint bufferId, GLsizeiptr size, void * data)
{
android::AutoMutex _lock(m_lock);
- m_buffers.replaceValueFor(bufferId, new BufferData(size, data));
+ ssize_t idx = m_buffers.indexOfKey(bufferId);
+ if (idx >= 0) {
+ delete m_buffers.valueAt(idx);
+ m_buffers.editValueAt(idx) = new BufferData(size, data);
+ } else {
+ m_buffers.add(bufferId, new BufferData(size, data));
+ }
}
GLenum GLSharedGroup::subUpdateBufferData(GLuint bufferId, GLintptr offset, GLsizeiptr size, void * data)
{
android::AutoMutex _lock(m_lock);
BufferData * buf = m_buffers.valueFor(bufferId);
- if ((!buf) || (buf->m_size < offset+size) || (offset < 0) || (size<0)) return GL_INVALID_VALUE;
+ if ((!buf) || (buf->m_size < offset+size) || (offset < 0) || (size<0)) return GL_INVALID_VALUE;
//it's safe to update now
memcpy((char*)buf->m_fixedBuffer.ptr() + offset, data, size);
- return GL_NO_ERROR;
+ return GL_NO_ERROR;
}
void GLSharedGroup::deleteBufferData(GLuint bufferId)
{
android::AutoMutex _lock(m_lock);
- m_buffers.removeItem(bufferId);
+ ssize_t idx = m_buffers.indexOfKey(bufferId);
+ if (idx >= 0) {
+ delete m_buffers.valueAt(idx);
+ m_buffers.removeItemsAt(idx);
+ }
}
void GLSharedGroup::addProgramData(GLuint program)
{
android::AutoMutex _lock(m_lock);
ProgramData *pData = m_programs.valueFor(program);
- if (pData)
- {
+ if (pData)
+ {
m_programs.removeItem(program);
delete pData;
}
@@ -290,7 +312,7 @@ bool GLSharedGroup::isProgramInitialized(GLuint program)
{
android::AutoMutex _lock(m_lock);
ProgramData* pData = m_programs.valueFor(program);
- if (pData)
+ if (pData)
{
return pData->isInitialized();
}
@@ -303,7 +325,7 @@ void GLSharedGroup::deleteProgramData(GLuint program)
ProgramData *pData = m_programs.valueFor(program);
if (pData)
delete pData;
- m_programs.removeItem(program);
+ m_programs.removeItem(program);
}
void GLSharedGroup::attachShader(GLuint program, GLuint shader)
@@ -363,7 +385,7 @@ GLenum GLSharedGroup::getProgramUniformType(GLuint program, GLint location)
android::AutoMutex _lock(m_lock);
ProgramData* pData = m_programs.valueFor(program);
GLenum type=0;
- if (pData)
+ if (pData)
{
type = pData->getTypeForLocation(location);
}