gdk: Add function to query alpha format for depth
authorBenjamin Otte <otte@redhat.com>
Fri, 21 Jul 2023 23:11:19 +0000 (01:11 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 21 Jul 2023 23:33:44 +0000 (01:33 +0200)
It's meant to be used in renderers.

gdk/gdkmemoryformat.c
gdk/gdkmemoryformatprivate.h

index 95663e9ba74466f582633a838bc8dce7887297b4..ec5583a2add97a4f574f342efdbfcbf38e64c730 100644 (file)
@@ -704,6 +704,33 @@ gdk_memory_depth_merge (GdkMemoryDepth depth1,
     }
 }
 
+/*
+ * gdk_memory_depth_get_alpha_format:
+ * @depth: the depth
+ *
+ * Gets the preferred format to use for rendering masks and other
+ * alpha-only content.
+ *
+ * Returns: the format
+ **/
+GdkMemoryFormat
+gdk_memory_depth_get_alpha_format (GdkMemoryDepth depth)
+{
+  switch (depth)
+    {
+      case GDK_MEMORY_U8:
+        return GDK_MEMORY_A8;
+      case GDK_MEMORY_U16:
+        return GDK_MEMORY_A16;
+      case GDK_MEMORY_FLOAT16:
+        return GDK_MEMORY_A16_FLOAT;
+      case GDK_MEMORY_FLOAT32:
+        return GDK_MEMORY_A32_FLOAT;
+      default:
+        g_return_val_if_reached (GDK_MEMORY_A8);
+    }
+}
+
 gboolean
 gdk_memory_format_gl_format (GdkMemoryFormat  format,
                              gboolean         gles,
index 07286d9a6ccd141c21b54621f95b1ee32f5f3b86..9f56442de598d7606335bca26dcdb55d42122512 100644 (file)
@@ -44,6 +44,7 @@ gsize                   gdk_memory_format_bytes_per_pixel   (GdkMemoryFormat
 GdkMemoryDepth          gdk_memory_format_get_depth         (GdkMemoryFormat             format) G_GNUC_CONST;
 GdkMemoryDepth          gdk_memory_depth_merge              (GdkMemoryDepth              depth1,
                                                              GdkMemoryDepth              depth2) G_GNUC_CONST;
+GdkMemoryFormat         gdk_memory_depth_get_alpha_format   (GdkMemoryDepth              depth) G_GNUC_CONST;
 gboolean                gdk_memory_format_gl_format         (GdkMemoryFormat             format,
                                                              gboolean                    gles,
                                                              guint                       gl_major,