1 /*
2  * Copyright (C) 2014 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 <GLES2/gl2.h>
18 #include <GLES2/gl2ext.h>
19 
20 #include <utils/Log.h>
21 
22 #include "GLUtils.h"
23 
24 #if DEBUG_OPENGL >= DEBUG_LEVEL_HIGH && !defined(HWUI_GLES_WRAP_ENABLED)
25 #error Setting DEBUG_OPENGL to HIGH requires setting HWUI_ENABLE_OPENGL_VALIDATION to true in the Android.mk!
26 #endif
27 
28 namespace android {
29 namespace uirenderer {
30 
dumpGLErrors()31 bool GLUtils::dumpGLErrors() {
32 #if DEBUG_OPENGL >= DEBUG_LEVEL_HIGH
33     // If DEBUG_LEVEL_HIGH is set then every GLES call is already wrapped
34     // and asserts that there was no error. So this can just return success.
35     return false;
36 #else
37     bool errorObserved = false;
38     GLenum status = GL_NO_ERROR;
39     while ((status = glGetError()) != GL_NO_ERROR) {
40         errorObserved = true;
41         switch (status) {
42             case GL_INVALID_ENUM:
43                 ALOGE("GL error:  GL_INVALID_ENUM");
44                 break;
45             case GL_INVALID_VALUE:
46                 ALOGE("GL error:  GL_INVALID_VALUE");
47                 break;
48             case GL_INVALID_OPERATION:
49                 ALOGE("GL error:  GL_INVALID_OPERATION");
50                 break;
51             case GL_OUT_OF_MEMORY:
52                 ALOGE("GL error:  Out of memory!");
53                 break;
54             default:
55                 ALOGE("GL error: 0x%x", status);
56         }
57     }
58     return errorObserved;
59 #endif
60 }
61 
62 };  // namespace uirenderer
63 };  // namespace android
64