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