Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1580)

Side by Side Diff: gpu/command_buffer/service/error_state.cc

Issue 14308014: Clean up of GLES2 Command Decoder by moving some of the error state into a separate class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the remaining tests. Added mock ErrorState. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 #include "gpu/command_buffer/service/error_state.h"
6
7 #include <string>
8
9 #include "base/stringprintf.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
11 #include "gpu/command_buffer/service/logger.h"
12 #include "ui/gl/gl_bindings.h"
13
14 namespace gpu {
15 namespace gles2 {
16
17 ErrorState::ErrorState() {}
18
19 ErrorState::~ErrorState() {}
20
21 ErrorStateImpl::ErrorStateImpl(Logger* logger) :
22 error_bits_(0),
23 logger_(logger) {}
24
25 ErrorStateImpl::~ErrorStateImpl() {}
26
27 uint32 ErrorStateImpl::GetGLError() {
28 // Check the GL error first, then our wrapped error.
29 GLenum error = glGetError();
30 if (error == GL_NO_ERROR && error_bits_ != 0) {
31 for (uint32 mask = 1; mask != 0; mask = mask << 1) {
32 if ((error_bits_ & mask) != 0) {
33 error = GLES2Util::GLErrorBitToGLError(mask);
34 break;
35 }
36 }
37 }
38
39 if (error != GL_NO_ERROR) {
40 // There was an error, clear the corresponding wrapped error.
41 error_bits_ &= ~GLES2Util::GLErrorToErrorBit(error);
42 }
43 return error;
44 }
45
46 unsigned int ErrorStateImpl::PeekGLError(
47 const char* filename, int line, const char* function_name) {
48 GLenum error = glGetError();
49 if (error != GL_NO_ERROR) {
50 SetGLError(filename, line, error, function_name, "");
51 }
52 return error;
53 }
54
55 void ErrorStateImpl::SetGLError(
56 const char* filename,
57 int line,
58 unsigned int error,
59 const char* function_name,
60 const char* msg) {
61 if (msg) {
62 last_error_ = msg;
63 logger_->LogMessage(
64 filename, line,
65 logger_->GetLogPrefix() + ": " + std::string("GL ERROR :") +
66 GLES2Util::GetStringEnum(error) + " : " +
67 function_name + ": " + msg);
68 }
69 error_bits_ |= GLES2Util::GLErrorToErrorBit(error);
70 }
71
72 void ErrorStateImpl::SetGLErrorInvalidEnum(
73 const char* filename,
74 int line,
75 const char* function_name,
76 unsigned int value,
77 const char* label) {
78 SetGLError(filename, line, GL_INVALID_ENUM, function_name,
79 (std::string(label) + " was " +
80 GLES2Util::GetStringEnum(value)).c_str());
81 }
82
83 void ErrorStateImpl::SetGLErrorInvalidParam(
84 const char* filename,
85 int line,
86 unsigned int error,
87 const char* function_name,
88 unsigned int pname, int param) {
89 if (error == GL_INVALID_ENUM) {
90 SetGLError(
91 filename, line, GL_INVALID_ENUM, function_name,
92 (std::string("trying to set ") +
93 GLES2Util::GetStringEnum(pname) + " to " +
94 GLES2Util::GetStringEnum(param)).c_str());
95 } else {
96 SetGLError(
97 filename, line, error, function_name,
98 (std::string("trying to set ") +
99 GLES2Util::GetStringEnum(pname) + " to " +
100 base::StringPrintf("%d", param)).c_str());
101 }
102 }
103
104 void ErrorStateImpl::CopyRealGLErrorsToWrapper(
105 const char* filename, int line, const char* function_name) {
106 GLenum error;
107 while ((error = glGetError()) != GL_NO_ERROR) {
108 SetGLError(filename, line, error, function_name,
109 "<- error from previous GL command");
110 }
111 }
112
113 void ErrorStateImpl::ClearRealGLErrors(
114 const char* filename, int line, const char* function_name) {
115 // Clears and logs all current gl errors.
116 GLenum error;
117 while ((error = glGetError()) != GL_NO_ERROR) {
118 if (error != GL_OUT_OF_MEMORY) {
119 // GL_OUT_OF_MEMORY can legally happen on lost device.
120 logger_->LogMessage(
121 filename, line,
122 logger_->GetLogPrefix() + ": " + std::string("GL ERROR :") +
123 GLES2Util::GetStringEnum(error) + " : " +
124 function_name + ": was unhandled");
125 NOTREACHED() << "GL error " << error << " was unhandled.";
126 }
127 }
128 }
129
130 } // namespace gles2
131 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698