summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gpu_performance_stats_win.cc
blob: 7472e92d73a4a4f5865737b75e45d58ed5bd2e1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/gpu_performance_stats.h"

#include <winsatcominterfacei.h>

static float GetComponentScore(IProvideWinSATAssessmentInfo* subcomponent) {
  float score;
  HRESULT hr = subcomponent->get_Score(&score);
  if (FAILED(hr))
    return 0.0;
  return score;
}

GpuPerformanceStats GpuPerformanceStats::RetrieveGpuPerformanceStats() {
  HRESULT hr = S_OK;
  IQueryRecentWinSATAssessment* assessment = NULL;
  IProvideWinSATResultsInfo* results = NULL;
  IProvideWinSATAssessmentInfo* subcomponent = NULL;
  GpuPerformanceStats stats;

  hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
  if (FAILED(hr))
    goto cleanup;

  hr = CoCreateInstance(__uuidof(CQueryWinSAT),
                        NULL,
                        CLSCTX_INPROC_SERVER,
                        __uuidof(IQueryRecentWinSATAssessment),
                        reinterpret_cast<void**>(&assessment));
  if (FAILED(hr))
    goto cleanup;

  hr = assessment->get_Info(&results);
  if (FAILED(hr))
    goto cleanup;

  hr = results->get_SystemRating(&stats.overall);
  if (FAILED(hr))
    goto cleanup;

  hr = results->GetAssessmentInfo(WINSAT_ASSESSMENT_D3D, &subcomponent);
  if (FAILED(hr))
    goto cleanup;
  stats.gaming = GetComponentScore(subcomponent);
  subcomponent->Release();
  subcomponent = NULL;

  hr = results->GetAssessmentInfo(WINSAT_ASSESSMENT_GRAPHICS, &subcomponent);
  if (FAILED(hr))
    goto cleanup;
  stats.graphics = GetComponentScore(subcomponent);
  subcomponent->Release();
  subcomponent = NULL;

 cleanup:
  if (assessment)
    assessment->Release();
  if (results)
    results->Release();
  if (subcomponent)
    subcomponent->Release();
  CoUninitialize();

  return stats;
}