| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/command_buffer/service/error_state.h" | 5 #include "gpu/command_buffer/service/error_state.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 void CopyRealGLErrorsToWrapper(const char* filename, | 51 void CopyRealGLErrorsToWrapper(const char* filename, |
| 52 int line, | 52 int line, |
| 53 const char* function_name) override; | 53 const char* function_name) override; |
| 54 | 54 |
| 55 void ClearRealGLErrors(const char* filename, | 55 void ClearRealGLErrors(const char* filename, |
| 56 int line, | 56 int line, |
| 57 const char* function_name) override; | 57 const char* function_name) override; |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 GLenum GetErrorHandleContextLoss(); |
| 61 |
| 60 // The last error message set. | 62 // The last error message set. |
| 61 std::string last_error_; | 63 std::string last_error_; |
| 62 // Current GL error bits. | 64 // Current GL error bits. |
| 63 uint32 error_bits_; | 65 uint32 error_bits_; |
| 64 | 66 |
| 65 ErrorStateClient* client_; | 67 ErrorStateClient* client_; |
| 66 Logger* logger_; | 68 Logger* logger_; |
| 67 | 69 |
| 68 DISALLOW_COPY_AND_ASSIGN(ErrorStateImpl); | 70 DISALLOW_COPY_AND_ASSIGN(ErrorStateImpl); |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 ErrorState::ErrorState() {} | 73 ErrorState::ErrorState() {} |
| 72 | 74 |
| 73 ErrorState::~ErrorState() {} | 75 ErrorState::~ErrorState() {} |
| 74 | 76 |
| 75 ErrorState* ErrorState::Create(ErrorStateClient* client, Logger* logger) { | 77 ErrorState* ErrorState::Create(ErrorStateClient* client, Logger* logger) { |
| 76 return new ErrorStateImpl(client, logger); | 78 return new ErrorStateImpl(client, logger); |
| 77 } | 79 } |
| 78 | 80 |
| 79 ErrorStateImpl::ErrorStateImpl(ErrorStateClient* client, Logger* logger) | 81 ErrorStateImpl::ErrorStateImpl(ErrorStateClient* client, Logger* logger) |
| 80 : error_bits_(0), client_(client), logger_(logger) {} | 82 : error_bits_(0), client_(client), logger_(logger) {} |
| 81 | 83 |
| 82 ErrorStateImpl::~ErrorStateImpl() {} | 84 ErrorStateImpl::~ErrorStateImpl() {} |
| 83 | 85 |
| 84 uint32 ErrorStateImpl::GetGLError() { | 86 uint32 ErrorStateImpl::GetGLError() { |
| 85 // Check the GL error first, then our wrapped error. | 87 // Check the GL error first, then our wrapped error. |
| 86 GLenum error = glGetError(); | 88 GLenum error = GetErrorHandleContextLoss(); |
| 87 if (error == GL_NO_ERROR && error_bits_ != 0) { | 89 if (error == GL_NO_ERROR && error_bits_ != 0) { |
| 88 for (uint32 mask = 1; mask != 0; mask = mask << 1) { | 90 for (uint32 mask = 1; mask != 0; mask = mask << 1) { |
| 89 if ((error_bits_ & mask) != 0) { | 91 if ((error_bits_ & mask) != 0) { |
| 90 error = GLES2Util::GLErrorBitToGLError(mask); | 92 error = GLES2Util::GLErrorBitToGLError(mask); |
| 91 break; | 93 break; |
| 92 } | 94 } |
| 93 } | 95 } |
| 94 } | 96 } |
| 95 | 97 |
| 96 if (error != GL_NO_ERROR) { | 98 if (error != GL_NO_ERROR) { |
| 97 // There was an error, clear the corresponding wrapped error. | 99 // There was an error, clear the corresponding wrapped error. |
| 98 error_bits_ &= ~GLES2Util::GLErrorToErrorBit(error); | 100 error_bits_ &= ~GLES2Util::GLErrorToErrorBit(error); |
| 99 } | 101 } |
| 100 return error; | 102 return error; |
| 101 } | 103 } |
| 102 | 104 |
| 105 GLenum ErrorStateImpl::GetErrorHandleContextLoss() { |
| 106 GLenum error = glGetError(); |
| 107 if (error == GL_CONTEXT_LOST_KHR) { |
| 108 client_->OnContextLostError(); |
| 109 // Do not expose GL_CONTEXT_LOST_KHR, as the version of the robustness |
| 110 // extension that introduces the error is not exposed by the command |
| 111 // buffer. |
| 112 error = GL_NO_ERROR; |
| 113 } |
| 114 return error; |
| 115 } |
| 116 |
| 103 unsigned int ErrorStateImpl::PeekGLError( | 117 unsigned int ErrorStateImpl::PeekGLError( |
| 104 const char* filename, int line, const char* function_name) { | 118 const char* filename, int line, const char* function_name) { |
| 105 GLenum error = glGetError(); | 119 GLenum error = GetErrorHandleContextLoss(); |
| 106 if (error != GL_NO_ERROR) { | 120 if (error != GL_NO_ERROR) { |
| 107 SetGLError(filename, line, error, function_name, ""); | 121 SetGLError(filename, line, error, function_name, ""); |
| 108 } | 122 } |
| 109 return error; | 123 return error; |
| 110 } | 124 } |
| 111 | 125 |
| 112 void ErrorStateImpl::SetGLError( | 126 void ErrorStateImpl::SetGLError( |
| 113 const char* filename, | 127 const char* filename, |
| 114 int line, | 128 int line, |
| 115 unsigned int error, | 129 unsigned int error, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 SetGLError( | 183 SetGLError( |
| 170 filename, line, error, function_name, | 184 filename, line, error, function_name, |
| 171 (std::string("trying to set ") + | 185 (std::string("trying to set ") + |
| 172 GLES2Util::GetStringEnum(pname) + " to " + | 186 GLES2Util::GetStringEnum(pname) + " to " + |
| 173 base::StringPrintf("%G", param)).c_str()); | 187 base::StringPrintf("%G", param)).c_str()); |
| 174 } | 188 } |
| 175 | 189 |
| 176 void ErrorStateImpl::CopyRealGLErrorsToWrapper( | 190 void ErrorStateImpl::CopyRealGLErrorsToWrapper( |
| 177 const char* filename, int line, const char* function_name) { | 191 const char* filename, int line, const char* function_name) { |
| 178 GLenum error; | 192 GLenum error; |
| 179 while ((error = glGetError()) != GL_NO_ERROR) { | 193 while ((error = GetErrorHandleContextLoss()) != GL_NO_ERROR) { |
| 180 SetGLError(filename, line, error, function_name, | 194 SetGLError(filename, line, error, function_name, |
| 181 "<- error from previous GL command"); | 195 "<- error from previous GL command"); |
| 182 } | 196 } |
| 183 } | 197 } |
| 184 | 198 |
| 185 void ErrorStateImpl::ClearRealGLErrors( | 199 void ErrorStateImpl::ClearRealGLErrors( |
| 186 const char* filename, int line, const char* function_name) { | 200 const char* filename, int line, const char* function_name) { |
| 187 // Clears and logs all current gl errors. | 201 // Clears and logs all current gl errors. |
| 188 GLenum error; | 202 GLenum error; |
| 189 while ((error = glGetError()) != GL_NO_ERROR) { | 203 while ((error = glGetError()) != GL_NO_ERROR) { |
| 190 if (error != GL_OUT_OF_MEMORY) { | 204 if (error != GL_CONTEXT_LOST_KHR && error != GL_OUT_OF_MEMORY) { |
| 191 // GL_OUT_OF_MEMORY can legally happen on lost device. | 205 // GL_OUT_OF_MEMORY can legally happen on lost device. |
| 192 logger_->LogMessage( | 206 logger_->LogMessage( |
| 193 filename, line, | 207 filename, line, |
| 194 std::string("GL ERROR :") + | 208 std::string("GL ERROR :") + |
| 195 GLES2Util::GetStringEnum(error) + " : " + | 209 GLES2Util::GetStringEnum(error) + " : " + |
| 196 function_name + ": was unhandled"); | 210 function_name + ": was unhandled"); |
| 197 NOTREACHED() << "GL error " << error << " was unhandled."; | 211 NOTREACHED() << "GL error " << error << " was unhandled."; |
| 198 } | 212 } |
| 199 } | 213 } |
| 200 } | 214 } |
| 201 | 215 |
| 202 } // namespace gles2 | 216 } // namespace gles2 |
| 203 } // namespace gpu | 217 } // namespace gpu |
| 204 | 218 |
| OLD | NEW |