• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "GlesErrorCheckWrapper.h"
18 
19 #include <log/log.h>
20 
21 namespace android {
22 namespace uirenderer {
23 namespace debug {
24 
assertNoErrors(const char * apicall)25 void GlesErrorCheckWrapper::assertNoErrors(const char* apicall) {
26     GLenum status = GL_NO_ERROR;
27     GLenum lastError = GL_NO_ERROR;
28     const char* lastErrorName = nullptr;
29     while ((status = mBase.glGetError_()) != GL_NO_ERROR) {
30         lastError = status;
31         switch (status) {
32             case GL_INVALID_ENUM:
33                 ALOGE("GL error:  GL_INVALID_ENUM");
34                 lastErrorName = "GL_INVALID_ENUM";
35                 break;
36             case GL_INVALID_VALUE:
37                 ALOGE("GL error:  GL_INVALID_VALUE");
38                 lastErrorName = "GL_INVALID_VALUE";
39                 break;
40             case GL_INVALID_OPERATION:
41                 ALOGE("GL error:  GL_INVALID_OPERATION");
42                 lastErrorName = "GL_INVALID_OPERATION";
43                 break;
44             case GL_OUT_OF_MEMORY:
45                 ALOGE("GL error:  Out of memory!");
46                 lastErrorName = "GL_OUT_OF_MEMORY";
47                 break;
48             default:
49                 ALOGE("GL error: 0x%x", status);
50                 lastErrorName = "UNKNOWN";
51         }
52     }
53     LOG_ALWAYS_FATAL_IF(lastError != GL_NO_ERROR, "%s error! %s (0x%x)", apicall, lastErrorName,
54                         lastError);
55 }
56 
57 #define API_ENTRY(x) GlesErrorCheckWrapper::x##_
58 #define CALL_GL_API(x, ...)  \
59     mBase.x##_(__VA_ARGS__); \
60     assertNoErrors(#x)
61 
62 #define CALL_GL_API_RETURN(x, ...)      \
63     auto ret = mBase.x##_(__VA_ARGS__); \
64     assertNoErrors(#x);                 \
65     return ret
66 
67 #include "gles_stubs.in"
68 
69 #undef API_ENTRY
70 #undef CALL_GL_API
71 #undef CALL_GL_API_RETURN
72 
73 }  // namespace debug
74 }  // namespace uirenderer
75 }  // namespace android
76