summaryrefslogtreecommitdiff
path: root/files/patches/gamescope_1826.diff
blob: 69c85e8e43d24e37ab3e2cfb6190d0d3fbbf470b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
index 7e68a44fb..65e35f525 100644
--- a/src/Backends/WaylandBackend.cpp
+++ b/src/Backends/WaylandBackend.cpp
@@ -2002,24 +2002,32 @@ namespace gamescope
         // Prefer opaque for composition on the Wayland backend.
 
         uint32_t u8BitFormat = DRM_FORMAT_INVALID;
-        if ( SupportsFormat( DRM_FORMAT_XRGB8888 ) )
-            u8BitFormat = DRM_FORMAT_XRGB8888;
-        else if ( SupportsFormat( DRM_FORMAT_XBGR8888 ) )
-            u8BitFormat = DRM_FORMAT_XBGR8888;
-        else if ( SupportsFormat( DRM_FORMAT_ARGB8888 ) )
-            u8BitFormat = DRM_FORMAT_ARGB8888;
-        else if ( SupportsFormat( DRM_FORMAT_ABGR8888 ) )
-            u8BitFormat = DRM_FORMAT_ABGR8888;
+        for (int i = 0; i < 2 && u8BitFormat == DRM_FORMAT_INVALID; i++)
+        {
+            bool invalidOnly = i == 0;
+            if ( SupportsFormat( DRM_FORMAT_XRGB8888, invalidOnly ) )
+                u8BitFormat = DRM_FORMAT_XRGB8888;
+            else if ( SupportsFormat( DRM_FORMAT_XBGR8888, invalidOnly ) )
+                u8BitFormat = DRM_FORMAT_XBGR8888;
+            else if ( SupportsFormat( DRM_FORMAT_ARGB8888, invalidOnly ) )
+                u8BitFormat = DRM_FORMAT_ARGB8888;
+            else if ( SupportsFormat( DRM_FORMAT_ABGR8888, invalidOnly ) )
+                u8BitFormat = DRM_FORMAT_ABGR8888;
+        }
 
         uint32_t u10BitFormat = DRM_FORMAT_INVALID;
-        if ( SupportsFormat( DRM_FORMAT_XBGR2101010 ) )
-            u10BitFormat = DRM_FORMAT_XBGR2101010;
-        else if ( SupportsFormat( DRM_FORMAT_XRGB2101010 ) )
-            u10BitFormat = DRM_FORMAT_XRGB2101010;
-        else if ( SupportsFormat( DRM_FORMAT_ABGR2101010 ) )
-            u10BitFormat = DRM_FORMAT_ABGR2101010;
-        else if ( SupportsFormat( DRM_FORMAT_ARGB2101010 ) )
-            u10BitFormat = DRM_FORMAT_ARGB2101010;
+        for (int i = 0; i < 2 && u10BitFormat == DRM_FORMAT_INVALID; i++)
+        {
+            bool invalidOnly = i == 0;
+            if ( SupportsFormat( DRM_FORMAT_XBGR2101010, invalidOnly ) )
+                u10BitFormat = DRM_FORMAT_XBGR2101010;
+            else if ( SupportsFormat( DRM_FORMAT_XRGB2101010, invalidOnly ) )
+                u10BitFormat = DRM_FORMAT_XRGB2101010;
+            else if ( SupportsFormat( DRM_FORMAT_ABGR2101010, invalidOnly ) )
+                u10BitFormat = DRM_FORMAT_ABGR2101010;
+            else if ( SupportsFormat( DRM_FORMAT_ARGB2101010, invalidOnly ) )
+                u10BitFormat = DRM_FORMAT_ARGB2101010;
+        }
 
         assert( u8BitFormat != DRM_FORMAT_INVALID );
 
diff --git a/src/backend.h b/src/backend.h
index 29219dbc8..2767546cd 100644
--- a/src/backend.h
+++ b/src/backend.h
@@ -309,9 +309,11 @@ namespace gamescope
 
         virtual bool UsesModifiers() const = 0;
         virtual std::span<const uint64_t> GetSupportedModifiers( uint32_t uDrmFormat ) const = 0;
-        inline bool SupportsFormat( uint32_t uDrmFormat ) const
+        inline bool SupportsFormat( uint32_t uDrmFormat, bool invalidOnly ) const
         {
-            return Algorithm::Contains( this->GetSupportedModifiers( uDrmFormat ), DRM_FORMAT_MOD_INVALID );
+            if ( invalidOnly )
+                return Algorithm::Contains( this->GetSupportedModifiers( uDrmFormat ), DRM_FORMAT_MOD_INVALID );
+            return !this->GetSupportedModifiers( uDrmFormat ).empty();
         }
 
         virtual IBackendConnector *GetCurrentConnector() = 0;
diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
index b8412b8fd..f41ef4c9b 100644
--- a/src/rendervulkan.cpp
+++ b/src/rendervulkan.cpp
@@ -2814,7 +2814,7 @@ bool vulkan_init_format(VkFormat format, uint32_t drmFormat)
 	}
 	else
 	{
-		if ( GetBackend()->UsesModifiers() && !GetBackend()->SupportsFormat( drmFormat ) )
+		if ( GetBackend()->UsesModifiers() && !GetBackend()->SupportsFormat( drmFormat, true ) )
 			return false;
 
 		wlr_drm_format_set_add( &sampledDRMFormats, drmFormat, DRM_FORMAT_MOD_INVALID );