backend/tdm: Split commit function into small functions 35/278035/1
authorSeunghun Lee <shiin.lee@samsung.com>
Fri, 4 Mar 2022 01:44:57 +0000 (10:44 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 18 Jul 2022 05:07:59 +0000 (14:07 +0900)
No functional changes. It improves readability.

Change-Id: I0b95360f5dc54e7023ab3f54c3b9cf2057a82686

src/libds/backend/tdm/output.c

index a67c618..bc931d7 100644 (file)
@@ -11,6 +11,9 @@ static bool tdm_output_init_modes(struct ds_tdm_output *output);
 static void tdm_output_destroy(struct ds_tdm_output *output);
 static void tdm_output_init_hwc(struct ds_tdm_output *output);
 static bool tdm_output_update_mode(struct ds_tdm_output *output);
 static void tdm_output_destroy(struct ds_tdm_output *output);
 static void tdm_output_init_hwc(struct ds_tdm_output *output);
 static bool tdm_output_update_mode(struct ds_tdm_output *output);
+static bool tdm_output_set_pending_fb(struct ds_tdm_output *output,
+        struct ds_buffer *ds_buffer);
+static bool tdm_output_hwc_commit(struct ds_tdm_output *output);
 
 struct ds_tdm_output *
 create_tdm_output(struct ds_tdm_backend *tdm, tdm_output *tdm_output)
 
 struct ds_tdm_output *
 create_tdm_output(struct ds_tdm_backend *tdm, tdm_output *tdm_output)
@@ -167,25 +170,10 @@ tdm_output_attach_back_buffer(struct ds_tdm_output *output,
     output->back_buffer = buffer;
 }
 
     output->back_buffer = buffer;
 }
 
-static void
-tdm_output_hwc_commit_handler(tdm_hwc *hwc, unsigned int sequence,
-        unsigned int tv_sec, unsigned int tv_usec, void *user_data)
-{
-    struct ds_tdm_output *output;
-
-    output = user_data;
-
-    tdm_output_update_front_buffer(output);
-
-    wl_signal_emit(&output->base.events.frame, &output->base);
-}
-
 static bool
 tdm_output_iface_commit(struct ds_output *ds_output)
 {
     struct ds_tdm_output *output;
 static bool
 tdm_output_iface_commit(struct ds_output *ds_output)
 {
     struct ds_tdm_output *output;
-    struct ds_tdm_buffer *buffer;
-    struct ds_buffer *ds_buffer;
 
     output = tdm_output_from_output(ds_output);
 
 
     output = tdm_output_from_output(ds_output);
 
@@ -197,51 +185,19 @@ tdm_output_iface_commit(struct ds_output *ds_output)
     }
 
     if (ds_output->pending.committed & DS_OUTPUT_STATE_BUFFER) {
     }
 
     if (ds_output->pending.committed & DS_OUTPUT_STATE_BUFFER) {
-        tdm_region fb_damage;
-        tdm_error err;
-        uint32_t num_changes;
-
-        ds_buffer = ds_output->pending.buffer;
-        buffer = get_or_create_tdm_buffer(output->backend, ds_buffer);
-        if (!buffer)
-            return false;
-
-        memset(&fb_damage, 0, sizeof(fb_damage));
-        err = tdm_hwc_set_client_target_buffer(output->tdm.hwc,
-                buffer->surface, fb_damage);
-        if (err != TDM_ERROR_NONE) {
-            ds_err("Could not set hwc client target buffer");
-            ds_buffer_unlock(buffer->buffer);
-            return false;
-        }
-
-        err = tdm_hwc_validate(output->tdm.hwc, NULL, 0, &num_changes);
-        if (err != TDM_ERROR_NONE) {
-            ds_err("Could not hwc validate");
-            ds_buffer_unlock(buffer->buffer);
-            return false;
-        }
-
-        err = tdm_hwc_accept_validation(output->tdm.hwc);
-        if (err != TDM_ERROR_NONE) {
-            ds_err("Could not hwc accept validation");
-            ds_buffer_unlock(buffer->buffer);
-            return false;
-        }
+        if (!tdm_output_set_pending_fb(output, ds_output->pending.buffer))
+            ds_err("Could not update buffer");
+    }
 
 
-        err = tdm_hwc_commit(output->tdm.hwc, 0, tdm_output_hwc_commit_handler,
-                output);
-        if (err != TDM_ERROR_NONE) {
-            ds_err("Could not hwc commit");
-            ds_buffer_unlock(buffer->buffer);
-            return false;
+    if (!tdm_output_hwc_commit(output)) {
+        ds_err("Could not commit tdm output");
+        if (output->back_buffer) {
+            tdm_buffer_release(output->back_buffer);
         }
         }
-
-        tdm_output_attach_back_buffer(output, buffer);
-
-        ds_dbg("Swap Buffer!!!!!");
     }
 
     }
 
+    ds_dbg("Swap Buffer!!!!!");
+
     return true;
 }
 
     return true;
 }
 
@@ -346,3 +302,70 @@ tdm_output_update_mode(struct ds_tdm_output *output)
 
     return true;
 }
 
     return true;
 }
+
+static bool
+tdm_output_set_pending_fb(struct ds_tdm_output *output,
+        struct ds_buffer *ds_buffer)
+{
+    struct ds_tdm_buffer *buffer;
+    tdm_region fb_damage;
+    tdm_error err;
+
+    buffer = get_or_create_tdm_buffer(output->backend, ds_buffer);
+    if (!buffer)
+        return false;
+
+    memset(&fb_damage, 0, sizeof(fb_damage));
+    err = tdm_hwc_set_client_target_buffer(output->tdm.hwc,
+            buffer->surface, fb_damage);
+    if (err != TDM_ERROR_NONE) {
+        ds_err("Could not set hwc client target buffer");
+        ds_buffer_unlock(buffer->buffer);
+        return false;
+    }
+
+    tdm_output_attach_back_buffer(output, buffer);
+
+    return true;
+}
+
+static void
+tdm_output_hwc_commit_handler(tdm_hwc *hwc, unsigned int sequence,
+        unsigned int tv_sec, unsigned int tv_usec, void *user_data)
+{
+    struct ds_tdm_output *output;
+
+    output = user_data;
+
+    tdm_output_update_front_buffer(output);
+
+    wl_signal_emit(&output->base.events.frame, &output->base);
+}
+
+static bool
+tdm_output_hwc_commit(struct ds_tdm_output *output)
+{
+    tdm_error err;
+    uint32_t num_changes;
+
+    err = tdm_hwc_validate(output->tdm.hwc, NULL, 0, &num_changes);
+    if (err != TDM_ERROR_NONE) {
+        ds_err("Could not hwc validate");
+        return false;
+    }
+
+    err = tdm_hwc_accept_validation(output->tdm.hwc);
+    if (err != TDM_ERROR_NONE) {
+        ds_err("Could not hwc accept validation");
+        return false;
+    }
+
+    err = tdm_hwc_commit(output->tdm.hwc, 0, tdm_output_hwc_commit_handler,
+            output);
+    if (err != TDM_ERROR_NONE) {
+        ds_err("Could not hwc commit");
+        return false;
+    }
+
+    return true;
+}