blob: 4d4f2df4d6837f0c37a3617b483df53db621803b [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
Zach Reizner09807052015-08-13 14:53:41 -070056 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer);
Sean Paul98e73c82015-06-24 14:38:49 -070057
Sean Paulacb2a442015-06-24 18:43:01 -070058 DrmCompositionType type() const;
59
Zach Reizner09807052015-08-13 14:53:41 -070060 int SetLayers(hwc_layer_1_t *layers, size_t num_layers, size_t *layer_indices,
61 std::vector<DrmPlane *> *primary_planes,
62 std::vector<DrmPlane *> *overlay_planes);
Sean Paul2e46fbd2015-07-09 17:22:22 -040063 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -070064 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul98e73c82015-06-24 14:38:49 -070065
Zach Reiznerb44fd102015-08-07 16:00:01 -070066 void RemoveNoPlaneLayers();
Zach Reizner09807052015-08-13 14:53:41 -070067 int SignalPreCompositionDone();
Sean Paul98e73c82015-06-24 14:38:49 -070068 int FinishComposition();
69
70 DrmCompositionLayerVector_t *GetCompositionLayers();
Zach Reizner09807052015-08-13 14:53:41 -070071 int pre_composition_layer_index() const;
Sean Pauldb7a17d2015-06-24 18:46:05 -070072 uint32_t dpms_mode() const;
Sean Paul98e73c82015-06-24 14:38:49 -070073
Zach Reizner46ddd452015-07-30 08:10:14 -070074 Importer *importer() const;
75
Sean Paul98e73c82015-06-24 14:38:49 -070076 private:
77 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
78
Sean Paulacb2a442015-06-24 18:43:01 -070079 bool validate_composition_type(DrmCompositionType desired);
80
Zach Reizner09807052015-08-13 14:53:41 -070081 int CreateNextTimelineFence();
82 int IncreaseTimelineToPoint(int point);
83
Sean Paul98e73c82015-06-24 14:38:49 -070084 DrmResources *drm_;
Zach Reizner09807052015-08-13 14:53:41 -070085 DrmCrtc *crtc_;
Sean Paul98e73c82015-06-24 14:38:49 -070086 Importer *importer_;
Zach Reiznerb44fd102015-08-07 16:00:01 -070087 const gralloc_module_t *gralloc_;
Zach Reizner09807052015-08-13 14:53:41 -070088 EGLDisplay egl_display_;
Sean Paul98e73c82015-06-24 14:38:49 -070089
Sean Paulacb2a442015-06-24 18:43:01 -070090 DrmCompositionType type_;
91
Sean Paul98e73c82015-06-24 14:38:49 -070092 int timeline_fd_;
93 int timeline_;
Zach Reiznerece04892015-07-17 14:13:28 -070094 int timeline_current_;
Zach Reizner09807052015-08-13 14:53:41 -070095 int timeline_pre_comp_done_;
Sean Paul98e73c82015-06-24 14:38:49 -070096
97 DrmCompositionLayerVector_t layers_;
Zach Reizner09807052015-08-13 14:53:41 -070098 int pre_composition_layer_index_;
Sean Pauldb7a17d2015-06-24 18:46:05 -070099 uint32_t dpms_mode_;
Sean Paul98e73c82015-06-24 14:38:49 -0700100};
101}
102
103#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_