• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SkTypes.h"
9 #if defined(SK_BUILD_FOR_WIN)
10 
11 #include "SkHRESULT.h"
12 
SkTraceHR(const char * file,unsigned long line,HRESULT hr,const char * msg)13 void SkTraceHR(const char* file, unsigned long line, HRESULT hr, const char* msg) {
14     if (msg) {
15         SkDebugf("%s\n", msg);
16     }
17     SkDebugf("%s(%lu) : error 0x%x: ", file, line, hr);
18 
19     LPSTR errorText = nullptr;
20     FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
21                    FORMAT_MESSAGE_FROM_SYSTEM |
22                    FORMAT_MESSAGE_IGNORE_INSERTS,
23                    nullptr,
24                    hr,
25                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
26                    (LPSTR) &errorText,
27                    0,
28                    nullptr
29     );
30 
31     if (nullptr == errorText) {
32         SkDebugf("<unknown>\n");
33     } else {
34         SkDebugf("%s", errorText);
35         LocalFree(errorText);
36         errorText = nullptr;
37     }
38 }
39 
40 #endif//defined(SK_BUILD_FOR_WIN)
41