History

drm: Add a new plane property to send damage during plane update

FB_DAMAGE_CLIPS is an optional plane property to mark damaged regions on the plane in framebuffer coordinates of the framebuffer attached to the plane. The layout of blob data is simply an array of "struct drm_mode_rect". Unlike plane src coordinates, damage clips are not in 16.16 fixed point. As plane src in framebuffer cannot be negative so are damage clips. In damage clip, x1/y1 are inclusive and x2/y2 are exclusive. This patch also exports the kernel internal drm_rect to userspace as drm_mode_rect. This is because "struct drm_clip_rect" is not sufficient to represent damage for current plane size. Driver which are interested in enabling FB_DAMAGE_CLIPS property for a plane should enable this property using drm_plane_enable_damage_clips. v2: - Input validation on damage clips against framebuffer size. - Doc update, other minor changes.

Lukasz Spintzyk committed 8 years ago

Commit d3b21761 parent 818182d10 files · +244 −1Browse files

Unified · Split

10 files
  1. Documentation/gpu/drm-kms.rst +12 −0
  2. drivers/gpu/drm/Makefile +1 −1
  3. drivers/gpu/drm/drm_atomic.c +22 −0
  4. drivers/gpu/drm/drm_atomic_uapi.c +13 −0
  5. drivers/gpu/drm/drm_damage_helper.c +83 −0
  6. drivers/gpu/drm/drm_mode_config.c +6 −0
  7. include/drm/drm_damage_helper.h +39 −0
  8. include/drm/drm_mode_config.h +9 −0
  9. include/drm/drm_plane.h +40 −0
  10. include/uapi/drm/drm_mode.h +19 −0
