Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2baf418 authored by Lloyd Atkinson's avatar Lloyd Atkinson
Browse files

drm/msm/sde: add merge rectangles utility



Move merge rectangles logic from sde crtc into a common helper
function to be reused by other components.

Change-Id: Iaec6ac49f4c9ab2ca54a20b7de6bb337d5dbd671
Signed-off-by: default avatarLloyd Atkinson <latkinso@codeaurora.org>
parent 11a6d8d3
Loading
Loading
Loading
Loading
+1 −37
Original line number Diff line number Diff line
@@ -731,7 +731,6 @@ static int _sde_crtc_set_crtc_roi(struct drm_crtc *crtc,
	struct sde_crtc *sde_crtc;
	struct sde_crtc_state *crtc_state;
	struct sde_rect *crtc_roi;
	struct drm_clip_rect crtc_clip, *user_rect;
	int i, num_attached_conns = 0;

	if (!crtc || !state)
@@ -741,12 +740,6 @@ static int _sde_crtc_set_crtc_roi(struct drm_crtc *crtc,
	crtc_state = to_sde_crtc_state(state);
	crtc_roi = &crtc_state->crtc_roi;

	/* init to invalid range maxes */
	crtc_clip.x1 = ~0;
	crtc_clip.y1 = ~0;
	crtc_clip.x2 = 0;
	crtc_clip.y2 = 0;

	for_each_connector_in_state(state->state, conn, conn_state, i) {
		struct sde_connector_state *sde_conn_state;

@@ -771,36 +764,7 @@ static int _sde_crtc_set_crtc_roi(struct drm_crtc *crtc,
		}
	}

	/* aggregate all clipping rectangles together for overall crtc roi */
	for (i = 0; i < crtc_state->user_roi_list.num_rects; i++) {
		user_rect = &crtc_state->user_roi_list.roi[i];

		crtc_clip.x1 = min(crtc_clip.x1, user_rect->x1);
		crtc_clip.y1 = min(crtc_clip.y1, user_rect->y1);
		crtc_clip.x2 = max(crtc_clip.x2, user_rect->x2);
		crtc_clip.y2 = max(crtc_clip.y2, user_rect->y2);

		SDE_DEBUG(
			"%s: conn%d roi%d (%d,%d),(%d,%d) -> crtc (%d,%d),(%d,%d)\n",
				sde_crtc->name, DRMID(crtc), i,
				user_rect->x1, user_rect->y1,
				user_rect->x2, user_rect->y2,
				crtc_clip.x1, crtc_clip.y1,
				crtc_clip.x2, crtc_clip.y2);

	}

	if (crtc_clip.x2  && crtc_clip.y2) {
		crtc_roi->x = crtc_clip.x1;
		crtc_roi->y = crtc_clip.y1;
		crtc_roi->w = crtc_clip.x2 - crtc_clip.x1;
		crtc_roi->h = crtc_clip.y2 - crtc_clip.y1;
	} else {
		crtc_roi->x = 0;
		crtc_roi->y = 0;
		crtc_roi->w = 0;
		crtc_roi->h = 0;
	}
	sde_kms_rect_merge_rectangles(&crtc_state->user_roi_list, crtc_roi);

	SDE_DEBUG("%s: crtc roi (%d,%d,%d,%d)\n", sde_crtc->name,
			crtc_roi->x, crtc_roi->y, crtc_roi->w, crtc_roi->h);
+8 −0
Original line number Diff line number Diff line
@@ -406,6 +406,14 @@ void sde_kms_rect_intersect(const struct sde_rect *r1,
		const struct sde_rect *r2,
		struct sde_rect *result);

/**
 * sde_kms_rect_merge_rectangles - merge a rectangle list into one rect
 * @rois: pointer to the list of rois
 * @result: output rectangle, all 0 on error
 */
void sde_kms_rect_merge_rectangles(const struct msm_roi_list *rois,
		struct sde_rect *result);

/**
 * sde_kms_rect_is_equal - compares two rects
 * @r1: rect value to compare
+43 −0
Original line number Diff line number Diff line
@@ -175,3 +175,46 @@ void sde_kms_rect_intersect(const struct sde_rect *r1,
		result->h = b - t;
	}
}

void sde_kms_rect_merge_rectangles(const struct msm_roi_list *rois,
		struct sde_rect *result)
{
	struct drm_clip_rect clip;
	const struct drm_clip_rect *roi_rect;
	int i;

	if (!rois || !result)
		return;

	memset(result, 0, sizeof(*result));

	/* init to invalid range maxes */
	clip.x1 = ~0;
	clip.y1 = ~0;
	clip.x2 = 0;
	clip.y2 = 0;

	/* aggregate all clipping rectangles together for overall roi */
	for (i = 0; i < rois->num_rects; i++) {
		roi_rect = &rois->roi[i];

		clip.x1 = min(clip.x1, roi_rect->x1);
		clip.y1 = min(clip.y1, roi_rect->y1);
		clip.x2 = max(clip.x2, roi_rect->x2);
		clip.y2 = max(clip.y2, roi_rect->y2);

		SDE_DEBUG("roi%d (%d,%d),(%d,%d) -> crtc (%d,%d),(%d,%d)\n", i,
				roi_rect->x1, roi_rect->y1,
				roi_rect->x2, roi_rect->y2,
				clip.x1, clip.y1,
				clip.x2, clip.y2);
	}

	if (clip.x2  && clip.y2) {
		result->x = clip.x1;
		result->y = clip.y1;
		result->w = clip.x2 - clip.x1;
		result->h = clip.y2 - clip.y1;
	}
}