mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-10-29 05:40:12 -04:00 
			
		
		
		
	backend/drm: use more descriptive names for match_obj()
This function is only used for connectors and CRTCs, so instead of the abstract "obj"/"resource" wording, just use the concrete names.
This commit is contained in:
		
							parent
							
								
									d2a5dbe104
								
							
						
					
					
						commit
						0bf642d246
					
				
					 3 changed files with 45 additions and 41 deletions
				
			
		|  | @ -1354,7 +1354,7 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, | |||
| 		++i; | ||||
| 	} | ||||
| 
 | ||||
| 	match_obj(num_connectors, connector_constraints, | ||||
| 	match_connectors_with_crtcs(num_connectors, connector_constraints, | ||||
| 		drm->num_crtcs, previous_match, new_match); | ||||
| 
 | ||||
| 	// Converts our crtc=>connector result into a connector=>crtc one.
 | ||||
|  |  | |||
|  | @ -112,9 +112,9 @@ static bool is_taken(size_t n, const uint32_t arr[static n], uint32_t key) { | |||
|  * passing 12 arguments to a function. | ||||
|  */ | ||||
| struct match_state { | ||||
| 	const size_t num_objs; | ||||
| 	const uint32_t *restrict objs; | ||||
| 	const size_t num_res; | ||||
| 	const size_t num_conns; | ||||
| 	const uint32_t *restrict conns; | ||||
| 	const size_t num_crtcs; | ||||
| 	size_t score; | ||||
| 	size_t replaced; | ||||
| 	uint32_t *restrict res; | ||||
|  | @ -127,23 +127,24 @@ struct match_state { | |||
|  * skips: The number of SKIP elements encountered so far. | ||||
|  * score: The number of resources we've matched so far. | ||||
|  * replaced: The number of changes from the original solution. | ||||
|  * i: The index of the current element. | ||||
|  * i: The index of the current CRTC. | ||||
|  * | ||||
|  * This tries to match a solution as close to st->orig as it can. | ||||
|  * | ||||
|  * Returns whether we've set a new best element with this solution. | ||||
|  */ | ||||
| static bool match_obj_(struct match_state *st, size_t skips, size_t score, size_t replaced, size_t i) { | ||||
| static bool match_connectors_with_crtcs_(struct match_state *st, size_t skips, | ||||
| 		size_t score, size_t replaced, size_t i) { | ||||
| 	// Finished
 | ||||
| 	if (i >= st->num_res) { | ||||
| 	if (i >= st->num_crtcs) { | ||||
| 		if (score > st->score || | ||||
| 				(score == st->score && replaced < st->replaced)) { | ||||
| 			st->score = score; | ||||
| 			st->replaced = replaced; | ||||
| 			memcpy(st->best, st->res, sizeof(st->best[0]) * st->num_res); | ||||
| 			memcpy(st->best, st->res, sizeof(st->best[0]) * st->num_crtcs); | ||||
| 
 | ||||
| 			st->exit_early = (st->score == st->num_res - skips | ||||
| 					|| st->score == st->num_objs) | ||||
| 			st->exit_early = (st->score == st->num_crtcs - skips | ||||
| 					|| st->score == st->num_conns) | ||||
| 					&& st->replaced == 0; | ||||
| 
 | ||||
| 			return true; | ||||
|  | @ -154,7 +155,7 @@ static bool match_obj_(struct match_state *st, size_t skips, size_t score, size_ | |||
| 
 | ||||
| 	if (st->orig[i] == SKIP) { | ||||
| 		st->res[i] = SKIP; | ||||
| 		return match_obj_(st, skips + 1, score, replaced, i + 1); | ||||
| 		return match_connectors_with_crtcs_(st, skips + 1, score, replaced, i + 1); | ||||
| 	} | ||||
| 
 | ||||
| 	bool has_best = false; | ||||
|  | @ -165,8 +166,8 @@ static bool match_obj_(struct match_state *st, size_t skips, size_t score, size_ | |||
| 	 */ | ||||
| 	if (st->orig[i] != UNMATCHED && !is_taken(i, st->res, st->orig[i])) { | ||||
| 		st->res[i] = st->orig[i]; | ||||
| 		size_t obj_score = st->objs[st->res[i]] != 0 ? 1 : 0; | ||||
| 		if (match_obj_(st, skips, score + obj_score, replaced, i + 1)) { | ||||
| 		size_t crtc_score = st->conns[st->res[i]] != 0 ? 1 : 0; | ||||
| 		if (match_connectors_with_crtcs_(st, skips, score + crtc_score, replaced, i + 1)) { | ||||
| 			has_best = true; | ||||
| 		} | ||||
| 	} | ||||
|  | @ -178,14 +179,14 @@ static bool match_obj_(struct match_state *st, size_t skips, size_t score, size_ | |||
| 		++replaced; | ||||
| 	} | ||||
| 
 | ||||
| 	for (size_t candidate = 0; candidate < st->num_objs; ++candidate) { | ||||
| 	for (size_t candidate = 0; candidate < st->num_conns; ++candidate) { | ||||
| 		// We tried this earlier
 | ||||
| 		if (candidate == st->orig[i]) { | ||||
| 			continue; | ||||
| 		} | ||||
| 
 | ||||
| 		// Not compatible
 | ||||
| 		if (!(st->objs[candidate] & (1 << i))) { | ||||
| 		if (!(st->conns[candidate] & (1 << i))) { | ||||
| 			continue; | ||||
| 		} | ||||
| 
 | ||||
|  | @ -195,8 +196,8 @@ static bool match_obj_(struct match_state *st, size_t skips, size_t score, size_ | |||
| 		} | ||||
| 
 | ||||
| 		st->res[i] = candidate; | ||||
| 		size_t obj_score = st->objs[candidate] != 0 ? 1 : 0; | ||||
| 		if (match_obj_(st, skips, score + obj_score, replaced, i + 1)) { | ||||
| 		size_t crtc_score = st->conns[candidate] != 0 ? 1 : 0; | ||||
| 		if (match_connectors_with_crtcs_(st, skips, score + crtc_score, replaced, i + 1)) { | ||||
| 			has_best = true; | ||||
| 		} | ||||
| 
 | ||||
|  | @ -205,36 +206,37 @@ static bool match_obj_(struct match_state *st, size_t skips, size_t score, size_ | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// Maybe this resource can't be matched
 | ||||
| 	// Maybe this CRTC can't be matched
 | ||||
| 	st->res[i] = UNMATCHED; | ||||
| 	if (match_obj_(st, skips, score, replaced, i + 1)) { | ||||
| 	if (match_connectors_with_crtcs_(st, skips, score, replaced, i + 1)) { | ||||
| 		has_best = true; | ||||
| 	} | ||||
| 
 | ||||
| 	return has_best; | ||||
| } | ||||
| 
 | ||||
| size_t match_obj(size_t num_objs, const uint32_t objs[static restrict num_objs], | ||||
| 		size_t num_res, const uint32_t res[static restrict num_res], | ||||
| 		uint32_t out[static restrict num_res]) { | ||||
| 	uint32_t solution[num_res]; | ||||
| 	for (size_t i = 0; i < num_res; ++i) { | ||||
| size_t match_connectors_with_crtcs(size_t num_conns, | ||||
| 		const uint32_t conns[static restrict num_conns], | ||||
| 		size_t num_crtcs, const uint32_t prev_crtcs[static restrict num_crtcs], | ||||
| 		uint32_t new_crtcs[static restrict num_crtcs]) { | ||||
| 	uint32_t solution[num_crtcs]; | ||||
| 	for (size_t i = 0; i < num_crtcs; ++i) { | ||||
| 		solution[i] = UNMATCHED; | ||||
| 	} | ||||
| 
 | ||||
| 	struct match_state st = { | ||||
| 		.num_objs = num_objs, | ||||
| 		.num_res = num_res, | ||||
| 		.num_conns = num_conns, | ||||
| 		.num_crtcs = num_crtcs, | ||||
| 		.score = 0, | ||||
| 		.replaced = SIZE_MAX, | ||||
| 		.objs = objs, | ||||
| 		.conns = conns, | ||||
| 		.res = solution, | ||||
| 		.best = out, | ||||
| 		.orig = res, | ||||
| 		.best = new_crtcs, | ||||
| 		.orig = prev_crtcs, | ||||
| 		.exit_early = false, | ||||
| 	}; | ||||
| 
 | ||||
| 	match_obj_(&st, 0, 0, 0, 0); | ||||
| 	match_connectors_with_crtcs_(&st, 0, 0, 0, 0); | ||||
| 	return st.score; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -18,26 +18,28 @@ const char *drm_connector_status_str(drmModeConnection status); | |||
| void generate_cvt_mode(drmModeModeInfo *mode, int hdisplay, int vdisplay, | ||||
| 	float vrefresh); | ||||
| 
 | ||||
| // Part of match_obj
 | ||||
| // Part of match_connectors_with_crtcs
 | ||||
| enum { | ||||
| 	UNMATCHED = (uint32_t)-1, | ||||
| 	SKIP = (uint32_t)-2, | ||||
| }; | ||||
| 
 | ||||
| /*
 | ||||
|  * Tries to match some DRM objects with some other DRM resource. | ||||
|  * e.g. Match CRTCs with Encoders, CRTCs with Planes. | ||||
| /**
 | ||||
|  * Tries to match DRM connectors with DRM CRTCs. | ||||
|  * | ||||
|  * objs contains a bit array which resources it can be matched with. | ||||
|  * e.g. Bit 0 set means can be matched with res[0] | ||||
|  * conns contains an array of bitmasks describing compatible CRTCs. For | ||||
|  * instance bit 0 set in an connector element means that it's compatible with | ||||
|  * CRTC 0. | ||||
|  * | ||||
|  * res contains an index of which objs it is matched with or UNMATCHED. | ||||
|  * prev_crtcs contains connector indices each CRTC was previously matched with, | ||||
|  * or UNMATCHED. | ||||
|  * | ||||
|  * This solution is left in out. | ||||
|  * new_crtcs is populated with the new connector indices. | ||||
|  * Returns the total number of matched solutions. | ||||
|  */ | ||||
| size_t match_obj(size_t num_objs, const uint32_t objs[static restrict num_objs], | ||||
| 		size_t num_res, const uint32_t res[static restrict num_res], | ||||
| 		uint32_t out[static restrict num_res]); | ||||
| size_t match_connectors_with_crtcs(size_t num_conns, | ||||
| 	const uint32_t conns[static restrict num_conns], | ||||
| 	size_t num_crtcs, const uint32_t prev_crtcs[static restrict num_crtcs], | ||||
| 	uint32_t new_crtcs[static restrict num_crtcs]); | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Simon Ser
						Simon Ser