1 /*
2 * Copyright (C) 2021 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 "Debug.h"
18
19 #include <cstdarg>
20
21 #include "OpenGLESDispatch/DispatchTables.h"
22
formatString(const char * format,...)23 std::string formatString(const char* format, ...) {
24 char buf[1024];
25 va_list args;
26 va_start(args, format);
27 vsnprintf(buf, 1024, format, args);
28 std::string ret(buf);
29 va_end(args);
30 return ret;
31 }
32
ScopedDebugGroup(const std::string & message)33 ScopedDebugGroup::ScopedDebugGroup(const std::string& message) {
34 s_gles2.glGetError();
35
36 bool groupPushed = false;
37 if (s_gles2.glPushDebugGroupKHR) {
38 s_gles2.glPushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION_KHR, 0, message.size(),
39 message.c_str());
40 groupPushed = s_gles2.glGetError() == GL_NO_ERROR;
41 }
42 if (s_gles2.glPushDebugGroup && !groupPushed) {
43 s_gles2.glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, message.size(), message.c_str());
44 groupPushed = s_gles2.glGetError() == GL_NO_ERROR;
45 }
46 }
47
~ScopedDebugGroup()48 ScopedDebugGroup::~ScopedDebugGroup() {
49 s_gles2.glGetError();
50
51 bool groupPopped = false;
52 if (s_gles2.glPopDebugGroupKHR) {
53 s_gles2.glPopDebugGroupKHR();
54 groupPopped = s_gles2.glGetError() == GL_NO_ERROR;
55 }
56 if (s_gles2.glPopDebugGroup && !groupPopped) {
57 s_gles2.glPopDebugGroup();
58 groupPopped = s_gles2.glGetError() == GL_NO_ERROR;
59 }
60 }