Adds enablable debug group messages for GPU capture

... which are useful for connecting Gfxstream objects and GL
objects at the GL translator level with the underlying GL objects
at the native driver level.

The debug group messages are initially disabled.

Bug: b/200832997
Test: launch_cvd --gpu_mode=gfxstream --gpu_capture_binary=ngfx
Change-Id: I35fccffba8038936c7fc2e3a4227ce54c5bb572c
diff --git a/stream-servers/Debug.cpp b/stream-servers/Debug.cpp
new file mode 100644
index 0000000..c39499f
--- /dev/null
+++ b/stream-servers/Debug.cpp
@@ -0,0 +1,57 @@
+/*
+* Copyright (C) 2021 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include "Debug.h"
+
+#include "OpenGLESDispatch/DispatchTables.h"
+
+std::string formatString(const char* format, ...) {
+    char buf[1024];
+    va_list args;
+    va_start(args, format);
+    vsnprintf(buf, 1024, format, args);
+    std::string ret(buf);
+    va_end(args);
+    return ret;
+}
+
+ScopedDebugGroup::ScopedDebugGroup(const std::string& message) {
+    s_gles2.glGetError();
+
+    bool groupPushed = false;
+    if (s_gles2.glPushDebugGroupKHR) {
+        s_gles2.glPushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION_KHR, 0, message.size(), message.c_str());
+        groupPushed = s_gles2.glGetError() == GL_NO_ERROR;
+    }
+    if (s_gles2.glPushDebugGroup && !groupPushed) {
+        s_gles2.glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, message.size(), message.c_str());
+        groupPushed = s_gles2.glGetError() == GL_NO_ERROR;
+    }
+}
+
+ScopedDebugGroup::~ScopedDebugGroup() {
+    s_gles2.glGetError();
+
+    bool groupPopped = false;
+    if (s_gles2.glPopDebugGroupKHR) {
+        s_gles2.glPopDebugGroupKHR();
+        groupPopped = s_gles2.glGetError() == GL_NO_ERROR;
+    }
+    if (s_gles2.glPopDebugGroup && !groupPopped) {
+        s_gles2.glPopDebugGroup();
+        groupPopped = s_gles2.glGetError() == GL_NO_ERROR;
+    }
+}
\ No newline at end of file