blob: 69324fdca60bc93905c8c8a556c8d1d7c889429f [file] [log] [blame]
Sean Paul98e73c82015-06-24 14:38:49 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_DRM_DISPLAY_COMPOSITION_H_
18#define ANDROID_DRM_DISPLAY_COMPOSITION_H_
19
20#include "drm_hwcomposer.h"
Zach Reizner09807052015-08-13 14:53:41 -070021#include "drmcrtc.h"
Sean Paul98e73c82015-06-24 14:38:49 -070022#include "drmplane.h"
Zach Reizner09807052015-08-13 14:53:41 -070023#include "glworker.h"
Sean Paul98e73c82015-06-24 14:38:49 -070024#include "importer.h"
25
Zach Reiznerfd6dc332015-10-13 21:12:48 -070026#include <sstream>
Sean Paul98e73c82015-06-24 14:38:49 -070027#include <vector>
28
Zach Reiznerb44fd102015-08-07 16:00:01 -070029#include <hardware/gralloc.h>
Sean Paul98e73c82015-06-24 14:38:49 -070030#include <hardware/hardware.h>
31#include <hardware/hwcomposer.h>
32
33namespace android {
34
Zach Reizner92f8e632015-10-12 17:47:13 -070035struct SquashState;
36
Sean Paulacb2a442015-06-24 18:43:01 -070037enum DrmCompositionType {
38 DRM_COMPOSITION_TYPE_EMPTY,
39 DRM_COMPOSITION_TYPE_FRAME,
Sean Pauldb7a17d2015-06-24 18:46:05 -070040 DRM_COMPOSITION_TYPE_DPMS,
Sean Paul57355412015-09-19 09:14:34 -040041 DRM_COMPOSITION_TYPE_MODESET,
Sean Paulacb2a442015-06-24 18:43:01 -070042};
43
Zach Reizner92f8e632015-10-12 17:47:13 -070044struct DrmCompositionRegion {
45 DrmHwcRect<int> frame;
46 std::vector<size_t> source_layers;
47};
Sean Paul98e73c82015-06-24 14:38:49 -070048
Zach Reizner92f8e632015-10-12 17:47:13 -070049struct DrmCompositionPlane {
50 const static size_t kSourceNone = SIZE_MAX;
51 const static size_t kSourcePreComp = kSourceNone - 1;
52 const static size_t kSourceSquash = kSourcePreComp - 1;
53 const static size_t kSourceLayerMax = kSourceSquash - 1;
54 DrmPlane *plane;
55 DrmCrtc *crtc;
56 size_t source_layer;
Zach Reizner4a253652015-09-10 18:30:54 -070057};
Sean Paul98e73c82015-06-24 14:38:49 -070058
59class DrmDisplayComposition {
60 public:
Zach Reizner92f8e632015-10-12 17:47:13 -070061 DrmDisplayComposition() = default;
62 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
Sean Paul98e73c82015-06-24 14:38:49 -070063 ~DrmDisplayComposition();
64
Sean Paulbdc67bf2015-09-21 10:04:02 -040065 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
66 uint64_t frame_no);
Sean Paul98e73c82015-06-24 14:38:49 -070067
Zach Reizner5757e822015-10-16 19:06:31 -070068 int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
Sean Paul2e46fbd2015-07-09 17:22:22 -040069 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -070070 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul57355412015-09-19 09:14:34 -040071 int SetDisplayMode(const DrmMode &display_mode);
Sean Paul98e73c82015-06-24 14:38:49 -070072
Zach Reizner92f8e632015-10-12 17:47:13 -070073 int Plan(SquashState *squash, std::vector<DrmPlane *> *primary_planes,
74 std::vector<DrmPlane *> *overlay_planes);
Sean Paulacb2a442015-06-24 18:43:01 -070075
Zach Reizner09807052015-08-13 14:53:41 -070076 int CreateNextTimelineFence();
Zach Reizner92f8e632015-10-12 17:47:13 -070077 int SignalSquashDone() {
78 return IncreaseTimelineToPoint(timeline_squash_done_);
79 }
80 int SignalPreCompDone() {
81 return IncreaseTimelineToPoint(timeline_pre_comp_done_);
82 }
83 int SignalCompositionDone() {
84 return IncreaseTimelineToPoint(timeline_);
85 }
86
87 std::vector<DrmHwcLayer> &layers() {
88 return layers_;
89 }
90
91 std::vector<DrmCompositionRegion> &squash_regions() {
92 return squash_regions_;
93 }
94
95 std::vector<DrmCompositionRegion> &pre_comp_regions() {
96 return pre_comp_regions_;
97 }
98
99 std::vector<DrmCompositionPlane> &composition_planes() {
100 return composition_planes_;
101 }
102
103 uint64_t frame_no() const {
104 return frame_no_;
105 }
106
107 DrmCompositionType type() const {
108 return type_;
109 }
110
111 uint32_t dpms_mode() const {
112 return dpms_mode_;
113 }
114
115 const DrmMode &display_mode() const {
116 return display_mode_;
117 }
118
119 DrmCrtc *crtc() const {
120 return crtc_;
121 }
122
123 Importer *importer() const {
124 return importer_;
125 }
126
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700127 void Dump(std::ostringstream *out) const;
128
Zach Reizner92f8e632015-10-12 17:47:13 -0700129 private:
130 bool validate_composition_type(DrmCompositionType desired);
131
Zach Reizner09807052015-08-13 14:53:41 -0700132 int IncreaseTimelineToPoint(int point);
133
Zach Reizner5757e822015-10-16 19:06:31 -0700134 int CreateAndAssignReleaseFences();
135
Zach Reizner92f8e632015-10-12 17:47:13 -0700136 DrmResources *drm_ = NULL;
137 DrmCrtc *crtc_ = NULL;
138 Importer *importer_ = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700139
Zach Reizner92f8e632015-10-12 17:47:13 -0700140 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
141 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
Sean Paul57355412015-09-19 09:14:34 -0400142 DrmMode display_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400143
Zach Reizner92f8e632015-10-12 17:47:13 -0700144 int timeline_fd_ = -1;
145 int timeline_ = 0;
146 int timeline_current_ = 0;
147 int timeline_squash_done_ = 0;
148 int timeline_pre_comp_done_ = 0;
149
Zach Reizner5757e822015-10-16 19:06:31 -0700150 bool geometry_changed_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700151 std::vector<DrmHwcLayer> layers_;
152 std::vector<DrmCompositionRegion> squash_regions_;
153 std::vector<DrmCompositionRegion> pre_comp_regions_;
154 std::vector<DrmCompositionPlane> composition_planes_;
155
156 uint64_t frame_no_ = 0;
Sean Paul98e73c82015-06-24 14:38:49 -0700157};
158}
159
160#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_