[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 5 | #include "gpu/config/gpu_info_collector.h" |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 6 | |
| 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 10 | #include "base/logging.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 11 | #include "base/memory/scoped_ptr.h" |
senorblanco | 930f690f | 2015-09-18 16:18:03 | [diff] [blame] | 12 | #include "base/metrics/sparse_histogram.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 13 | #include "base/strings/string_number_conversions.h" |
[email protected] | b9e7c479f | 2013-04-12 04:33:24 | [diff] [blame] | 14 | #include "base/strings/string_piece.h" |
[email protected] | 27c0573 | 2013-02-15 21:55:49 | [diff] [blame] | 15 | #include "base/strings/string_split.h" |
primiano | 05dadf01 | 2015-01-28 13:10:32 | [diff] [blame] | 16 | #include "base/trace_event/trace_event.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 17 | #include "ui/gl/gl_bindings.h" |
| 18 | #include "ui/gl/gl_context.h" |
[email protected] | 4589503 | 2013-05-30 17:06:43 | [diff] [blame] | 19 | #include "ui/gl/gl_implementation.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 20 | #include "ui/gl/gl_surface.h" |
j.isorce | 246d1be5 | 2015-12-03 21:53:36 | [diff] [blame^] | 21 | #include "ui/gl/gl_version_info.h" |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 22 | |
| 23 | namespace { |
| 24 | |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 25 | scoped_refptr<gfx::GLSurface> InitializeGLSurface() { |
| 26 | scoped_refptr<gfx::GLSurface> surface( |
[email protected] | 772aa83 | 2014-05-30 01:27:47 | [diff] [blame] | 27 | gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size())); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 28 | if (!surface.get()) { |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 29 | LOG(ERROR) << "gfx::GLContext::CreateOffscreenGLSurface failed"; |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 30 | return NULL; |
| 31 | } |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 32 | |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 33 | return surface; |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 34 | } |
| 35 | |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 36 | scoped_refptr<gfx::GLContext> InitializeGLContext(gfx::GLSurface* surface) { |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 37 | |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 38 | scoped_refptr<gfx::GLContext> context( |
[email protected] | 276f8906 | 2011-10-13 22:55:50 | [diff] [blame] | 39 | gfx::GLContext::CreateGLContext(NULL, |
| 40 | surface, |
[email protected] | 56403c2 | 2012-10-04 18:27:04 | [diff] [blame] | 41 | gfx::PreferIntegratedGpu)); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 42 | if (!context.get()) { |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 43 | LOG(ERROR) << "gfx::GLContext::CreateGLContext failed"; |
| 44 | return NULL; |
| 45 | } |
| 46 | |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 47 | if (!context->MakeCurrent(surface)) { |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 48 | LOG(ERROR) << "gfx::GLContext::MakeCurrent() failed"; |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 49 | return NULL; |
| 50 | } |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 51 | |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 52 | return context; |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | std::string GetGLString(unsigned int pname) { |
| 56 | const char* gl_string = |
| 57 | reinterpret_cast<const char*>(glGetString(pname)); |
| 58 | if (gl_string) |
| 59 | return std::string(gl_string); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 60 | return std::string(); |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 61 | } |
| 62 | |
[email protected] | 6cc8ece6 | 2011-03-14 20:05:47 | [diff] [blame] | 63 | // Return a version string in the format of "major.minor". |
| 64 | std::string GetVersionFromString(const std::string& version_string) { |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 65 | size_t begin = version_string.find_first_of("0123456789"); |
| 66 | if (begin != std::string::npos) { |
| 67 | size_t end = version_string.find_first_not_of("01234567890.", begin); |
| 68 | std::string sub_string; |
| 69 | if (end != std::string::npos) |
| 70 | sub_string = version_string.substr(begin, end - begin); |
| 71 | else |
| 72 | sub_string = version_string.substr(begin); |
brettw | 26dab8f0 | 2015-08-08 00:28:47 | [diff] [blame] | 73 | std::vector<std::string> pieces = base::SplitString( |
| 74 | sub_string, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
[email protected] | 6cc8ece6 | 2011-03-14 20:05:47 | [diff] [blame] | 75 | if (pieces.size() >= 2) |
| 76 | return pieces[0] + "." + pieces[1]; |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 77 | } |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 78 | return std::string(); |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | } // namespace anonymous |
| 82 | |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 83 | namespace gpu { |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 84 | |
[email protected] | 0e8cac7 | 2014-03-22 00:37:18 | [diff] [blame] | 85 | CollectInfoResult CollectGraphicsInfoGL(GPUInfo* gpu_info) { |
[email protected] | aa328c7 | 2013-05-03 10:55:43 | [diff] [blame] | 86 | TRACE_EVENT0("startup", "gpu_info_collector::CollectGraphicsInfoGL"); |
[email protected] | 9338904 | 2014-02-11 03:46:52 | [diff] [blame] | 87 | DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone); |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 88 | |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 89 | scoped_refptr<gfx::GLSurface> surface(InitializeGLSurface()); |
[email protected] | 0e8cac7 | 2014-03-22 00:37:18 | [diff] [blame] | 90 | if (!surface.get()) { |
| 91 | LOG(ERROR) << "Could not create surface for info collection."; |
| 92 | return kCollectInfoFatalFailure; |
| 93 | } |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 94 | |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 95 | scoped_refptr<gfx::GLContext> context(InitializeGLContext(surface.get())); |
[email protected] | 0e8cac7 | 2014-03-22 00:37:18 | [diff] [blame] | 96 | if (!context.get()) { |
| 97 | LOG(ERROR) << "Could not create context for info collection."; |
| 98 | return kCollectInfoFatalFailure; |
| 99 | } |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 100 | |
[email protected] | a61508e5 | 2011-03-08 17:59:42 | [diff] [blame] | 101 | gpu_info->gl_renderer = GetGLString(GL_RENDERER); |
| 102 | gpu_info->gl_vendor = GetGLString(GL_VENDOR); |
kbr | 53edb99 | 2015-08-06 01:16:29 | [diff] [blame] | 103 | gpu_info->gl_extensions = gfx::GetGLExtensionsFromCurrentContext(); |
[email protected] | 39c54262 | 2014-05-07 22:16:36 | [diff] [blame] | 104 | gpu_info->gl_version = GetGLString(GL_VERSION); |
[email protected] | 4df0884f | 2012-12-17 21:10:09 | [diff] [blame] | 105 | std::string glsl_version_string = GetGLString(GL_SHADING_LANGUAGE_VERSION); |
j.isorce | 246d1be5 | 2015-12-03 21:53:36 | [diff] [blame^] | 106 | |
| 107 | gfx::GLVersionInfo gl_info(gpu_info->gl_version.c_str(), |
| 108 | gpu_info->gl_renderer.c_str(), |
| 109 | gpu_info->gl_extensions.c_str()); |
senorblanco | b7a64d5 | 2015-04-08 16:59:02 | [diff] [blame] | 110 | GLint max_samples = 0; |
j.isorce | 246d1be5 | 2015-12-03 21:53:36 | [diff] [blame^] | 111 | if (gl_info.IsAtLeastGL(3, 0) || gl_info.IsAtLeastGLES(3, 0) || |
| 112 | gpu_info->gl_extensions.find("GL_ANGLE_framebuffer_multisample") != |
| 113 | std::string::npos || |
| 114 | gpu_info->gl_extensions.find("GL_APPLE_framebuffer_multisample") != |
| 115 | std::string::npos || |
| 116 | gpu_info->gl_extensions.find("GL_EXT_framebuffer_multisample") != |
| 117 | std::string::npos || |
| 118 | gpu_info->gl_extensions.find("GL_EXT_multisampled_render_to_texture") != |
| 119 | std::string::npos || |
| 120 | gpu_info->gl_extensions.find("GL_NV_framebuffer_multisample") != |
| 121 | std::string::npos) { |
| 122 | glGetIntegerv(GL_MAX_SAMPLES, &max_samples); |
| 123 | } |
ricea | a01edead | 2015-07-01 15:56:50 | [diff] [blame] | 124 | gpu_info->max_msaa_samples = base::IntToString(max_samples); |
senorblanco | 930f690f | 2015-09-18 16:18:03 | [diff] [blame] | 125 | UMA_HISTOGRAM_SPARSE_SLOWLY("GPU.MaxMSAASampleCount", max_samples); |
[email protected] | 4589503 | 2013-05-30 17:06:43 | [diff] [blame] | 126 | |
| 127 | gfx::GLWindowSystemBindingInfo window_system_binding_info; |
| 128 | if (GetGLWindowSystemBindingInfo(&window_system_binding_info)) { |
| 129 | gpu_info->gl_ws_vendor = window_system_binding_info.vendor; |
| 130 | gpu_info->gl_ws_version = window_system_binding_info.version; |
| 131 | gpu_info->gl_ws_extensions = window_system_binding_info.extensions; |
[email protected] | 0e8cac7 | 2014-03-22 00:37:18 | [diff] [blame] | 132 | gpu_info->direct_rendering = window_system_binding_info.direct_rendering; |
[email protected] | 4589503 | 2013-05-30 17:06:43 | [diff] [blame] | 133 | } |
| 134 | |
[email protected] | 6c7784e | 2013-08-01 22:41:28 | [diff] [blame] | 135 | bool supports_robustness = |
| 136 | gpu_info->gl_extensions.find("GL_EXT_robustness") != std::string::npos || |
dongseong.hwang | e1cb2aa | 2015-02-11 09:33:33 | [diff] [blame] | 137 | gpu_info->gl_extensions.find("GL_KHR_robustness") != std::string::npos || |
[email protected] | 6c7784e | 2013-08-01 22:41:28 | [diff] [blame] | 138 | gpu_info->gl_extensions.find("GL_ARB_robustness") != std::string::npos; |
| 139 | if (supports_robustness) { |
| 140 | glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, |
| 141 | reinterpret_cast<GLint*>(&gpu_info->gl_reset_notification_strategy)); |
| 142 | } |
| 143 | |
[email protected] | 2436a6b | 2012-04-13 21:08:51 | [diff] [blame] | 144 | // TODO(kbr): remove once the destruction of a current context automatically |
| 145 | // clears the current context. |
| 146 | context->ReleaseCurrent(surface.get()); |
| 147 | |
[email protected] | 6cc8ece6 | 2011-03-14 20:05:47 | [diff] [blame] | 148 | std::string glsl_version = GetVersionFromString(glsl_version_string); |
[email protected] | a61508e5 | 2011-03-08 17:59:42 | [diff] [blame] | 149 | gpu_info->pixel_shader_version = glsl_version; |
| 150 | gpu_info->vertex_shader_version = glsl_version; |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 151 | |
[email protected] | 4df0884f | 2012-12-17 21:10:09 | [diff] [blame] | 152 | return CollectDriverInfoGL(gpu_info); |
| 153 | } |
| 154 | |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 155 | void MergeGPUInfoGL(GPUInfo* basic_gpu_info, |
| 156 | const GPUInfo& context_gpu_info) { |
[email protected] | 4df0884f | 2012-12-17 21:10:09 | [diff] [blame] | 157 | DCHECK(basic_gpu_info); |
| 158 | basic_gpu_info->gl_renderer = context_gpu_info.gl_renderer; |
| 159 | basic_gpu_info->gl_vendor = context_gpu_info.gl_vendor; |
[email protected] | 4df0884f | 2012-12-17 21:10:09 | [diff] [blame] | 160 | basic_gpu_info->gl_version = context_gpu_info.gl_version; |
[email protected] | 39c54262 | 2014-05-07 22:16:36 | [diff] [blame] | 161 | basic_gpu_info->gl_extensions = context_gpu_info.gl_extensions; |
[email protected] | 4df0884f | 2012-12-17 21:10:09 | [diff] [blame] | 162 | basic_gpu_info->pixel_shader_version = |
| 163 | context_gpu_info.pixel_shader_version; |
| 164 | basic_gpu_info->vertex_shader_version = |
| 165 | context_gpu_info.vertex_shader_version; |
senorblanco | b7a64d5 | 2015-04-08 16:59:02 | [diff] [blame] | 166 | basic_gpu_info->max_msaa_samples = |
| 167 | context_gpu_info.max_msaa_samples; |
[email protected] | 4589503 | 2013-05-30 17:06:43 | [diff] [blame] | 168 | basic_gpu_info->gl_ws_vendor = context_gpu_info.gl_ws_vendor; |
| 169 | basic_gpu_info->gl_ws_version = context_gpu_info.gl_ws_version; |
| 170 | basic_gpu_info->gl_ws_extensions = context_gpu_info.gl_ws_extensions; |
[email protected] | 6c7784e | 2013-08-01 22:41:28 | [diff] [blame] | 171 | basic_gpu_info->gl_reset_notification_strategy = |
| 172 | context_gpu_info.gl_reset_notification_strategy; |
[email protected] | 4df0884f | 2012-12-17 21:10:09 | [diff] [blame] | 173 | |
| 174 | if (!context_gpu_info.driver_vendor.empty()) |
| 175 | basic_gpu_info->driver_vendor = context_gpu_info.driver_vendor; |
| 176 | if (!context_gpu_info.driver_version.empty()) |
| 177 | basic_gpu_info->driver_version = context_gpu_info.driver_version; |
| 178 | |
| 179 | basic_gpu_info->can_lose_context = context_gpu_info.can_lose_context; |
| 180 | basic_gpu_info->sandboxed = context_gpu_info.sandboxed; |
[email protected] | 0e8cac7 | 2014-03-22 00:37:18 | [diff] [blame] | 181 | basic_gpu_info->direct_rendering = context_gpu_info.direct_rendering; |
bajones | e3677b64 | 2015-07-25 00:41:56 | [diff] [blame] | 182 | basic_gpu_info->in_process_gpu = context_gpu_info.in_process_gpu; |
zmo | 84eae5e | 2014-09-05 01:36:23 | [diff] [blame] | 183 | basic_gpu_info->context_info_state = context_gpu_info.context_info_state; |
[email protected] | 4df0884f | 2012-12-17 21:10:09 | [diff] [blame] | 184 | basic_gpu_info->initialization_time = context_gpu_info.initialization_time; |
henryhsu | d118544 | 2015-04-10 06:39:14 | [diff] [blame] | 185 | basic_gpu_info->video_decode_accelerator_supported_profiles = |
| 186 | context_gpu_info.video_decode_accelerator_supported_profiles; |
wuchengli | 7980832 | 2014-09-23 05:58:14 | [diff] [blame] | 187 | basic_gpu_info->video_encode_accelerator_supported_profiles = |
| 188 | context_gpu_info.video_encode_accelerator_supported_profiles; |
henryhsu | 74f6ef1 | 2015-07-23 08:34:37 | [diff] [blame] | 189 | basic_gpu_info->jpeg_decode_accelerator_supported = |
| 190 | context_gpu_info.jpeg_decode_accelerator_supported; |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 191 | } |
| 192 | |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 193 | } // namespace gpu |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 194 | |