fix reallocation-free issue of output modes 25/85025/1
authorBoram Park <boram1288.park@samsung.com>
Tue, 23 Aug 2016 09:51:41 +0000 (18:51 +0900)
committerBoram Park <boram1288.park@samsung.com>
Tue, 23 Aug 2016 09:51:41 +0000 (18:51 +0900)
Change-Id: I76fb49f0d00906ff380531e5ab021da9ecc122a1

include/tdm_backend.h
src/tdm.c
src/tdm_display.c
src/tdm_private.h

index 0cfc3cd..18d0f72 100644 (file)
@@ -477,6 +477,7 @@ typedef struct _tdm_func_output {
 
        /**
         * @brief Get the mode of a output object
+        * @deprecated
         * @param[in] output A output object
         * @param[out] mode A output mode
         * @return #TDM_ERROR_NONE if success. Otherwise, error value.
index 3f6388c..a4dcdf8 100644 (file)
--- a/src/tdm.c
+++ b/src/tdm.c
@@ -389,13 +389,35 @@ tdm_display_update_output(tdm_private_display *private_display,
                        private_output->regist_change_cb = 1;
                }
 
-       } else
-               _tdm_display_destroy_caps_output(&private_output->caps);
+               ret = _tdm_display_update_caps_output(private_display, pipe, output_backend,
+                                                                                         &private_output->caps);
+               if (ret != TDM_ERROR_NONE)
+                       return ret;
+       } else {
+               tdm_caps_output new_caps;
 
-       ret = _tdm_display_update_caps_output(private_display, pipe, output_backend,
-                                                                                 &private_output->caps);
-       if (ret != TDM_ERROR_NONE)
-               return ret;
+               ret = _tdm_display_update_caps_output(private_display, pipe, output_backend,
+                                                                                         &new_caps);
+               if (ret != TDM_ERROR_NONE)
+                       return ret;
+
+               /* FIXME: This is very ugly. need to fix after the TDM ABI is changed. */
+               if (private_output->caps.status != new_caps.status) {
+                       _tdm_display_destroy_caps_output(&private_output->caps);
+                       private_output->caps = new_caps;
+                       private_output->current_mode = NULL;
+               } else {
+                       tdm_output_mode *old_modes = private_output->caps.modes;
+                       unsigned int old_mode_count = private_output->caps.mode_count;
+                       if (new_caps.modes)
+                               free(new_caps.modes);
+                       new_caps.modes = old_modes;
+                       new_caps.mode_count = old_mode_count;
+                       if (private_output->caps.props)
+                               free(private_output->caps.props);
+                       private_output->caps = new_caps;
+               }
+       }
 
        layers = func_output->output_get_layers(output_backend, &layer_count, &ret);
        if (ret != TDM_ERROR_NONE)
@@ -503,6 +525,8 @@ _tdm_display_get_ordered_outputs(tdm_private_display *private_display, int *coun
                                break;
                        }
                }
+
+               _tdm_display_destroy_caps_output(&caps);
        }
 
        /* ordering : main output is first */
index 38cec19..7d9b08f 100644 (file)
@@ -1084,7 +1084,8 @@ tdm_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
        }
 
        ret = func_output->output_set_mode(private_output->output_backend, mode);
-
+       if (ret == TDM_ERROR_NONE)
+               private_output->current_mode = mode;
        _pthread_mutex_unlock(&private_display->lock);
 
        return ret;
@@ -1093,22 +1094,13 @@ tdm_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
 EXTERN tdm_error
 tdm_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
 {
-       tdm_func_output *func_output;
        OUTPUT_FUNC_ENTRY();
 
        TDM_RETURN_VAL_IF_FAIL(mode != NULL, TDM_ERROR_INVALID_PARAMETER);
 
        _pthread_mutex_lock(&private_display->lock);
 
-       func_output = &private_display->func_output;
-
-       if (!func_output->output_get_mode) {
-               _pthread_mutex_unlock(&private_display->lock);
-               TDM_ERR("not implemented!!");
-               return TDM_ERROR_NOT_IMPLEMENTED;
-       }
-
-       ret = func_output->output_get_mode(private_output->output_backend, mode);
+       *mode = private_output->current_mode;
 
        _pthread_mutex_unlock(&private_display->lock);
 
index e56a19a..bc04971 100644 (file)
@@ -172,6 +172,7 @@ struct _tdm_private_output {
 
        unsigned int pipe;
        tdm_output_dpms current_dpms_value;
+       const tdm_output_mode *current_mode;
 
        int regist_vblank_cb;
        int regist_commit_cb;