vulkan: Allocate render ops differently
authorBenjamin Otte <otte@redhat.com>
Sat, 24 Jun 2023 02:09:56 +0000 (04:09 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 16 Jul 2023 10:12:36 +0000 (12:12 +0200)
Allocate the memory up front instead of passing the Op into it.

This way, we can split ops into their own source file and use
init/finish style to use them.

gsk/vulkan/gskvulkanrenderpass.c

index f0ffc0dea0624f13abafe3b1f28358924ddc2d70..12322fd8930abf89b414105204d23a2fbe50e2a6 100644 (file)
@@ -293,6 +293,23 @@ gsk_vulkan_render_pass_free (GskVulkanRenderPass *self)
   g_free (self);
 }
 
+static gpointer
+gsk_vulkan_render_pass_alloc_op (GskVulkanRenderPass *self,
+                                 gsize                size)
+{
+  gsize pos;
+
+  pos = gsk_vulkan_render_ops_get_size (&self->render_ops);
+
+  gsk_vulkan_render_ops_splice (&self->render_ops,
+                                pos,
+                                0, FALSE,
+                                NULL,
+                                size);
+
+  return gsk_vulkan_render_ops_index (&self->render_ops, pos);
+}
+
 static void
 gsk_vulkan_render_pass_add_op (GskVulkanRenderPass *self,
                                GskVulkanOp         *op);
@@ -2536,12 +2553,11 @@ static void
 gsk_vulkan_render_pass_add_op (GskVulkanRenderPass *self,
                                GskVulkanOp         *op)
 {
-  op->op_class = &GSK_VULKAN_OP_ALL_CLASS;
+  GskVulkanOpAll *alloc;
 
-  gsk_vulkan_render_ops_splice (&self->render_ops,
-                                gsk_vulkan_render_ops_get_size (&self->render_ops),
-                                0, FALSE,
-                                (guchar *) op,
-                                sizeof (GskVulkanOpAll));
+  alloc = gsk_vulkan_render_pass_alloc_op (self, GSK_VULKAN_OP_ALL_CLASS.size);
+
+  op->op_class = &GSK_VULKAN_OP_ALL_CLASS;
+  *alloc = *(GskVulkanOpAll *) op;
 }