• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GStreamer
3  * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <glib/gprintf.h>
26 
27 #include "vkerror.h"
28 
29 /* *INDENT-OFF* */
30 static const struct
31 {
32   VkResult result;
33   const char *str;
34 } vk_result_string_map[] = {
35   {VK_ERROR_OUT_OF_HOST_MEMORY, "Out Of host memory"},
36   {VK_ERROR_OUT_OF_DEVICE_MEMORY, "Out of device memory"},
37   {VK_ERROR_INITIALIZATION_FAILED, "Initialization failed"},
38   {VK_ERROR_DEVICE_LOST, "Device lost"},
39   {VK_ERROR_MEMORY_MAP_FAILED, "Map failed"},
40   {VK_ERROR_LAYER_NOT_PRESENT, "Layer not present"},
41   {VK_ERROR_EXTENSION_NOT_PRESENT, "Extension not present"},
42   {VK_ERROR_FEATURE_NOT_PRESENT, "Feature not present"},
43   {VK_ERROR_INCOMPATIBLE_DRIVER, "Incompatible driver"},
44   {VK_ERROR_TOO_MANY_OBJECTS, "Too many objects"},
45   {VK_ERROR_FORMAT_NOT_SUPPORTED, "format not supported"},
46   {VK_ERROR_SURFACE_LOST_KHR, "Surface lost"},
47   {VK_ERROR_OUT_OF_DATE_KHR, "out of date"},
48   {VK_ERROR_INCOMPATIBLE_DISPLAY_KHR, "Incompatible display"},
49   {VK_ERROR_NATIVE_WINDOW_IN_USE_KHR, "Native window in use"},
50 };
51 /* *INDENT-ON* */
52 
53 GQuark
gst_vulkan_error_quark(void)54 gst_vulkan_error_quark (void)
55 {
56   return g_quark_from_static_string ("gst-vulkan-error");
57 }
58 
59 static const char *
_vk_result_to_string(VkResult result)60 _vk_result_to_string (VkResult result)
61 {
62   int i;
63 
64   if (result >= 0)
65     return NULL;
66   if (result < VK_RESULT_BEGIN_RANGE)
67     return "Unknown Error";
68 
69   for (i = 0; i < G_N_ELEMENTS (vk_result_string_map); i++) {
70     if (result == vk_result_string_map[i].result)
71       return vk_result_string_map[i].str;
72   }
73 
74   return "Unknown Error";
75 }
76 
77 VkResult
gst_vulkan_error_to_g_error(VkResult result,GError ** error,const char * format,...)78 gst_vulkan_error_to_g_error (VkResult result, GError ** error,
79     const char *format, ...)
80 {
81   const char *result_str;
82   gchar *string;
83   va_list args;
84 
85   if (error == NULL)
86     /* we don't have an error to set */
87     return result;
88 
89   result_str = _vk_result_to_string (result);
90   if (result_str == NULL)
91     return result;
92 
93   va_start (args, format);
94   g_vasprintf (&string, format, args);
95   va_end (args);
96 
97   g_set_error (error, GST_VULKAN_ERROR, result, "%s: %s", result_str, string);
98 
99   return result;
100 }
101