drm_hwcomposer: Split the drm compositor into per-display threads
This patch splits out the current single drm compositor with
per-display compositors, each with their own thread.
The per-display compositors are hidden behind a singleton
drm compositor. This allows us to maintain a whole-world view
of all displays involved in a frame. This becomes useful if
we start switching up crtcs/encoders for the displays.
This also allows us to issue one DrmComposition when the
frame is being assembled.
The single DrmComposition handles the plane allocation (since they
might switch between displays), and contains per-display compositions
which are used to store the layer->plane/crtc information for each
frame. The display compositors use the per-display compositions to
display the frame on their output.
Each display compositor receives a shared pointer to the frame's
DrmComposition on QueueComposition. As a result, both the composition,
and the per-display compositions, live for as long as any one
display is still using it. While this is sub-optimal (since a display
might never update again), this is probably fine for now.
Finally, splitting things up per-display will allow us to inject
non-compositing jobs into the composite queue. An example would be
turning the display off, or setting the mode. This ensures that all
frames in the composite queue are displayed before the mode changes
or the display is disabled.
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Change-Id: I8a233ea64710b238f70acbcde1f6d771e297b069
diff --git a/drmdisplaycompositor.h b/drmdisplaycompositor.h
new file mode 100644
index 0000000..928ce46
--- /dev/null
+++ b/drmdisplaycompositor.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_DRM_DISPLAY_COMPOSITOR_H_
+#define ANDROID_DRM_DISPLAY_COMPOSITOR_H_
+
+#include "drm_hwcomposer.h"
+#include "drmcomposition.h"
+#include "drmcompositorworker.h"
+
+#include <pthread.h>
+#include <queue>
+#include <sstream>
+
+#include <hardware/hardware.h>
+#include <hardware/hwcomposer.h>
+
+namespace android {
+
+class DrmDisplayCompositor {
+ public:
+ DrmDisplayCompositor();
+ ~DrmDisplayCompositor();
+
+ int Init(DrmResources *drm, int display);
+
+ int QueueComposition(std::unique_ptr<DrmDisplayComposition> composition);
+ int Composite();
+ void Dump(std::ostringstream *out) const;
+
+ bool HaveQueuedComposites() const;
+
+ private:
+ DrmDisplayCompositor(const DrmDisplayCompositor &) = delete;
+
+ int ApplyFrame(DrmDisplayComposition *display_comp);
+
+ DrmResources *drm_;
+ int display_;
+
+ DrmCompositorWorker worker_;
+
+ std::queue<std::unique_ptr<DrmDisplayComposition>> composite_queue_;
+ std::unique_ptr<DrmDisplayComposition> active_composition_;
+
+ uint64_t frame_no_;
+
+ bool initialized_;
+
+ // mutable since we need to acquire in HaveQueuedComposites
+ mutable pthread_mutex_t lock_;
+
+ // State tracking progress since our last Dump(). These are mutable since
+ // we need to reset them on every Dump() call.
+ mutable uint64_t dump_frames_composited_;
+ mutable uint64_t dump_last_timestamp_ns_;
+};
+}
+
+#endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_