blob: be4ecef8dac691d3e03db71c0489099157beeb5b [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
Sean Paul98e73c82015-06-24 14:38:49 -070040typedef struct DrmCompositionLayer {
41 DrmCompositionLayer();
Sean Paul98e73c82015-06-24 14:38:49 -070042
43 hwc_layer_1_t layer;
44 hwc_drm_bo_t bo;
45 DrmCrtc *crtc;
46 DrmPlane *plane;
Zach Reiznerb44fd102015-08-07 16:00:01 -070047 native_handle_t *handle;
Sean Paul98e73c82015-06-24 14:38:49 -070048} DrmCompositionLayer_t;
49typedef std::vector<DrmCompositionLayer_t> DrmCompositionLayerVector_t;
50
51class DrmDisplayComposition {
52 public:
53 DrmDisplayComposition();
54 ~DrmDisplayComposition();
55
Sean Paulbdc67bf2015-09-21 10:04:02 -040056 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
57 uint64_t frame_no);
Sean Paul98e73c82015-06-24 14:38:49 -070058
Sean Paulacb2a442015-06-24 18:43:01 -070059 DrmCompositionType type() const;
60
Zach Reizner09807052015-08-13 14:53:41 -070061 int SetLayers(hwc_layer_1_t *layers, size_t num_layers, size_t *layer_indices,
62 std::vector<DrmPlane *> *primary_planes,
63 std::vector<DrmPlane *> *overlay_planes);
Sean Paul2e46fbd2015-07-09 17:22:22 -040064 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -070065 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul98e73c82015-06-24 14:38:49 -070066
Zach Reiznerb44fd102015-08-07 16:00:01 -070067 void RemoveNoPlaneLayers();
Zach Reizner09807052015-08-13 14:53:41 -070068 int SignalPreCompositionDone();
Sean Paul98e73c82015-06-24 14:38:49 -070069 int FinishComposition();
70
71 DrmCompositionLayerVector_t *GetCompositionLayers();
Zach Reizner09807052015-08-13 14:53:41 -070072 int pre_composition_layer_index() const;
Sean Pauldb7a17d2015-06-24 18:46:05 -070073 uint32_t dpms_mode() const;
Sean Paul98e73c82015-06-24 14:38:49 -070074
Sean Paulbdc67bf2015-09-21 10:04:02 -040075 uint64_t frame_no() const;
76
Zach Reizner46ddd452015-07-30 08:10:14 -070077 Importer *importer() const;
78
Sean Paul98e73c82015-06-24 14:38:49 -070079 private:
80 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
81
Sean Paulacb2a442015-06-24 18:43:01 -070082 bool validate_composition_type(DrmCompositionType desired);
83
Zach Reizner09807052015-08-13 14:53:41 -070084 int CreateNextTimelineFence();
85 int IncreaseTimelineToPoint(int point);
86
Sean Paul98e73c82015-06-24 14:38:49 -070087 DrmResources *drm_;
Zach Reizner09807052015-08-13 14:53:41 -070088 DrmCrtc *crtc_;
Sean Paul98e73c82015-06-24 14:38:49 -070089 Importer *importer_;
Zach Reiznerb44fd102015-08-07 16:00:01 -070090 const gralloc_module_t *gralloc_;
Zach Reizner09807052015-08-13 14:53:41 -070091 EGLDisplay egl_display_;
Sean Paul98e73c82015-06-24 14:38:49 -070092
Sean Paulacb2a442015-06-24 18:43:01 -070093 DrmCompositionType type_;
94
Sean Paul98e73c82015-06-24 14:38:49 -070095 int timeline_fd_;
96 int timeline_;
Zach Reiznerece04892015-07-17 14:13:28 -070097 int timeline_current_;
Zach Reizner09807052015-08-13 14:53:41 -070098 int timeline_pre_comp_done_;
Sean Paul98e73c82015-06-24 14:38:49 -070099
100 DrmCompositionLayerVector_t layers_;
Zach Reizner09807052015-08-13 14:53:41 -0700101 int pre_composition_layer_index_;
Sean Pauldb7a17d2015-06-24 18:46:05 -0700102 uint32_t dpms_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400103
104 uint64_t frame_no_;
Sean Paul98e73c82015-06-24 14:38:49 -0700105};
106}
107
108#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_