demos: Clean up logging for Android
authorCody Northrop <cnorthrop@google.com>
Tue, 27 Sep 2016 16:50:57 +0000 (10:50 -0600)
committerCody Northrop <cnorthrop@google.com>
Wed, 28 Sep 2016 17:41:16 +0000 (11:41 -0600)
demos/cube.c

index 42a6f73..7f12ed9 100644 (file)
@@ -422,55 +422,71 @@ VKAPI_ATTR VkBool32 VKAPI_CALL
 dbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
     uint64_t srcObject, size_t location, int32_t msgCode,
     const char *pLayerPrefix, const char *pMsg, void *pUserData) {
+
+    // clang-format off
     char *message = (char *)malloc(strlen(pMsg) + 100);
 
     assert(message);
 
-    if (msgFlags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
-        sprintf(message, "ERROR: [%s] Code %d : %s", pLayerPrefix, msgCode,
-            pMsg);
+    // We know we're submitting queues without fences, ignore this
+    if (strstr(pMsg, "vkQueueSubmit parameter, VkFence fence, is null pointer"))
+        return false;
+
+    if (msgFlags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) {
+        sprintf(message, "INFORMATION: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg);
         validation_error = 1;
     } else if (msgFlags & VK_DEBUG_REPORT_WARNING_BIT_EXT) {
-        // We know that we're submitting queues without fences, ignore this
-        // warning
-        if (strstr(pMsg,
-            "vkQueueSubmit parameter, VkFence fence, is null pointer")) {
-            return false;
-        }
-        sprintf(message, "WARNING: [%s] Code %d : %s", pLayerPrefix, msgCode,
-            pMsg);
+        sprintf(message, "WARNING: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg);
+        validation_error = 1;
+    } else if (msgFlags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) {
+        sprintf(message, "PERFOERMANCE WARNING: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg);
+        validation_error = 1;
+    } else if (msgFlags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
+        sprintf(message, "ERROR: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg);
+        validation_error = 1;
+    } else if (msgFlags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) {
+        sprintf(message, "DEBUG: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg);
         validation_error = 1;
     } else {
+        sprintf(message, "INFORMATION: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg);
         validation_error = 1;
-        return false;
     }
 
 #ifdef _WIN32
+
     in_callback = true;
     struct demo *demo = (struct demo*) pUserData;
     if (!demo->suppress_popups)
         MessageBox(NULL, message, "Alert", MB_OK);
     in_callback = false;
+
 #elif defined(ANDROID)
+
     if (msgFlags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) {
-        __android_log_print(ANDROID_LOG_INFO,  "Cube", "%s", message);
+        __android_log_print(ANDROID_LOG_INFO,  APP_SHORT_NAME, "%s", message);
     } else if (msgFlags & VK_DEBUG_REPORT_WARNING_BIT_EXT) {
-        __android_log_print(ANDROID_LOG_WARN,  "Cube", "%s", message);
+        __android_log_print(ANDROID_LOG_WARN,  APP_SHORT_NAME, "%s", message);
     } else if (msgFlags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) {
-        __android_log_print(ANDROID_LOG_WARN,  "Cube", "%s", message);
+        __android_log_print(ANDROID_LOG_WARN,  APP_SHORT_NAME, "%s", message);
     } else if (msgFlags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
-        __android_log_print(ANDROID_LOG_ERROR, "Cube", "%s", message);
+        __android_log_print(ANDROID_LOG_ERROR, APP_SHORT_NAME, "%s", message);
     } else if (msgFlags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) {
-        __android_log_print(ANDROID_LOG_DEBUG, "Cube", "%s", message);
+        __android_log_print(ANDROID_LOG_DEBUG, APP_SHORT_NAME, "%s", message);
     } else {
-        __android_log_print(ANDROID_LOG_INFO,  "Cube", "%s", message);
+        __android_log_print(ANDROID_LOG_INFO,  APP_SHORT_NAME, "%s", message);
     }
+
 #else
+
     printf("%s\n", message);
     fflush(stdout);
+
 #endif
+
     free(message);
 
+    //clang-format on
+
     /*
     * false indicates that layer should not bail-out of an
     * API call that had validation failures. This may mean that the
@@ -3209,6 +3225,9 @@ static void demo_init(struct demo *demo, int argc, char **argv) {
             continue;
         }
 
+#if defined(ANDROID)
+        ERR_EXIT("Usage: cube [--validate]\n", "Usage");
+#else
         fprintf(stderr, "Usage:\n  %s [--use_staging] [--validate] [--break] "
 #if defined(VK_USE_PLATFORM_XLIB_KHR)
                         "[--xlib] "
@@ -3217,6 +3236,7 @@ static void demo_init(struct demo *demo, int argc, char **argv) {
                 APP_SHORT_NAME);
         fflush(stderr);
         exit(1);
+#endif
     }
 
     if (!demo->use_xlib)
@@ -3355,7 +3375,7 @@ static void processCommand(struct android_app* app, int32_t cmd) {
                 // Use the following key to send arguments, i.e.
                 // --es args "--validate"
                 const char key[] = "args";
-                char* appTag = (char*) "Cube";
+                char* appTag = (char*) APP_SHORT_NAME;
                 int argc = 0;
                 char** argv = get_args(app, key, appTag, &argc);