1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
2 | /* |
3 | * Copyright (C) 2016 Noralf Trønnes |
4 | */ |
5 | |
6 | #ifndef __LINUX_DRM_FORMAT_HELPER_H |
7 | #define __LINUX_DRM_FORMAT_HELPER_H |
8 | |
9 | #include <linux/types.h> |
10 | |
11 | struct drm_device; |
12 | struct drm_format_info; |
13 | struct drm_framebuffer; |
14 | struct drm_rect; |
15 | |
16 | struct iosys_map; |
17 | |
18 | /** |
19 | * struct drm_format_conv_state - Stores format-conversion state |
20 | * |
21 | * DRM helpers for format conversion store temporary state in |
22 | * struct drm_xfrm_buf. The buffer's resources can be reused |
23 | * among multiple conversion operations. |
24 | * |
25 | * All fields are considered private. |
26 | */ |
27 | struct drm_format_conv_state { |
28 | struct { |
29 | void *mem; |
30 | size_t size; |
31 | bool preallocated; |
32 | } tmp; |
33 | }; |
34 | |
35 | #define __DRM_FORMAT_CONV_STATE_INIT(_mem, _size, _preallocated) { \ |
36 | .tmp = { \ |
37 | .mem = (_mem), \ |
38 | .size = (_size), \ |
39 | .preallocated = (_preallocated), \ |
40 | } \ |
41 | } |
42 | |
43 | /** |
44 | * DRM_FORMAT_CONV_STATE_INIT - Initializer for struct drm_format_conv_state |
45 | * |
46 | * Initializes an instance of struct drm_format_conv_state to default values. |
47 | */ |
48 | #define DRM_FORMAT_CONV_STATE_INIT \ |
49 | __DRM_FORMAT_CONV_STATE_INIT(NULL, 0, false) |
50 | |
51 | /** |
52 | * DRM_FORMAT_CONV_STATE_INIT_PREALLOCATED - Initializer for struct drm_format_conv_state |
53 | * @_mem: The preallocated memory area |
54 | * @_size: The number of bytes in _mem |
55 | * |
56 | * Initializes an instance of struct drm_format_conv_state to preallocated |
57 | * storage. The caller is responsible for releasing the provided memory range. |
58 | */ |
59 | #define DRM_FORMAT_CONV_STATE_INIT_PREALLOCATED(_mem, _size) \ |
60 | __DRM_FORMAT_CONV_STATE_INIT(_mem, _size, true) |
61 | |
62 | void drm_format_conv_state_init(struct drm_format_conv_state *state); |
63 | void drm_format_conv_state_copy(struct drm_format_conv_state *state, |
64 | const struct drm_format_conv_state *old_state); |
65 | void *drm_format_conv_state_reserve(struct drm_format_conv_state *state, |
66 | size_t new_size, gfp_t flags); |
67 | void drm_format_conv_state_release(struct drm_format_conv_state *state); |
68 | |
69 | unsigned int drm_fb_clip_offset(unsigned int pitch, const struct drm_format_info *format, |
70 | const struct drm_rect *clip); |
71 | |
72 | void drm_fb_memcpy(struct iosys_map *dst, const unsigned int *dst_pitch, |
73 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
74 | const struct drm_rect *clip); |
75 | void drm_fb_swab(struct iosys_map *dst, const unsigned int *dst_pitch, |
76 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
77 | const struct drm_rect *clip, bool cached, |
78 | struct drm_format_conv_state *state); |
79 | void drm_fb_xrgb8888_to_rgb332(struct iosys_map *dst, const unsigned int *dst_pitch, |
80 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
81 | const struct drm_rect *clip, struct drm_format_conv_state *state); |
82 | void drm_fb_xrgb8888_to_rgb565(struct iosys_map *dst, const unsigned int *dst_pitch, |
83 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
84 | const struct drm_rect *clip, struct drm_format_conv_state *state, |
85 | bool swab); |
86 | void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, const unsigned int *dst_pitch, |
87 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
88 | const struct drm_rect *clip, struct drm_format_conv_state *state); |
89 | void drm_fb_xrgb8888_to_argb1555(struct iosys_map *dst, const unsigned int *dst_pitch, |
90 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
91 | const struct drm_rect *clip, struct drm_format_conv_state *state); |
92 | void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_pitch, |
93 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
94 | const struct drm_rect *clip, struct drm_format_conv_state *state); |
95 | void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pitch, |
96 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
97 | const struct drm_rect *clip, struct drm_format_conv_state *state); |
98 | void drm_fb_xrgb8888_to_argb8888(struct iosys_map *dst, const unsigned int *dst_pitch, |
99 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
100 | const struct drm_rect *clip, struct drm_format_conv_state *state); |
101 | void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *dst_pitch, |
102 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
103 | const struct drm_rect *clip, |
104 | struct drm_format_conv_state *state); |
105 | void drm_fb_xrgb8888_to_argb2101010(struct iosys_map *dst, const unsigned int *dst_pitch, |
106 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
107 | const struct drm_rect *clip, |
108 | struct drm_format_conv_state *state); |
109 | void drm_fb_xrgb8888_to_gray8(struct iosys_map *dst, const unsigned int *dst_pitch, |
110 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
111 | const struct drm_rect *clip, struct drm_format_conv_state *state); |
112 | |
113 | int drm_fb_blit(struct iosys_map *dst, const unsigned int *dst_pitch, uint32_t dst_format, |
114 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
115 | const struct drm_rect *clip, struct drm_format_conv_state *state); |
116 | |
117 | void drm_fb_xrgb8888_to_mono(struct iosys_map *dst, const unsigned int *dst_pitch, |
118 | const struct iosys_map *src, const struct drm_framebuffer *fb, |
119 | const struct drm_rect *clip, struct drm_format_conv_state *state); |
120 | |
121 | size_t drm_fb_build_fourcc_list(struct drm_device *dev, |
122 | const u32 *native_fourccs, size_t native_nfourccs, |
123 | u32 *fourccs_out, size_t nfourccs_out); |
124 | |
125 | #endif /* __LINUX_DRM_FORMAT_HELPER_H */ |
126 | |