emulator opengl: Added glUtilsPixelBitSize function to glUtils.

moved pixel size calculation from GLClientState to glUtils to be used
outside the client state scope. (needed for the renderControl encoder
which will follow in next commit).

Change-Id: I5adbc40b241537054c6743e2afc52ba44454664f
diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/GLClientState.cpp b/tools/emulator/opengl/shared/OpenglCodecCommon/GLClientState.cpp
index 7fc5068..9c70fc1 100644
--- a/tools/emulator/opengl/shared/OpenglCodecCommon/GLClientState.cpp
+++ b/tools/emulator/opengl/shared/OpenglCodecCommon/GLClientState.cpp
@@ -164,56 +164,7 @@
 
 size_t GLClientState::pixelDataSize(GLsizei width, GLsizei height, GLenum format, GLenum type, int pack)
 {
-
-    int components = 0;
-    int componentsize = 0;
-    int pixelsize = 0;
-    switch(type) {
-    case GL_UNSIGNED_BYTE:
-        componentsize = 1;
-        break;
-    case GL_UNSIGNED_SHORT_5_6_5:
-    case GL_UNSIGNED_SHORT_4_4_4_4:
-    case GL_UNSIGNED_SHORT_5_5_5_1:
-        pixelsize = 2;
-        break;
-    default:
-        ERR("pixelDataSize: unknown pixel type - assuming pixel data 0\n");
-        componentsize = 0;
-    }
-
-    if (pixelsize == 0) {
-        switch(format) {
-#if 0
-        case GL_RED:
-        case GL_GREEN:
-        case GL_BLUE:
-#endif
-        case GL_ALPHA:
-        case GL_LUMINANCE:
-            components = 1;
-            break;
-        case GL_LUMINANCE_ALPHA:
-            components = 2;
-            break;
-        case GL_RGB:
-#if 0
-        case GL_BGR:
-#endif
-            components = 3;
-            break;
-        case GL_RGBA:
-#if 0
-        case GL_BGRA:
-#endif
-            components = 4;
-            break;
-        default:
-            ERR("pixelDataSize: unknown pixel format...\n");
-            components = 0;
-        }
-        pixelsize = components * componentsize;
-    }
+    int pixelsize = glUtilsPixelBitSize(format, type) >> 3;
 
     int alignment = pack ? m_pixelStore.pack_alignment : m_pixelStore.unpack_alignment;
 
diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.cpp b/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.cpp
index ad4888a..645d08f 100644
--- a/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.cpp
+++ b/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.cpp
@@ -145,3 +145,59 @@
         }
     }
 }
+
+int glUtilsPixelBitSize(GLenum format, GLenum type)
+{
+    int components = 0;
+    int componentsize = 0;
+    int pixelsize = 0;
+    switch(type) {
+    case GL_UNSIGNED_BYTE:
+        componentsize = 8;
+        break;
+    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_RGB565_OES:
+    case GL_RGB5_A1_OES:
+    case GL_RGBA4_OES:
+        pixelsize = 16;
+        break;
+    default:
+        ERR("glUtilsPixelBitSize: unknown pixel type - assuming pixel data 0\n");
+        componentsize = 0;
+    }
+
+    if (pixelsize == 0) {
+        switch(format) {
+#if 0
+        case GL_RED:
+        case GL_GREEN:
+        case GL_BLUE:
+#endif
+        case GL_ALPHA:
+        case GL_LUMINANCE:
+            components = 1;
+            break;
+        case GL_LUMINANCE_ALPHA:
+            components = 2;
+            break;
+        case GL_RGB:
+#if 0
+        case GL_BGR:
+#endif
+            components = 3;
+            break;
+        case GL_RGBA:
+        case GL_BGRA_EXT:
+            components = 4;
+            break;
+        default:
+            ERR("glUtilsPixelBitSize: unknown pixel format...\n");
+            components = 0;
+        }
+        pixelsize = components * componentsize;
+    }
+
+    return pixelsize;
+}
diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.h b/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.h
index 96b29d6..3596406 100644
--- a/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.h
+++ b/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.h
@@ -49,6 +49,7 @@
     void   glUtilsPackPointerData(unsigned char *dst, unsigned char *str,
                            int size, GLenum type, unsigned int stride,
                            unsigned int datalen);
+    int glUtilsPixelBitSize(GLenum format, GLenum type);
 #ifdef __cplusplus
 };
 #endif