|
3 | 3 | #include <drm/drm_atomic.h>
|
4 | 4 | #include <drm/drm_atomic_helper.h>
|
5 | 5 | #include <drm/drm_drv.h>
|
| 6 | +#include <drm/drm_fourcc.h> |
6 | 7 | #include <drm/drm_kunit_helpers.h>
|
7 | 8 | #include <drm/drm_managed.h>
|
8 | 9 |
|
@@ -164,5 +165,89 @@ drm_kunit_helper_atomic_state_alloc(struct kunit *test,
|
164 | 165 | }
|
165 | 166 | EXPORT_SYMBOL_GPL(drm_kunit_helper_atomic_state_alloc);
|
166 | 167 |
|
| 168 | +static const uint32_t default_plane_formats[] = { |
| 169 | + DRM_FORMAT_XRGB8888, |
| 170 | +}; |
| 171 | + |
| 172 | +static const uint64_t default_plane_modifiers[] = { |
| 173 | + DRM_FORMAT_MOD_LINEAR, |
| 174 | + DRM_FORMAT_MOD_INVALID |
| 175 | +}; |
| 176 | + |
| 177 | +static const struct drm_plane_helper_funcs default_plane_helper_funcs = { |
| 178 | +}; |
| 179 | + |
| 180 | +static const struct drm_plane_funcs default_plane_funcs = { |
| 181 | + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, |
| 182 | + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, |
| 183 | + .reset = drm_atomic_helper_plane_reset, |
| 184 | +}; |
| 185 | + |
| 186 | +/** |
| 187 | + * drm_kunit_helper_create_primary_plane - Creates a mock primary plane for a KUnit test |
| 188 | + * @test: The test context object |
| 189 | + * @drm: The device to alloc the plane for |
| 190 | + * @funcs: Callbacks for the new plane. Optional. |
| 191 | + * @helper_funcs: Helpers callbacks for the new plane. Optional. |
| 192 | + * @formats: array of supported formats (DRM_FORMAT\_\*). Optional. |
| 193 | + * @num_formats: number of elements in @formats |
| 194 | + * @modifiers: array of struct drm_format modifiers terminated by |
| 195 | + * DRM_FORMAT_MOD_INVALID. Optional. |
| 196 | + * |
| 197 | + * This allocates and initializes a mock struct &drm_plane meant to be |
| 198 | + * part of a mock device for a KUnit test. |
| 199 | + * |
| 200 | + * Resources will be cleaned up automatically. |
| 201 | + * |
| 202 | + * @funcs will default to the default helpers implementations. |
| 203 | + * @helper_funcs will default to an empty implementation. @formats will |
| 204 | + * default to XRGB8888 only. @modifiers will default to a linear |
| 205 | + * modifier only. |
| 206 | + * |
| 207 | + * Returns: |
| 208 | + * A pointer to the new plane, or an ERR_PTR() otherwise. |
| 209 | + */ |
| 210 | +struct drm_plane * |
| 211 | +drm_kunit_helper_create_primary_plane(struct kunit *test, |
| 212 | + struct drm_device *drm, |
| 213 | + const struct drm_plane_funcs *funcs, |
| 214 | + const struct drm_plane_helper_funcs *helper_funcs, |
| 215 | + const uint32_t *formats, |
| 216 | + unsigned int num_formats, |
| 217 | + const uint64_t *modifiers) |
| 218 | +{ |
| 219 | + struct drm_plane *plane; |
| 220 | + |
| 221 | + if (!funcs) |
| 222 | + funcs = &default_plane_funcs; |
| 223 | + |
| 224 | + if (!helper_funcs) |
| 225 | + helper_funcs = &default_plane_helper_funcs; |
| 226 | + |
| 227 | + if (!formats || !num_formats) { |
| 228 | + formats = default_plane_formats; |
| 229 | + num_formats = ARRAY_SIZE(default_plane_formats); |
| 230 | + } |
| 231 | + |
| 232 | + if (!modifiers) |
| 233 | + modifiers = default_plane_modifiers; |
| 234 | + |
| 235 | + plane = __drmm_universal_plane_alloc(drm, |
| 236 | + sizeof(struct drm_plane), 0, |
| 237 | + 0, |
| 238 | + funcs, |
| 239 | + formats, |
| 240 | + num_formats, |
| 241 | + default_plane_modifiers, |
| 242 | + DRM_PLANE_TYPE_PRIMARY, |
| 243 | + NULL); |
| 244 | + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, plane); |
| 245 | + |
| 246 | + drm_plane_helper_add(plane, helper_funcs); |
| 247 | + |
| 248 | + return plane; |
| 249 | +} |
| 250 | +EXPORT_SYMBOL_GPL(drm_kunit_helper_create_primary_plane); |
| 251 | + |
167 | 252 | MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>");
|
168 | 253 | MODULE_LICENSE("GPL");
|
0 commit comments