@@ -28,7 +28,7 @@ static void showError(std::string msg)
2828}
2929
3030
31- static  void   SetHDR (bool  enabled)
31+ static  void   SetGlobalHDR (bool  enabled)
3232{
3333	uint32_t  pathCount, modeCount;
3434
@@ -112,6 +112,174 @@ static void  SetHDR(bool enabled)
112112	}
113113}
114114
115+ 
116+ static  void   SetHDR (UINT32 uid, bool  enabled)
117+ {
118+ 	uint32_t  pathCount, modeCount;
119+ 
120+ 	uint8_t  set[] = { 0x0A , 0x00 , 0x00 , 0x00 , 0x18 , 0x00 , 0x00 , 0x00 , 0x14 , 0x81 , 0x00 , 0x00 ,
121+ 					 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x01 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00  };
122+ 
123+ 	uint8_t  request[] = { 0x09 , 0x00 , 0x00 , 0x00 , 0x20 , 0x00 , 0x00 , 0x00 , 0x7C , 0x6F , 0x00 ,
124+ 						 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x01 , 0x00 , 0x00 , 0xDB , 0x00 ,
125+ 						 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x40 , 0x00 , 0x00  };
126+ 
127+ 	if  (ERROR_SUCCESS == GetDisplayConfigBufferSizes (QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount))
128+ 	{
129+ 		DISPLAYCONFIG_PATH_INFO* pathsArray = nullptr ;
130+ 		DISPLAYCONFIG_MODE_INFO* modesArray = nullptr ;
131+ 
132+ 		const  size_t  sizePathsArray = pathCount * sizeof (DISPLAYCONFIG_PATH_INFO);
133+ 		const  size_t  sizeModesArray = modeCount * sizeof (DISPLAYCONFIG_MODE_INFO);
134+ 
135+ 		pathsArray = static_cast <DISPLAYCONFIG_PATH_INFO*>(std::malloc (sizePathsArray));
136+ 		modesArray = static_cast <DISPLAYCONFIG_MODE_INFO*>(std::malloc (sizeModesArray));
137+ 
138+ 
139+ 		if  (pathsArray != nullptr  && modesArray != nullptr )
140+ 		{
141+ 			std::memset (pathsArray, 0 , sizePathsArray);
142+ 			std::memset (modesArray, 0 , sizeModesArray);
143+ 
144+ 			LONG queryRet = QueryDisplayConfig (QDC_ONLY_ACTIVE_PATHS, &pathCount, pathsArray,
145+ 				&modeCount, modesArray, 0 );
146+ 			if  (ERROR_SUCCESS == queryRet)
147+ 			{
148+ 				DISPLAYCONFIG_DEVICE_INFO_HEADER* setPacket =
149+ 					reinterpret_cast <DISPLAYCONFIG_DEVICE_INFO_HEADER*>(set);
150+ 				DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket =
151+ 					reinterpret_cast <DISPLAYCONFIG_DEVICE_INFO_HEADER*>(request);
152+ 
153+ 				for  (int  i = 0 ; i < modeCount; i++)
154+ 				{
155+ 					try 
156+ 					{
157+ 						if  (modesArray[i].id  != uid)
158+ 							continue ;
159+ 						if  (modesArray[i].infoType  == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET)
160+ 						{
161+ 							setPacket->adapterId .HighPart  = modesArray[i].adapterId .HighPart ;
162+ 							setPacket->adapterId .LowPart  = modesArray[i].adapterId .LowPart ;
163+ 							setPacket->id  = modesArray[i].id ;
164+ 
165+ 							requestPacket->adapterId .HighPart  = modesArray[i].adapterId .HighPart ;
166+ 							requestPacket->adapterId .LowPart  = modesArray[i].adapterId .LowPart ;
167+ 							requestPacket->id  = modesArray[i].id ;
168+ 	
169+ 							if  (ERROR_SUCCESS == DisplayConfigGetDeviceInfo (requestPacket))
170+ 							{
171+ 								if  (enabled == true )
172+ 								{
173+ 									set[20 ] = 1 ;
174+ 									DisplayConfigSetDeviceInfo (setPacket);
175+ 								}
176+ 								else  if  (enabled == false )
177+ 								{
178+ 									set[20 ] = 0 ;
179+ 									DisplayConfigSetDeviceInfo (setPacket);
180+ 								}
181+ 							}
182+ 						}
183+ 					}
184+ 					catch  (const  std::exception&)
185+ 					{
186+ 
187+ 					}
188+ 				}
189+ 
190+ 			}
191+ 
192+ 			std::free (pathsArray);
193+ 			std::free (modesArray);
194+ 		}
195+ 		else 
196+ 		{
197+ 			throw  std::invalid_argument (" No monitor found." 
198+ 		}
199+ 	}
200+ }
201+ 
202+ 
203+ 
204+ static  bool  HDRIsOn (UINT32 uid)
205+ {
206+ 	bool  returnValue = false ;
207+ 
208+ 	uint32_t  pathCount, modeCount;
209+ 
210+ 	uint8_t  set[] = { 0x0A , 0x00 , 0x00 , 0x00 , 0x18 , 0x00 , 0x00 , 0x00 , 0x14 , 0x81 , 0x00 , 0x00 ,
211+ 					 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x01 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00  };
212+ 
213+ 	uint8_t  request[] = { 0x09 , 0x00 , 0x00 , 0x00 , 0x20 , 0x00 , 0x00 , 0x00 , 0x7C , 0x6F , 0x00 ,
214+ 						 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x01 , 0x00 , 0x00 , 0xDB , 0x00 ,
215+ 						 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x40 , 0x00 , 0x00  };
216+ 
217+ 	if  (ERROR_SUCCESS == GetDisplayConfigBufferSizes (QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount))
218+ 	{
219+ 		DISPLAYCONFIG_PATH_INFO* pathsArray = nullptr ;
220+ 		DISPLAYCONFIG_MODE_INFO* modesArray = nullptr ;
221+ 
222+ 		const  size_t  sizePathsArray = pathCount * sizeof (DISPLAYCONFIG_PATH_INFO);
223+ 		const  size_t  sizeModesArray = modeCount * sizeof (DISPLAYCONFIG_MODE_INFO);
224+ 
225+ 		pathsArray = static_cast <DISPLAYCONFIG_PATH_INFO*>(std::malloc (sizePathsArray));
226+ 		modesArray = static_cast <DISPLAYCONFIG_MODE_INFO*>(std::malloc (sizeModesArray));
227+ 
228+ 		if  (pathsArray != nullptr  && modesArray != nullptr )
229+ 		{
230+ 			std::memset (pathsArray, 0 , sizePathsArray);
231+ 			std::memset (modesArray, 0 , sizeModesArray);
232+ 
233+ 			if  (ERROR_SUCCESS == QueryDisplayConfig (QDC_ONLY_ACTIVE_PATHS, &pathCount, pathsArray,
234+ 				&modeCount, modesArray, 0 ))
235+ 			{
236+ 				DISPLAYCONFIG_DEVICE_INFO_HEADER* setPacket =
237+ 					reinterpret_cast <DISPLAYCONFIG_DEVICE_INFO_HEADER*>(set);
238+ 				DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket =
239+ 					reinterpret_cast <DISPLAYCONFIG_DEVICE_INFO_HEADER*>(request);
240+ 
241+ 				// HDR is off
242+ 				returnValue = false ;
243+ 				for  (int  i = 0 ; i < modeCount; i++)
244+ 				{
245+ 					try 
246+ 					{
247+ 						if  (modesArray[i].id  != uid)
248+ 							continue ;
249+ 						if  (modesArray[i].infoType  == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET)
250+ 						{
251+ 							setPacket->adapterId .HighPart  = modesArray[i].adapterId .HighPart ;
252+ 							setPacket->adapterId .LowPart  = modesArray[i].adapterId .LowPart ;
253+ 							setPacket->id  = modesArray[i].id ;
254+ 
255+ 							requestPacket->adapterId .HighPart  = modesArray[i].adapterId .HighPart ;
256+ 							requestPacket->adapterId .LowPart  = modesArray[i].adapterId .LowPart ;
257+ 							requestPacket->id  = modesArray[i].id ;
258+ 						}
259+ 						if  (ERROR_SUCCESS == DisplayConfigGetDeviceInfo (requestPacket))
260+ 						{
261+ 							if  (request[20 ] == 0xD3 ) //  HDR is ON
262+ 							{
263+ 								returnValue = true ;
264+ 								break ;
265+ 							}
266+ 						}
267+ 					}
268+ 					catch  (const  std::exception&)
269+ 					{
270+ 
271+ 					}
272+ 
273+ 				}
274+ 			}
275+ 			std::free (pathsArray);
276+ 			std::free (modesArray);
277+ 			return  returnValue;
278+ 		}
279+ 	}
280+ }
281+ 
282+ 
115283static  bool  HDRIsOn ()
116284{
117285	bool  returnValue = false ;
@@ -190,13 +358,23 @@ static bool HDRIsOn()
190358
191359extern  " C" 
192360{
193- 	__declspec (dllexport) void SetHDRState (bool  enabled)
361+ 	__declspec (dllexport) void SetGlobalHDRState (bool  enabled)
194362	{
195- 		SetHDR (enabled);
363+ 		SetGlobalHDR (enabled);
196364	}
197365
198- 	__declspec (dllexport) bool GetHDRState ()
366+ 	__declspec (dllexport) bool GetGlobalHDRState ()
199367	{
200368		return  HDRIsOn ();
201369	}
370+ 
371+ 	__declspec (dllexport) void SetHDRState(UINT32 uid, bool  enabled)
372+ 	{
373+ 		SetHDR (uid, enabled);
374+ 	}
375+ 
376+ 	__declspec (dllexport) bool GetHDRState(UINT32 uid)
377+ 	{
378+ 		return  HDRIsOn (uid);
379+ 	}
202380}
0 commit comments