blob: 036240436002530c5b497854fd9d592664f746d7 [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
Zach Reizner09807052015-08-13 14:53:41 -070020#include "drmcrtc.h"
Haixia Shi6afbb6a2015-11-24 12:42:45 -080021#include "drmhwcomposer.h"
Sean Paul98e73c82015-06-24 14:38:49 -070022#include "drmplane.h"
Zach Reizner09807052015-08-13 14:53:41 -070023#include "glworker.h"
Sean Paul63769962016-04-21 16:25:06 -040024#include "platform.h"
Sean Paul98e73c82015-06-24 14:38:49 -070025
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
Sean Paul5325e102016-03-29 13:55:35 -040035class SquashState;
Zach Reizner92f8e632015-10-12 17:47:13 -070036
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
Sean Paul39b37842016-05-11 13:50:28 -040049enum class DrmCompositionPlaneType : int32_t {
50 kDisable,
51 kLayer,
52 kPrecomp,
53 kSquash,
54};
55
Zach Reizner92f8e632015-10-12 17:47:13 -070056struct DrmCompositionPlane {
Sean Paul39b37842016-05-11 13:50:28 -040057 DrmCompositionPlaneType type;
Zach Reizner92f8e632015-10-12 17:47:13 -070058 DrmPlane *plane;
59 DrmCrtc *crtc;
Sean Paul39b37842016-05-11 13:50:28 -040060 int source_layer;
Zach Reizner4a253652015-09-10 18:30:54 -070061};
Sean Paul98e73c82015-06-24 14:38:49 -070062
63class DrmDisplayComposition {
64 public:
Zach Reizner92f8e632015-10-12 17:47:13 -070065 DrmDisplayComposition() = default;
66 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
Sean Paul98e73c82015-06-24 14:38:49 -070067 ~DrmDisplayComposition();
68
Sean Paulbdc67bf2015-09-21 10:04:02 -040069 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
70 uint64_t frame_no);
Sean Paul98e73c82015-06-24 14:38:49 -070071
Zach Reizner5757e822015-10-16 19:06:31 -070072 int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
Sean Paul2e46fbd2015-07-09 17:22:22 -040073 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -070074 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul57355412015-09-19 09:14:34 -040075 int SetDisplayMode(const DrmMode &display_mode);
Sean Paul98e73c82015-06-24 14:38:49 -070076
Zach Reizner92f8e632015-10-12 17:47:13 -070077 int Plan(SquashState *squash, std::vector<DrmPlane *> *primary_planes,
78 std::vector<DrmPlane *> *overlay_planes);
Sean Paulacb2a442015-06-24 18:43:01 -070079
Zach Reizner09807052015-08-13 14:53:41 -070080 int CreateNextTimelineFence();
Zach Reizner92f8e632015-10-12 17:47:13 -070081 int SignalSquashDone() {
82 return IncreaseTimelineToPoint(timeline_squash_done_);
83 }
84 int SignalPreCompDone() {
85 return IncreaseTimelineToPoint(timeline_pre_comp_done_);
86 }
87 int SignalCompositionDone() {
88 return IncreaseTimelineToPoint(timeline_);
89 }
90
91 std::vector<DrmHwcLayer> &layers() {
92 return layers_;
93 }
94
95 std::vector<DrmCompositionRegion> &squash_regions() {
96 return squash_regions_;
97 }
98
99 std::vector<DrmCompositionRegion> &pre_comp_regions() {
100 return pre_comp_regions_;
101 }
102
103 std::vector<DrmCompositionPlane> &composition_planes() {
104 return composition_planes_;
105 }
106
Haixia Shi6afbb6a2015-11-24 12:42:45 -0800107 bool geometry_changed() const {
108 return geometry_changed_;
109 }
110
Zach Reizner92f8e632015-10-12 17:47:13 -0700111 uint64_t frame_no() const {
112 return frame_no_;
113 }
114
115 DrmCompositionType type() const {
116 return type_;
117 }
118
119 uint32_t dpms_mode() const {
120 return dpms_mode_;
121 }
122
123 const DrmMode &display_mode() const {
124 return display_mode_;
125 }
126
127 DrmCrtc *crtc() const {
128 return crtc_;
129 }
130
131 Importer *importer() const {
132 return importer_;
133 }
134
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700135 void Dump(std::ostringstream *out) const;
136
Zach Reizner92f8e632015-10-12 17:47:13 -0700137 private:
138 bool validate_composition_type(DrmCompositionType desired);
139
Zach Reizner09807052015-08-13 14:53:41 -0700140 int IncreaseTimelineToPoint(int point);
141
Sean Paul39b37842016-05-11 13:50:28 -0400142 void EmplaceCompositionPlane(DrmCompositionPlaneType type, int source_layer,
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700143 std::vector<DrmPlane *> *primary_planes,
144 std::vector<DrmPlane *> *overlay_planes);
Zach Reizner5757e822015-10-16 19:06:31 -0700145 int CreateAndAssignReleaseFences();
146
Zach Reizner92f8e632015-10-12 17:47:13 -0700147 DrmResources *drm_ = NULL;
148 DrmCrtc *crtc_ = NULL;
149 Importer *importer_ = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700150
Zach Reizner92f8e632015-10-12 17:47:13 -0700151 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
152 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
Sean Paul57355412015-09-19 09:14:34 -0400153 DrmMode display_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400154
Zach Reizner92f8e632015-10-12 17:47:13 -0700155 int timeline_fd_ = -1;
156 int timeline_ = 0;
157 int timeline_current_ = 0;
158 int timeline_squash_done_ = 0;
159 int timeline_pre_comp_done_ = 0;
160
Zach Reizner5757e822015-10-16 19:06:31 -0700161 bool geometry_changed_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700162 std::vector<DrmHwcLayer> layers_;
163 std::vector<DrmCompositionRegion> squash_regions_;
164 std::vector<DrmCompositionRegion> pre_comp_regions_;
165 std::vector<DrmCompositionPlane> composition_planes_;
166
167 uint64_t frame_no_ = 0;
Sean Paul98e73c82015-06-24 14:38:49 -0700168};
169}
170
171#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_