OSDN Git Service

drm_hwcomposer: Plumb frame number through display composition
[android-x86/external-drm_hwcomposer.git] / drmdisplaycomposition.h
1 /*
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"
21 #include "drmcrtc.h"
22 #include "drmplane.h"
23 #include "glworker.h"
24 #include "importer.h"
25
26 #include <vector>
27
28 #include <hardware/gralloc.h>
29 #include <hardware/hardware.h>
30 #include <hardware/hwcomposer.h>
31
32 namespace android {
33
34 enum DrmCompositionType {
35   DRM_COMPOSITION_TYPE_EMPTY,
36   DRM_COMPOSITION_TYPE_FRAME,
37   DRM_COMPOSITION_TYPE_DPMS,
38 };
39
40 typedef struct DrmCompositionLayer {
41   DrmCompositionLayer();
42
43   hwc_layer_1_t layer;
44   hwc_drm_bo_t bo;
45   DrmCrtc *crtc;
46   DrmPlane *plane;
47   native_handle_t *handle;
48 } DrmCompositionLayer_t;
49 typedef std::vector<DrmCompositionLayer_t> DrmCompositionLayerVector_t;
50
51 class DrmDisplayComposition {
52  public:
53   DrmDisplayComposition();
54   ~DrmDisplayComposition();
55
56   int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
57            uint64_t frame_no);
58
59   DrmCompositionType type() const;
60
61   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);
64   int AddPlaneDisable(DrmPlane *plane);
65   int SetDpmsMode(uint32_t dpms_mode);
66
67   void RemoveNoPlaneLayers();
68   int SignalPreCompositionDone();
69   int FinishComposition();
70
71   DrmCompositionLayerVector_t *GetCompositionLayers();
72   int pre_composition_layer_index() const;
73   uint32_t dpms_mode() const;
74
75   uint64_t frame_no() const;
76
77   Importer *importer() const;
78
79  private:
80   DrmDisplayComposition(const DrmDisplayComposition &) = delete;
81
82   bool validate_composition_type(DrmCompositionType desired);
83
84   int CreateNextTimelineFence();
85   int IncreaseTimelineToPoint(int point);
86
87   DrmResources *drm_;
88   DrmCrtc *crtc_;
89   Importer *importer_;
90   const gralloc_module_t *gralloc_;
91   EGLDisplay egl_display_;
92
93   DrmCompositionType type_;
94
95   int timeline_fd_;
96   int timeline_;
97   int timeline_current_;
98   int timeline_pre_comp_done_;
99
100   DrmCompositionLayerVector_t layers_;
101   int pre_composition_layer_index_;
102   uint32_t dpms_mode_;
103
104   uint64_t frame_no_;
105 };
106 }
107
108 #endif  // ANDROID_DRM_DISPLAY_COMPOSITION_H_