blob: 6b61906f4ed92326dac91721db4b004bc36e8971 [file] [log] [blame]
Avi Drissman05dfbc822022-09-13 21:25:341// Copyright 2013 The Chromium Authors
kloveless@chromium.org1d82e822013-04-10 21:32:322// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "gpu/command_buffer/service/logger.h"
6
7#include "base/command_line.h"
8#include "base/logging.h"
avi@chromium.orgf4390962013-06-11 07:29:229#include "base/strings/string_number_conversions.h"
kloveless@chromium.org1d82e822013-04-10 21:32:3210#include "gpu/command_buffer/common/debug_marker_manager.h"
11#include "gpu/command_buffer/service/gpu_switches.h"
12
13namespace gpu {
14namespace gles2 {
15
Antoine Labourf679fa42017-06-07 00:32:4316Logger::Logger(const DebugMarkerManager* debug_marker_manager,
James Darpinian104af6f2018-12-06 03:24:5517 const LogMessageCallback& callback,
18 bool disable_gl_error_limit)
kloveless@chromium.org1d82e822013-04-10 21:32:3219 : debug_marker_manager_(debug_marker_manager),
Peng Huang61eccfe42018-11-15 22:10:1320 log_message_callback_(callback),
kloveless@chromium.org1d82e822013-04-10 21:32:3221 log_message_count_(0),
James Darpinian104af6f2018-12-06 03:24:5522 log_synthesized_gl_errors_(true),
23 disable_gl_error_limit_(disable_gl_error_limit) {
kloveless@chromium.org1d82e822013-04-10 21:32:3224 Logger* this_temp = this;
gman@chromium.org40de8512013-05-28 20:15:0025 this_in_hex_ = std::string("GroupMarkerNotSet(crbug.com/242999)!:") +
26 base::HexEncode(&this_temp, sizeof(this_temp));
kloveless@chromium.org1d82e822013-04-10 21:32:3227}
28
Chris Watkins81030772017-12-07 01:20:5629Logger::~Logger() = default;
kloveless@chromium.org1d82e822013-04-10 21:32:3230
31void Logger::LogMessage(
32 const char* filename, int line, const std::string& msg) {
James Darpinian104af6f2018-12-06 03:24:5533 if (log_message_count_ < kMaxLogMessages || disable_gl_error_limit_) {
gman@chromium.org40de8512013-05-28 20:15:0034 std::string prefixed_msg(std::string("[") + GetLogPrefix() + "]" + msg);
kloveless@chromium.org1d82e822013-04-10 21:32:3235 ++log_message_count_;
36 // LOG this unless logging is turned off as any chromium code that
37 // generates these errors probably has a bug.
38 if (log_synthesized_gl_errors_) {
Peter BostrΓΆm9c202bb2024-01-05 05:33:0639 ::logging::LogMessage(filename, line, ::logging::LOGGING_ERROR).stream()
40 << prefixed_msg;
kloveless@chromium.org1d82e822013-04-10 21:32:3241 }
Peng Huang61eccfe42018-11-15 22:10:1342 log_message_callback_.Run(prefixed_msg);
kloveless@chromium.org1d82e822013-04-10 21:32:3243 } else {
44 if (log_message_count_ == kMaxLogMessages) {
45 ++log_message_count_;
46 LOG(ERROR)
47 << "Too many GL errors, not reporting any more for this context."
48 << " use --disable-gl-error-limit to see all errors.";
49 }
50 }
51}
52
53const std::string& Logger::GetLogPrefix() const {
54 const std::string& prefix(debug_marker_manager_->GetMarker());
55 return prefix.empty() ? this_in_hex_ : prefix;
56}
57
kloveless@chromium.org1d82e822013-04-10 21:32:3258} // namespace gles2
59} // namespace gpu