// SPDX-License-Identifier: GPL-2.0 or MIT /* * Copyright (C) 2016 Noralf Trønnes * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version.
*/
/** * drm_format_conv_state_init - Initialize format-conversion state * @state: The state to initialize * * Clears all fields in struct drm_format_conv_state. The state will * be empty with no preallocated resources.
*/ void drm_format_conv_state_init(struct drm_format_conv_state *state)
{
state->tmp.mem = NULL;
state->tmp.size = 0;
state->tmp.preallocated = false;
}
EXPORT_SYMBOL(drm_format_conv_state_init);
/** * drm_format_conv_state_copy - Copy format-conversion state * @state: Destination state * @old_state: Source state * * Copies format-conversion state from @old_state to @state; except for * temporary storage.
*/ void drm_format_conv_state_copy(struct drm_format_conv_state *state, conststruct drm_format_conv_state *old_state)
{ /* * So far, there's only temporary storage here, which we don't * duplicate. Just clear the fields.
*/
state->tmp.mem = NULL;
state->tmp.size = 0;
state->tmp.preallocated = false;
}
EXPORT_SYMBOL(drm_format_conv_state_copy);
/** * drm_format_conv_state_reserve - Allocates storage for format conversion * @state: The format-conversion state * @new_size: The minimum allocation size * @flags: Flags for kmalloc() * * Allocates at least @new_size bytes and returns a pointer to the memory * range. After calling this function, previously returned memory blocks * are invalid. It's best to collect all memory requirements of a format * conversion and call this function once to allocate the range. * * Returns: * A pointer to the allocated memory range, or NULL otherwise.
*/ void *drm_format_conv_state_reserve(struct drm_format_conv_state *state,
size_t new_size, gfp_t flags)
{ void *mem;
if (new_size <= state->tmp.size) goto out; elseif (state->tmp.preallocated) return NULL;
mem = krealloc(state->tmp.mem, new_size, flags); if (!mem) return NULL;
/** * drm_format_conv_state_release - Releases an format-conversion storage * @state: The format-conversion state * * Releases the memory range references by the format-conversion state. * After this call, all pointers to the memory are invalid. Prefer * drm_format_conv_state_init() for cleaning up and unloading a driver.
*/ void drm_format_conv_state_release(struct drm_format_conv_state *state)
{ if (state->tmp.preallocated) return;
/* * Some source buffers, such as DMA memory, use write-combine * caching, so reads are uncached. Speed up access by fetching * one line at a time.
*/ if (!vaddr_cached_hint) {
stmp = drm_format_conv_state_reserve(state, sbuf_len, GFP_KERNEL); if (!stmp) return -ENOMEM;
}
while (sbuf32 < send32)
*dbuf32++ = cpu_to_le32(xfrm_pixel(le32_to_cpup(sbuf32++)));
}
/** * drm_fb_memcpy - Copy clip buffer * @dst: Array of destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of source buffers * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * * This function copies parts of a framebuffer to display memory. Destination and * framebuffer formats must match. No conversion takes place. The parameters @dst, * @dst_pitch and @src refer to arrays. Each array must have at least as many entries * as there are planes in @fb's format. Each entry stores the value for the format's * respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner).
*/ void drm_fb_memcpy(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip)
{ staticconstunsignedint default_dst_pitch[DRM_FORMAT_MAX_PLANES] = {
0, 0, 0, 0
};
conststruct drm_format_info *format = fb->format; unsignedint i, y, lines = drm_rect_height(clip);
while (sbuf32 < send32)
*dbuf32++ = swab32(*sbuf32++);
}
/** * drm_fb_swab - Swap bytes into clip buffer * @dst: Array of destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of source buffers * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @cached: Source buffer is mapped cached (eg. not write-combined) * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and swaps per-pixel * bytes during the process. Destination and framebuffer formats must match. The * parameters @dst, @dst_pitch and @src refer to arrays. Each array must have at * least as many entries as there are planes in @fb's format. Each entry stores the * value for the format's respective color plane at the same index. If @cached is * false a temporary buffer is used to cache one pixel line at a time to speed up * slow uncached reads. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner).
*/ void drm_fb_swab(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, bool cached, struct drm_format_conv_state *state)
{ conststruct drm_format_info *format = fb->format;
u8 cpp = DIV_ROUND_UP(drm_format_info_bpp(format, 0), 8); void (*swab_line)(void *dbuf, constvoid *sbuf, unsignedint npixels);
switch (cpp) { case 4:
swab_line = drm_fb_swab32_line; break; case 2:
swab_line = drm_fb_swab16_line; break; default:
drm_warn_once(fb->dev, "Format %p4cc has unsupported pixel size.\n",
&format->format); return;
}
/** * drm_fb_xrgb8888_to_rgb332 - Convert XRGB8888 to RGB332 clip buffer * @dst: Array of RGB332 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffers * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts the * color format during the process. Destination and framebuffer formats must match. The * parameters @dst, @dst_pitch and @src refer to arrays. Each array must have at * least as many entries as there are planes in @fb's format. Each entry stores the * value for the format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for RGB332 devices that don't support XRGB8888 natively.
*/ void drm_fb_xrgb8888_to_rgb332(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
1,
};
/** * drm_fb_xrgb8888_to_rgb565 - Convert XRGB8888 to RGB565 clip buffer * @dst: Array of RGB565 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffer * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts the * color format during the process. Destination and framebuffer formats must match. The * parameters @dst, @dst_pitch and @src refer to arrays. Each array must have at * least as many entries as there are planes in @fb's format. Each entry stores the * value for the format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for RGB565 devices that don't support XRGB8888 natively.
*/ void drm_fb_xrgb8888_to_rgb565(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
2,
};
/** * drm_fb_xrgb8888_to_rgb565be - Convert XRGB8888 to RGB565|DRM_FORMAT_BIG_ENDIAN clip buffer * @dst: Array of RGB565BE destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffer * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts the * color format during the process. Destination and framebuffer formats must match. The * parameters @dst, @dst_pitch and @src refer to arrays. Each array must have at * least as many entries as there are planes in @fb's format. Each entry stores the * value for the format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for RGB565BE devices that don't support XRGB8888 natively.
*/ void drm_fb_xrgb8888_to_rgb565be(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
2,
};
/** * drm_fb_xrgb8888_to_xrgb1555 - Convert XRGB8888 to XRGB1555 clip buffer * @dst: Array of XRGB1555 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffer * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts * the color format during the process. The parameters @dst, @dst_pitch and * @src refer to arrays. Each array must have at least as many entries as * there are planes in @fb's format. Each entry stores the value for the * format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for XRGB1555 devices that don't support * XRGB8888 natively.
*/ void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
2,
};
/** * drm_fb_xrgb8888_to_argb1555 - Convert XRGB8888 to ARGB1555 clip buffer * @dst: Array of ARGB1555 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffer * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts * the color format during the process. The parameters @dst, @dst_pitch and * @src refer to arrays. Each array must have at least as many entries as * there are planes in @fb's format. Each entry stores the value for the * format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for ARGB1555 devices that don't support * XRGB8888 natively. It sets an opaque alpha channel as part of the conversion.
*/ void drm_fb_xrgb8888_to_argb1555(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
2,
};
/** * drm_fb_xrgb8888_to_rgba5551 - Convert XRGB8888 to RGBA5551 clip buffer * @dst: Array of RGBA5551 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffer * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts * the color format during the process. The parameters @dst, @dst_pitch and * @src refer to arrays. Each array must have at least as many entries as * there are planes in @fb's format. Each entry stores the value for the * format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for RGBA5551 devices that don't support * XRGB8888 natively. It sets an opaque alpha channel as part of the conversion.
*/ void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
2,
};
/** * drm_fb_xrgb8888_to_rgb888 - Convert XRGB8888 to RGB888 clip buffer * @dst: Array of RGB888 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffers * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts the * color format during the process. Destination and framebuffer formats must match. The * parameters @dst, @dst_pitch and @src refer to arrays. Each array must have at * least as many entries as there are planes in @fb's format. Each entry stores the * value for the format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for RGB888 devices that don't natively * support XRGB8888.
*/ void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
3,
};
/** * drm_fb_xrgb8888_to_bgr888 - Convert XRGB8888 to BGR888 clip buffer * @dst: Array of BGR888 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffers * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts the * color format during the process. Destination and framebuffer formats must match. The * parameters @dst, @dst_pitch and @src refer to arrays. Each array must have at * least as many entries as there are planes in @fb's format. Each entry stores the * value for the format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for BGR888 devices that don't natively * support XRGB8888.
*/ void drm_fb_xrgb8888_to_bgr888(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
3,
};
/** * drm_fb_xrgb8888_to_argb8888 - Convert XRGB8888 to ARGB8888 clip buffer * @dst: Array of ARGB8888 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffer * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts the * color format during the process. The parameters @dst, @dst_pitch and @src refer * to arrays. Each array must have at least as many entries as there are planes in * @fb's format. Each entry stores the value for the format's respective color plane * at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for ARGB8888 devices that don't support XRGB8888 * natively. It sets an opaque alpha channel as part of the conversion.
*/ void drm_fb_xrgb8888_to_argb8888(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
4,
};
/** * drm_fb_xrgb8888_to_abgr8888 - Convert XRGB8888 to ABGR8888 clip buffer * @dst: Array of ABGR8888 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffer * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts the * color format during the process. The parameters @dst, @dst_pitch and @src refer * to arrays. Each array must have at least as many entries as there are planes in * @fb's format. Each entry stores the value for the format's respective color plane * at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for ABGR8888 devices that don't support XRGB8888 * natively. It sets an opaque alpha channel as part of the conversion.
*/ void drm_fb_xrgb8888_to_abgr8888(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
4,
};
/** * drm_fb_xrgb8888_to_xbgr8888 - Convert XRGB8888 to XBGR8888 clip buffer * @dst: Array of XBGR8888 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffer * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts the * color format during the process. The parameters @dst, @dst_pitch and @src refer * to arrays. Each array must have at least as many entries as there are planes in * @fb's format. Each entry stores the value for the format's respective color plane * at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for XBGR8888 devices that don't support XRGB8888 * natively.
*/ void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
4,
};
/** * drm_fb_xrgb8888_to_bgrx8888 - Convert XRGB8888 to BGRX8888 clip buffer * @dst: Array of BGRX8888 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffer * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts the * color format during the process. The parameters @dst, @dst_pitch and @src refer * to arrays. Each array must have at least as many entries as there are planes in * @fb's format. Each entry stores the value for the format's respective color plane * at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for BGRX8888 devices that don't support XRGB8888 * natively.
*/ void drm_fb_xrgb8888_to_bgrx8888(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
4,
};
/** * drm_fb_xrgb8888_to_xrgb2101010 - Convert XRGB8888 to XRGB2101010 clip buffer * @dst: Array of XRGB2101010 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffers * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts the * color format during the process. Destination and framebuffer formats must match. The * parameters @dst, @dst_pitch and @src refer to arrays. Each array must have at * least as many entries as there are planes in @fb's format. Each entry stores the * value for the format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for XRGB2101010 devices that don't support XRGB8888 * natively.
*/ void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
4,
};
/** * drm_fb_xrgb8888_to_argb2101010 - Convert XRGB8888 to ARGB2101010 clip buffer * @dst: Array of ARGB2101010 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffers * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts * the color format during the process. The parameters @dst, @dst_pitch and * @src refer to arrays. Each array must have at least as many entries as * there are planes in @fb's format. Each entry stores the value for the * format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for ARGB2101010 devices that don't support XRGB8888 * natively.
*/ void drm_fb_xrgb8888_to_argb2101010(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
4,
};
/** * drm_fb_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale * @dst: Array of 8-bit grayscale destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffers * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts the * color format during the process. Destination and framebuffer formats must match. The * parameters @dst, @dst_pitch and @src refer to arrays. Each array must have at * least as many entries as there are planes in @fb's format. Each entry stores the * value for the format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * DRM doesn't have native monochrome or grayscale support. Drivers can use this * function for grayscale devices that don't support XRGB8888 natively.Such * drivers can announce the commonly supported XR24 format to userspace and use * this function to convert to the native format. Monochrome drivers will use the * most significant bit, where 1 means foreground color and 0 background color. * ITU BT.601 is being used for the RGB -> luma (brightness) conversion.
*/ void drm_fb_xrgb8888_to_gray8(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
1,
};
/** * drm_fb_argb8888_to_argb4444 - Convert ARGB8888 to ARGB4444 clip buffer * @dst: Array of ARGB4444 destination buffers * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of ARGB8888 source buffer * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts * the color format during the process. The parameters @dst, @dst_pitch and * @src refer to arrays. Each array must have at least as many entries as * there are planes in @fb's format. Each entry stores the value for the * format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Drivers can use this function for ARGB4444 devices that don't support * ARGB8888 natively.
*/ void drm_fb_argb8888_to_argb4444(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconst u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
2,
};
/** * drm_fb_blit - Copy parts of a framebuffer to display memory * @dst: Array of display-memory addresses to copy to * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @dst_format: FOURCC code of the display's color format * @src: The framebuffer memory to copy from * @fb: The framebuffer to copy from * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory. If the * formats of the display and the framebuffer mismatch, the blit function * will attempt to convert between them during the process. The parameters @dst, * @dst_pitch and @src refer to arrays. Each array must have at least as many * entries as there are planes in @dst_format's format. Each entry stores the * value for the format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). * * Returns: * 0 on success, or * -EINVAL if the color-format conversion failed, or * a negative error code otherwise.
*/ int drm_fb_blit(struct iosys_map *dst, constunsignedint *dst_pitch, uint32_t dst_format, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{
uint32_t fb_format = fb->format->format;
while (pixels) { unsignedint i, bits = min(pixels, 8U);
u8 byte = 0;
for (i = 0; i < bits; i++, pixels--) { if (*sbuf8++ >= 128)
byte |= BIT(i);
}
*dbuf8++ = byte;
}
}
/** * drm_fb_xrgb8888_to_mono - Convert XRGB8888 to monochrome * @dst: Array of monochrome destination buffers (0=black, 1=white) * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines * within @dst; can be NULL if scanlines are stored next to each other. * @src: Array of XRGB8888 source buffers * @fb: DRM framebuffer * @clip: Clip rectangle area to copy * @state: Transform and conversion state * * This function copies parts of a framebuffer to display memory and converts the * color format during the process. Destination and framebuffer formats must match. The * parameters @dst, @dst_pitch and @src refer to arrays. Each array must have at * least as many entries as there are planes in @fb's format. Each entry stores the * value for the format's respective color plane at the same index. * * This function does not apply clipping on @dst (i.e. the destination is at the * top-left corner). The first pixel (upper left corner of the clip rectangle) will * be converted and copied to the first bit (LSB) in the first byte of the monochrome * destination buffer. If the caller requires that the first pixel in a byte must * be located at an x-coordinate that is a multiple of 8, then the caller must take * care itself of supplying a suitable clip rectangle. * * DRM doesn't have native monochrome support. Drivers can use this function for * monochrome devices that don't support XRGB8888 natively. Such drivers can * announce the commonly supported XR24 format to userspace and use this function * to convert to the native format. * * This function uses drm_fb_xrgb8888_to_gray8() to convert to grayscale and * then the result is converted from grayscale to monochrome.
*/ void drm_fb_xrgb8888_to_mono(struct iosys_map *dst, constunsignedint *dst_pitch, conststruct iosys_map *src, conststruct drm_framebuffer *fb, conststruct drm_rect *clip, struct drm_format_conv_state *state)
{ staticconstunsignedint default_dst_pitch[DRM_FORMAT_MAX_PLANES] = {
0, 0, 0, 0
}; unsignedint linepixels = drm_rect_width(clip); unsignedint lines = drm_rect_height(clip); unsignedint cpp = fb->format->cpp[0]; unsignedint len_src32 = linepixels * cpp; struct drm_device *dev = fb->dev; void *vaddr = src[0].vaddr; unsignedint dst_pitch_0; unsignedint y;
u8 *mono = dst[0].vaddr, *gray8;
u32 *src32;
if (drm_WARN_ON(dev, fb->format->format != DRM_FORMAT_XRGB8888)) return;
if (!dst_pitch)
dst_pitch = default_dst_pitch;
dst_pitch_0 = dst_pitch[0];
/* * The mono destination buffer contains 1 bit per pixel
*/ if (!dst_pitch_0)
dst_pitch_0 = DIV_ROUND_UP(linepixels, 8);
/* * The dma memory is write-combined so reads are uncached. * Speed up by fetching one line at a time. * * Also, format conversion from XR24 to monochrome are done * line-by-line but are converted to 8-bit grayscale as an * intermediate step. * * Allocate a buffer to be used for both copying from the cma * memory and to store the intermediate grayscale line pixels.
*/
src32 = drm_format_conv_state_reserve(state, len_src32 + linepixels, GFP_KERNEL); if (!src32) return;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.