Skip to content

Commit

Permalink
drm/vkms: Implement and enable damage clipping
Browse files Browse the repository at this point in the history
Testcase igt@kms_atomic@atomic_plane_damage now passes
  • Loading branch information
vliaskov committed Jan 23, 2023
1 parent 69b41ac commit e088df3
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion drivers/gpu/drm/vkms/vkms_plane.c
Expand Up @@ -4,7 +4,9 @@

#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_damage_helper.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_format_helper.h>
#include <drm/drm_gem_atomic_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>

Expand Down Expand Up @@ -101,10 +103,13 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,
{
struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
plane);
struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state, plane);
struct vkms_plane_state *vkms_plane_state;
struct drm_shadow_plane_state *shadow_plane_state;
struct drm_framebuffer *fb = new_state->fb;
struct vkms_frame_info *frame_info;
struct drm_atomic_helper_damage_iter iter;
struct drm_rect damage;
u32 fmt;

if (!new_state->crtc || !fb)
Expand All @@ -116,14 +121,29 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,

frame_info = vkms_plane_state->frame_info;
memcpy(&frame_info->src, &new_state->src, sizeof(struct drm_rect));
memcpy(&frame_info->dst, &new_state->dst, sizeof(struct drm_rect));
drm_rect_init(&frame_info->dst, 0, 0, 0, 0);

frame_info->fb = fb;
memcpy(&frame_info->map, &shadow_plane_state->data, sizeof(frame_info->map));
drm_framebuffer_get(frame_info->fb);
frame_info->offset = fb->offsets[0];
frame_info->pitch = fb->pitches[0];
frame_info->cpp = fb->format->cpp[0];
vkms_plane_state->plane_read = get_frame_to_line_function(fmt);

drm_atomic_helper_damage_iter_init(&iter, old_state, new_state);
drm_atomic_for_each_plane_damage(&iter, &damage) {
struct iosys_map dst = frame_info->map[0];
struct drm_rect dst_clip = new_state->dst;

if (!drm_rect_intersect(&dst_clip, &damage))
continue;

iosys_map_incr(&dst, drm_fb_clip_offset(frame_info->pitch, fb->format /*?*/, &dst_clip));
drm_fb_blit(&dst, frame_info->pitch, fb->format, shadow_plane_state->data, fb,
&damage);
drm_rect_intersect(&frame_info->dst, &dst_clip);
}
}

static int vkms_plane_atomic_check(struct drm_plane *plane,
Expand Down Expand Up @@ -202,6 +222,7 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
return plane;

drm_plane_helper_add(&plane->base, funcs);
drm_plane_enable_fb_damage_clips(&plane->base);

return plane;
}

0 comments on commit e088df3

Please sign in to comment.