#ifndef ANDROID_DRM_DISPLAY_COMPOSITION_H_
#define ANDROID_DRM_DISPLAY_COMPOSITION_H_
-#include "drm_hwcomposer.h"
+#include "drmcrtc.h"
+#include "drmhwcomposer.h"
#include "drmplane.h"
+#include "glworker.h"
#include "importer.h"
+#include <sstream>
#include <vector>
+#include <hardware/gralloc.h>
#include <hardware/hardware.h>
#include <hardware/hwcomposer.h>
namespace android {
+struct SquashState;
+
enum DrmCompositionType {
DRM_COMPOSITION_TYPE_EMPTY,
DRM_COMPOSITION_TYPE_FRAME,
DRM_COMPOSITION_TYPE_DPMS,
+ DRM_COMPOSITION_TYPE_MODESET,
};
-typedef struct DrmCompositionLayer {
- DrmCompositionLayer();
- ~DrmCompositionLayer();
+struct DrmCompositionRegion {
+ DrmHwcRect<int> frame;
+ std::vector<size_t> source_layers;
+};
- hwc_layer_1_t layer;
- hwc_drm_bo_t bo;
- DrmCrtc *crtc;
+struct DrmCompositionPlane {
+ const static size_t kSourceNone = SIZE_MAX;
+ const static size_t kSourcePreComp = kSourceNone - 1;
+ const static size_t kSourceSquash = kSourcePreComp - 1;
+ const static size_t kSourceLayerMax = kSourceSquash - 1;
DrmPlane *plane;
-} DrmCompositionLayer_t;
-typedef std::vector<DrmCompositionLayer_t> DrmCompositionLayerVector_t;
+ DrmCrtc *crtc;
+ size_t source_layer;
+};
class DrmDisplayComposition {
public:
- DrmDisplayComposition();
+ DrmDisplayComposition() = default;
+ DrmDisplayComposition(const DrmDisplayComposition &) = delete;
~DrmDisplayComposition();
- int Init(DrmResources *drm, Importer *importer);
+ int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
+ uint64_t frame_no);
- DrmCompositionType type() const;
-
- int AddLayer(hwc_layer_1_t *layer, hwc_drm_bo_t *bo, DrmCrtc *crtc,
- DrmPlane *plane);
- // Like the AddLayer that accepts a hwc_drm_bo_t, but uses Importer to import
- // the layer->handle itself.
- int AddLayer(hwc_layer_1_t *layer, DrmCrtc *crtc, DrmPlane *plane);
+ int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
int AddPlaneDisable(DrmPlane *plane);
- int AddDpmsMode(uint32_t dpms_mode);
+ int SetDpmsMode(uint32_t dpms_mode);
+ int SetDisplayMode(const DrmMode &display_mode);
- int FinishComposition();
+ int Plan(SquashState *squash, std::vector<DrmPlane *> *primary_planes,
+ std::vector<DrmPlane *> *overlay_planes);
- DrmCompositionLayerVector_t *GetCompositionLayers();
- uint32_t dpms_mode() const;
+ int CreateNextTimelineFence();
+ int SignalSquashDone() {
+ return IncreaseTimelineToPoint(timeline_squash_done_);
+ }
+ int SignalPreCompDone() {
+ return IncreaseTimelineToPoint(timeline_pre_comp_done_);
+ }
+ int SignalCompositionDone() {
+ return IncreaseTimelineToPoint(timeline_);
+ }
- private:
- DrmDisplayComposition(const DrmDisplayComposition &) = delete;
+ std::vector<DrmHwcLayer> &layers() {
+ return layers_;
+ }
+
+ std::vector<DrmCompositionRegion> &squash_regions() {
+ return squash_regions_;
+ }
+
+ std::vector<DrmCompositionRegion> &pre_comp_regions() {
+ return pre_comp_regions_;
+ }
+
+ std::vector<DrmCompositionPlane> &composition_planes() {
+ return composition_planes_;
+ }
+ bool geometry_changed() const {
+ return geometry_changed_;
+ }
+
+ uint64_t frame_no() const {
+ return frame_no_;
+ }
+
+ DrmCompositionType type() const {
+ return type_;
+ }
+
+ uint32_t dpms_mode() const {
+ return dpms_mode_;
+ }
+
+ const DrmMode &display_mode() const {
+ return display_mode_;
+ }
+
+ DrmCrtc *crtc() const {
+ return crtc_;
+ }
+
+ Importer *importer() const {
+ return importer_;
+ }
+
+ void Dump(std::ostringstream *out) const;
+
+ private:
bool validate_composition_type(DrmCompositionType desired);
- DrmResources *drm_;
- Importer *importer_;
+ int IncreaseTimelineToPoint(int point);
+
+ void EmplaceCompositionPlane(size_t source_layer,
+ std::vector<DrmPlane *> *primary_planes,
+ std::vector<DrmPlane *> *overlay_planes);
+ int CreateAndAssignReleaseFences();
+
+ DrmResources *drm_ = NULL;
+ DrmCrtc *crtc_ = NULL;
+ Importer *importer_ = NULL;
+
+ DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
+ uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
+ DrmMode display_mode_;
- DrmCompositionType type_;
+ int timeline_fd_ = -1;
+ int timeline_ = 0;
+ int timeline_current_ = 0;
+ int timeline_squash_done_ = 0;
+ int timeline_pre_comp_done_ = 0;
- int timeline_fd_;
- int timeline_;
- int timeline_current_;
+ bool geometry_changed_;
+ std::vector<DrmHwcLayer> layers_;
+ std::vector<DrmCompositionRegion> squash_regions_;
+ std::vector<DrmCompositionRegion> pre_comp_regions_;
+ std::vector<DrmCompositionPlane> composition_planes_;
- DrmCompositionLayerVector_t layers_;
- uint32_t dpms_mode_;
+ uint64_t frame_no_ = 0;
};
}