Elim cr-checkbox
[chromium-blink-merge.git] / gpu / command_buffer / service / error_state.h
blob96815655c23500f53d614189ebf81653e378cf31
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file contains the ErrorState class.
7 #ifndef GPU_COMMAND_BUFFER_SERVICE_ERROR_STATE_H_
8 #define GPU_COMMAND_BUFFER_SERVICE_ERROR_STATE_H_
10 #include <stdint.h>
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 #include "gpu/gpu_export.h"
16 namespace gpu {
17 namespace gles2 {
19 class Logger;
21 // Use these macro to synthesize GL errors instead of calling the error_state
22 // functions directly as they will propogate the __FILE__ and __LINE__.
24 // Use to synthesize a GL error on the error_state.
25 #define ERRORSTATE_SET_GL_ERROR(error_state, error, function_name, msg) \
26 error_state->SetGLError(__FILE__, __LINE__, error, function_name, msg)
28 // Use to synthesize an INVALID_ENUM GL error on the error_state. Will attempt
29 // to expand the enum to a string.
30 #define ERRORSTATE_SET_GL_ERROR_INVALID_ENUM( \
31 error_state, function_name, value, label) \
32 error_state->SetGLErrorInvalidEnum( \
33 __FILE__, __LINE__, function_name, value, label)
35 // Use to synthesize a GL error on the error_state for an invalid enum based
36 // integer parameter. Will attempt to expand the parameter to a string.
37 #define ERRORSTATE_SET_GL_ERROR_INVALID_PARAMI( \
38 error_state, error, function_name, pname, param) \
39 error_state->SetGLErrorInvalidParami( \
40 __FILE__, __LINE__, error, function_name, pname, param)
42 // Use to synthesize a GL error on the error_state for an invalid enum based
43 // float parameter. Will attempt to expand the parameter to a string.
44 #define ERRORSTATE_SET_GL_ERROR_INVALID_PARAMF( \
45 error_state, error, function_name, pname, param) \
46 error_state->SetGLErrorInvalidParamf( \
47 __FILE__, __LINE__, error, function_name, pname, param)
49 // Use to move all pending error to the wrapper so on your next GL call
50 // you can see if that call generates an error.
51 #define ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state, function_name) \
52 error_state->CopyRealGLErrorsToWrapper(__FILE__, __LINE__, function_name)
53 // Use to look at the real GL error and still pass it on to the user.
54 #define ERRORSTATE_PEEK_GL_ERROR(error_state, function_name) \
55 error_state->PeekGLError(__FILE__, __LINE__, function_name)
56 // Use to clear all current GL errors. FAILS if there are any.
57 #define ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state, function_name) \
58 error_state->ClearRealGLErrors(__FILE__, __LINE__, function_name)
60 class GPU_EXPORT ErrorStateClient {
61 public:
62 virtual void OnContextLostError() = 0;
63 // GL_OUT_OF_MEMORY can cause side effects such as losing the context.
64 virtual void OnOutOfMemoryError() = 0;
67 class GPU_EXPORT ErrorState {
68 public:
69 virtual ~ErrorState();
71 static ErrorState* Create(ErrorStateClient* client, Logger* logger);
73 virtual uint32_t GetGLError() = 0;
75 virtual void SetGLError(
76 const char* filename,
77 int line,
78 unsigned int error,
79 const char* function_name,
80 const char* msg) = 0;
81 virtual void SetGLErrorInvalidEnum(
82 const char* filename,
83 int line,
84 const char* function_name,
85 unsigned int value,
86 const char* label) = 0;
87 virtual void SetGLErrorInvalidParami(
88 const char* filename,
89 int line,
90 unsigned int error,
91 const char* function_name,
92 unsigned int pname,
93 int param) = 0;
94 virtual void SetGLErrorInvalidParamf(
95 const char* filename,
96 int line,
97 unsigned int error,
98 const char* function_name,
99 unsigned int pname,
100 float param) = 0;
102 // Gets the GLError and stores it in our wrapper. Effectively
103 // this lets us peek at the error without losing it.
104 virtual unsigned int PeekGLError(
105 const char* filename, int line, const char* function_name) = 0;
107 // Copies the real GL errors to the wrapper. This is so we can
108 // make sure there are no native GL errors before calling some GL function
109 // so that on return we know any error generated was for that specific
110 // command.
111 virtual void CopyRealGLErrorsToWrapper(
112 const char* filename, int line, const char* function_name) = 0;
114 // Clear all real GL errors. This is to prevent the client from seeing any
115 // errors caused by GL calls that it was not responsible for issuing.
116 virtual void ClearRealGLErrors(
117 const char* filename, int line, const char* function_name) = 0;
119 protected:
120 ErrorState();
122 DISALLOW_COPY_AND_ASSIGN(ErrorState);
125 } // namespace gles2
126 } // namespace gpu
128 #endif // GPU_COMMAND_BUFFER_SERVICE_ERROR_STATE_H_