summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/amd/dal/mode_manager/mode_query_allow_pan.c
blob: 30ee7cea090fa230e2c426701aba45266a31a8e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
 * Copyright 2012-15 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: AMD
 *
 */

#include "dal_services.h"
#include "mode_query_allow_pan.h"

struct mode_query_allow_pan {
	struct mode_query base;
	uint32_t panning_view_solution_indicies[MAX_COFUNC_PATH];
};

static bool build_cofunc_view_solution_set(struct mode_query *mq)
{
	struct mode_query_allow_pan *mq_allow_pan =
		container_of(mq, struct mode_query_allow_pan, base);
	uint32_t i;

	for (i = 0; i < mq->query_set->num_path; i++) {
		struct view_solution vs =
			get_solution_on_path_by_index(mq, i, mq->cur_view_idx);

		if (view_solution_get_display_view_importance(&vs) <=
				mq->enum_display_view_level)
			return true;

		if (view_solution_get_count(&vs) > 0) {
			mq->cur_view_solutions_idxs[i] = mq->cur_view_idx;
			mq->cur_view_solutions[i] = vs;
		} else {
			struct view_solution vs_pan;

			if (mq_allow_pan->panning_view_solution_indicies[i]
				== INVALID_VIEW_SOLUTION_INDEX){
				BREAK_TO_DEBUGGER();
				return false;
			}
			vs_pan = get_solution_on_path_by_index(
					mq,
					i,
					mq_allow_pan->
					panning_view_solution_indicies[i]);
			ASSERT(view_solution_get_count(&vs_pan) > 0);
			ASSERT(mq->enum_display_view_level >=
				view_solution_get_display_view_importance(
						&vs_pan));

			mq->cur_view_solutions_idxs[i] =
					mq_allow_pan->
					panning_view_solution_indicies[i];
			mq->cur_view_solutions[i] = vs_pan;
		}
	}
	return is_view_important_enough(
					mq->query_set,
					mq->cur_view_idx,
					mq->enum_adapter_view_match);
}

static bool pan_on_limited_build_cofunc_view_solution_set(struct mode_query *mq)
{
	uint32_t i;
	bool is_supported_by_at_least1 = false;

	for (i = 0; i < mq->query_set->num_path; i++) {
		struct view_solution vs = get_solution_on_path_by_index(
				mq,
				i,
				mq->cur_view_idx);

		if (view_solution_get_count(&vs) != 0) {
			is_supported_by_at_least1 = true;
			break;
		}
	}

	return is_supported_by_at_least1 && build_cofunc_view_solution_set(mq);
}

static const struct mode_query_funcs
mode_query_pan_on_limited_funcs = {
		.select_next_render_mode =
				dal_mode_query_base_select_next_render_mode,
		.select_next_scaling =
				dal_mode_query_base_select_next_scaling,
		.select_next_refresh_rate =
				dal_mode_query_base_select_next_refresh_rate,
		.build_cofunc_view_solution_set =
				pan_on_limited_build_cofunc_view_solution_set,
};

static const struct mode_query_funcs mode_query_allow_pan_funcs = {
		.select_next_render_mode =
				dal_mode_query_base_select_next_render_mode,
		.select_next_scaling =
				dal_mode_query_base_select_next_scaling,
		.select_next_refresh_rate =
				dal_mode_query_base_select_next_refresh_rate,
		.build_cofunc_view_solution_set = build_cofunc_view_solution_set
};

static const struct mode_query_funcs
mode_query_allow_pan_no_view_restriction_funcs = {
		.select_next_render_mode =
				dal_mode_query_base_select_next_render_mode,
		.select_next_scaling =
				dal_mode_query_base_select_next_scaling,
		.select_next_refresh_rate =
				dal_mode_query_base_select_next_refresh_rate,
		.build_cofunc_view_solution_set = build_cofunc_view_solution_set
};

static bool mode_query_allow_pan_construct(
		struct mode_query_allow_pan *mq_allow_pan,
		struct mode_query_init_data *mq_init_data)
{
	if (!dal_mode_query_construct(&mq_allow_pan->base, mq_init_data))
		return false;
	mq_allow_pan->base.funcs = &mode_query_allow_pan_funcs;
	return true;
}

