Fix using an alpha-less GL format for Android's RGBX.

Bug 19979126

Change-Id: Ic074079cbe3630751a95ffcc2b2b33700063abcf
Reviewed-on: https://swiftshader-review.googlesource.com/2782
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-by: Ping-Hao Wu <pinghao@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/libGLES_CM/Image.cpp b/src/OpenGL/libGLES_CM/Image.cpp
index a66d2eb..d4f9d5a 100644
--- a/src/OpenGL/libGLES_CM/Image.cpp
+++ b/src/OpenGL/libGLES_CM/Image.cpp
@@ -167,7 +167,7 @@
 
 		GLsizei inputPitch = ComputePitch(width, format, type, unpackAlignment);
 		void *buffer = lock(0, 0, sw::LOCK_WRITEONLY);
-		
+
 		if(buffer)
 		{
 			switch(type)
@@ -276,7 +276,7 @@
 		{
 			const float *source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
 			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 16);
-			
+
 			for(int x = 0; x < width; x++)
 			{
 				dest[4 * x + 0] = 0;
@@ -304,7 +304,7 @@
 		{
 			const float *source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
 			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 16);
-			
+
 			for(int x = 0; x < width; x++)
 			{
 				dest[4 * x + 0] = source[x];
@@ -321,7 +321,7 @@
 		{
 			const unsigned char *source = static_cast<const unsigned char*>(input) + y * inputPitch;
 			unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 2;
-        
+
 			memcpy(dest, source, width * 2);
 		}
 	}
@@ -332,7 +332,7 @@
 		{
 			const float *source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
 			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 16);
-			
+
 			for(int x = 0; x < width; x++)
 			{
 				dest[4 * x + 0] = source[2*x+0];
@@ -349,7 +349,7 @@
 		{
 			const unsigned char *source = static_cast<const unsigned char*>(input) + y * inputPitch;
 			unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4;
-			
+
 			for(int x = 0; x < width; x++)
 			{
 				dest[4 * x + 0] = source[x * 3 + 0];
@@ -366,7 +366,7 @@
 		{
 			const unsigned short *source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
 			unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4;
-			
+
 			for(int x = 0; x < width; x++)
 			{
 				unsigned short rgba = source[x];
@@ -384,7 +384,7 @@
 		{
 			const float *source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
 			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 16);
-			
+
 			for(int x = 0; x < width; x++)
 			{
 				dest[4 * x + 0] = source[x * 3 + 0];
@@ -412,7 +412,7 @@
 		{
 			const unsigned short *source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
 			unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4;
-			
+
 			for(int x = 0; x < width; x++)
 			{
 				unsigned short rgba = source[x];
@@ -430,7 +430,7 @@
 		{
 			const unsigned short *source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
 			unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 4;
-			
+
 			for(int x = 0; x < width; x++)
 			{
 				unsigned short rgba = source[x];
@@ -448,7 +448,7 @@
 		{
 			const float *source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
 			float *dest = reinterpret_cast<float*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 16);
-			
+
 			memcpy(dest, source, width * 16);
 		}
 	}
@@ -538,8 +538,9 @@
 		switch(format)
 		{
 		case HAL_PIXEL_FORMAT_RGBA_8888:
-		case HAL_PIXEL_FORMAT_RGBX_8888:
 			return GL_RGBA;
+		case HAL_PIXEL_FORMAT_RGBX_8888:
+			return GL_RGB;
 		case HAL_PIXEL_FORMAT_RGB_888:
 			return GL_RGB;
 		case HAL_PIXEL_FORMAT_RGB_565:
diff --git a/src/OpenGL/libGLESv2/Context.h b/src/OpenGL/libGLESv2/Context.h
index 5a3af6e..e6cefb1 100644
--- a/src/OpenGL/libGLESv2/Context.h
+++ b/src/OpenGL/libGLESv2/Context.h
@@ -89,15 +89,15 @@
 	GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE,

 #endif

 #if (GL_ES_VERSION_3_0)

-	GL_COMPRESSED_R11_EAC,
-	GL_COMPRESSED_SIGNED_R11_EAC,
-	GL_COMPRESSED_RG11_EAC,
-	GL_COMPRESSED_SIGNED_RG11_EAC,
-	GL_COMPRESSED_RGB8_ETC2,
-	GL_COMPRESSED_SRGB8_ETC2,
-	GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
-	GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
-	GL_COMPRESSED_RGBA8_ETC2_EAC,
+	GL_COMPRESSED_R11_EAC,

+	GL_COMPRESSED_SIGNED_R11_EAC,

+	GL_COMPRESSED_RG11_EAC,

+	GL_COMPRESSED_SIGNED_RG11_EAC,

+	GL_COMPRESSED_RGB8_ETC2,

+	GL_COMPRESSED_SRGB8_ETC2,

+	GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,

+	GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,

+	GL_COMPRESSED_RGBA8_ETC2_EAC,

 	GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,

 #endif

 };

diff --git a/src/OpenGL/libGLESv2/Image.cpp b/src/OpenGL/libGLESv2/Image.cpp
index cfca395..821c21c 100644
--- a/src/OpenGL/libGLESv2/Image.cpp
+++ b/src/OpenGL/libGLESv2/Image.cpp
@@ -515,7 +515,7 @@
 	{
 		GLsizei inputPitch = ComputePitch(width, format, type, unpackAlignment);
 		void *buffer = lock(0, 0, sw::LOCK_WRITEONLY);
-		
+
 		if(buffer)
 		{
 			switch(type)
@@ -669,8 +669,9 @@
 		switch(format)
 		{
 		case HAL_PIXEL_FORMAT_RGBA_8888:
-		case HAL_PIXEL_FORMAT_RGBX_8888:
 			return GL_RGBA;
+		case HAL_PIXEL_FORMAT_RGBX_8888:
+			return GL_RGB;
 		case HAL_PIXEL_FORMAT_RGB_888:
 			return GL_RGB;
 		case HAL_PIXEL_FORMAT_RGB_565: