Control the creation of DX9 or DX11 renderers through eglGetDisplay.

TRAC #23029
Signed-off-by: Jamie Madill
Signed-off-by: Shannon Woods
Author: Nicolas Capens

git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@2223 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index b670840..c06d4c0 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -306,6 +306,12 @@
 #define EGL_SOFTWARE_DISPLAY_ANGLE ((EGLNativeDisplayType)-1)
 #endif
 
+#ifndef EGL_ANGLE_direct3d_display
+#define EGL_ANGLE_direct3d_display 1
+#define EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE ((EGLNativeDisplayType)-2)
+#define EGL_D3D11_ONLY_DISPLAY_ANGLE ((EGLNativeDisplayType)-3)
+#endif
+
 #ifndef EGL_ANGLE_surface_d3d_texture_2d_share_handle
 #define EGL_ANGLE_surface_d3d_texture_2d_share_handle 1
 #define EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE	0x3200
diff --git a/src/libEGL/Display.cpp b/src/libEGL/Display.cpp
index d5d0f0f..73dc3c5 100644
--- a/src/libEGL/Display.cpp
+++ b/src/libEGL/Display.cpp
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 //
@@ -37,32 +37,17 @@
     {
         return displays[displayId];
     }
+    
+    // FIXME: Check if displayId is a valid display device context
 
-    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);
-    }
+    egl::Display *display = new egl::Display(displayId, (HDC)displayId);
 
     displays[displayId] = display;
     return display;
 }
 
-Display::Display(EGLNativeDisplayType displayId, HDC deviceContext, bool software) : mDc(deviceContext)
+Display::Display(EGLNativeDisplayType displayId, HDC deviceContext) : mDc(deviceContext)
 {
-
-    mSoftwareDevice = software;
     mDisplayId = displayId;
     mRenderer = NULL;
 }
@@ -86,7 +71,7 @@
         return true;
     }
 
-    mRenderer = glCreateRenderer(this, mDc, mSoftwareDevice);
+    mRenderer = glCreateRenderer(this, mDc, mDisplayId);
     
     if (!mRenderer)
     {
diff --git a/src/libEGL/Display.h b/src/libEGL/Display.h
index 8c71e51..8e83b1c 100644
--- a/src/libEGL/Display.h
+++ b/src/libEGL/Display.h
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 //
@@ -64,7 +64,7 @@
   private:
     DISALLOW_COPY_AND_ASSIGN(Display);
 
-    Display(EGLNativeDisplayType displayId, HDC deviceContext, bool software);
+    Display(EGLNativeDisplayType displayId, HDC deviceContext);
 
     bool restoreLostDevice();
 
diff --git a/src/libGLESv2/main.h b/src/libGLESv2/main.h
index 9168a22..196afae 100644
--- a/src/libGLESv2/main.h
+++ b/src/libGLESv2/main.h
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 //
@@ -58,7 +58,7 @@
 void glDestroyContext(gl::Context *context);
 void glMakeCurrent(gl::Context *context, egl::Display *display, egl::Surface *surface);
 gl::Context *glGetCurrentContext();
-rx::Renderer *glCreateRenderer(egl::Display *display, HDC hDc, bool softwareDevice);
+rx::Renderer *glCreateRenderer(egl::Display *display, HDC hDc, EGLNativeDisplayType displayId);
 void glDestroyRenderer(rx::Renderer *renderer);
 
 __eglMustCastToProperFunctionPointerType __stdcall glGetProcAddress(const char *procname);
diff --git a/src/libGLESv2/renderer/Renderer.cpp b/src/libGLESv2/renderer/Renderer.cpp
index 7e5b801..6138e6d 100644
--- a/src/libGLESv2/renderer/Renderer.cpp
+++ b/src/libGLESv2/renderer/Renderer.cpp
@@ -7,6 +7,7 @@
 
 // Renderer.cpp: Implements EGL dependencies for creating and destroying Renderer instances.
 
+#include <EGL/eglext.h>
 #include "libGLESv2/main.h"
 #include "libGLESv2/Program.h"
 #include "libGLESv2/renderer/Renderer.h"
@@ -15,7 +16,7 @@
 #include "libGLESv2/utilities.h"
 
 #if !defined(ANGLE_ENABLE_D3D11)
-// Enables use of the Direct3D 11 API, when available
+// Enables use of the Direct3D 11 API for a default display, when available
 #define ANGLE_ENABLE_D3D11 0
 #endif
 
@@ -166,12 +167,14 @@
 extern "C"
 {
 
-rx::Renderer *glCreateRenderer(egl::Display *display, HDC hDc, bool softwareDevice)
+rx::Renderer *glCreateRenderer(egl::Display *display, HDC hDc, EGLNativeDisplayType displayId)
 {
     rx::Renderer *renderer = NULL;
     EGLint status = EGL_BAD_ALLOC;
     
-    if (ANGLE_ENABLE_D3D11)
+    if (ANGLE_ENABLE_D3D11 ||
+        displayId == EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE ||
+        displayId == EGL_D3D11_ONLY_DISPLAY_ANGLE)
     {
         renderer = new rx::Renderer11(display, hDc);
     
@@ -184,11 +187,16 @@
         {
             return renderer;
         }
+        else if (displayId == EGL_D3D11_ONLY_DISPLAY_ANGLE)
+        {
+            return NULL;
+        }
 
         // Failed to create a D3D11 renderer, try creating a D3D9 renderer
         delete renderer;
     }
 
+    bool softwareDevice = (displayId == EGL_SOFTWARE_DISPLAY_ANGLE);
     renderer = new rx::Renderer9(display, hDc, softwareDevice);
     
     if (renderer)