mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-28 02:26:16 +00:00
comp: Use U_TYPED_CALLOC/U_TYPED_ARRAY_CALLOC
This commit is contained in:
parent
f7d990c7e3
commit
5b4c3a2f94
|
@ -12,7 +12,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util/u_misc.h"
|
||||
#include "util/u_debug.h"
|
||||
|
||||
#include "common/comp_vk.h"
|
||||
|
||||
|
||||
|
@ -847,8 +849,7 @@ vk_find_graphics_queue(struct vk_bundle *vk, uint32_t *out_graphics_queue)
|
|||
&num_queues, NULL);
|
||||
|
||||
VkQueueFamilyProperties *queue_family_props =
|
||||
(VkQueueFamilyProperties *)malloc(sizeof(VkQueueFamilyProperties) *
|
||||
num_queues);
|
||||
U_TYPED_ARRAY_CALLOC(VkQueueFamilyProperties, num_queues);
|
||||
|
||||
vk->vkGetPhysicalDeviceQueueFamilyProperties(
|
||||
vk->physical_device, &num_queues, queue_family_props);
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util/u_misc.h"
|
||||
|
||||
#include "comp_vk_swapchain.h"
|
||||
|
||||
|
||||
|
@ -241,8 +243,7 @@ _find_surface_format(struct vk_swapchain *sc,
|
|||
sc->vk->physical_device, surface, &num_formats, NULL);
|
||||
|
||||
if (num_formats != 0) {
|
||||
formats = (VkSurfaceFormatKHR *)malloc(
|
||||
sizeof(VkSurfaceFormatKHR) * num_formats);
|
||||
formats = U_TYPED_ARRAY_CALLOC(VkSurfaceFormatKHR, num_formats);
|
||||
sc->vk->vkGetPhysicalDeviceSurfaceFormatsKHR(
|
||||
sc->vk->physical_device, surface, &num_formats, formats);
|
||||
} else {
|
||||
|
@ -276,8 +277,8 @@ _check_surface_present_mode(struct vk_bundle *vk,
|
|||
vk->physical_device, surface, &num_present_modes, NULL);
|
||||
|
||||
if (num_present_modes != 0) {
|
||||
present_modes = (VkPresentModeKHR *)malloc(
|
||||
sizeof(VkPresentModeKHR) * num_present_modes);
|
||||
present_modes =
|
||||
U_TYPED_ARRAY_CALLOC(VkPresentModeKHR, num_present_modes);
|
||||
vk->vkGetPhysicalDeviceSurfacePresentModesKHR(
|
||||
vk->physical_device, surface, &num_present_modes,
|
||||
present_modes);
|
||||
|
@ -306,7 +307,7 @@ vk_swapchain_create_image_views(struct vk_swapchain *sc)
|
|||
assert(sc->image_count > 0);
|
||||
VK_DEBUG(sc->vk, "Creating %d image views.", sc->image_count);
|
||||
|
||||
VkImage *images = (VkImage *)malloc(sizeof(VkImage) * sc->image_count);
|
||||
VkImage *images = U_TYPED_ARRAY_CALLOC(VkImage, sc->image_count);
|
||||
sc->vk->vkGetSwapchainImagesKHR(sc->vk->device, sc->swap_chain,
|
||||
&sc->image_count, images);
|
||||
|
||||
|
@ -314,8 +315,8 @@ vk_swapchain_create_image_views(struct vk_swapchain *sc)
|
|||
free(sc->buffers);
|
||||
}
|
||||
|
||||
sc->buffers = (struct vk_swapchain_buffer *)malloc(
|
||||
sizeof(struct vk_swapchain_buffer) * sc->image_count);
|
||||
sc->buffers =
|
||||
U_TYPED_ARRAY_CALLOC(struct vk_swapchain_buffer, sc->image_count);
|
||||
|
||||
for (uint32_t i = 0; i < sc->image_count; i++) {
|
||||
sc->buffers[i].image = images[i];
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "util/u_misc.h"
|
||||
|
||||
#include "xrt/xrt_compositor.h"
|
||||
#include "main/comp_distortion.h"
|
||||
|
||||
|
@ -144,7 +146,7 @@ renderer_destroy(struct comp_renderer *r);
|
|||
struct comp_renderer *
|
||||
comp_renderer_create(struct comp_compositor *c)
|
||||
{
|
||||
struct comp_renderer *r = malloc(sizeof(struct comp_renderer));
|
||||
struct comp_renderer *r = U_TYPED_CALLOC(struct comp_renderer);
|
||||
|
||||
renderer_create(r, c);
|
||||
renderer_init(r);
|
||||
|
@ -690,7 +692,7 @@ renderer_allocate_command_buffers(struct comp_renderer *r, uint32_t count)
|
|||
|
||||
r->num_cmd_buffers = count;
|
||||
|
||||
r->cmd_buffers = malloc(sizeof(VkCommandBuffer) * count);
|
||||
r->cmd_buffers = U_TYPED_ARRAY_CALLOC(VkCommandBuffer, count);
|
||||
|
||||
VkCommandBufferAllocateInfo cmd_buffer_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
||||
|
@ -797,7 +799,7 @@ renderer_create_frame_buffers(struct comp_renderer *r, uint32_t count)
|
|||
if (r->frame_buffers != NULL)
|
||||
free(r->frame_buffers);
|
||||
|
||||
r->frame_buffers = malloc(sizeof(VkFramebuffer) * count);
|
||||
r->frame_buffers = U_TYPED_ARRAY_CALLOC(VkFramebuffer, count);
|
||||
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
VkImageView attachments[1] = {
|
||||
|
|
Loading…
Reference in a new issue