1b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com/*
2b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com * Copyright 2011 Google Inc.
3b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com *
4b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com * Use of this source code is governed by a BSD-style license that can be
5b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com * found in the LICENSE file.
6b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com */
7b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com
8b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#include "SkTypes.h"
9b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com
108e13a159f3a54f761ab80b16377015e5a9077411commit-bot@chromium.org#include "SkHRESULT.h"
11b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com
12e4ae0bc5caeed52e07c7e5939fa4ac38d9e408abbungeman@google.comvoid SkTraceHR(const char* file, unsigned long line, HRESULT hr, const char* msg) {
13e4ae0bc5caeed52e07c7e5939fa4ac38d9e408abbungeman@google.com    if (NULL != msg) {
14e4ae0bc5caeed52e07c7e5939fa4ac38d9e408abbungeman@google.com        SkDebugf("%s\n", msg);
15e4ae0bc5caeed52e07c7e5939fa4ac38d9e408abbungeman@google.com    }
16e4ae0bc5caeed52e07c7e5939fa4ac38d9e408abbungeman@google.com    SkDebugf("%s(%lu) : error 0x%x: ", file, line, hr);
17d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
18b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    LPSTR errorText = NULL;
19b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
20b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   FORMAT_MESSAGE_FROM_SYSTEM |
21b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   FORMAT_MESSAGE_IGNORE_INSERTS,
22b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   NULL,
23b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   hr,
24b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
25b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   (LPSTR) &errorText,
26b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   0,
27b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   NULL
28b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    );
29d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
30b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    if (NULL == errorText) {
31e4ae0bc5caeed52e07c7e5939fa4ac38d9e408abbungeman@google.com        SkDebugf("<unknown>\n");
32b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    } else {
33e4ae0bc5caeed52e07c7e5939fa4ac38d9e408abbungeman@google.com        SkDebugf("%s", errorText);
34b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com        LocalFree(errorText);
35b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com        errorText = NULL;
36b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    }
37b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com}
38