2020-07-07 10:06:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Andri Yngvason
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2020-06-20 21:41:53 +00:00
|
|
|
#include "pixels.h"
|
|
|
|
|
|
|
|
#include <pixman.h>
|
|
|
|
#include <wayland-client.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <libdrm/drm_fourcc.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
enum wl_shm_format fourcc_to_wl_shm(uint32_t in)
|
|
|
|
{
|
|
|
|
assert(!(in & DRM_FORMAT_BIG_ENDIAN));
|
|
|
|
|
|
|
|
switch (in) {
|
|
|
|
case DRM_FORMAT_ARGB8888: return WL_SHM_FORMAT_ARGB8888;
|
|
|
|
case DRM_FORMAT_XRGB8888: return WL_SHM_FORMAT_XRGB8888;
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2020-07-16 18:09:18 +00:00
|
|
|
uint32_t fourcc_from_wl_shm(enum wl_shm_format in)
|
|
|
|
{
|
|
|
|
switch (in) {
|
|
|
|
case WL_SHM_FORMAT_ARGB8888: return DRM_FORMAT_ARGB8888;
|
|
|
|
case WL_SHM_FORMAT_XRGB8888: return DRM_FORMAT_XRGB8888;
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
2023-09-26 17:59:26 +00:00
|
|
|
|
|
|
|
int pixel_size_from_fourcc(uint32_t fourcc)
|
|
|
|
{
|
|
|
|
switch (fourcc & ~DRM_FORMAT_BIG_ENDIAN) {
|
|
|
|
case DRM_FORMAT_RGBA1010102:
|
|
|
|
case DRM_FORMAT_RGBX1010102:
|
|
|
|
case DRM_FORMAT_BGRA1010102:
|
|
|
|
case DRM_FORMAT_BGRX1010102:
|
|
|
|
case DRM_FORMAT_ARGB2101010:
|
|
|
|
case DRM_FORMAT_XRGB2101010:
|
|
|
|
case DRM_FORMAT_ABGR2101010:
|
|
|
|
case DRM_FORMAT_XBGR2101010:
|
|
|
|
case DRM_FORMAT_RGBA8888:
|
|
|
|
case DRM_FORMAT_RGBX8888:
|
|
|
|
case DRM_FORMAT_BGRA8888:
|
|
|
|
case DRM_FORMAT_BGRX8888:
|
|
|
|
case DRM_FORMAT_ARGB8888:
|
|
|
|
case DRM_FORMAT_XRGB8888:
|
|
|
|
case DRM_FORMAT_ABGR8888:
|
|
|
|
case DRM_FORMAT_XBGR8888:
|
|
|
|
return 4;
|
|
|
|
case DRM_FORMAT_BGR888:
|
|
|
|
case DRM_FORMAT_RGB888:
|
|
|
|
return 3;
|
|
|
|
case DRM_FORMAT_RGBA4444:
|
|
|
|
case DRM_FORMAT_RGBX4444:
|
|
|
|
case DRM_FORMAT_BGRA4444:
|
|
|
|
case DRM_FORMAT_BGRX4444:
|
|
|
|
case DRM_FORMAT_ARGB4444:
|
|
|
|
case DRM_FORMAT_XRGB4444:
|
|
|
|
case DRM_FORMAT_ABGR4444:
|
|
|
|
case DRM_FORMAT_XBGR4444:
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|