Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / gpu / command_buffer / service / error_state.h
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.
4
5 // This file contains the ErrorState class.
6
7 #ifndef GPU_COMMAND_BUFFER_SERVICE_ERROR_STATE_H_
8 #define GPU_COMMAND_BUFFER_SERVICE_ERROR_STATE_H_
9
10 #include "base/compiler_specific.h"
11 #include "gpu/command_buffer/common/types.h"
12 #include "gpu/gpu_export.h"
13
14 namespace gpu {
15 namespace gles2 {
16
17 class Logger;
18
19 // Use these macro to synthesize GL errors instead of calling the error_state
20 // functions directly as they will propogate the __FILE__ and __LINE__.
21
22 // Use to synthesize a GL error on the error_state.
23 #define ERRORSTATE_SET_GL_ERROR(error_state, error, function_name, msg) \
24     error_state->SetGLError(__FILE__, __LINE__, error, function_name, msg)
25
26 // Use to synthesize an INVALID_ENUM GL error on the error_state. Will attempt
27 // to expand the enum to a string.
28 #define ERRORSTATE_SET_GL_ERROR_INVALID_ENUM( \
29     error_state, function_name, value, label) \
30     error_state->SetGLErrorInvalidEnum( \
31         __FILE__, __LINE__, function_name, value, label)
32
33 // Use to synthesize a GL error on the error_state for an invalid enum based
34 // integer parameter. Will attempt to expand the parameter to a string.
35 #define ERRORSTATE_SET_GL_ERROR_INVALID_PARAMI( \
36     error_state, error, function_name, pname, param) \
37     error_state->SetGLErrorInvalidParami( \
38         __FILE__, __LINE__, error, function_name, pname, param)
39
40 // Use to synthesize a GL error on the error_state for an invalid enum based
41 // float parameter. Will attempt to expand the parameter to a string.
42 #define ERRORSTATE_SET_GL_ERROR_INVALID_PARAMF( \
43     error_state, error, function_name, pname, param) \
44     error_state->SetGLErrorInvalidParamf( \
45         __FILE__, __LINE__, error, function_name, pname, param)
46
47 // Use to move all pending error to the wrapper so on your next GL call
48 // you can see if that call generates an error.
49 #define ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state, function_name) \
50     error_state->CopyRealGLErrorsToWrapper(__FILE__, __LINE__, function_name)
51 // Use to look at the real GL error and still pass it on to the user.
52 #define ERRORSTATE_PEEK_GL_ERROR(error_state, function_name) \
53     error_state->PeekGLError(__FILE__, __LINE__, function_name)
54 // Use to clear all current GL errors. FAILS if there are any.
55 #define ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state, function_name) \
56     error_state->ClearRealGLErrors(__FILE__, __LINE__, function_name)
57
58 class GPU_EXPORT ErrorStateClient {
59  public:
60   // GL_OUT_OF_MEMORY can cause side effects such as losing the context.
61   virtual void OnOutOfMemoryError() = 0;
62 };
63
64 class GPU_EXPORT ErrorState {
65  public:
66   virtual ~ErrorState();
67
68   static ErrorState* Create(ErrorStateClient* client, Logger* logger);
69
70   virtual uint32 GetGLError() = 0;
71
72   virtual void SetGLError(
73       const char* filename,
74       int line,
75       unsigned int error,
76       const char* function_name,
77       const char* msg) = 0;
78   virtual void SetGLErrorInvalidEnum(
79       const char* filename,
80       int line,
81       const char* function_name,
82       unsigned int value,
83       const char* label) = 0;
84   virtual void SetGLErrorInvalidParami(
85       const char* filename,
86       int line,
87       unsigned int error,
88       const char* function_name,
89       unsigned int pname,
90       int param) = 0;
91   virtual void SetGLErrorInvalidParamf(
92       const char* filename,
93       int line,
94       unsigned int error,
95       const char* function_name,
96       unsigned int pname,
97       float param) = 0;
98
99   // Gets the GLError and stores it in our wrapper. Effectively
100   // this lets us peek at the error without losing it.
101   virtual unsigned int PeekGLError(
102       const char* filename, int line, const char* function_name) = 0;
103
104   // Copies the real GL errors to the wrapper. This is so we can
105   // make sure there are no native GL errors before calling some GL function
106   // so that on return we know any error generated was for that specific
107   // command.
108   virtual void CopyRealGLErrorsToWrapper(
109       const char* filename, int line, const char* function_name) = 0;
110
111   // Clear all real GL errors. This is to prevent the client from seeing any
112   // errors caused by GL calls that it was not responsible for issuing.
113   virtual void ClearRealGLErrors(
114       const char* filename, int line, const char* function_name) = 0;
115
116  protected:
117   ErrorState();
118
119   DISALLOW_COPY_AND_ASSIGN(ErrorState);
120 };
121
122 }  // namespace gles2
123 }  // namespace gpu
124
125 #endif  // GPU_COMMAND_BUFFER_SERVICE_ERROR_STATE_H_
126