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