From c279bff31d1c989b13adffad9e82a64bace4945a Mon Sep 17 00:00:00 2001 From: "erg@google.com" Date: Thu, 1 Sep 2011 19:46:46 +0000 Subject: Static initializers: Remove include from GPU logging system. GPU can't rely on base because of nacl so it has its own logger. The logger includes in the header, so most gles2 and command buffer files have std::__ioinit static initializers. Create a common logging.cc which has a simple method that just returns std::cerr so all the __ioinits collapse down to one. BUG=94794 TEST=compiles R=apatrick TBR=noelallen Review URL: http://codereview.chromium.org/7821004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99229 0039d316-1c4b-4281-b951-d872f2087c98 --- gpu/command_buffer/common/logging.cc | 24 ++++++++++++++++++++++++ gpu/command_buffer/common/logging.h | 18 ++++++++---------- gpu/gpu.gyp | 1 + 3 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 gpu/command_buffer/common/logging.cc (limited to 'gpu') diff --git a/gpu/command_buffer/common/logging.cc b/gpu/command_buffer/common/logging.cc new file mode 100644 index 0000000..4bc3510 --- /dev/null +++ b/gpu/command_buffer/common/logging.cc @@ -0,0 +1,24 @@ +// Copyright (c) 2011 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 "gpu/command_buffer/common/logging.h" + +#include + +namespace gpu { + +std::ostream& Logger::stream() { + return std::cerr; +} + +Logger::~Logger() { + if (!condition_) { + std::cerr << std::endl; + std::cerr.flush(); + if (level_ == FATAL) + assert(false); + } +} + +} // namespace gpu diff --git a/gpu/command_buffer/common/logging.h b/gpu/command_buffer/common/logging.h index 6f8c99e..47d0b4dc 100644 --- a/gpu/command_buffer/common/logging.h +++ b/gpu/command_buffer/common/logging.h @@ -7,7 +7,7 @@ #include -#include +#include // Windows defines an ERROR macro. #ifdef ERROR @@ -132,19 +132,17 @@ class Logger { << y_name << "(" << y << ")) failed. "; } - ~Logger() { - if (!condition_) { - std::cerr << std::endl; - std::cerr.flush(); - if (level_ == FATAL) - assert(false); - } - } + // Retrieves the stream that we write to. This header cannot depend on + // because that will add static initializers to all files that + // include this header. + std::ostream& stream(); + + ~Logger(); template Logger& operator<<(const T& value) { if (!condition_) - std::cerr << value; + stream() << value; return *this; } diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp index 6acbc8a..436545b 100644 --- a/gpu/gpu.gyp +++ b/gpu/gpu.gyp @@ -59,6 +59,7 @@ 'command_buffer/common/gles2_cmd_utils.h', 'command_buffer/common/id_allocator.cc', 'command_buffer/common/id_allocator.h', + 'command_buffer/common/logging.cc', 'command_buffer/common/logging.h', 'command_buffer/common/thread_local.h', 'command_buffer/common/types.h', -- cgit v1.1