Windows: On context lost, GPU process exits.

Some drivers cannot recover from device lost. IDirect3DDevice9::ResetEx returns an access denied error after a GPU hang. Although this results in a fallback to software, exiting the GPU process allows a newly launched GPU process to reinitialize D3D and GPU accelerated features continue to work.

I have observed this with an AMD driver but suspect there are issues with Intel from crash reports.

Review URL: https://chromiumcodereview.appspot.com/12617020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191705 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gpu/command_buffer/service/feature_info.cc b/gpu/command_buffer/service/feature_info.cc
index cd49d08..f70debd7 100644
--- a/gpu/command_buffer/service/feature_info.cc
+++ b/gpu/command_buffer/service/feature_info.cc
@@ -97,6 +97,7 @@
       flush_on_context_switch(false),
       delete_instead_of_resize_fbo(false),
       use_client_side_arrays_for_stream_buffers(false),
+      exit_on_context_lost(false),
       max_texture_size(0),
       max_cube_map_texture_size(0) {
 }
@@ -701,6 +702,12 @@
     // TODO(dsinclair): Add AddExtensionString("GL_CHROMIUM_sampler_objects")
     // when available.
   }
+
+#if defined(OS_WIN)
+  // Some drivers are unable to reset the D3D device in the GPU process
+  // sandbox.
+  workarounds_.exit_on_context_lost = true;
+#endif
 }
 
 void FeatureInfo::AddExtensionString(const std::string& str) {
diff --git a/gpu/command_buffer/service/feature_info.h b/gpu/command_buffer/service/feature_info.h
index 4efff80f..3192444 100644
--- a/gpu/command_buffer/service/feature_info.h
+++ b/gpu/command_buffer/service/feature_info.h
@@ -57,6 +57,7 @@
     bool flush_on_context_switch;
     bool delete_instead_of_resize_fbo;
     bool use_client_side_arrays_for_stream_buffers;
+    bool exit_on_context_lost;
 
     // Note: 0 here means use driver limit.
     GLint max_texture_size;
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index ec5b2ab..a28bb4c 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -2853,6 +2853,15 @@
 
   if (WasContextLost()) {
     LOG(ERROR) << "  GLES2DecoderImpl: Context lost during MakeCurrent.";
+
+    // Some D3D drivers cannot recover from device lost in the GPU process
+    // sandbox. Allow a new GPU process to launch.
+    if (workarounds().exit_on_context_lost) {
+      LOG(ERROR) << "Exiting GPU process because some drivers cannot reset"
+                 << " a D3D device in the Chrome GPU process sandbox.";
+      exit(0);
+    }
+
     return false;
   }