18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR MIT */
28c2ecf20Sopenharmony_ci/**************************************************************************
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 2018 VMware, Inc., Palo Alto, CA., USA
58c2ecf20Sopenharmony_ci * All Rights Reserved.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
88c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the
98c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
108c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
118c2ecf20Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
128c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
138c2ecf20Sopenharmony_ci * the following conditions:
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the
168c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
178c2ecf20Sopenharmony_ci * of the Software.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
208c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
218c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
228c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
238c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
248c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
258c2ecf20Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * Authors:
288c2ecf20Sopenharmony_ci * Deepak Rawat <drawat@vmware.com>
298c2ecf20Sopenharmony_ci *
308c2ecf20Sopenharmony_ci **************************************************************************/
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#ifndef DRM_DAMAGE_HELPER_H_
338c2ecf20Sopenharmony_ci#define DRM_DAMAGE_HELPER_H_
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#include <drm/drm_atomic_helper.h>
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/**
388c2ecf20Sopenharmony_ci * drm_atomic_for_each_plane_damage - Iterator macro for plane damage.
398c2ecf20Sopenharmony_ci * @iter: The iterator to advance.
408c2ecf20Sopenharmony_ci * @rect: Return a rectangle in fb coordinate clipped to plane src.
418c2ecf20Sopenharmony_ci *
428c2ecf20Sopenharmony_ci * Note that if the first call to iterator macro return false then no need to do
438c2ecf20Sopenharmony_ci * plane update. Iterator will return full plane src when damage is not passed
448c2ecf20Sopenharmony_ci * by user-space.
458c2ecf20Sopenharmony_ci */
468c2ecf20Sopenharmony_ci#define drm_atomic_for_each_plane_damage(iter, rect) \
478c2ecf20Sopenharmony_ci	while (drm_atomic_helper_damage_iter_next(iter, rect))
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/**
508c2ecf20Sopenharmony_ci * struct drm_atomic_helper_damage_iter - Closure structure for damage iterator.
518c2ecf20Sopenharmony_ci *
528c2ecf20Sopenharmony_ci * This structure tracks state needed to walk the list of plane damage clips.
538c2ecf20Sopenharmony_ci */
548c2ecf20Sopenharmony_cistruct drm_atomic_helper_damage_iter {
558c2ecf20Sopenharmony_ci	/* private: Plane src in whole number. */
568c2ecf20Sopenharmony_ci	struct drm_rect plane_src;
578c2ecf20Sopenharmony_ci	/* private: Rectangles in plane damage blob. */
588c2ecf20Sopenharmony_ci	const struct drm_rect *clips;
598c2ecf20Sopenharmony_ci	/* private: Number of rectangles in plane damage blob. */
608c2ecf20Sopenharmony_ci	uint32_t num_clips;
618c2ecf20Sopenharmony_ci	/* private: Current clip iterator is advancing on. */
628c2ecf20Sopenharmony_ci	uint32_t curr_clip;
638c2ecf20Sopenharmony_ci	/* private: Whether need full plane update. */
648c2ecf20Sopenharmony_ci	bool full_update;
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_civoid drm_plane_enable_fb_damage_clips(struct drm_plane *plane);
688c2ecf20Sopenharmony_civoid drm_atomic_helper_check_plane_damage(struct drm_atomic_state *state,
698c2ecf20Sopenharmony_ci					  struct drm_plane_state *plane_state);
708c2ecf20Sopenharmony_ciint drm_atomic_helper_dirtyfb(struct drm_framebuffer *fb,
718c2ecf20Sopenharmony_ci			      struct drm_file *file_priv, unsigned int flags,
728c2ecf20Sopenharmony_ci			      unsigned int color, struct drm_clip_rect *clips,
738c2ecf20Sopenharmony_ci			      unsigned int num_clips);
748c2ecf20Sopenharmony_civoid
758c2ecf20Sopenharmony_cidrm_atomic_helper_damage_iter_init(struct drm_atomic_helper_damage_iter *iter,
768c2ecf20Sopenharmony_ci				   const struct drm_plane_state *old_state,
778c2ecf20Sopenharmony_ci				   const struct drm_plane_state *new_state);
788c2ecf20Sopenharmony_cibool
798c2ecf20Sopenharmony_cidrm_atomic_helper_damage_iter_next(struct drm_atomic_helper_damage_iter *iter,
808c2ecf20Sopenharmony_ci				   struct drm_rect *rect);
818c2ecf20Sopenharmony_cibool drm_atomic_helper_damage_merged(const struct drm_plane_state *old_state,
828c2ecf20Sopenharmony_ci				     struct drm_plane_state *state,
838c2ecf20Sopenharmony_ci				     struct drm_rect *rect);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/**
868c2ecf20Sopenharmony_ci * drm_helper_get_plane_damage_clips - Returns damage clips in &drm_rect.
878c2ecf20Sopenharmony_ci * @state: Plane state.
888c2ecf20Sopenharmony_ci *
898c2ecf20Sopenharmony_ci * Returns plane damage rectangles in internal &drm_rect. Currently &drm_rect
908c2ecf20Sopenharmony_ci * can be obtained by simply typecasting &drm_mode_rect. This is because both
918c2ecf20Sopenharmony_ci * are signed 32 and during drm_atomic_check_only() it is verified that damage
928c2ecf20Sopenharmony_ci * clips are inside fb.
938c2ecf20Sopenharmony_ci *
948c2ecf20Sopenharmony_ci * Return: Clips in plane fb_damage_clips blob property.
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_cistatic inline struct drm_rect *
978c2ecf20Sopenharmony_cidrm_helper_get_plane_damage_clips(const struct drm_plane_state *state)
988c2ecf20Sopenharmony_ci{
998c2ecf20Sopenharmony_ci	return (struct drm_rect *)drm_plane_get_damage_clips(state);
1008c2ecf20Sopenharmony_ci}
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci#endif
103