drm_hwcomposer: Rework KMS state tracking

1. Store only FrameBuffer shared handle to keep buffer alive while
it is a part of active composition.
2. Store used planes to allow clearing of the composition.

Before this both of mentioned above was a part of DrmDisplayComposition.
Any external modification DrmDisplayComposition caused framebuffer object
to be destroyed, which forced screen to go blank.

We want to modify DrmDisplayComposition, to allow re-using previous
composition data.

This change will also help us tracking STAGED frame state and
migrate to non-blocking atomic commit.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
Tested-by: Martin Juecker <martin.juecker@gmail.com>
Reviewed-by: Matvii Zorin <matvii.zorin@globallogic.com>
diff --git a/compositor/DrmDisplayCompositor.h b/compositor/DrmDisplayCompositor.h
index 55fe77d..6d2c421 100644
--- a/compositor/DrmDisplayCompositor.h
+++ b/compositor/DrmDisplayCompositor.h
@@ -67,11 +67,26 @@
 
   auto CommitFrame(AtomicCommitArgs &args) -> int;
 
-  struct {
-    std::shared_ptr<DrmDisplayComposition> composition;
+  struct KmsState {
+    /* Required to cleanup unused planes */
+    std::vector<DrmPlane *> used_planes;
+    /* We have to hold a reference to framebuffer while displaying it ,
+     * otherwise picture will blink */
+    std::vector<std::shared_ptr<DrmFbIdHandle>> used_framebuffers;
+
     DrmModeUserPropertyBlobUnique mode_blob;
-    bool active_state{};
-  } active_kms_data;
+
+    /* To avoid setting the inactive state twice, which will fail the commit */
+    bool crtc_active_state{};
+  } active_frame_state;
+
+  auto NewFrameState() -> KmsState {
+    return (KmsState){
+        .used_planes = active_frame_state.used_planes,
+        .used_framebuffers = active_frame_state.used_framebuffers,
+        .crtc_active_state = active_frame_state.crtc_active_state,
+    };
+  }
 
   ResourceManager *resource_manager_ = nullptr;
   std::unique_ptr<Planner> planner_;