xref: /OK3568_Linux_fs/kernel/include/drm/drm_damage_helper.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2*4882a593Smuzhiyun /**************************************************************************
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (c) 2018 VMware, Inc., Palo Alto, CA., USA
5*4882a593Smuzhiyun  * All Rights Reserved.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
8*4882a593Smuzhiyun  * copy of this software and associated documentation files (the
9*4882a593Smuzhiyun  * "Software"), to deal in the Software without restriction, including
10*4882a593Smuzhiyun  * without limitation the rights to use, copy, modify, merge, publish,
11*4882a593Smuzhiyun  * distribute, sub license, and/or sell copies of the Software, and to
12*4882a593Smuzhiyun  * permit persons to whom the Software is furnished to do so, subject to
13*4882a593Smuzhiyun  * the following conditions:
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the
16*4882a593Smuzhiyun  * next paragraph) shall be included in all copies or substantial portions
17*4882a593Smuzhiyun  * of the Software.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22*4882a593Smuzhiyun  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
23*4882a593Smuzhiyun  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24*4882a593Smuzhiyun  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25*4882a593Smuzhiyun  * USE OR OTHER DEALINGS IN THE SOFTWARE.
26*4882a593Smuzhiyun  *
27*4882a593Smuzhiyun  * Authors:
28*4882a593Smuzhiyun  * Deepak Rawat <drawat@vmware.com>
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  **************************************************************************/
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #ifndef DRM_DAMAGE_HELPER_H_
33*4882a593Smuzhiyun #define DRM_DAMAGE_HELPER_H_
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #include <drm/drm_atomic_helper.h>
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /**
38*4882a593Smuzhiyun  * drm_atomic_for_each_plane_damage - Iterator macro for plane damage.
39*4882a593Smuzhiyun  * @iter: The iterator to advance.
40*4882a593Smuzhiyun  * @rect: Return a rectangle in fb coordinate clipped to plane src.
41*4882a593Smuzhiyun  *
42*4882a593Smuzhiyun  * Note that if the first call to iterator macro return false then no need to do
43*4882a593Smuzhiyun  * plane update. Iterator will return full plane src when damage is not passed
44*4882a593Smuzhiyun  * by user-space.
45*4882a593Smuzhiyun  */
46*4882a593Smuzhiyun #define drm_atomic_for_each_plane_damage(iter, rect) \
47*4882a593Smuzhiyun 	while (drm_atomic_helper_damage_iter_next(iter, rect))
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /**
50*4882a593Smuzhiyun  * struct drm_atomic_helper_damage_iter - Closure structure for damage iterator.
51*4882a593Smuzhiyun  *
52*4882a593Smuzhiyun  * This structure tracks state needed to walk the list of plane damage clips.
53*4882a593Smuzhiyun  */
54*4882a593Smuzhiyun struct drm_atomic_helper_damage_iter {
55*4882a593Smuzhiyun 	/* private: Plane src in whole number. */
56*4882a593Smuzhiyun 	struct drm_rect plane_src;
57*4882a593Smuzhiyun 	/* private: Rectangles in plane damage blob. */
58*4882a593Smuzhiyun 	const struct drm_rect *clips;
59*4882a593Smuzhiyun 	/* private: Number of rectangles in plane damage blob. */
60*4882a593Smuzhiyun 	uint32_t num_clips;
61*4882a593Smuzhiyun 	/* private: Current clip iterator is advancing on. */
62*4882a593Smuzhiyun 	uint32_t curr_clip;
63*4882a593Smuzhiyun 	/* private: Whether need full plane update. */
64*4882a593Smuzhiyun 	bool full_update;
65*4882a593Smuzhiyun };
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun void drm_plane_enable_fb_damage_clips(struct drm_plane *plane);
68*4882a593Smuzhiyun void drm_atomic_helper_check_plane_damage(struct drm_atomic_state *state,
69*4882a593Smuzhiyun 					  struct drm_plane_state *plane_state);
70*4882a593Smuzhiyun int drm_atomic_helper_dirtyfb(struct drm_framebuffer *fb,
71*4882a593Smuzhiyun 			      struct drm_file *file_priv, unsigned int flags,
72*4882a593Smuzhiyun 			      unsigned int color, struct drm_clip_rect *clips,
73*4882a593Smuzhiyun 			      unsigned int num_clips);
74*4882a593Smuzhiyun void
75*4882a593Smuzhiyun drm_atomic_helper_damage_iter_init(struct drm_atomic_helper_damage_iter *iter,
76*4882a593Smuzhiyun 				   const struct drm_plane_state *old_state,
77*4882a593Smuzhiyun 				   const struct drm_plane_state *new_state);
78*4882a593Smuzhiyun bool
79*4882a593Smuzhiyun drm_atomic_helper_damage_iter_next(struct drm_atomic_helper_damage_iter *iter,
80*4882a593Smuzhiyun 				   struct drm_rect *rect);
81*4882a593Smuzhiyun bool drm_atomic_helper_damage_merged(const struct drm_plane_state *old_state,
82*4882a593Smuzhiyun 				     struct drm_plane_state *state,
83*4882a593Smuzhiyun 				     struct drm_rect *rect);
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun /**
86*4882a593Smuzhiyun  * drm_helper_get_plane_damage_clips - Returns damage clips in &drm_rect.
87*4882a593Smuzhiyun  * @state: Plane state.
88*4882a593Smuzhiyun  *
89*4882a593Smuzhiyun  * Returns plane damage rectangles in internal &drm_rect. Currently &drm_rect
90*4882a593Smuzhiyun  * can be obtained by simply typecasting &drm_mode_rect. This is because both
91*4882a593Smuzhiyun  * are signed 32 and during drm_atomic_check_only() it is verified that damage
92*4882a593Smuzhiyun  * clips are inside fb.
93*4882a593Smuzhiyun  *
94*4882a593Smuzhiyun  * Return: Clips in plane fb_damage_clips blob property.
95*4882a593Smuzhiyun  */
96*4882a593Smuzhiyun static inline struct drm_rect *
drm_helper_get_plane_damage_clips(const struct drm_plane_state * state)97*4882a593Smuzhiyun drm_helper_get_plane_damage_clips(const struct drm_plane_state *state)
98*4882a593Smuzhiyun {
99*4882a593Smuzhiyun 	return (struct drm_rect *)drm_plane_get_damage_clips(state);
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun #endif
103