Documentation/gpu/drm-kms.rst+12−0
@@ -554,6 +554,18 @@ Plane Composition Properties · 553 unmodified lines
554554 .. kernel-doc:: drivers/gpu/drm/drm_blend.c
555555 :export:
556556
557+FB_DAMAGE_CLIPS
558+~~~~~~~~~~~~~~~
559+
560+.. kernel-doc:: drivers/gpu/drm/drm_damage_helper.c
561+ :doc: overview
562+
563+.. kernel-doc:: drivers/gpu/drm/drm_damage_helper.c
564+ :export:
565+
566+.. kernel-doc:: include/drm/drm_damage_helper.h
567+ :internal:
568+
557569 Color Management Properties
558570 ---------------------------
559571
drivers/gpu/drm/Makefile+1−1
@@ -37,7 +37,7 @@ drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \ · 36 unmodified lines
3737 drm_kms_helper_common.o drm_dp_dual_mode_helper.o \
3838 drm_simple_kms_helper.o drm_modeset_helper.o \
3939 drm_scdc_helper.o drm_gem_framebuffer_helper.o \
40− drm_atomic_state_helper.o
40+ drm_atomic_state_helper.o drm_damage_helper.o
4141
4242 drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o
4343 drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
drivers/gpu/drm/drm_atomic.c+22−0
@@ -531,6 +531,8 @@ static int drm_atomic_plane_check(const struct drm_plane_state *old_plane_state, · 530 unmodified lines
531531 struct drm_crtc *crtc = new_plane_state->crtc;
532532 const struct drm_framebuffer *fb = new_plane_state->fb;
533533 unsigned int fb_width, fb_height;
534+ struct drm_mode_rect *clips;
535+ uint32_t num_clips;
534536 int ret;
535537
536538 /* either *both* CRTC and FB must be set, or neither */
@@ -604,6 +606,26 @@ static int drm_atomic_plane_check(const struct drm_plane_state *old_plane_state, · 67 unmodified lines
604606 return -ENOSPC;
605607 }
606608
609+ clips = drm_plane_get_damage_clips(new_plane_state);
610+ num_clips = drm_plane_get_damage_clips_count(new_plane_state);
611+
612+ /* Make sure damage clips are valid and inside the fb. */
613+ while (num_clips > 0) {
614+ if (clips->x1 >= clips->x2 ||
615+ clips->y1 >= clips->y2 ||
616+ clips->x1 < 0 ||
617+ clips->y1 < 0 ||
618+ clips->x2 > fb_width ||
619+ clips->y2 > fb_height) {
620+ DRM_DEBUG_ATOMIC("[PLANE:%d:%s] invalid damage clip %d %d %d %d\n",
621+ plane->base.id, plane->name, clips->x1,
622+ clips->y1, clips->x2, clips->y2);
623+ return -EINVAL;
624+ }
625+ clips++;
626+ num_clips--;
627+ }
628+
607629 if (plane_switching_crtc(old_plane_state, new_plane_state)) {
608630 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] switching CRTC directly\n",
609631 plane->base.id, plane->name);
drivers/gpu/drm/drm_atomic_uapi.c+13−0
@@ -513,6 +513,8 @@ static int drm_atomic_plane_set_property(struct drm_plane *plane, · 512 unmodified lines
513513 {
514514 struct drm_device *dev = plane->dev;
515515 struct drm_mode_config *config = &dev->mode_config;
516+ bool replaced = false;
517+ int ret;
516518
517519 if (property == config->prop_fb_id) {
518520 struct drm_framebuffer *fb = drm_framebuffer_lookup(dev, NULL, val);
@@ -566,6 +568,14 @@ static int drm_atomic_plane_set_property(struct drm_plane *plane, · 47 unmodified lines
566568 state->color_encoding = val;
567569 } else if (property == plane->color_range_property) {
568570 state->color_range = val;
571+ } else if (property == config->prop_fb_damage_clips) {
572+ ret = drm_atomic_replace_property_blob_from_id(dev,
573+ &state->fb_damage_clips,
574+ val,
575+ -1,
576+ sizeof(struct drm_rect),
577+ &replaced);
578+ return ret;
569579 } else if (plane->funcs->atomic_set_property) {
570580 return plane->funcs->atomic_set_property(plane, state,
571581 property, val);
@@ -621,6 +631,9 @@ drm_atomic_plane_get_property(struct drm_plane *plane, · 49 unmodified lines
621631 *val = state->color_encoding;
622632 } else if (property == plane->color_range_property) {
623633 *val = state->color_range;
634+ } else if (property == config->prop_fb_damage_clips) {
635+ *val = (state->fb_damage_clips) ?
636+ state->fb_damage_clips->base.id : 0;
624637 } else if (plane->funcs->atomic_get_property) {
625638 return plane->funcs->atomic_get_property(plane, state, property, val);
626639 } else {
drivers/gpu/drm/drm_damage_helper.c+83−0
@@ -0,0 +1,83 @@
1+// SPDX-License-Identifier: GPL-2.0 OR MIT
2+/**************************************************************************
3+ *
4+ * Copyright (c) 2018 VMware, Inc., Palo Alto, CA., USA
5+ * All Rights Reserved.
6+ *
7+ * Permission is hereby granted, free of charge, to any person obtaining a
8+ * copy of this software and associated documentation files (the
9+ * "Software"), to deal in the Software without restriction, including
10+ * without limitation the rights to use, copy, modify, merge, publish,
11+ * distribute, sub license, and/or sell copies of the Software, and to
12+ * permit persons to whom the Software is furnished to do so, subject to
13+ * the following conditions:
14+ *
15+ * The above copyright notice and this permission notice (including the
16+ * next paragraph) shall be included in all copies or substantial portions
17+ * of the Software.
18+ *
19+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
23+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
26+ *
27+ * Authors:
28+ * Deepak Rawat <drawat@vmware.com>
29+ *
30+ **************************************************************************/
31+
32+#include <drm/drm_damage_helper.h>
33+
34+/**
35+ * DOC: overview
36+ *
37+ * FB_DAMAGE_CLIPS is an optional plane property which provides a means to
38+ * specify a list of damage rectangles on a plane in framebuffer coordinates of
39+ * the framebuffer attached to the plane. In current context damage is the area
40+ * of plane framebuffer that has changed since last plane update (also called
41+ * page-flip), irrespective of whether currently attached framebuffer is same as
42+ * framebuffer attached during last plane update or not.
43+ *
44+ * FB_DAMAGE_CLIPS is a hint to kernel which could be helpful for some drivers
45+ * to optimize internally especially for virtual devices where each framebuffer
46+ * change needs to be transmitted over network, usb, etc.
47+ *
48+ * Since FB_DAMAGE_CLIPS is a hint so it is an optional property. User-space can
49+ * ignore damage clips property and in that case driver will do a full plane
50+ * update. In case damage clips are provided then it is guaranteed that the area
51+ * inside damage clips will be updated to plane. For efficiency driver can do
52+ * full update or can update more than specified in damage clips. Since driver
53+ * is free to read more, user-space must always render the entire visible
54+ * framebuffer. Otherwise there can be corruptions. Also, if a user-space
55+ * provides damage clips which doesn't encompass the actual damage to
56+ * framebuffer (since last plane update) can result in incorrect rendering.
57+ *
58+ * FB_DAMAGE_CLIPS is a blob property with the layout of blob data is simply an
59+ * array of &drm_mode_rect. Unlike plane &drm_plane_state.src coordinates,
60+ * damage clips are not in 16.16 fixed point. Similar to plane src in
61+ * framebuffer, damage clips cannot be negative. In damage clip, x1/y1 are
62+ * inclusive and x2/y2 are exclusive. While kernel does not error for overlapped
63+ * damage clips, it is strongly discouraged.
64+ *
65+ * Drivers that are interested in damage interface for plane should enable
66+ * FB_DAMAGE_CLIPS property by calling drm_plane_enable_fb_damage_clips().
67+ */
68+
69+/**
70+ * drm_plane_enable_fb_damage_clips - Enables plane fb damage clips property.
71+ * @plane: Plane on which to enable damage clips property.
72+ *
73+ * This function lets driver to enable the damage clips property on a plane.
74+ */
75+void drm_plane_enable_fb_damage_clips(struct drm_plane *plane)
76+{
77+ struct drm_device *dev = plane->dev;
78+ struct drm_mode_config *config = &dev->mode_config;
79+
80+ drm_object_attach_property(&plane->base, config->prop_fb_damage_clips,
81+ 0);
82+}
83+EXPORT_SYMBOL(drm_plane_enable_fb_damage_clips);
drivers/gpu/drm/drm_mode_config.c+6−0
@@ -297,6 +297,12 @@ static int drm_mode_create_standard_properties(struct drm_device *dev) · 296 unmodified lines
297297 return -ENOMEM;
298298 dev->mode_config.prop_crtc_id = prop;
299299
300+ prop = drm_property_create(dev, DRM_MODE_PROP_BLOB, "FB_DAMAGE_CLIPS",
301+ 0);
302+ if (!prop)
303+ return -ENOMEM;
304+ dev->mode_config.prop_fb_damage_clips = prop;
305+
300306 prop = drm_property_create_bool(dev, DRM_MODE_PROP_ATOMIC,
301307 "ACTIVE");
302308 if (!prop)
include/drm/drm_damage_helper.h+39−0
@@ -0,0 +1,39 @@
1+/* SPDX-License-Identifier: GPL-2.0 OR MIT */
2+/**************************************************************************
3+ *
4+ * Copyright (c) 2018 VMware, Inc., Palo Alto, CA., USA
5+ * All Rights Reserved.
6+ *
7+ * Permission is hereby granted, free of charge, to any person obtaining a
8+ * copy of this software and associated documentation files (the
9+ * "Software"), to deal in the Software without restriction, including
10+ * without limitation the rights to use, copy, modify, merge, publish,
11+ * distribute, sub license, and/or sell copies of the Software, and to
12+ * permit persons to whom the Software is furnished to do so, subject to
13+ * the following conditions:
14+ *
15+ * The above copyright notice and this permission notice (including the
16+ * next paragraph) shall be included in all copies or substantial portions
17+ * of the Software.
18+ *
19+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
23+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
26+ *
27+ * Authors:
28+ * Deepak Rawat <drawat@vmware.com>
29+ *
30+ **************************************************************************/
31+
32+#ifndef DRM_DAMAGE_HELPER_H_
33+#define DRM_DAMAGE_HELPER_H_
34+
35+#include <drm/drm_atomic_helper.h>
36+
37+void drm_plane_enable_fb_damage_clips(struct drm_plane *plane);
38+
39+#endif
include/drm/drm_mode_config.h+9−0
@@ -633,6 +633,15 @@ struct drm_mode_config { · 632 unmodified lines
633633 * &drm_crtc.
634634 */
635635 struct drm_property *prop_crtc_id;
636+ /**
637+ * @prop_fb_damage_clips: Optional plane property to mark damaged
638+ * regions on the plane in framebuffer coordinates of the framebuffer
639+ * attached to the plane.
640+ *
641+ * The layout of blob data is simply an array of &drm_mode_rect. Unlike
642+ * plane src coordinates, damage clips are not in 16.16 fixed point.
643+ */
644+ struct drm_property *prop_fb_damage_clips;
636645 /**
637646 * @prop_active: Default atomic CRTC property to control the active
638647 * state, which is the simplified implementation for DPMS in atomic
include/drm/drm_plane.h+40−0
@@ -173,6 +173,16 @@ struct drm_plane_state { · 172 unmodified lines
173173 */
174174 enum drm_color_range color_range;
175175
176+ /**
177+ * @fb_damage_clips:
178+ *
179+ * Blob representing damage (area in plane framebuffer that changed
180+ * since last plane update) as an array of &drm_mode_rect in framebuffer
181+ * coodinates of the attached framebuffer. Note that unlike plane src,
182+ * damage clips are not in 16.16 fixed point.
183+ */
184+ struct drm_property_blob *fb_damage_clips;
185+
176186 /** @src: clipped source coordinates of the plane (in 16.16) */
177187 /** @dst: clipped destination coordinates of the plane */
178188 struct drm_rect src, dst;
@@ -800,5 +810,35 @@ static inline struct drm_plane *drm_plane_find(struct drm_device *dev, · 621 unmodified lines
800810
801811 bool drm_any_plane_has_format(struct drm_device *dev,
802812 u32 format, u64 modifier);
813+/**
814+ * drm_plane_get_damage_clips_count - Returns damage clips count.
815+ * @state: Plane state.
816+ *
817+ * Simple helper to get the number of &drm_mode_rect clips set by user-space
818+ * during plane update.
819+ *
820+ * Return: Number of clips in plane fb_damage_clips blob property.
821+ */
822+static inline unsigned int
823+drm_plane_get_damage_clips_count(const struct drm_plane_state *state)
824+{
825+ return (state && state->fb_damage_clips) ?
826+ state->fb_damage_clips->length/sizeof(struct drm_mode_rect) : 0;
827+}
828+
829+/**
830+ * drm_plane_get_damage_clips - Returns damage clips.
831+ * @state: Plane state.
832+ *
833+ * Note that this function returns uapi type &drm_mode_rect.
834+ *
835+ * Return: Damage clips in plane fb_damage_clips blob property.
836+ */
837+static inline struct drm_mode_rect *
838+drm_plane_get_damage_clips(const struct drm_plane_state *state)
839+{
840+ return (struct drm_mode_rect *)((state && state->fb_damage_clips) ?
841+ state->fb_damage_clips->data : NULL);
842+}
803843
804844 #endif
include/uapi/drm/drm_mode.h+19−0
@@ -888,6 +888,25 @@ struct drm_mode_revoke_lease { · 887 unmodified lines
888888 __u32 lessee_id;
889889 };
890890
891+/**
892+ * struct drm_mode_rect - Two dimensional rectangle.
893+ * @x1: Horizontal starting coordinate (inclusive).
894+ * @y1: Vertical starting coordinate (inclusive).
895+ * @x2: Horizontal ending coordinate (exclusive).
896+ * @y2: Vertical ending coordinate (exclusive).
897+ *
898+ * With drm subsystem using struct drm_rect to manage rectangular area this
899+ * export it to user-space.
900+ *
901+ * Currently used by drm_mode_atomic blob property FB_DAMAGE_CLIPS.
902+ */
903+struct drm_mode_rect {
904+ __s32 x1;
905+ __s32 y1;
906+ __s32 x2;
907+ __s32 y2;
908+};
909+
891910 #if defined(__cplusplus)
892911 }
893912 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t