Add extension to create software device.

Add an extension so that users can receive a device that renders in software. Currently this is done by loading a swiftshader dll.

BUG=
TEST=

Review URL: http://codereview.appspot.com/4631093

git-svn-id: https://angleproject.googlecode.com/svn/trunk@705 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libEGL/Display.cpp b/src/libEGL/Display.cpp
index ac51af2..ea5fcc3 100644
--- a/src/libEGL/Display.cpp
+++ b/src/libEGL/Display.cpp
@@ -11,6 +11,7 @@
 #include "libEGL/Display.h"
 
 #include <algorithm>
+#include <map>
 #include <vector>
 
 #include "common/debug.h"
@@ -31,7 +32,41 @@
 
 namespace egl
 {
-Display::Display(HDC deviceContext) : mDc(deviceContext)
+namespace
+{
+    typedef std::map<EGLNativeDisplayType, Display*> DisplayMap; 
+    DisplayMap displays;
+}
+
+egl::Display *Display::getDisplay(EGLNativeDisplayType displayId)
+{
+    if (displays.find(displayId) != displays.end())
+    {
+        return displays[displayId];
+    }
+
+    egl::Display *display = NULL;
+
+    if (displayId == EGL_DEFAULT_DISPLAY)
+    {
+        display = new egl::Display(displayId, (HDC)NULL, false);
+    }
+    else if (displayId == EGL_SOFTWARE_DISPLAY_ANGLE)
+    {
+        display = new egl::Display(displayId, (HDC)NULL, true);
+    }
+    else
+    {
+        // FIXME: Check if displayId is a valid display device context
+
+        display = new egl::Display(displayId, (HDC)displayId, false);
+    }
+
+    displays[displayId] = display;
+    return display;
+}
+
+Display::Display(EGLNativeDisplayType displayId, HDC deviceContext, bool software) : mDc(deviceContext)
 {
     mD3d9Module = NULL;
     
@@ -51,11 +86,20 @@
 
     mMinSwapInterval = 1;
     mMaxSwapInterval = 1;
+    mSoftwareDevice = software;
+    mDisplayId = displayId;
 }
 
 Display::~Display()
 {
     terminate();
+
+    DisplayMap::iterator thisDisplay = displays.find(mDisplayId);
+
+    if (thisDisplay != displays.end())
+    {
+      displays.erase(thisDisplay);
+    }
 }
 
 bool Display::initialize()
@@ -65,7 +109,14 @@
         return true;
     }
 
-    mD3d9Module = GetModuleHandle(TEXT("d3d9.dll"));
+    if (mSoftwareDevice)
+    {
+      mD3d9Module = GetModuleHandle(TEXT("swiftshader_d3d9.dll"));
+    } 
+    else
+    {
+      mD3d9Module = GetModuleHandle(TEXT("d3d9.dll"));
+    }
     if (mD3d9Module == NULL)
     {
         terminate();
@@ -856,6 +907,12 @@
 void Display::initExtensionString()
 {
     mExtensionString += "EGL_ANGLE_query_surface_pointer ";
+    HMODULE swiftShader = GetModuleHandle(TEXT("swiftshader_d3d9.dll"));
+
+    if (swiftShader)
+    {
+      mExtensionString += "EGL_ANGLE_software_display ";
+    }
 
     if (isD3d9ExDevice()) {
         mExtensionString += "EGL_ANGLE_surface_d3d_texture_2d_share_handle ";