KWin
Loading...
Searching...
No Matches
drm_format_helper.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2023 Xaver Hugl <xaver.hugl@gmail.com>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "drm_format_helper.h"
10
11namespace KWin
12{
13
14std::optional<FormatInfo> FormatInfo::get(uint32_t drmFormat)
15{
16 switch (drmFormat) {
17 case DRM_FORMAT_XRGB8888:
18 case DRM_FORMAT_XBGR8888:
19 case DRM_FORMAT_RGBX8888:
20 case DRM_FORMAT_BGRX8888:
21 return FormatInfo{
23 .bitsPerColor = 8,
24 .alphaBits = 0,
25 .bitsPerPixel = 32,
26 .openglFormat = GL_RGBA8,
27 };
28 case DRM_FORMAT_ARGB8888:
29 case DRM_FORMAT_ABGR8888:
30 case DRM_FORMAT_RGBA8888:
31 case DRM_FORMAT_BGRA8888:
32 return FormatInfo{
34 .bitsPerColor = 8,
35 .alphaBits = 8,
36 .bitsPerPixel = 32,
37 .openglFormat = GL_RGBA8,
38 };
39 case DRM_FORMAT_XRGB2101010:
40 case DRM_FORMAT_XBGR2101010:
41 case DRM_FORMAT_RGBX1010102:
42 case DRM_FORMAT_BGRX1010102:
43 return FormatInfo{
45 .bitsPerColor = 10,
46 .alphaBits = 0,
47 .bitsPerPixel = 32,
48 .openglFormat = GL_RGB10_A2,
49 };
50 case DRM_FORMAT_ARGB2101010:
51 case DRM_FORMAT_ABGR2101010:
52 case DRM_FORMAT_RGBA1010102:
53 case DRM_FORMAT_BGRA1010102:
54 return FormatInfo{
56 .bitsPerColor = 10,
57 .alphaBits = 2,
58 .bitsPerPixel = 32,
59 .openglFormat = GL_RGB10_A2,
60 };
61 case DRM_FORMAT_XRGB16161616F:
62 case DRM_FORMAT_XBGR16161616F:
63 return FormatInfo{
65 .bitsPerColor = 16,
66 .alphaBits = 0,
67 .bitsPerPixel = 64,
68 .openglFormat = GL_RGBA16F,
69 };
70 case DRM_FORMAT_ARGB16161616F:
71 case DRM_FORMAT_ABGR16161616F:
72 return FormatInfo{
74 .bitsPerColor = 16,
75 .alphaBits = 16,
76 .bitsPerPixel = 64,
77 .openglFormat = GL_RGBA16F,
78 };
79 case DRM_FORMAT_ARGB4444:
80 case DRM_FORMAT_ABGR4444:
81 case DRM_FORMAT_RGBA4444:
82 case DRM_FORMAT_BGRA4444:
83 return FormatInfo{
85 .bitsPerColor = 4,
86 .alphaBits = 4,
87 .bitsPerPixel = 16,
88 .openglFormat = GL_RGBA4,
89 };
90 case DRM_FORMAT_ARGB1555:
91 case DRM_FORMAT_ABGR1555:
92 case DRM_FORMAT_RGBA5551:
93 case DRM_FORMAT_BGRA5551:
94 return FormatInfo{
96 .bitsPerColor = 5,
97 .alphaBits = 1,
98 .bitsPerPixel = 16,
99 .openglFormat = GL_RGB5_A1,
100 };
101 case DRM_FORMAT_NV12:
102 return FormatInfo{
104 .bitsPerColor = 8,
105 .alphaBits = 0,
106 .bitsPerPixel = 24,
107 .openglFormat = GL_R8,
108 };
109 default:
110 return std::nullopt;
111 }
112}
113
114QString FormatInfo::drmFormatName(const QString &prefix, uint32_t format)
115{
116 return QString::asprintf(
117 "%s%c%c%c%c %s-endian (0x%08x)", prefix.toUtf8().constData(),
118 QLatin1Char(format & 0xff).toLatin1(),
119 QLatin1Char((format >> 8) & 0xff).toLatin1(),
120 QLatin1Char((format >> 16) & 0xff).toLatin1(),
121 QLatin1Char((format >> 24) & 0x7f).toLatin1(),
122 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
123 format);
124}
125
126}
GLenum format
Definition gltexture.cpp:49
static QString drmFormatName(const QString &prefix, uint32_t format)
static std::optional< FormatInfo > get(uint32_t drmFormat)