summaryrefslogtreecommitdiffstats
path: root/opengl/libs/GLES2_dbg
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2011-05-13 16:21:08 -0700
committerMathias Agopian <mathias@google.com>2011-05-16 19:02:45 -0700
commit7adf4ef0fad9973d9a07f2a73b2c4238c8e6bf7c (patch)
tree4c28764f141b482a42f152531e4920284a45f643 /opengl/libs/GLES2_dbg
parent90bf262591a1772d06a18581c11a6115b89fc143 (diff)
downloadframeworks_base-7adf4ef0fad9973d9a07f2a73b2c4238c8e6bf7c.zip
frameworks_base-7adf4ef0fad9973d9a07f2a73b2c4238c8e6bf7c.tar.gz
frameworks_base-7adf4ef0fad9973d9a07f2a73b2c4238c8e6bf7c.tar.bz2
refactor EGL source code
no changes is functionality. split various objects into their own files. make egl_display objec's lock internal.
Diffstat (limited to 'opengl/libs/GLES2_dbg')
-rw-r--r--opengl/libs/GLES2_dbg/src/dbgcontext.cpp34
-rw-r--r--opengl/libs/GLES2_dbg/test/test_server.cpp30
-rw-r--r--opengl/libs/GLES2_dbg/test/test_socket.cpp34
3 files changed, 43 insertions, 55 deletions
diff --git a/opengl/libs/GLES2_dbg/src/dbgcontext.cpp b/opengl/libs/GLES2_dbg/src/dbgcontext.cpp
index 7f5b27b..ff9be3c 100644
--- a/opengl/libs/GLES2_dbg/src/dbgcontext.cpp
+++ b/opengl/libs/GLES2_dbg/src/dbgcontext.cpp
@@ -15,22 +15,18 @@
*/
#include "header.h"
-#include "egl_tls.h"
-extern "C"
-{
+extern "C" {
#include "liblzf/lzf.h"
}
-namespace android
-{
+namespace android {
-pthread_key_t dbgEGLThreadLocalStorageKey = -1;
+static pthread_key_t dbgEGLThreadLocalStorageKey = -1;
+static pthread_mutex_t gThreadLocalStorageKeyMutex = PTHREAD_MUTEX_INITIALIZER;
-DbgContext * getDbgContextThreadSpecific()
-{
- tls_t* tls = (tls_t*)pthread_getspecific(dbgEGLThreadLocalStorageKey);
- return tls->dbg;
+DbgContext * getDbgContextThreadSpecific() {
+ return (DbgContext*)pthread_getspecific(dbgEGLThreadLocalStorageKey);
}
DbgContext::DbgContext(const unsigned version, const gl_hooks_t * const hooks,
@@ -60,10 +56,13 @@ DbgContext::~DbgContext()
free(lzf_ref[1]);
}
-DbgContext * CreateDbgContext(const pthread_key_t EGLThreadLocalStorageKey,
- const unsigned version, const gl_hooks_t * const hooks)
+DbgContext* CreateDbgContext(const unsigned version, const gl_hooks_t * const hooks)
{
- dbgEGLThreadLocalStorageKey = EGLThreadLocalStorageKey;
+ pthread_mutex_lock(&gThreadLocalStorageKeyMutex);
+ if (dbgEGLThreadLocalStorageKey == -1)
+ pthread_key_create(&dbgEGLThreadLocalStorageKey, NULL);
+ pthread_mutex_unlock(&gThreadLocalStorageKeyMutex);
+
assert(version < 2);
assert(GL_NO_ERROR == hooks->gl.glGetError());
GLint MAX_VERTEX_ATTRIBS = 0;
@@ -71,7 +70,7 @@ DbgContext * CreateDbgContext(const pthread_key_t EGLThreadLocalStorageKey,
GLint readFormat, readType;
hooks->gl.glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &readFormat);
hooks->gl.glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &readType);
- DbgContext * const dbg = new DbgContext(version, hooks, MAX_VERTEX_ATTRIBS, readFormat, readType);
+ DbgContext* dbg = new DbgContext(version, hooks, MAX_VERTEX_ATTRIBS, readFormat, readType);
glesv2debugger::Message msg, cmd;
msg.set_context_id(reinterpret_cast<int>(dbg));
@@ -88,12 +87,13 @@ DbgContext * CreateDbgContext(const pthread_key_t EGLThreadLocalStorageKey,
msg.set_arg0(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS);
msg.set_arg1(MAX_COMBINED_TEXTURE_IMAGE_UNITS);
Send(msg, cmd);
+
+ *(DbgContext **)pthread_getspecific(dbgEGLThreadLocalStorageKey) = dbg;
return dbg;
}
-void DestroyDbgContext(DbgContext * const dbg)
-{
- delete dbg;
+void dbgReleaseThread() {
+ delete getDbgContextThreadSpecific();
}
unsigned GetBytesPerPixel(const GLenum format, const GLenum type)
diff --git a/opengl/libs/GLES2_dbg/test/test_server.cpp b/opengl/libs/GLES2_dbg/test/test_server.cpp
index b6401e0..bbbe913 100644
--- a/opengl/libs/GLES2_dbg/test/test_server.cpp
+++ b/opengl/libs/GLES2_dbg/test/test_server.cpp
@@ -16,14 +16,12 @@
#include "header.h"
#include "gtest/gtest.h"
-#include "egl_tls.h"
#include "hooks.h"
namespace android
{
extern FILE * file;
extern unsigned int MAX_FILE_SIZE;
-extern pthread_key_t dbgEGLThreadLocalStorageKey;
};
// tmpfile fails, so need to manually make a writable file first
@@ -114,7 +112,7 @@ TEST_F(ServerFileTest, CreateDbgContext)
};
hooks.gl.glGetError = HookMock::GetError;
hooks.gl.glGetIntegerv = HookMock::GetIntegerv;
- DbgContext * const dbg = CreateDbgContext(-1, 1, &hooks);
+ DbgContext * const dbg = CreateDbgContext(1, &hooks);
ASSERT_TRUE(dbg != NULL);
EXPECT_TRUE(dbg->vertexAttribs != NULL);
@@ -132,7 +130,7 @@ TEST_F(ServerFileTest, CreateDbgContext)
EXPECT_EQ(expectedConstant, read.arg1());
}
CheckNoAvailable();
- DestroyDbgContext(dbg);
+ dbgReleaseThread();
}
void * glNoop()
@@ -143,7 +141,7 @@ void * glNoop()
class ServerFileContextTest : public ServerFileTest
{
protected:
- tls_t tls;
+ DbgContext* dbg;
gl_hooks_t hooks;
ServerFileContextTest() { }
@@ -153,12 +151,8 @@ protected:
virtual void SetUp() {
ServerFileTest::SetUp();
- if (dbgEGLThreadLocalStorageKey == -1)
- pthread_key_create(&dbgEGLThreadLocalStorageKey, NULL);
- ASSERT_NE(-1, dbgEGLThreadLocalStorageKey);
- tls.dbg = new DbgContext(1, &hooks, 32, GL_RGBA, GL_UNSIGNED_BYTE);
- ASSERT_NE((void *)NULL, tls.dbg);
- pthread_setspecific(dbgEGLThreadLocalStorageKey, &tls);
+ dbg = new DbgContext(1, &hooks, 32, GL_RGBA, GL_UNSIGNED_BYTE);
+ ASSERT_NE((void *)NULL, dbg);
for (unsigned int i = 0; i < sizeof(hooks) / sizeof(void *); i++)
((void **)&hooks)[i] = reinterpret_cast<void *>(glNoop);
}
@@ -183,7 +177,7 @@ TEST_F(ServerFileContextTest, MessageLoop)
return ret;
}
} caller;
- const int contextId = reinterpret_cast<int>(tls.dbg);
+ const int contextId = reinterpret_cast<int>(dbg);
glesv2debugger::Message msg, read;
EXPECT_EQ(ret, MessageLoop(caller, msg, msg.glFinish));
@@ -214,25 +208,25 @@ TEST_F(ServerFileContextTest, MessageLoop)
TEST_F(ServerFileContextTest, DisableEnableVertexAttribArray)
{
- Debug_glEnableVertexAttribArray(tls.dbg->MAX_VERTEX_ATTRIBS + 2); // should just ignore invalid index
+ Debug_glEnableVertexAttribArray(dbg->MAX_VERTEX_ATTRIBS + 2); // should just ignore invalid index
glesv2debugger::Message read;
rewind(file);
Read(read);
EXPECT_EQ(read.glEnableVertexAttribArray, read.function());
- EXPECT_EQ(tls.dbg->MAX_VERTEX_ATTRIBS + 2, read.arg0());
+ EXPECT_EQ(dbg->MAX_VERTEX_ATTRIBS + 2, read.arg0());
Read(read);
rewind(file);
- Debug_glDisableVertexAttribArray(tls.dbg->MAX_VERTEX_ATTRIBS + 4); // should just ignore invalid index
+ Debug_glDisableVertexAttribArray(dbg->MAX_VERTEX_ATTRIBS + 4); // should just ignore invalid index
rewind(file);
Read(read);
Read(read);
- for (unsigned int i = 0; i < tls.dbg->MAX_VERTEX_ATTRIBS; i += 5) {
+ for (unsigned int i = 0; i < dbg->MAX_VERTEX_ATTRIBS; i += 5) {
rewind(file);
Debug_glEnableVertexAttribArray(i);
- EXPECT_TRUE(tls.dbg->vertexAttribs[i].enabled);
+ EXPECT_TRUE(dbg->vertexAttribs[i].enabled);
rewind(file);
Read(read);
EXPECT_EQ(read.glEnableVertexAttribArray, read.function());
@@ -241,7 +235,7 @@ TEST_F(ServerFileContextTest, DisableEnableVertexAttribArray)
rewind(file);
Debug_glDisableVertexAttribArray(i);
- EXPECT_FALSE(tls.dbg->vertexAttribs[i].enabled);
+ EXPECT_FALSE(dbg->vertexAttribs[i].enabled);
rewind(file);
Read(read);
EXPECT_EQ(read.glDisableVertexAttribArray, read.function());
diff --git a/opengl/libs/GLES2_dbg/test/test_socket.cpp b/opengl/libs/GLES2_dbg/test/test_socket.cpp
index 617292e..b2148ac 100644
--- a/opengl/libs/GLES2_dbg/test/test_socket.cpp
+++ b/opengl/libs/GLES2_dbg/test/test_socket.cpp
@@ -19,13 +19,11 @@
#include "header.h"
#include "gtest/gtest.h"
-#include "egl_tls.h"
#include "hooks.h"
namespace android
{
extern int serverSock, clientSock;
-extern pthread_key_t dbgEGLThreadLocalStorageKey;
};
void * glNoop();
@@ -33,7 +31,7 @@ void * glNoop();
class SocketContextTest : public ::testing::Test
{
protected:
- tls_t tls;
+ DbgContext* dbg;
gl_hooks_t hooks;
int sock;
char * buffer;
@@ -46,12 +44,8 @@ protected:
}
virtual void SetUp() {
- if (dbgEGLThreadLocalStorageKey == -1)
- pthread_key_create(&dbgEGLThreadLocalStorageKey, NULL);
- ASSERT_NE(-1, dbgEGLThreadLocalStorageKey);
- tls.dbg = new DbgContext(1, &hooks, 32, GL_RGBA, GL_UNSIGNED_BYTE);
- ASSERT_TRUE(tls.dbg != NULL);
- pthread_setspecific(dbgEGLThreadLocalStorageKey, &tls);
+ dbg = new DbgContext(1, &hooks, 32, GL_RGBA, GL_UNSIGNED_BYTE);
+ ASSERT_TRUE(dbg != NULL);
for (unsigned int i = 0; i < sizeof(hooks) / sizeof(void *); i++)
((void **)&hooks)[i] = (void *)glNoop;
@@ -73,7 +67,7 @@ protected:
}
void Write(glesv2debugger::Message & msg) const {
- msg.set_context_id((int)tls.dbg);
+ msg.set_context_id((int)dbg);
msg.set_type(msg.Response);
ASSERT_TRUE(msg.has_context_id());
ASSERT_TRUE(msg.has_function());
@@ -129,7 +123,7 @@ TEST_F(SocketContextTest, MessageLoopSkip)
}
} caller;
glesv2debugger::Message msg, read, cmd;
- tls.dbg->expectResponse.Bit(msg.glFinish, true);
+ dbg->expectResponse.Bit(msg.glFinish, true);
cmd.set_function(cmd.SKIP);
cmd.set_expect_response(false);
@@ -158,7 +152,7 @@ TEST_F(SocketContextTest, MessageLoopContinue)
}
} caller;
glesv2debugger::Message msg, read, cmd;
- tls.dbg->expectResponse.Bit(msg.glCreateShader, true);
+ dbg->expectResponse.Bit(msg.glCreateShader, true);
cmd.set_function(cmd.CONTINUE);
cmd.set_expect_response(false); // MessageLoop should automatically skip after continue
@@ -204,7 +198,7 @@ TEST_F(SocketContextTest, MessageLoopGenerateCall)
glesv2debugger::Message msg, read, cmd;
hooks.gl.glCreateShader = caller.CreateShader;
hooks.gl.glCreateProgram = caller.CreateProgram;
- tls.dbg->expectResponse.Bit(msg.glCreateProgram, true);
+ dbg->expectResponse.Bit(msg.glCreateProgram, true);
cmd.set_function(cmd.glCreateShader);
cmd.set_arg0(GL_FRAGMENT_SHADER);
@@ -272,7 +266,7 @@ TEST_F(SocketContextTest, MessageLoopSetProp)
glesv2debugger::Message msg, read, cmd;
hooks.gl.glCreateShader = caller.CreateShader;
hooks.gl.glCreateProgram = caller.CreateProgram;
- tls.dbg->expectResponse.Bit(msg.glCreateProgram, false);
+ dbg->expectResponse.Bit(msg.glCreateProgram, false);
cmd.set_function(cmd.SETPROP);
cmd.set_prop(cmd.ExpectResponse);
@@ -305,8 +299,8 @@ TEST_F(SocketContextTest, MessageLoopSetProp)
EXPECT_EQ((int *)ret, MessageLoop(caller, msg, msg.glCreateProgram));
- EXPECT_TRUE(tls.dbg->expectResponse.Bit(msg.glCreateProgram));
- EXPECT_EQ(819, tls.dbg->captureDraw);
+ EXPECT_TRUE(dbg->expectResponse.Bit(msg.glCreateProgram));
+ EXPECT_EQ(819, dbg->captureDraw);
Read(read);
EXPECT_EQ(read.glCreateProgram, read.function());
@@ -362,7 +356,7 @@ TEST_F(SocketContextTest, TexImage2D)
} caller;
glesv2debugger::Message msg, read, cmd;
hooks.gl.glTexImage2D = caller.TexImage2D;
- tls.dbg->expectResponse.Bit(msg.glTexImage2D, false);
+ dbg->expectResponse.Bit(msg.glTexImage2D, false);
Debug_glTexImage2D(_target, _level, _internalformat, _width, _height, _border,
_format, _type, _pixels);
@@ -382,7 +376,7 @@ TEST_F(SocketContextTest, TexImage2D)
EXPECT_TRUE(read.has_data());
uint32_t dataLen = 0;
- const unsigned char * data = tls.dbg->Decompress(read.data().data(),
+ const unsigned char * data = dbg->Decompress(read.data().data(),
read.data().length(), &dataLen);
EXPECT_EQ(sizeof(_pixels), dataLen);
if (sizeof(_pixels) == dataLen)
@@ -435,7 +429,7 @@ TEST_F(SocketContextTest, CopyTexImage2D)
glesv2debugger::Message msg, read, cmd;
hooks.gl.glCopyTexImage2D = caller.CopyTexImage2D;
hooks.gl.glReadPixels = caller.ReadPixels;
- tls.dbg->expectResponse.Bit(msg.glCopyTexImage2D, false);
+ dbg->expectResponse.Bit(msg.glCopyTexImage2D, false);
Debug_glCopyTexImage2D(_target, _level, _internalformat, _x, _y, _width, _height,
_border);
@@ -459,7 +453,7 @@ TEST_F(SocketContextTest, CopyTexImage2D)
EXPECT_EQ(GL_RGBA, read.pixel_format());
EXPECT_EQ(GL_UNSIGNED_BYTE, read.pixel_type());
uint32_t dataLen = 0;
- unsigned char * const data = tls.dbg->Decompress(read.data().data(),
+ unsigned char * const data = dbg->Decompress(read.data().data(),
read.data().length(), &dataLen);
ASSERT_EQ(sizeof(_pixels), dataLen);
for (unsigned i = 0; i < sizeof(_pixels) / sizeof(*_pixels); i++)