Treat all X8R8G8B8 and A8R8G8B8 formats as fast EGL configs.

The display format does not have to match the framebuffer image format,
so we only care about the latter.

Bug 18510357

Change-Id: Ie3382b7b006a5007e56ff9e2ae572e8a60f500d8
Reviewed-on: https://swiftshader-review.googlesource.com/1572
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Main/FrameBufferX11.cpp b/src/Main/FrameBufferX11.cpp
index 21d413d..948c26b 100644
--- a/src/Main/FrameBufferX11.cpp
+++ b/src/Main/FrameBufferX11.cpp
@@ -17,7 +17,8 @@
 

 #include <sys/ipc.h>

 #include <sys/shm.h>

-#include <string.h>

+#include <string.h>
+#include <assert.h>

 

 namespace sw

 {

@@ -47,14 +48,17 @@
 

 		int screen = DefaultScreen(x_display);

 		x_gc = XDefaultGC(x_display, screen);

-		Visual *x_visual = XDefaultVisual(x_display, screen);

-		int depth = XDefaultDepth(x_display, screen);

+		int depth = XDefaultDepth(x_display, screen);
+
+		Status status = XMatchVisualInfo(x_display, screen, 32, TrueColor, &x_visual);
+		assert(status != 0 && x_visual.blue_mask == 0xFF);   // Only X8R8G8B8 implemented
+		Visual *visual = x_visual.visual;

 

 		mit_shm = (XShmQueryExtension(x_display) == True);

 

 		if(mit_shm)

 		{

-			x_image = XShmCreateImage(x_display, x_visual, depth, ZPixmap, 0, &shminfo, width, height);

+			x_image = XShmCreateImage(x_display, visual, depth, ZPixmap, 0, &shminfo, width, height);

 

 			shminfo.shmid = shmget(IPC_PRIVATE, x_image->bytes_per_line * x_image->height, IPC_CREAT | SHM_R | SHM_W);

 			shminfo.shmaddr = x_image->data = buffer = (char*)shmat(shminfo.shmid, 0, 0);

@@ -80,17 +84,17 @@
 		if(!mit_shm)

 		{

 			buffer = new char[width * height * 4];

-			x_image = XCreateImage(x_display, x_visual, depth, ZPixmap, 0, buffer, width, height, 32, width * 4);

+			x_image = XCreateImage(x_display, visual, depth, ZPixmap, 0, buffer, width, height, 32, width * 4);

 		}

 	}

-	

+

 	FrameBufferX11::~FrameBufferX11()

 	{

 		if(!mit_shm)

 		{

 			x_image->data = 0;

 			XDestroyImage(x_image);

-			

+

 			delete[] buffer;

 			buffer = 0;

 		}

@@ -101,30 +105,30 @@
 			shmdt(shminfo.shmaddr);

 			shmctl(shminfo.shmid, IPC_RMID, 0);

 		}

-		

+

 		if(ownX11)

 		{

 			XCloseDisplay(x_display);

 		}

 	}

-	

+

 	void *FrameBufferX11::lock()

 	{

 		stride = x_image->bytes_per_line;

 		locked = buffer;

-		

+

 		return locked;

 	}

-	

+

 	void FrameBufferX11::unlock()

 	{

 		locked = 0;

 	}

-		

+

 	void FrameBufferX11::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format format)

 	{

 		copy(source, format);

-	

+

 		if(!mit_shm)

 		{

 			XPutImage(x_display, x_window, x_gc, x_image, 0, 0, 0, 0, width, height);

@@ -133,7 +137,7 @@
 		{

 			XShmPutImage(x_display, x_window, x_gc, x_image, 0, 0, 0, 0, width, height, False);

 		}

-	

+

 		XSync(x_display, False);

 	}

 }

diff --git a/src/Main/FrameBufferX11.hpp b/src/Main/FrameBufferX11.hpp
index 30f836d..4bd2e0a 100644
--- a/src/Main/FrameBufferX11.hpp
+++ b/src/Main/FrameBufferX11.hpp
@@ -29,12 +29,12 @@
 	{

 	public:

 		FrameBufferX11(Display *display, Window window, int width, int height);

-		

+

 		~FrameBufferX11();

-		

+

 		virtual void flip(void *source, Format format) {blit(source, 0, 0, format);};

 		virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format format);

-		

+

 		virtual void *lock();

 		virtual void unlock();

 

@@ -43,11 +43,12 @@
 		Display *x_display;

 		Window x_window;

 		XImage *x_image;

-		GC x_gc;

-		

+		GC x_gc;
+		XVisualInfo x_visual;

+

 		bool mit_shm;

 		XShmSegmentInfo shminfo;

-		

+

 		char *buffer;

 	};

 }

diff --git a/src/OpenGL/libEGL/Config.cpp b/src/OpenGL/libEGL/Config.cpp
index 4b370b8..45eb38e 100644
--- a/src/OpenGL/libEGL/Config.cpp
+++ b/src/OpenGL/libEGL/Config.cpp
@@ -156,12 +156,7 @@
 
 bool Config::isSlowConfig() const
 {
-    if(mDisplayMode.format == sw::FORMAT_X8R8G8B8 && mRenderTargetFormat == sw::FORMAT_A8R8G8B8)
-	{
-		return false;
-	}
-
-    return mDisplayMode.format != mRenderTargetFormat;
+	return mRenderTargetFormat != sw::FORMAT_X8R8G8B8 && mRenderTargetFormat != sw::FORMAT_A8R8G8B8;
 }
 
 SortConfig::SortConfig(const EGLint *attribList)