blob: b4caeb686d37ff8c712e8edc2cad7ab04e3c1cb2 [file] [log] [blame]
bungeman@google.comb29c8832011-10-10 13:19:10 +00001/*
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"
Mike Klein8f11d4d2018-01-24 12:42:55 -05009#if defined(SK_BUILD_FOR_WIN)
bungeman@google.comb29c8832011-10-10 13:19:10 +000010
commit-bot@chromium.org8e13a152014-03-19 19:28:00 +000011#include "SkHRESULT.h"
bungeman@google.comb29c8832011-10-10 13:19:10 +000012
bungeman@google.come4ae0bc2014-05-21 19:44:39 +000013void SkTraceHR(const char* file, unsigned long line, HRESULT hr, const char* msg) {
bsalomon49f085d2014-09-05 13:34:00 -070014 if (msg) {
bungeman@google.come4ae0bc2014-05-21 19:44:39 +000015 SkDebugf("%s\n", msg);
16 }
17 SkDebugf("%s(%lu) : error 0x%x: ", file, line, hr);
rmistry@google.comd6176b02012-08-23 18:14:13 +000018
halcanary96fcdcc2015-08-27 07:41:13 -070019 LPSTR errorText = nullptr;
bungeman@google.comb29c8832011-10-10 13:19:10 +000020 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
21 FORMAT_MESSAGE_FROM_SYSTEM |
22 FORMAT_MESSAGE_IGNORE_INSERTS,
halcanary96fcdcc2015-08-27 07:41:13 -070023 nullptr,
bungeman@google.comb29c8832011-10-10 13:19:10 +000024 hr,
25 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
26 (LPSTR) &errorText,
27 0,
halcanary96fcdcc2015-08-27 07:41:13 -070028 nullptr
bungeman@google.comb29c8832011-10-10 13:19:10 +000029 );
rmistry@google.comd6176b02012-08-23 18:14:13 +000030
halcanary96fcdcc2015-08-27 07:41:13 -070031 if (nullptr == errorText) {
bungeman@google.come4ae0bc2014-05-21 19:44:39 +000032 SkDebugf("<unknown>\n");
bungeman@google.comb29c8832011-10-10 13:19:10 +000033 } else {
bungeman@google.come4ae0bc2014-05-21 19:44:39 +000034 SkDebugf("%s", errorText);
bungeman@google.comb29c8832011-10-10 13:19:10 +000035 LocalFree(errorText);
halcanary96fcdcc2015-08-27 07:41:13 -070036 errorText = nullptr;
bungeman@google.comb29c8832011-10-10 13:19:10 +000037 }
38}
mtklein1ee76512015-11-02 10:20:27 -080039
Mike Klein8f11d4d2018-01-24 12:42:55 -050040#endif//defined(SK_BUILD_FOR_WIN)