MCPcopy Create free account
hub / github.com/defold/defold / GetOptimalDisplayProfile

Function GetOptimalDisplayProfile

engine/render/src/render/display_profiles.cpp:157–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155 }
156
157 dmhash_t GetOptimalDisplayProfile(HDisplayProfiles profiles, uint32_t width, uint32_t height, uint32_t dpi, const dmArray<dmhash_t>* id_choices)
158 {
159 dmSys::SystemInfo sys_info;
160 dmSys::GetSystemInfo(&sys_info);
161 float width_f = (float) width;
162 float height_f = (float) height;
163 float match_area = width_f * height_f;
164 float match_ratio = height_f > 0.0f ? (width_f / height_f) : 0.0f;
165 float match_dpi = (float)dpi;
166 double match_distance[2] = { DBL_MAX, DBL_MAX };
167 dmhash_t match_id[2] = { 0, 0 };
168
169 for(uint32_t i = 0; i < profiles->m_Profiles.Size(); ++i)
170 {
171 DisplayProfiles::Profile& profile = profiles->m_Profiles[i];
172 uint32_t ci;
173 if(id_choices)
174 {
175 for(ci = 0; ci < id_choices->Size(); ++ci)
176 {
177 if(profile.m_Id == (*id_choices)[ci])
178 break;
179 }
180 if(ci == id_choices->Size())
181 continue;
182 }
183
184 for(uint32_t q = 0; q < profile.m_QualifierCount; ++q)
185 {
186 DisplayProfiles::Qualifier& qualifier = profile.m_Qualifiers[q];
187
188 bool device_model_match = (qualifier.m_NumDeviceModels == 0) ? true : DeviceModelMatch(&qualifier, &sys_info);
189
190 if (!device_model_match)
191 {
192 continue;
193 }
194
195 int category = IsPortrait(qualifier.m_Width, qualifier.m_Height);
196 float area = qualifier.m_Width * qualifier.m_Height;
197 float ratio = qualifier.m_Width / qualifier.m_Height;
198 double distance = dmMath::Abs(1.0 - (match_area / area)) + dmMath::Abs(1.0 - (match_ratio / ratio)) + (dpi == 0 ? 0.0 : dmMath::Abs(1.0 - (qualifier.m_Dpi / match_dpi)));
199 if(distance < match_distance[category])
200 {
201 match_distance[category] = distance;
202 match_id[category] = profile.m_Id;
203 }
204 }
205 }
206
207 // If there doesn't exist one of the correct category, we must choose one from the other category
208 int wantedcategory = IsPortrait(width, height);
209 dmhash_t id = match_id[wantedcategory];
210 if( id == 0 )
211 id = match_id[ (wantedcategory+1) & 0x01 ];
212 return id;
213 }
214

Callers 3

TESTFunction · 0.85
OnWindowResizeCallbackFunction · 0.85
SetupGuiSceneFunction · 0.85

Calls 5

DeviceModelMatchFunction · 0.85
IsPortraitFunction · 0.85
AbsFunction · 0.85
GetSystemInfoFunction · 0.50
SizeMethod · 0.45

Tested by 1

TESTFunction · 0.68