blob: 56f286b70dec49a56eec39f81f0aefae0fb09860 [file] [log] [blame]
[email protected]c9e2cbbb2012-05-12 21:17:271// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7004d7eb2011-01-21 00:27:532// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]d7b5cc72013-05-23 20:05:005#include "gpu/config/gpu_info_collector.h"
[email protected]7004d7eb2011-01-21 00:27:536
7#include <string>
8#include <vector>
9
[email protected]7004d7eb2011-01-21 00:27:5310#include "base/logging.h"
[email protected]c9e2cbbb2012-05-12 21:17:2711#include "base/memory/scoped_ptr.h"
[email protected]f4390962013-06-11 07:29:2212#include "base/strings/string_number_conversions.h"
[email protected]b9e7c479f2013-04-12 04:33:2413#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4914#include "base/strings/string_split.h"
primiano05dadf012015-01-28 13:10:3215#include "base/trace_event/trace_event.h"
[email protected]c9e2cbbb2012-05-12 21:17:2716#include "ui/gl/gl_bindings.h"
17#include "ui/gl/gl_context.h"
[email protected]45895032013-05-30 17:06:4318#include "ui/gl/gl_implementation.h"
[email protected]c9e2cbbb2012-05-12 21:17:2719#include "ui/gl/gl_surface.h"
[email protected]7004d7eb2011-01-21 00:27:5320
21namespace {
22
[email protected]fbe20372011-06-01 01:46:3823scoped_refptr<gfx::GLSurface> InitializeGLSurface() {
24 scoped_refptr<gfx::GLSurface> surface(
[email protected]772aa832014-05-30 01:27:4725 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()));
[email protected]7cd76fd2013-06-02 21:11:1126 if (!surface.get()) {
[email protected]ffae4022011-05-12 22:54:2927 LOG(ERROR) << "gfx::GLContext::CreateOffscreenGLSurface failed";
[email protected]7004d7eb2011-01-21 00:27:5328 return NULL;
29 }
[email protected]ffae4022011-05-12 22:54:2930
[email protected]fbe20372011-06-01 01:46:3831 return surface;
[email protected]f62a5ab2011-05-23 20:34:1532}
33
[email protected]fbe20372011-06-01 01:46:3834scoped_refptr<gfx::GLContext> InitializeGLContext(gfx::GLSurface* surface) {
[email protected]f62a5ab2011-05-23 20:34:1535
[email protected]7196e012011-06-16 20:54:5336 scoped_refptr<gfx::GLContext> context(
[email protected]276f89062011-10-13 22:55:5037 gfx::GLContext::CreateGLContext(NULL,
38 surface,
[email protected]56403c22012-10-04 18:27:0439 gfx::PreferIntegratedGpu));
[email protected]7cd76fd2013-06-02 21:11:1140 if (!context.get()) {
[email protected]ffae4022011-05-12 22:54:2941 LOG(ERROR) << "gfx::GLContext::CreateGLContext failed";
42 return NULL;
43 }
44
[email protected]f62a5ab2011-05-23 20:34:1545 if (!context->MakeCurrent(surface)) {
[email protected]7004d7eb2011-01-21 00:27:5346 LOG(ERROR) << "gfx::GLContext::MakeCurrent() failed";
[email protected]7004d7eb2011-01-21 00:27:5347 return NULL;
48 }
[email protected]7004d7eb2011-01-21 00:27:5349
[email protected]fbe20372011-06-01 01:46:3850 return context;
[email protected]7004d7eb2011-01-21 00:27:5351}
52
53std::string GetGLString(unsigned int pname) {
54 const char* gl_string =
55 reinterpret_cast<const char*>(glGetString(pname));
56 if (gl_string)
57 return std::string(gl_string);
[email protected]007b3f82013-04-09 08:46:4558 return std::string();
[email protected]7004d7eb2011-01-21 00:27:5359}
60
[email protected]6cc8ece62011-03-14 20:05:4761// Return a version string in the format of "major.minor".
62std::string GetVersionFromString(const std::string& version_string) {
[email protected]7004d7eb2011-01-21 00:27:5363 size_t begin = version_string.find_first_of("0123456789");
64 if (begin != std::string::npos) {
65 size_t end = version_string.find_first_not_of("01234567890.", begin);
66 std::string sub_string;
67 if (end != std::string::npos)
68 sub_string = version_string.substr(begin, end - begin);
69 else
70 sub_string = version_string.substr(begin);
71 std::vector<std::string> pieces;
72 base::SplitString(sub_string, '.', &pieces);
[email protected]6cc8ece62011-03-14 20:05:4773 if (pieces.size() >= 2)
74 return pieces[0] + "." + pieces[1];
[email protected]7004d7eb2011-01-21 00:27:5375 }
[email protected]007b3f82013-04-09 08:46:4576 return std::string();
[email protected]7004d7eb2011-01-21 00:27:5377}
78
79} // namespace anonymous
80
[email protected]d7b5cc72013-05-23 20:05:0081namespace gpu {
[email protected]7004d7eb2011-01-21 00:27:5382
[email protected]0e8cac72014-03-22 00:37:1883CollectInfoResult CollectGraphicsInfoGL(GPUInfo* gpu_info) {
[email protected]aa328c72013-05-03 10:55:4384 TRACE_EVENT0("startup", "gpu_info_collector::CollectGraphicsInfoGL");
[email protected]93389042014-02-11 03:46:5285 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone);
[email protected]f62a5ab2011-05-23 20:34:1586
[email protected]fbe20372011-06-01 01:46:3887 scoped_refptr<gfx::GLSurface> surface(InitializeGLSurface());
[email protected]0e8cac72014-03-22 00:37:1888 if (!surface.get()) {
89 LOG(ERROR) << "Could not create surface for info collection.";
90 return kCollectInfoFatalFailure;
91 }
[email protected]f62a5ab2011-05-23 20:34:1592
[email protected]fbe20372011-06-01 01:46:3893 scoped_refptr<gfx::GLContext> context(InitializeGLContext(surface.get()));
[email protected]0e8cac72014-03-22 00:37:1894 if (!context.get()) {
95 LOG(ERROR) << "Could not create context for info collection.";
96 return kCollectInfoFatalFailure;
97 }
[email protected]7004d7eb2011-01-21 00:27:5398
[email protected]a61508e52011-03-08 17:59:4299 gpu_info->gl_renderer = GetGLString(GL_RENDERER);
100 gpu_info->gl_vendor = GetGLString(GL_VENDOR);
marcheu1856f5d52015-04-04 01:42:53101 gpu_info->gl_extensions = GetGLString(GL_EXTENSIONS);
[email protected]39c542622014-05-07 22:16:36102 gpu_info->gl_version = GetGLString(GL_VERSION);
[email protected]4df0884f2012-12-17 21:10:09103 std::string glsl_version_string = GetGLString(GL_SHADING_LANGUAGE_VERSION);
senorblancob7a64d52015-04-08 16:59:02104 GLint max_samples = 0;
105 glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
riceaa01edead2015-07-01 15:56:50106 gpu_info->max_msaa_samples = base::IntToString(max_samples);
[email protected]45895032013-05-30 17:06:43107
108 gfx::GLWindowSystemBindingInfo window_system_binding_info;
109 if (GetGLWindowSystemBindingInfo(&window_system_binding_info)) {
110 gpu_info->gl_ws_vendor = window_system_binding_info.vendor;
111 gpu_info->gl_ws_version = window_system_binding_info.version;
112 gpu_info->gl_ws_extensions = window_system_binding_info.extensions;
[email protected]0e8cac72014-03-22 00:37:18113 gpu_info->direct_rendering = window_system_binding_info.direct_rendering;
[email protected]45895032013-05-30 17:06:43114 }
115
[email protected]6c7784e2013-08-01 22:41:28116 bool supports_robustness =
117 gpu_info->gl_extensions.find("GL_EXT_robustness") != std::string::npos ||
dongseong.hwange1cb2aa2015-02-11 09:33:33118 gpu_info->gl_extensions.find("GL_KHR_robustness") != std::string::npos ||
[email protected]6c7784e2013-08-01 22:41:28119 gpu_info->gl_extensions.find("GL_ARB_robustness") != std::string::npos;
120 if (supports_robustness) {
121 glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB,
122 reinterpret_cast<GLint*>(&gpu_info->gl_reset_notification_strategy));
123 }
124
[email protected]2436a6b2012-04-13 21:08:51125 // TODO(kbr): remove once the destruction of a current context automatically
126 // clears the current context.
127 context->ReleaseCurrent(surface.get());
128
[email protected]6cc8ece62011-03-14 20:05:47129 std::string glsl_version = GetVersionFromString(glsl_version_string);
[email protected]a61508e52011-03-08 17:59:42130 gpu_info->pixel_shader_version = glsl_version;
131 gpu_info->vertex_shader_version = glsl_version;
[email protected]7004d7eb2011-01-21 00:27:53132
[email protected]4df0884f2012-12-17 21:10:09133 return CollectDriverInfoGL(gpu_info);
134}
135
[email protected]d7b5cc72013-05-23 20:05:00136void MergeGPUInfoGL(GPUInfo* basic_gpu_info,
137 const GPUInfo& context_gpu_info) {
[email protected]4df0884f2012-12-17 21:10:09138 DCHECK(basic_gpu_info);
139 basic_gpu_info->gl_renderer = context_gpu_info.gl_renderer;
140 basic_gpu_info->gl_vendor = context_gpu_info.gl_vendor;
[email protected]4df0884f2012-12-17 21:10:09141 basic_gpu_info->gl_version = context_gpu_info.gl_version;
[email protected]39c542622014-05-07 22:16:36142 basic_gpu_info->gl_extensions = context_gpu_info.gl_extensions;
[email protected]4df0884f2012-12-17 21:10:09143 basic_gpu_info->pixel_shader_version =
144 context_gpu_info.pixel_shader_version;
145 basic_gpu_info->vertex_shader_version =
146 context_gpu_info.vertex_shader_version;
senorblancob7a64d52015-04-08 16:59:02147 basic_gpu_info->max_msaa_samples =
148 context_gpu_info.max_msaa_samples;
[email protected]45895032013-05-30 17:06:43149 basic_gpu_info->gl_ws_vendor = context_gpu_info.gl_ws_vendor;
150 basic_gpu_info->gl_ws_version = context_gpu_info.gl_ws_version;
151 basic_gpu_info->gl_ws_extensions = context_gpu_info.gl_ws_extensions;
[email protected]6c7784e2013-08-01 22:41:28152 basic_gpu_info->gl_reset_notification_strategy =
153 context_gpu_info.gl_reset_notification_strategy;
[email protected]4df0884f2012-12-17 21:10:09154
155 if (!context_gpu_info.driver_vendor.empty())
156 basic_gpu_info->driver_vendor = context_gpu_info.driver_vendor;
157 if (!context_gpu_info.driver_version.empty())
158 basic_gpu_info->driver_version = context_gpu_info.driver_version;
159
160 basic_gpu_info->can_lose_context = context_gpu_info.can_lose_context;
161 basic_gpu_info->sandboxed = context_gpu_info.sandboxed;
[email protected]0e8cac72014-03-22 00:37:18162 basic_gpu_info->direct_rendering = context_gpu_info.direct_rendering;
bajonese3677b642015-07-25 00:41:56163 basic_gpu_info->in_process_gpu = context_gpu_info.in_process_gpu;
zmo84eae5e2014-09-05 01:36:23164 basic_gpu_info->context_info_state = context_gpu_info.context_info_state;
[email protected]4df0884f2012-12-17 21:10:09165 basic_gpu_info->initialization_time = context_gpu_info.initialization_time;
henryhsud1185442015-04-10 06:39:14166 basic_gpu_info->video_decode_accelerator_supported_profiles =
167 context_gpu_info.video_decode_accelerator_supported_profiles;
wuchengli79808322014-09-23 05:58:14168 basic_gpu_info->video_encode_accelerator_supported_profiles =
169 context_gpu_info.video_encode_accelerator_supported_profiles;
henryhsu74f6ef12015-07-23 08:34:37170 basic_gpu_info->jpeg_decode_accelerator_supported =
171 context_gpu_info.jpeg_decode_accelerator_supported;
[email protected]7004d7eb2011-01-21 00:27:53172}
173
[email protected]d7b5cc72013-05-23 20:05:00174} // namespace gpu
[email protected]7004d7eb2011-01-21 00:27:53175