drm_hwcomposer: limit maximum depth of frame worker queue

Each element of the queue requires use of limited resources
(file descriptors). If the queue doesn't get throttled when
frame worker is not getting scheduled to consume the elements
from it then  it can quickly reach max fd limit and cause
unexpected behavior such as system crash.

Test: run cts including CtsMediaTestCases
Bug: 31594201
Change-Id: I77345ae66da5675f4214f42f0c5bfb773bf5fd3f
diff --git a/drmdisplaycompositor.cpp b/drmdisplaycompositor.cpp
index 92323b6..5da9152 100644
--- a/drmdisplaycompositor.cpp
+++ b/drmdisplaycompositor.cpp
@@ -191,6 +191,16 @@
 void DrmDisplayCompositor::FrameWorker::QueueFrame(
     std::unique_ptr<DrmDisplayComposition> composition, int status) {
   Lock();
+
+  // Block queue if it gets too large. Otherwise composition will
+  // start stacking up and eat limited resources (file descriptors)
+  // allocated for these.
+  while (frame_queue_.size() >= DRM_DISPLAY_COMPOSITOR_MAX_QUEUE_DEPTH) {
+    Unlock();
+    sched_yield();
+    Lock();
+  }
+
   FrameState frame;
   frame.composition = std::move(composition);
   frame.status = status;