blob: 06784f13a7853d9ba70765adc79ccf3352514c4d [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 Paulacb2a442015-06-24 18:43:01 -070038};
39
Zach Reizner4a253652015-09-10 18:30:54 -070040struct DrmCompositionLayer {
41 DrmCrtc *crtc = NULL;
42 DrmPlane *plane = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -070043
Zach Reizner4a253652015-09-10 18:30:54 -070044 buffer_handle_t sf_handle = NULL;
45 DrmHwcBuffer buffer;
46 DrmHwcNativeHandle handle;
47 DrmHwcTransform transform = DrmHwcTransform::kIdentity;
48 DrmHwcBlending blending = DrmHwcBlending::kNone;
49 uint8_t alpha = 0xff;
50 DrmHwcRect<float> source_crop;
51 DrmHwcRect<int> display_frame;
52 std::vector<DrmHwcRect<int>> source_damage;
53
54 UniqueFd acquire_fence;
55
56 DrmCompositionLayer() = default;
57 DrmCompositionLayer(DrmCrtc *crtc, DrmHwcLayer &&l);
58 DrmCompositionLayer(DrmCompositionLayer &&l) = default;
59
60 DrmCompositionLayer &operator=(DrmCompositionLayer &&l) = default;
61
62 buffer_handle_t get_usable_handle() const {
63 return handle.get() != NULL ? handle.get() : sf_handle;
64 }
65};
Sean Paul98e73c82015-06-24 14:38:49 -070066
67class DrmDisplayComposition {
68 public:
69 DrmDisplayComposition();
70 ~DrmDisplayComposition();
71
Sean Paulbdc67bf2015-09-21 10:04:02 -040072 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
73 uint64_t frame_no);
Sean Paul98e73c82015-06-24 14:38:49 -070074
Sean Paulacb2a442015-06-24 18:43:01 -070075 DrmCompositionType type() const;
76
Zach Reizner4a253652015-09-10 18:30:54 -070077 int SetLayers(DrmHwcLayer *layers, size_t num_layers,
Zach Reizner09807052015-08-13 14:53:41 -070078 std::vector<DrmPlane *> *primary_planes,
79 std::vector<DrmPlane *> *overlay_planes);
Sean Paul2e46fbd2015-07-09 17:22:22 -040080 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -070081 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul98e73c82015-06-24 14:38:49 -070082
Zach Reiznerb44fd102015-08-07 16:00:01 -070083 void RemoveNoPlaneLayers();
Zach Reizner09807052015-08-13 14:53:41 -070084 int SignalPreCompositionDone();
Sean Paul98e73c82015-06-24 14:38:49 -070085 int FinishComposition();
86
Zach Reizner4a253652015-09-10 18:30:54 -070087 std::vector<DrmCompositionLayer> *GetCompositionLayers();
Zach Reizner09807052015-08-13 14:53:41 -070088 int pre_composition_layer_index() const;
Sean Pauldb7a17d2015-06-24 18:46:05 -070089 uint32_t dpms_mode() const;
Sean Paul98e73c82015-06-24 14:38:49 -070090
Sean Paulbdc67bf2015-09-21 10:04:02 -040091 uint64_t frame_no() const;
92
Zach Reizner46ddd452015-07-30 08:10:14 -070093 Importer *importer() const;
94
Sean Paul98e73c82015-06-24 14:38:49 -070095 private:
96 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
97
Sean Paulacb2a442015-06-24 18:43:01 -070098 bool validate_composition_type(DrmCompositionType desired);
99
Zach Reizner09807052015-08-13 14:53:41 -0700100 int CreateNextTimelineFence();
101 int IncreaseTimelineToPoint(int point);
102
Sean Paul98e73c82015-06-24 14:38:49 -0700103 DrmResources *drm_;
Zach Reizner09807052015-08-13 14:53:41 -0700104 DrmCrtc *crtc_;
Sean Paul98e73c82015-06-24 14:38:49 -0700105 Importer *importer_;
Zach Reiznerb44fd102015-08-07 16:00:01 -0700106 const gralloc_module_t *gralloc_;
Zach Reizner09807052015-08-13 14:53:41 -0700107 EGLDisplay egl_display_;
Sean Paul98e73c82015-06-24 14:38:49 -0700108
Sean Paulacb2a442015-06-24 18:43:01 -0700109 DrmCompositionType type_;
110
Sean Paul98e73c82015-06-24 14:38:49 -0700111 int timeline_fd_;
112 int timeline_;
Zach Reiznerece04892015-07-17 14:13:28 -0700113 int timeline_current_;
Zach Reizner09807052015-08-13 14:53:41 -0700114 int timeline_pre_comp_done_;
Sean Paul98e73c82015-06-24 14:38:49 -0700115
Zach Reizner4a253652015-09-10 18:30:54 -0700116 std::vector<DrmCompositionLayer> layers_;
Zach Reizner09807052015-08-13 14:53:41 -0700117 int pre_composition_layer_index_;
Sean Pauldb7a17d2015-06-24 18:46:05 -0700118 uint32_t dpms_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400119
120 uint64_t frame_no_;
Sean Paul98e73c82015-06-24 14:38:49 -0700121};
122}
123
124#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_