drivers/gpu/drm/tests/drm_damage_helper_test.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/tests/drm_damage_helper_test.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/tests/drm_damage_helper_test.c
Extension
.c
Size
22468 bytes
Lines
641
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct drm_damage_mock {
	struct drm_driver driver;
	struct drm_device device;
	struct drm_object_properties obj_props;
	struct drm_plane plane;
	struct drm_property prop;
	struct drm_framebuffer fb;
	struct drm_plane_state state;
	struct drm_plane_state old_state;
};

static int drm_damage_helper_init(struct kunit *test)
{
	struct drm_damage_mock *mock;

	mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL);
	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mock);

	mock->fb.width = 2048;
	mock->fb.height = 2048;

	mock->state.crtc = ZERO_SIZE_PTR;
	mock->state.fb = &mock->fb;
	mock->state.visible = true;

	mock->old_state.plane = &mock->plane;
	mock->state.plane = &mock->plane;

	/* just enough so that drm_plane_enable_fb_damage_clips() works */
	mock->device.driver = &mock->driver;
	mock->device.mode_config.prop_fb_damage_clips = &mock->prop;
	mock->plane.dev = &mock->device;
	mock->obj_props.count = 0;
	mock->plane.base.properties = &mock->obj_props;
	mock->prop.base.id = 1; /* 0 is an invalid id */
	mock->prop.dev = &mock->device;

	drm_plane_enable_fb_damage_clips(&mock->plane);

	test->priv = mock;

	return 0;
}

static void set_plane_src(struct drm_plane_state *state, int x1, int y1, int x2,
			  int y2)
{
	state->src_x = x1;
	state->src_y = y1;
	state->src_w = x2 - x1;
	state->src_h = y2 - y1;

	state->src.x1 = x1;
	state->src.y1 = y1;
	state->src.x2 = x2;
	state->src.y2 = y2;
}

static void set_damage_clip(struct drm_mode_rect *r, int x1, int y1, int x2,
			    int y2)
{
	r->x1 = x1;
	r->y1 = y1;
	r->x2 = x2;
	r->y2 = y2;
}

static void set_damage_blob(struct drm_property_blob *damage_blob,
			    struct drm_mode_rect *r, u32 size)
{
	damage_blob->length = size;
	damage_blob->data = r;
}

static void set_plane_damage(struct drm_plane_state *state,
			     struct drm_property_blob *damage_blob)
{
	state->fb_damage_clips = damage_blob;
}

static void check_damage_clip(struct kunit *test, struct drm_rect *r,
			      int x1, int y1, int x2, int y2)
{
	struct drm_damage_mock *mock = test->priv;
	struct drm_plane_state state = mock->state;

	/*
	 * Round down x1/y1 and round up x2/y2. This is because damage is not in
	 * 16.16 fixed point so to catch all pixels.
	 */

Annotation

Implementation Notes