File indexing completed on 2024-11-10 04:57:22
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2023 Xaver Hugl <xaver.hugl@gmail.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include "drm_format_helper.h" 0010 0011 namespace KWin 0012 { 0013 0014 std::optional<FormatInfo> FormatInfo::get(uint32_t drmFormat) 0015 { 0016 switch (drmFormat) { 0017 case DRM_FORMAT_XRGB8888: 0018 case DRM_FORMAT_XBGR8888: 0019 case DRM_FORMAT_RGBX8888: 0020 case DRM_FORMAT_BGRX8888: 0021 return FormatInfo{ 0022 .drmFormat = drmFormat, 0023 .bitsPerColor = 8, 0024 .alphaBits = 0, 0025 .bitsPerPixel = 32, 0026 .openglFormat = GL_RGBA8, 0027 }; 0028 case DRM_FORMAT_ARGB8888: 0029 case DRM_FORMAT_ABGR8888: 0030 case DRM_FORMAT_RGBA8888: 0031 case DRM_FORMAT_BGRA8888: 0032 return FormatInfo{ 0033 .drmFormat = drmFormat, 0034 .bitsPerColor = 8, 0035 .alphaBits = 8, 0036 .bitsPerPixel = 32, 0037 .openglFormat = GL_RGBA8, 0038 }; 0039 case DRM_FORMAT_XRGB2101010: 0040 case DRM_FORMAT_XBGR2101010: 0041 case DRM_FORMAT_RGBX1010102: 0042 case DRM_FORMAT_BGRX1010102: 0043 return FormatInfo{ 0044 .drmFormat = drmFormat, 0045 .bitsPerColor = 10, 0046 .alphaBits = 0, 0047 .bitsPerPixel = 32, 0048 .openglFormat = GL_RGB10_A2, 0049 }; 0050 case DRM_FORMAT_ARGB2101010: 0051 case DRM_FORMAT_ABGR2101010: 0052 case DRM_FORMAT_RGBA1010102: 0053 case DRM_FORMAT_BGRA1010102: 0054 return FormatInfo{ 0055 .drmFormat = drmFormat, 0056 .bitsPerColor = 10, 0057 .alphaBits = 2, 0058 .bitsPerPixel = 32, 0059 .openglFormat = GL_RGB10_A2, 0060 }; 0061 case DRM_FORMAT_XRGB16161616F: 0062 case DRM_FORMAT_XBGR16161616F: 0063 return FormatInfo{ 0064 .drmFormat = drmFormat, 0065 .bitsPerColor = 16, 0066 .alphaBits = 0, 0067 .bitsPerPixel = 64, 0068 .openglFormat = GL_RGBA16F, 0069 }; 0070 case DRM_FORMAT_ARGB16161616F: 0071 case DRM_FORMAT_ABGR16161616F: 0072 return FormatInfo{ 0073 .drmFormat = drmFormat, 0074 .bitsPerColor = 16, 0075 .alphaBits = 16, 0076 .bitsPerPixel = 64, 0077 .openglFormat = GL_RGBA16F, 0078 }; 0079 case DRM_FORMAT_ARGB4444: 0080 case DRM_FORMAT_ABGR4444: 0081 case DRM_FORMAT_RGBA4444: 0082 case DRM_FORMAT_BGRA4444: 0083 return FormatInfo{ 0084 .drmFormat = drmFormat, 0085 .bitsPerColor = 4, 0086 .alphaBits = 4, 0087 .bitsPerPixel = 16, 0088 .openglFormat = GL_RGBA4, 0089 }; 0090 case DRM_FORMAT_ARGB1555: 0091 case DRM_FORMAT_ABGR1555: 0092 case DRM_FORMAT_RGBA5551: 0093 case DRM_FORMAT_BGRA5551: 0094 return FormatInfo{ 0095 .drmFormat = drmFormat, 0096 .bitsPerColor = 5, 0097 .alphaBits = 1, 0098 .bitsPerPixel = 16, 0099 .openglFormat = GL_RGB5_A1, 0100 }; 0101 case DRM_FORMAT_NV12: 0102 return FormatInfo{ 0103 .drmFormat = drmFormat, 0104 .bitsPerColor = 8, 0105 .alphaBits = 0, 0106 .bitsPerPixel = 24, 0107 .openglFormat = GL_R8, 0108 }; 0109 default: 0110 return std::nullopt; 0111 } 0112 } 0113 0114 QString FormatInfo::drmFormatName(const QString &prefix, uint32_t format) 0115 { 0116 return QString::asprintf( 0117 "%s%c%c%c%c %s-endian (0x%08x)", prefix.toUtf8().constData(), 0118 QLatin1Char(format & 0xff).toLatin1(), 0119 QLatin1Char((format >> 8) & 0xff).toLatin1(), 0120 QLatin1Char((format >> 16) & 0xff).toLatin1(), 0121 QLatin1Char((format >> 24) & 0x7f).toLatin1(), 0122 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little", 0123 format); 0124 } 0125 0126 }