<commit_before>// 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 "content/gpu/gpu_info_collector.h"

#include <windows.h>
#include <d3d9.h>
#include <setupapi.h>
#include <winsatcominterfacei.h>

#include "base/command_line.h"
#include "base/file_path.h"
#include "base/logging.h"
#include "base/scoped_native_library.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "ui/gfx/gl/gl_implementation.h"
#include "ui/gfx/gl/gl_surface_egl.h"

// ANGLE seems to require that main.h be included before any other ANGLE header.
#include "libEGL/Display.h"
#include "libEGL/main.h"

namespace {

// The version number stores the major and minor version in the least 16 bits;
// for example, 2.5 is 0x00000205.
// Returned string is in the format of "major.minor".
std::string VersionNumberToString(uint32 version_number) {
  int hi = (version_number >> 8) & 0xff;
  int low = version_number & 0xff;
  return base::IntToString(hi) + "." + base::IntToString(low);
}

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

content::GpuPerformanceStats RetrieveGpuPerformanceStats() {
  HRESULT hr = S_OK;
  IQueryRecentWinSATAssessment* assessment = NULL;
  IProvideWinSATResultsInfo* results = NULL;
  IProvideWinSATAssessmentInfo* subcomponent = NULL;
  content::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;
}

}  // namespace anonymous

namespace gpu_info_collector {

bool CollectGraphicsInfo(content::GPUInfo* gpu_info) {
  DCHECK(gpu_info);

  gpu_info->performance_stats = RetrieveGpuPerformanceStats();

  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) {
    std::string requested_implementation_name =
        CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL);
    if (requested_implementation_name == "swiftshader") {
      gpu_info->software_rendering = true;
      return false;
    }
  }

  if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {<commit_msg>Add LOG(ERROR) to win performance stats collection.<commit_after>// 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 "content/gpu/gpu_info_collector.h"

#include <windows.h>
#include <d3d9.h>
#include <setupapi.h>
#include <winsatcominterfacei.h>

#include "base/command_line.h"
#include "base/file_path.h"
#include "base/logging.h"
#include "base/scoped_native_library.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "ui/gfx/gl/gl_implementation.h"
#include "ui/gfx/gl/gl_surface_egl.h"

// ANGLE seems to require that main.h be included before any other ANGLE header.
#include "libEGL/Display.h"
#include "libEGL/main.h"

namespace {

// The version number stores the major and minor version in the least 16 bits;
// for example, 2.5 is 0x00000205.
// Returned string is in the format of "major.minor".
std::string VersionNumberToString(uint32 version_number) {
  int hi = (version_number >> 8) & 0xff;
  int low = version_number & 0xff;
  return base::IntToString(hi) + "." + base::IntToString(low);
}

float GetAssessmentScore(IProvideWinSATResultsInfo* results,
                         WINSAT_ASSESSMENT_TYPE type) {
  IProvideWinSATAssessmentInfo* subcomponent = NULL;
  if (FAILED(results->GetAssessmentInfo(type, &subcomponent)))
    return 0.0;

  float score = 0.0;
  if (FAILED(subcomponent->get_Score(&score)))
    score = 0.0;
  subcomponent->Release();
  return score;
}

content::GpuPerformanceStats RetrieveGpuPerformanceStats() {
  IQueryRecentWinSATAssessment* assessment = NULL;
  IProvideWinSATResultsInfo* results = NULL;

  content::GpuPerformanceStats stats;

  do {
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    if (FAILED(hr)) {
      LOG(ERROR) << "CoInitializeEx() failed";
      break;
    }

    hr = CoCreateInstance(__uuidof(CQueryWinSAT),
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          __uuidof(IQueryRecentWinSATAssessment),
                          reinterpret_cast<void**>(&assessment));
    if (FAILED(hr)) {
      LOG(ERROR) << "CoCreateInstance() failed";
      break;
    }

    hr = assessment->get_Info(&results);
    if (FAILED(hr)) {
      LOG(ERROR) << "assessment->get_Info() failed";
      break;
    }

    hr = results->get_SystemRating(&stats.overall);
    if (FAILED(hr))
      LOG(ERROR) << "Get overall score failed";

    stats.gaming = GetAssessmentScore(results, WINSAT_ASSESSMENT_D3D);
    if (stats.gaming == 0.0)
      LOG(ERROR) << "Get gaming score failed";

    stats.graphics = GetAssessmentScore(results, WINSAT_ASSESSMENT_GRAPHICS);
    if (stats.graphics == 0.0)
      LOG(ERROR) << "Get graphics score failed";
  } while (false);

  if (assessment)
    assessment->Release();
  if (results)
    results->Release();
  CoUninitialize();

  return stats;
}

}  // namespace anonymous

namespace gpu_info_collector {

bool CollectGraphicsInfo(content::GPUInfo* gpu_info) {
  DCHECK(gpu_info);

  gpu_info->performance_stats = RetrieveGpuPerformanceStats();

  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) {
    std::string requested_implementation_name =
        CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL);
    if (requested_implementation_name == "swiftshader") {
      gpu_info->software_rendering = true;
      return false;
    }
  }

  if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
{'fraction_non_alphanumeric': 0.11832778822508318, 'fraction_numerical': 0.009257919861131203, 'mean_word_length': 3.9741007194244604, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3382802', 'n_tokens_mistral': 2313, 'n_tokens_neox': 2218, 'n_words': 488}