static bool mode_query_allow_pan_on_limited_construct(
		struct mode_query_allow_pan *mq_allow_pan_no_view_restriction,
		struct mode_query_init_data *mq_init_data)
{
	if (!mode_query_allow_pan_construct(
			mq_allow_pan_no_view_restriction,
			mq_init_data))
		return false;
	mq_allow_pan_no_view_restriction->base.funcs =
			&mode_query_pan_on_limited_funcs;
	return true;
}

static bool mode_query_allow_pan_no_view_restriction_construct(
		struct mode_query_allow_pan *mq,
		struct mode_query_init_data *mq_init_data)
{
	if (!mode_query_allow_pan_construct(
			mq,
			mq_init_data))
		return false;

	mq->base.enum_adapter_view_match.flags.OPTIONAL = 1;
	mq->base.enum_display_view_level =
			DISPLAY_VIEW_IMPORTANCE_NON_GUARANTEED;
	mq->base.enum_solution_importance = SOLUTION_IMPORTANCE_UNSAFE;
	mq->base.funcs =
				&mode_query_allow_pan_no_view_restriction_funcs;
	return true;
}

struct mode_query *dal_mode_query_allow_pan_create(
				struct mode_query_init_data *mq_init_data)
{
	struct mode_query_allow_pan *mq_allow_pan =
			dal_alloc(sizeof(struct mode_query_allow_pan));

	if (mq_allow_pan == NULL)
		return NULL;

	if (mode_query_allow_pan_construct(
			mq_allow_pan,
			mq_init_data))
		return &mq_allow_pan->base;

	dal_free(mq_allow_pan);
	return NULL;
}

struct mode_query *dal_mode_query_pan_on_limited_create(
				struct mode_query_init_data *mq_init_data)
{
	struct mode_query_allow_pan *mq_allow_pan_on_limited =
			dal_alloc(sizeof(struct mode_query_allow_pan));
	if (mq_allow_pan_on_limited == NULL)
		return NULL;

	if (mode_query_allow_pan_on_limited_construct(
			mq_allow_pan_on_limited, mq_init_data))
		return &mq_allow_pan_on_limited->base;

	dal_free(mq_allow_pan_on_limited);
	return NULL;
}

struct mode_query *dal_mode_query_allow_pan_no_view_restriction_create(
				struct mode_query_init_data *mq_init_data)
{
	struct mode_query_allow_pan *mq_allow_pan_no_view_restriction =
			dal_alloc(sizeof(struct mode_query_allow_pan));
	if (mq_allow_pan_no_view_restriction == NULL)
		return NULL;

	if (mode_query_allow_pan_no_view_restriction_construct(
			mq_allow_pan_no_view_restriction, mq_init_data))
		return &mq_allow_pan_no_view_restriction->base;

	dal_free(mq_allow_pan_no_view_restriction);
	return NULL;
}

void dal_mode_query_allow_pan_post_initialize(struct mode_query *mq)
{
	uint32_t i;
	struct mode_query_allow_pan *mq_allow_pan = container_of(
			mq,
			struct mode_query_allow_pan,
			base);
	for (i = 0; i < mq->query_set->num_path; i++) {
		uint32_t j;

		mq_allow_pan->panning_view_solution_indicies[i] =
				INVALID_VIEW_SOLUTION_INDEX;

		for (j = dal_mode_query_set_get_view_count(mq->query_set);
				j > 0;
				j--) {
			struct view_solution vs =
					get_solution_on_path_by_index(
						mq,
						i,
						j - 1);

			if (view_solution_get_count(&vs) == 0)
				continue;

			if (view_solution_get_display_view_importance(&vs) <=
				DISPLAY_VIEW_IMPORTANCE_GUARANTEED) {

				mq_allow_pan->panning_view_solution_indicies[i]
					= j - 1;
				break;
			}

			if (mq_allow_pan->
				panning_view_solution_indicies[i] ==
					INVALID_VIEW_SOLUTION_INDEX &&
			view_solution_get_display_view_importance(&vs)
					<= mq->enum_display_view_level)

				mq_allow_pan->
				panning_view_solution_indicies[i] =
						j - 1;
		}

		ASSERT(mq_allow_pan->panning_view_solution_indicies[i] !=
				INVALID_VIEW_SOLUTION_INDEX);
	}
}