• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "gpu/config/gpu_info_collector.h"
6 
7 #include "base/command_line.h"
8 #include "base/debug/trace_event.h"
9 #include "base/logging.h"
10 #include "base/strings/string_split.h"
11 #include "ui/gl/gl_surface_egl.h"
12 #include "ui/gl/gl_switches.h"
13 
14 namespace gpu {
15 
CollectContextGraphicsInfo(GPUInfo * gpu_info)16 CollectInfoResult CollectContextGraphicsInfo(GPUInfo* gpu_info) {
17   DCHECK(gpu_info);
18   TRACE_EVENT0("gpu", "gpu_info_collector::CollectGraphicsInfo");
19   CollectInfoResult result = CollectGraphicsInfoGL(gpu_info);
20   if (CommandLine::ForCurrentProcess()->HasSwitch(
21           switches::kGpuNoContextLost)) {
22     gpu_info->can_lose_context = false;
23   } else {
24 #if defined(OS_CHROMEOS)
25     gpu_info->can_lose_context = false;
26 #else
27     gpu_info->can_lose_context =
28         !gfx::GLSurfaceEGL::IsCreateContextRobustnessSupported();
29 #endif
30   }
31 
32   gpu_info->finalized = true;
33   return result;
34 }
35 
CollectGpuID(uint32 * vendor_id,uint32 * device_id)36 GpuIDResult CollectGpuID(uint32* vendor_id, uint32* device_id) {
37   DCHECK(vendor_id && device_id);
38   *vendor_id = 0;
39   *device_id = 0;
40   return kGpuIDNotSupported;
41 }
42 
CollectBasicGraphicsInfo(GPUInfo * gpu_info)43 CollectInfoResult CollectBasicGraphicsInfo(GPUInfo* gpu_info) {
44   gpu_info->can_lose_context = false;
45   return kCollectInfoSuccess;
46 }
47 
CollectDriverInfoGL(GPUInfo * gpu_info)48 CollectInfoResult CollectDriverInfoGL(GPUInfo* gpu_info) {
49   DCHECK(gpu_info);
50   // Extract driver vendor, version from a string like:
51   // "OpenGL ES 3.0 V@6.0 AU@ (CL@2946718)"
52   size_t begin = gpu_info->gl_version.find_first_of("0123456789");
53   if (begin == std::string::npos)
54     return kCollectInfoNonFatalFailure;
55 
56   std::string sub_string = gpu_info->gl_version.substr(begin);
57   std::vector<std::string> pieces;
58   base::SplitStringAlongWhitespace(sub_string, &pieces);
59   if (pieces.size() < 3)
60     return kCollectInfoNonFatalFailure;
61 
62   std::string driver_version = pieces[2];
63   size_t pos = driver_version.find_first_not_of("0123456789.");
64   if (pos == 0)
65     return kCollectInfoNonFatalFailure;
66 
67   if (pos != std::string::npos)
68     driver_version = driver_version.substr(0, pos);
69 
70   gpu_info->driver_vendor = pieces[1];
71   gpu_info->driver_version = driver_version;
72   return kCollectInfoSuccess;
73 }
74 
MergeGPUInfo(GPUInfo * basic_gpu_info,const GPUInfo & context_gpu_info)75 void MergeGPUInfo(GPUInfo* basic_gpu_info,
76                   const GPUInfo& context_gpu_info) {
77   MergeGPUInfoGL(basic_gpu_info, context_gpu_info);
78 }
79 
80 }  // namespace gpu
81