blob: 57e8521058376ce273aa3fd83f8e734f934df4d5 [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
26#include <vector>
27
Zach Reiznerb44fd102015-08-07 16:00:01 -070028#include <hardware/gralloc.h>
Sean Paul98e73c82015-06-24 14:38:49 -070029#include <hardware/hardware.h>
30#include <hardware/hwcomposer.h>
31
32namespace android {
33
Sean Paulacb2a442015-06-24 18:43:01 -070034enum DrmCompositionType {
35 DRM_COMPOSITION_TYPE_EMPTY,
36 DRM_COMPOSITION_TYPE_FRAME,
Sean Pauldb7a17d2015-06-24 18:46:05 -070037 DRM_COMPOSITION_TYPE_DPMS,
Sean Paul57355412015-09-19 09:14:34 -040038 DRM_COMPOSITION_TYPE_MODESET,
Sean Paulacb2a442015-06-24 18:43:01 -070039};
40
Zach Reizner4a253652015-09-10 18:30:54 -070041struct DrmCompositionLayer {
42 DrmCrtc *crtc = NULL;
43 DrmPlane *plane = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -070044
Zach Reizner4a253652015-09-10 18:30:54 -070045 buffer_handle_t sf_handle = NULL;
46 DrmHwcBuffer buffer;
47 DrmHwcNativeHandle handle;
48 DrmHwcTransform transform = DrmHwcTransform::kIdentity;
49 DrmHwcBlending blending = DrmHwcBlending::kNone;
50 uint8_t alpha = 0xff;
51 DrmHwcRect<float> source_crop;
52 DrmHwcRect<int> display_frame;
53 std::vector<DrmHwcRect<int>> source_damage;
54
55 UniqueFd acquire_fence;
56
57 DrmCompositionLayer() = default;
58 DrmCompositionLayer(DrmCrtc *crtc, DrmHwcLayer &&l);
59 DrmCompositionLayer(DrmCompositionLayer &&l) = default;
60
61 DrmCompositionLayer &operator=(DrmCompositionLayer &&l) = default;
62
63 buffer_handle_t get_usable_handle() const {
64 return handle.get() != NULL ? handle.get() : sf_handle;
65 }
66};
Sean Paul98e73c82015-06-24 14:38:49 -070067
68class DrmDisplayComposition {
69 public:
70 DrmDisplayComposition();
71 ~DrmDisplayComposition();
72
Sean Paulbdc67bf2015-09-21 10:04:02 -040073 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
74 uint64_t frame_no);
Sean Paul98e73c82015-06-24 14:38:49 -070075
Sean Paulacb2a442015-06-24 18:43:01 -070076 DrmCompositionType type() const;
77
Zach Reizner4a253652015-09-10 18:30:54 -070078 int SetLayers(DrmHwcLayer *layers, size_t num_layers,
Zach Reizner09807052015-08-13 14:53:41 -070079 std::vector<DrmPlane *> *primary_planes,
80 std::vector<DrmPlane *> *overlay_planes);
Sean Paul2e46fbd2015-07-09 17:22:22 -040081 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -070082 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul57355412015-09-19 09:14:34 -040083 int SetDisplayMode(const DrmMode &display_mode);
Sean Paul98e73c82015-06-24 14:38:49 -070084
Zach Reiznerb44fd102015-08-07 16:00:01 -070085 void RemoveNoPlaneLayers();
Zach Reizner09807052015-08-13 14:53:41 -070086 int SignalPreCompositionDone();
Sean Paul98e73c82015-06-24 14:38:49 -070087 int FinishComposition();
88
Zach Reizner4a253652015-09-10 18:30:54 -070089 std::vector<DrmCompositionLayer> *GetCompositionLayers();
Zach Reizner09807052015-08-13 14:53:41 -070090 int pre_composition_layer_index() const;
Sean Pauldb7a17d2015-06-24 18:46:05 -070091 uint32_t dpms_mode() const;
Sean Paul57355412015-09-19 09:14:34 -040092 const DrmMode &display_mode() const;
Sean Paul98e73c82015-06-24 14:38:49 -070093
Sean Paulbdc67bf2015-09-21 10:04:02 -040094 uint64_t frame_no() const;
95
Zach Reizner46ddd452015-07-30 08:10:14 -070096 Importer *importer() const;
97
Sean Paul98e73c82015-06-24 14:38:49 -070098 private:
99 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
100
Sean Paulacb2a442015-06-24 18:43:01 -0700101 bool validate_composition_type(DrmCompositionType desired);
102
Zach Reizner09807052015-08-13 14:53:41 -0700103 int CreateNextTimelineFence();
104 int IncreaseTimelineToPoint(int point);
105
Sean Paul98e73c82015-06-24 14:38:49 -0700106 DrmResources *drm_;
Zach Reizner09807052015-08-13 14:53:41 -0700107 DrmCrtc *crtc_;
Sean Paul98e73c82015-06-24 14:38:49 -0700108 Importer *importer_;
Zach Reiznerb44fd102015-08-07 16:00:01 -0700109 const gralloc_module_t *gralloc_;
Zach Reizner09807052015-08-13 14:53:41 -0700110 EGLDisplay egl_display_;
Sean Paul98e73c82015-06-24 14:38:49 -0700111
Sean Paulacb2a442015-06-24 18:43:01 -0700112 DrmCompositionType type_;
113
Sean Paul98e73c82015-06-24 14:38:49 -0700114 int timeline_fd_;
115 int timeline_;
Zach Reiznerece04892015-07-17 14:13:28 -0700116 int timeline_current_;
Zach Reizner09807052015-08-13 14:53:41 -0700117 int timeline_pre_comp_done_;
Sean Paul98e73c82015-06-24 14:38:49 -0700118
Zach Reizner4a253652015-09-10 18:30:54 -0700119 std::vector<DrmCompositionLayer> layers_;
Zach Reizner09807052015-08-13 14:53:41 -0700120 int pre_composition_layer_index_;
Sean Pauldb7a17d2015-06-24 18:46:05 -0700121 uint32_t dpms_mode_;
Sean Paul57355412015-09-19 09:14:34 -0400122 DrmMode display_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400123
124 uint64_t frame_no_;
Sean Paul98e73c82015-06-24 14:38:49 -0700125};
126}
127
128#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_