- Check for D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES capability during initialization to fail on DirectX8 drivers.
- Fail in GetDeviceCaps loop after one second.

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

git-svn-id: https://angleproject.googlecode.com/svn/trunk@446 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libEGL/Display.cpp b/src/libEGL/Display.cpp
index c95e1f6..f141cee 100644
--- a/src/libEGL/Display.cpp
+++ b/src/libEGL/Display.cpp
@@ -97,22 +97,25 @@
 
         HRESULT result;
         
-        do
+        // Give up on getting device caps after about one second.
+        for (int i = 0; i < 10; ++i)
         {
             result = mD3d9->GetDeviceCaps(mAdapter, mDeviceType, &mDeviceCaps);
-
-            if (result == D3DERR_NOTAVAILABLE)
+            
+            if (SUCCEEDED(result))
             {
-                Sleep(0);   // Give the driver some time to initialize/recover
+                break;
+            }
+            else if (result == D3DERR_NOTAVAILABLE)
+            {
+                Sleep(100);   // Give the driver some time to initialize/recover
             }
             else if (FAILED(result))   // D3DERR_OUTOFVIDEOMEMORY, E_OUTOFMEMORY, D3DERR_INVALIDDEVICE, or another error we can't recover from
             {
+                terminate();
                 return error(EGL_BAD_ALLOC, false);
             }
         }
-        while(result == D3DERR_NOTAVAILABLE);
-
-        ASSERT(SUCCEEDED(result));
 
         if (mDeviceCaps.PixelShaderVersion < D3DPS_VERSION(2, 0))
         {
@@ -120,6 +123,14 @@
             return error(EGL_NOT_INITIALIZED, false);
         }
 
+        // When DirectX9 is running with an older DirectX8 driver, a StretchRect from a regular texture to a render target texture is not supported.
+        // This is required by Texture2D::convertToRenderTarget.
+        if ((mDeviceCaps.DevCaps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES) == 0)
+        {
+            terminate();
+            return error(EGL_NOT_INITIALIZED, false);
+        }
+
         mMinSwapInterval = 4;
         mMaxSwapInterval = 0;