summaryrefslogtreecommitdiffstats
path: root/gpu/command_buffer/common/logging.h
diff options
context:
space:
mode:
authorapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-08 18:31:08 +0000
committerapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-08 18:31:08 +0000
commit20407e957e31a0faf159403d47dc5d1d6c903f9e (patch)
tree350962b37d2cb6d9e0fdae78a24efb2bd3c72723 /gpu/command_buffer/common/logging.h
parent9283f2789927383ece6aedbd948a645164c35c53 (diff)
downloadchromium_src-20407e957e31a0faf159403d47dc5d1d6c903f9e.zip
chromium_src-20407e957e31a0faf159403d47dc5d1d6c903f9e.tar.gz
chromium_src-20407e957e31a0faf159403d47dc5d1d6c903f9e.tar.bz2
Removed dependencies on base from GPU common and client code.
The main change was to make scoped_ptr and the basic types the same for both NaCl and trusted plugins and to implement new logging code for GPU common and client code. Service code and unit tests can still use the logging code in base. I am really not happy with the new logging code but I thought I'd let you take a look at it to see what you think. The biggest thing I don't like is it uses assert(false) to throw an exception in a platform independent way, which brings up a modal dialog. Not ideal in the middle of a unit test run. I don't know if that will make the bots hang. Hopefully they'll time out or something. TEST=try BUG=none Review URL: http://codereview.chromium.org/2936009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58857 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu/command_buffer/common/logging.h')
-rw-r--r--gpu/command_buffer/common/logging.h222
1 files changed, 187 insertions, 35 deletions
diff --git a/gpu/command_buffer/common/logging.h b/gpu/command_buffer/common/logging.h
index 969fdbf..191f711a 100644
--- a/gpu/command_buffer/common/logging.h
+++ b/gpu/command_buffer/common/logging.h
@@ -2,43 +2,195 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// This file provides ability to stub LOG and CHECK.
-
#ifndef GPU_COMMAND_BUFFER_COMMON_LOGGING_H_
#define GPU_COMMAND_BUFFER_COMMON_LOGGING_H_
-#if defined(__native_client__)
-#define STUB_LOG_AND_CHECK 1
-#endif // __native_client__
-
-#if defined STUB_LOG_AND_CHECK
-#include <sstream>
-
-// TODO: implement logging through nacl's debug service runtime if
-// available.
-#define CHECK(X) if (0) std::ostringstream()
-#define CHECK_EQ(X, Y) if (0) std::ostringstream()
-#define CHECK_NE(X, Y) if (0) std::ostringstream()
-#define CHECK_GT(X, Y) if (0) std::ostringstream()
-#define CHECK_GE(X, Y) if (0) std::ostringstream()
-#define CHECK_LT(X, Y) if (0) std::ostringstream()
-#define CHECK_LE(X, Y) if (0) std::ostringstream()
-
-#define DCHECK(X) if (0) std::ostringstream()
-#define DCHECK_EQ(X, Y) if (0) std::ostringstream()
-#define DCHECK_NE(X, Y) if (0) std::ostringstream()
-#define DCHECK_GT(X, Y) if (0) std::ostringstream()
-#define DCHECK_GE(X, Y) if (0) std::ostringstream()
-#define DCHECK_LT(X, Y) if (0) std::ostringstream()
-#define DCHECK_LE(X, Y) if (0) std::ostringstream()
-
-#define LOG(LEVEL) if (0) std::ostringstream()
-#define DLOG(LEVEL) if (0) std::ostringstream()
-
-#define NOTREACHED() DCHECK(false)
-
-#else // STUB_LOG_AND_CHECK
-#include "base/logging.h"
-#endif // STUB_LOG_AND_CHECK
+#include <assert.h>
+
+#include <iostream>
+
+// Windows defines an ERROR macro.
+#ifdef ERROR
+#undef ERROR
+#endif
+
+namespace gpu {
+
+// Members are uppercase instead of kCamelCase for consistency with base log
+// severity enum.
+enum LogLevel {
+ INFO,
+ WARNING,
+ ERROR,
+ FATAL,
+};
+
+// This is a very simple logger for use in command buffer code. Common and
+// command buffer code cannot be dependent on base. It just outputs the message
+// to stderr.
+class Logger {
+ public:
+ Logger(bool condition, LogLevel level)
+ : condition_(condition),
+ level_(level) {
+ }
+
+ template <typename X>
+ static Logger CheckTrue(const X& x,
+ const char* file, int line,
+ const char* x_name,
+ const char* check_name) {
+ return Logger(!!x, FATAL)
+ << file << "(" << line << "): " << check_name
+ << "(" << x_name << " (" << x << ")) failed. ";
+ }
+
+ template <typename X, typename Y>
+ static Logger CheckEqual(const X& x, const Y& y,
+ const char* file, int line,
+ const char* x_name, const char* y_name,
+ const char* check_name) {
+ return Logger(x == y, FATAL)
+ << file << "(" << line << "): " << check_name
+ << "(" << x_name << " (" << x << "), "
+ << y_name << "(" << y << ")) failed. ";
+ }
+
+ template <typename X, typename Y>
+ static Logger CheckNotEqual(const X& x, const Y& y,
+ const char* file, int line,
+ const char* x_name, const char* y_name,
+ const char* check_name) {
+ return Logger(x != y, FATAL)
+ << file << "(" << line << "): " << check_name
+ << "(" << x_name << " (" << x << "), "
+ << y_name << "(" << y << ")) failed. ";
+ }
+
+ template <typename X, typename Y>
+ static Logger CheckLessThan(const X& x, const Y& y,
+ const char* file, int line,
+ const char* x_name, const char* y_name,
+ const char* check_name) {
+ return Logger(x < y, FATAL)
+ << file << "(" << line << "): " << check_name
+ << "(" << x_name << " (" << x << "), "
+ << y_name << "(" << y << ")) failed. ";
+ }
+
+ template <typename X, typename Y>
+ static Logger CheckGreaterThan(const X& x, const Y& y,
+ const char* file, int line,
+ const char* x_name, const char* y_name,
+ const char* check_name) {
+ return Logger(x > y, FATAL)
+ << file << "(" << line << "): " << check_name
+ << "(" << x_name << " (" << x << "), "
+ << y_name << "(" << y << ")) failed. ";
+ }
+
+ template <typename X, typename Y>
+ static Logger CheckLessEqual(const X& x, const Y& y,
+ const char* file, int line,
+ const char* x_name, const char* y_name,
+ const char* check_name) {
+ return Logger(x <= y, FATAL)
+ << file << "(" << line << "): " << check_name
+ << "(" << x_name << " (" << x << "), "
+ << y_name << "(" << y << ")) failed. ";
+ }
+
+ template <typename X, typename Y>
+ static Logger CheckGreaterEqual(const X& x, const Y& y,
+ const char* file, int line,
+ const char* x_name, const char* y_name,
+ const char* check_name) {
+ return Logger(x >= y, FATAL)
+ << file << "(" << line << "): " << check_name
+ << "(" << x_name << " (" << x << "), "
+ << y_name << "(" << y << ")) failed. ";
+ }
+
+ ~Logger() {
+ if (!condition_) {
+ std::cerr << std::endl;
+ std::cerr.flush();
+ if (level_ == FATAL)
+ assert(false);
+ }
+ }
+
+ template <typename T>
+ Logger& operator<<(const T& value) {
+ if (!condition_)
+ std::cerr << value;
+ return *this;
+ }
+
+ private:
+ Logger(const Logger& logger): condition_(logger.condition_) {
+ }
+
+ bool condition_;
+ LogLevel level_;
+};
+
+} // namespace gpu
+
+#define GPU_CHECK(X) ::gpu::Logger::CheckTrue( \
+ (X), __FILE__, __LINE__, #X, "GPU_CHECK")
+#define GPU_CHECK_EQ(X, Y) ::gpu::Logger::CheckEqual( \
+ (X), (Y), __FILE__, __LINE__, #X, #Y, "GPU_CHECK_EQ")
+#define GPU_CHECK_NE(X, Y) ::gpu::Logger::CheckNotEqual( \
+ (X), (Y), __FILE__, __LINE__, #X, #Y, "GPU_CHECK_NE")
+#define GPU_CHECK_GT(X, Y) ::gpu::Logger::CheckGreaterThan( \
+ (X), (Y), __FILE__, __LINE__, #X, #Y, "GPU_CHECK_GT")
+#define GPU_CHECK_LT(X, Y) ::gpu::Logger::CheckLessThan( \
+ (X), (Y), __FILE__, __LINE__, #X, #Y, "GPU_CHECK_LT")
+#define GPU_CHECK_GE(X, Y) ::gpu::Logger::CheckGreaterEqual( \
+ (X), (Y), __FILE__, __LINE__, #X, #Y, "GPU_CHECK_GE")
+#define GPU_CHECK_LE(X, Y) ::gpu::Logger::CheckLessEqual( \
+ (X), (Y), __FILE__, __LINE__, #X, #Y, "GPU_CHECK_LE")
+#define GPU_LOG(LEVEL) ::gpu::Logger(false, LEVEL)
+
+#if defined(NDEBUG)
+
+#define GPU_DCHECK(X) ::gpu::Logger::CheckTrue( \
+ true, __FILE__, __LINE__, #X, "GPU_DCHECK")
+#define GPU_DCHECK_EQ(X, Y) ::gpu::Logger::CheckEqual( \
+ false, false, __FILE__, __LINE__, #X, #Y, "GPU_DCHECK_EQ")
+#define GPU_DCHECK_NE(X, Y) ::gpu::Logger::CheckEqual( \
+ false, false, __FILE__, __LINE__, #X, #Y, "GPU_DCHECK_NE")
+#define GPU_DCHECK_GT(X, Y) ::gpu::Logger::CheckEqual( \
+ false, false, __FILE__, __LINE__, #X, #Y, "GPU_DCHECK_GT")
+#define GPU_DCHECK_LT(X, Y) ::gpu::Logger::CheckEqual( \
+ false, false, __FILE__, __LINE__, #X, #Y, "GPU_DCHECK_LT")
+#define GPU_DCHECK_GE(X, Y) ::gpu::Logger::CheckEqual( \
+ false, false, __FILE__, __LINE__, #X, #Y, "GPU_DCHECK_GE")
+#define GPU_DCHECK_LE(X, Y) ::gpu::Logger::CheckEqual( \
+ false, false, __FILE__, __LINE__, #X, #Y, "GPU_DCHECK_LE")
+#define GPU_DLOG(LEVEL) ::gpu::Logger(false, LEVEL)
+
+#else // NDEBUG
+
+#define GPU_DCHECK(X) ::gpu::Logger::CheckTrue( \
+ (X), __FILE__, __LINE__, #X, "GPU_DCHECK")
+#define GPU_DCHECK_EQ(X, Y) ::gpu::Logger::CheckEqual( \
+ (X), (Y), __FILE__, __LINE__, #X, #Y, "GPU_DCHECK_EQ")
+#define GPU_DCHECK_NE(X, Y) ::gpu::Logger::CheckNotEqual( \
+ (X), (Y), __FILE__, __LINE__, #X, #Y, "GPU_DCHECK_NE")
+#define GPU_DCHECK_GT(X, Y) ::gpu::Logger::CheckGreaterThan( \
+ (X), (Y), __FILE__, __LINE__, #X, #Y, "GPU_DCHECK_GT")
+#define GPU_DCHECK_LT(X, Y) ::gpu::Logger::CheckLessThan( \
+ (X), (Y), __FILE__, __LINE__, #X, #Y, "GPU_DCHECK_LT")
+#define GPU_DCHECK_GE(X, Y) ::gpu::Logger::CheckGreaterEqual( \
+ (X), (Y), __FILE__, __LINE__, #X, #Y, "GPU_DCHECK_GE")
+#define GPU_DCHECK_LE(X, Y) ::gpu::Logger::CheckLessEqual( \
+ (X), (Y), __FILE__, __LINE__, #X, #Y, "GPU_DCHECK_LE")
+#define GPU_DLOG(LEVEL) ::gpu::Logger(true, LEVEL)
+
+#endif // NDEBUG
+
+#define GPU_NOTREACHED() GPU_DCHECK(false)
#endif // GPU_COMMAND_BUFFER_COMMON_LOGGING_H_