1+ //
2+ // Copyright (c) 2021 - 2025 Advanced Micro Devices, Inc. All rights reserved.
3+ //
4+ //-------------------------------------------------------------------------------------------------
5+
6+ /// \file mainDisplayFreeSyncColorAccuracy.c
7+ /// \brief Demonstrates how to configure the FreeSync color accuracy options, and perform related testing when programming with ADLX.
8+
9+
10+ #include "SDK/ADLXHelper/Windows/C/ADLXHelper.h"
11+ #include "SDK/Include/IDisplaySettings.h"
12+ #include "SDK/Include/IDisplays.h"
13+ #include "SDK/Include/IDisplays3.h"
14+
15+ // Thread to quit event
16+ static HANDLE quitEvent = NULL ;
17+
18+ // Thread to quit flag
19+ static int g_quit = 0 ;
20+
21+ // Thread to timeout
22+ static HANDLE thread = NULL ;
23+
24+ // Show FreeSync color accuracy support
25+ void ShowFreeSyncColorAccuracySupport (IADLXDisplayServices3 * displayService3 , IADLXDisplay * display );
26+
27+ // Get current FreeSync color accuracy state
28+ void GetFreeSyncColorAccuracyState (IADLXDisplayServices3 * displayService3 , IADLXDisplay * display );
29+
30+ // Set FreeSync color accuracy state
31+ void SetFreeSyncColorAccuracyState (IADLXDisplayServices3 * displayService3 , IADLXDisplay * display , const int key );
32+
33+ // Main menu
34+ void MainMenu ();
35+
36+ // Menu action control
37+ void MenuControl (IADLXDisplayServices3 * displayService3 , const IADLXDisplay * display );
38+
39+ // Wait for exit with error message
40+ int WaitAndExit (const char * msg , const int retCode );
41+
42+ int main ()
43+ {
44+
45+ // Define return code
46+ ADLX_RESULT res = ADLX_FAIL ;
47+
48+ // Initialize ADLX
49+ res = ADLXHelper_Initialize ();
50+ if (ADLX_SUCCEEDED (res ))
51+ {
52+ // Get system service
53+ IADLXSystem * sys = ADLXHelper_GetSystemServices ();
54+
55+ // Get display service
56+ IADLXDisplayServices * displayService = NULL ;
57+ res = sys -> pVtbl -> GetDisplaysServices (sys , & displayService );
58+ if (ADLX_SUCCEEDED (res ))
59+ {
60+ IADLXDisplayServices3 * displayServices3 = NULL ;
61+ ADLX_RESULT res3 = displayService -> pVtbl -> QueryInterface (displayService , IID_IADLXDisplayServices3 (), (void * * )& displayServices3 );
62+
63+ // Get display list
64+ IADLXDisplayList * displayList = NULL ;
65+ res = displayService -> pVtbl -> GetDisplays (displayService , & displayList );
66+ if (ADLX_SUCCEEDED (res ) && ADLX_SUCCEEDED (res3 ))
67+ {
68+ // Inspect for the first display in the list
69+ adlx_uint it = 0 ;
70+ IADLXDisplay * display = NULL ;
71+ res = displayList -> pVtbl -> At_DisplayList (displayList , it , & display );
72+ if (ADLX_SUCCEEDED (res ))
73+ {
74+ // Display main menu options
75+ MainMenu ();
76+ // Get and execute the choice
77+ MenuControl (displayServices3 , display );
78+ }
79+
80+ // Release the display interface
81+ if (NULL != display )
82+ {
83+ display -> pVtbl -> Release (display );
84+ display = NULL ;
85+ }
86+ }
87+
88+ // Release the displayList interface
89+ if (NULL != displayList )
90+ {
91+ displayList -> pVtbl -> Release (displayList );
92+ displayList = NULL ;
93+ }
94+
95+ if (NULL != displayServices3 )
96+ {
97+ displayServices3 -> pVtbl -> Release (displayServices3 );
98+ displayServices3 = NULL ;
99+ }
100+ }
101+
102+ // Release the displayService interface
103+ if (NULL != displayService )
104+ {
105+ displayService -> pVtbl -> Release (displayService );
106+ displayService = NULL ;
107+ }
108+ }
109+ else
110+ {
111+ return WaitAndExit ("ADLX initialization failed" , 0 );
112+ }
113+
114+ // Destroy ADLX
115+ res = ADLXHelper_Terminate ();
116+ printf ("Destroy ADLX res: %d\n" , res );
117+
118+ // Pause to see the print out
119+ system ("pause" );
120+
121+ return 0 ;
122+ }
123+
124+ void ShowFreeSyncColorAccuracySupport (IADLXDisplayServices3 * displayService3 , IADLXDisplay * display )
125+ {
126+ IADLXDisplayFreeSyncColorAccuracy * displayFreeSyncColorAccuracy ;
127+ ADLX_RESULT res = displayService3 -> pVtbl -> GetFreeSyncColorAccuracy (displayService3 , display , & displayFreeSyncColorAccuracy );
128+ if (ADLX_SUCCEEDED (res ))
129+ {
130+ printf (" === Get FreeSync color accuracy Supported ===\n" );
131+ adlx_bool supported = false;
132+ res = displayFreeSyncColorAccuracy -> pVtbl -> IsSupported (displayFreeSyncColorAccuracy , & supported );
133+ printf ("\tFreeSync color accuracy is supported on the display: %s, return code: %d (0 means success)\n" , supported ? "true" : "false" , res );
134+ displayFreeSyncColorAccuracy -> pVtbl -> Release (displayFreeSyncColorAccuracy );
135+ }
136+ }
137+ void GetFreeSyncColorAccuracyState (IADLXDisplayServices3 * displayService3 , IADLXDisplay * display )
138+ {
139+ IADLXDisplayFreeSyncColorAccuracy * displayFreeSyncColorAccuracy ;
140+ ADLX_RESULT res = displayService3 -> pVtbl -> GetFreeSyncColorAccuracy (displayService3 , display , & displayFreeSyncColorAccuracy );
141+ if (ADLX_SUCCEEDED (res ))
142+ {
143+ printf (" === Get FreeSync color accuracy enabled ===\n" );
144+ adlx_bool enabled = false;
145+ res = displayFreeSyncColorAccuracy -> pVtbl -> IsEnabled (displayFreeSyncColorAccuracy , & enabled );
146+ printf ("\tFreeSync color accuracy is enabled on the display, res: %d, enabled: %s\n" , res , enabled ? "true" : "false" );
147+ displayFreeSyncColorAccuracy -> pVtbl -> Release (displayFreeSyncColorAccuracy );
148+ }
149+ }
150+
151+ void SetFreeSyncColorAccuracyState (IADLXDisplayServices3 * displayService3 , IADLXDisplay * display , const int key )
152+ {
153+ IADLXDisplayFreeSyncColorAccuracy * displayFreeSyncColorAccuracy ;
154+ ADLX_RESULT res = displayService3 -> pVtbl -> GetFreeSyncColorAccuracy (displayService3 , display , & displayFreeSyncColorAccuracy );
155+ if (ADLX_SUCCEEDED (res ))
156+ {
157+ printf (" === Set FreeSync color accuracy Control ===\n" );
158+ ADLX_RESULT res = ADLX_FAIL ;
159+ switch (key )
160+ {
161+ // Set FreeSync color accuracy disabled
162+ case 0 :
163+ res = displayFreeSyncColorAccuracy -> pVtbl -> SetEnabled (displayFreeSyncColorAccuracy , false);
164+ break ;
165+ // Set FreeSync color accuracy enabled
166+ case 1 :
167+ res = displayFreeSyncColorAccuracy -> pVtbl -> SetEnabled (displayFreeSyncColorAccuracy , true);
168+ break ;
169+ default :
170+ break ;
171+ }
172+ printf ("\treturn code is: %d (0 means Success)\n" , res );
173+ displayFreeSyncColorAccuracy -> pVtbl -> Release (displayFreeSyncColorAccuracy );
174+ }
175+ }
176+
177+ void MainMenu ()
178+ {
179+ printf ("\tChoose from following options:\n" );
180+
181+ printf ("\t->Press 1 to FreeSync color accuracy support\n" );
182+
183+ printf ("\t->Press 2 to get FreeSync color accuracy state\n" );
184+
185+ printf ("\t->Press 3 to set FreeSync color accuracy disabled\n" );
186+ printf ("\t->Press 4 to set FreeSync color accuracy enabled\n" );
187+
188+ printf ("\t->Press Q/q to terminate the application\n" );
189+ printf ("\t->Press M/m to display main menu options\n" );
190+ }
191+
192+ // Menu action control
193+ void MenuControl (IADLXDisplayServices3 * displayService3 , const IADLXDisplay * display )
194+ {
195+ int num = 0 ;
196+ while ((num = getchar ()) != 'q' && num != 'Q' )
197+ {
198+ switch (num )
199+ {
200+ // Display FreeSync color accuracy support
201+ case '1' :
202+ ShowFreeSyncColorAccuracySupport (displayService3 , display );
203+ break ;
204+
205+ // Display current FreeSync color accuracy state
206+ case '2' :
207+ GetFreeSyncColorAccuracyState (displayService3 , display );
208+ break ;
209+
210+ // Set FreeSync color accuracy state
211+ case '3' :
212+ case '4' :
213+ SetFreeSyncColorAccuracyState (displayService3 , display , num - '3' );
214+ break ;
215+
216+ // Display main menu options
217+ case 'm' :
218+ case 'M' :
219+ MainMenu ();
220+ break ;
221+ default :
222+ break ;
223+ }
224+ }
225+ }
226+
227+ // Wait for exit with error message
228+ int WaitAndExit (const char * msg , const int retCode )
229+ {
230+ // Printout the message and pause to see it before returning the desired code
231+ if (NULL != msg )
232+ printf ("%s\n" , msg );
233+
234+ system ("pause" );
235+ return retCode ;
236+ }
0 commit comments