SDL: Make sure we're actually using the HDR10 colorspace before using that shader

From fb823fbe95ebfde539616f5cea7f265be5897349 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 6 Feb 2024 16:32:07 -0800
Subject: [PATCH] Make sure we're actually using the HDR10 colorspace before
 using that shader

---
 src/render/metal/SDL_render_metal.m | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m
index 7fa4c1b5a9b1..bb2862941782 100644
--- a/src/render/metal/SDL_render_metal.m
+++ b/src/render/metal/SDL_render_metal.m
@@ -758,7 +758,12 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL
         } else if (texture->format == SDL_PIXELFORMAT_NV21) {
             texturedata.fragmentFunction = SDL_METAL_FRAGMENT_NV21;
         } else if (texture->format == SDL_PIXELFORMAT_P010) {
-            texturedata.fragmentFunction = SDL_METAL_FRAGMENT_HDR10;
+            if(SDL_COLORSPACEPRIMARIES(texture->colorspace) == SDL_COLOR_PRIMARIES_BT2020 &&
+               SDL_COLORSPACETRANSFER(texture->colorspace) == SDL_TRANSFER_CHARACTERISTICS_PQ) {
+                texturedata.fragmentFunction = SDL_METAL_FRAGMENT_HDR10;
+            } else {
+                return SDL_SetError("Unsupported YUV colorspace");
+            }
         } else
 #endif
         {