This is a better fix for https://github.com/libsdl-org/SDL/issues/16227. It also allows you to create a whole set of indexed textures from surfaces that share a single palette and then modify that palette to change all textures.
Validation Error: [ VUID-VkImageMemoryBarrier-oldLayout-01212 ] | MessageID = 0xff795e16
vkCmdPipelineBarrier(): pImageMemoryBarriers[0].newLayout (VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) is not compatible with VkImage 0x2160000000216 usage flags VK_IMAGE_USAGE_2_TRANSFER_DST_BIT_KHR|VK_IMAGE_USAGE_2_COLOR_ATTACHMENT_BIT_KHR.
The Vulkan spec states: If layouts are not ignored, oldLayout or newLayout is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL then image must have been created with the VK_IMAGE_USAGE_TRANSFER_SRC_BIT usage flag set (https://docs.vulkan.org/spec/latest/chapters/synchronization.html#VUID-VkImageMemoryBarrier-oldLayout-01212)
The use case for this is 2D render target overlays on HDR10 output. In this case we've already done the conversion to the output colorspace and we just want to get the pixels on the screen as fast as possible. Video frames still need YUV conversion, so they shouldn't go through this output path.
This doesn't actually save much code size and complicates the drivers a fair bit.
Upside is that you'll now be able to build SDL without software YUV support and still be able to play videos with hardware acceleration enabled.
The window may not have keyboard focus when using remote control tools, so drop the keyboard focus requirement. Tested not to regress clickthrough suppression.
This is a better fix for https://github.com/libsdl-org/SDL/issues/16227.
The original problem was that the newly created texture didn't have any palette, so when the surface data was set, colors couldn't be mapped to pixel index values. The old fix temporarily set the texture palette to the surface palette, copied the surface data, and then set the texture palette to a copy of the surface palette. This caused Vulkan validation errors because we were deleting the original palette which was still referenced by the active command buffer. Instead, we'll create the palette that we want the texture to have to start with, then copy the surface data once that's set.
By convention, PNNN YUV formats are bi-planar, and SDL was using them to refer to 3 plane YUV formats.
These have been replaced with I444 and I4FL, which are the most standard FOURCC values for these that I could find.
Reference: https://github.com/videolan/vlc/blob/master/src/misc/fourcc_list.h
The output integer scale may not be re-sent if the display geometry changed, but the scale factor didn't. Cache and restore it on the integer path, to prevent an old value from being used, and possibly rounded to zero if the old value was less than 1.0.
Clear the internal X11 clipboard selection data when updating the clipboard during SelectionNotify events, as it is invalid after the update. Otherwise, an out-of-date SelectionRequest can end up attempting to read the invalid data, and cause a crash.
Once the lock is released, another thread can clean up the completed
command buffer, return it to the pool and resubmit it with a different
fence before we read d3d12CommandBuffer->inFlightFence, handing the
caller a fence it doesn't own (or NULL).
METAL_ReleaseFence cleared the fence's MTLCommandBuffer without holding
submitLock, while METAL_Submit's cleanup loop may still be polling it
through submittedCommandBuffers. It also did so before the DecRef, so
any non-final release broke later waits on a still-owned fence.