3 * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
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.
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.
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.
25 #include <glib/gprintf.h>
27 #include "gstvkerror.h"
31 * @title: GstVulkanError
32 * @short_description: Vulkan errors
33 * @see_also: #GstVulkanInstance, #GstVulkanDevice
41 } vk_result_string_map[] = {
42 {VK_ERROR_OUT_OF_HOST_MEMORY, "Out Of host memory"},
43 {VK_ERROR_OUT_OF_DEVICE_MEMORY, "Out of device memory"},
44 {VK_ERROR_INITIALIZATION_FAILED, "Initialization failed"},
45 {VK_ERROR_DEVICE_LOST, "Device lost"},
46 {VK_ERROR_MEMORY_MAP_FAILED, "Map failed"},
47 {VK_ERROR_LAYER_NOT_PRESENT, "Layer not present"},
48 {VK_ERROR_EXTENSION_NOT_PRESENT, "Extension not present"},
49 {VK_ERROR_FEATURE_NOT_PRESENT, "Feature not present"},
50 {VK_ERROR_INCOMPATIBLE_DRIVER, "Incompatible driver"},
51 {VK_ERROR_TOO_MANY_OBJECTS, "Too many objects"},
52 {VK_ERROR_FORMAT_NOT_SUPPORTED, "format not supported"},
53 {VK_ERROR_SURFACE_LOST_KHR, "Surface lost"},
54 {VK_ERROR_OUT_OF_DATE_KHR, "out of date"},
55 {VK_ERROR_INCOMPATIBLE_DISPLAY_KHR, "Incompatible display"},
56 {VK_ERROR_NATIVE_WINDOW_IN_USE_KHR, "Native window in use"},
61 gst_vulkan_error_quark (void)
63 return g_quark_from_static_string ("gst-vulkan-error");
67 _vk_result_to_string (VkResult result)
74 for (i = 0; i < G_N_ELEMENTS (vk_result_string_map); i++) {
75 if (result == vk_result_string_map[i].result)
76 return vk_result_string_map[i].str;
79 return "Unknown Error";
83 * gst_vulkan_error_to_g_error: (skip)
85 * @error: (inout) (optional): a #GError to fill
86 * @format: the printf-like format to write into the #GError
87 * @...: arguments for @format
89 * if @result indicates an error condition, fills out #GError with details of
92 * Returns: @result for easy chaining
97 gst_vulkan_error_to_g_error (VkResult result, GError ** error,
98 const char *format, ...)
100 const char *result_str;
105 /* we don't have an error to set */
108 result_str = _vk_result_to_string (result);
109 if (result_str == NULL) {
111 result_str = "Unknown";
117 va_start (args, format);
118 g_vasprintf (&string, format, args);
121 g_set_error (error, GST_VULKAN_ERROR, result, "%s (0x%x, %i): %s", result_str,
122 result, result, string);