display: find the correct output 42/175242/1
authorBoram Park <boram1288.park@samsung.com>
Mon, 9 Apr 2018 12:18:37 +0000 (21:18 +0900)
committerBoram Park <boram1288.park@samsung.com>
Mon, 9 Apr 2018 12:18:37 +0000 (21:18 +0900)
To find a primary output, we have to check the connection status first.
If there is no connected output, this function will return the first output.

Change-Id: If386dcabc6524ce81a1f08c87082342a259278f3

src/tdm_display.c

index 9f66167..45ccdf2 100644 (file)
@@ -634,18 +634,50 @@ tdm_display_find_output(tdm_display *dpy, const char *name, tdm_error *error)
 {
        tdm_private_module *private_module = NULL;
        tdm_private_output *private_output = NULL;
+       tdm_private_output *mode_setted_output = NULL;
+       tdm_private_output *connected_output = NULL;
+       unsigned int find_primary = 0;
 
        DISPLAY_FUNC_ENTRY_ERROR();
 
-       if (!strncasecmp(name, "primary", 7) || !strncasecmp(name, "default", 7)) {
-               return tdm_display_get_output(dpy, 0, error);
-       }
+       if (!strncasecmp(name, "primary", 7) || !strncasecmp(name, "default", 7))
+               find_primary = 1;
 
        _pthread_mutex_lock(&private_display->lock);
 
        if (error)
                *error = TDM_ERROR_NONE;
 
+       if (find_primary) {
+               LIST_FOR_EACH_ENTRY(private_module, &private_display->module_list, link) {
+                       LIST_FOR_EACH_ENTRY(private_output, &private_module->output_list, link) {
+                               if (private_output->caps.status == TDM_OUTPUT_CONN_STATUS_CONNECTED && !connected_output)
+                                       connected_output = private_output;
+                               else if (private_output->caps.status == TDM_OUTPUT_CONN_STATUS_MODE_SETTED && !mode_setted_output)
+                                       mode_setted_output = private_output;
+                       }
+               }
+
+               if (mode_setted_output) {
+                       _pthread_mutex_unlock(&private_display->lock);
+                       return mode_setted_output;
+               }
+
+               if (connected_output) {
+                       _pthread_mutex_unlock(&private_display->lock);
+                       return connected_output;
+               }
+
+               LIST_FOR_EACH_ENTRY(private_module, &private_display->module_list, link) {
+                       LIST_FOR_EACH_ENTRY(private_output, &private_module->output_list, link) {
+                               if (private_output->index == 0) {
+                                       _pthread_mutex_unlock(&private_display->lock);
+                                       return private_output;
+                               }
+                       }
+               }
+       }
+
        LIST_FOR_EACH_ENTRY(private_module, &private_display->module_list, link) {
                LIST_FOR_EACH_ENTRY(private_output, &private_module->output_list, link) {
                        if (strncmp(private_output->caps.model, name, TDM_NAME_LEN))