OSDN Git Service

drm_hwcomposer: implement the safe handling of layers
[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 struct DrmCompositionLayer {
41   DrmCrtc *crtc = NULL;
42   DrmPlane *plane = NULL;
43
44   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 };
66
67 class DrmDisplayComposition {
68  public:
69   DrmDisplayComposition();
70   ~DrmDisplayComposition();
71
72   int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
73            uint64_t frame_no);
74
75   DrmCompositionType type() const;
76
77   int SetLayers(DrmHwcLayer *layers, size_t num_layers,
78                 std::vector<DrmPlane *> *primary_planes,
79                 std::vector<DrmPlane *> *overlay_planes);
80   int AddPlaneDisable(DrmPlane *plane);
81   int SetDpmsMode(uint32_t dpms_mode);
82
83   void RemoveNoPlaneLayers();
84   int SignalPreCompositionDone();
85   int FinishComposition();
86
87   std::vector<DrmCompositionLayer> *GetCompositionLayers();
88   int pre_composition_layer_index() const;
89   uint32_t dpms_mode() const;
90
91   uint64_t frame_no() const;
92
93   Importer *importer() const;
94
95  private:
96   DrmDisplayComposition(const DrmDisplayComposition &) = delete;
97
98   bool validate_composition_type(DrmCompositionType desired);
99
100   int CreateNextTimelineFence();
101   int IncreaseTimelineToPoint(int point);
102
103   DrmResources *drm_;
104   DrmCrtc *crtc_;
105   Importer *importer_;
106   const gralloc_module_t *gralloc_;
107   EGLDisplay egl_display_;
108
109   DrmCompositionType type_;
110
111   int timeline_fd_;
112   int timeline_;
113   int timeline_current_;
114   int timeline_pre_comp_done_;
115
116   std::vector<DrmCompositionLayer> layers_;
117   int pre_composition_layer_index_;
118   uint32_t dpms_mode_;
119
120   uint64_t frame_no_;
121 };
122 }
123
124 #endif  // ANDROID_DRM_DISPLAY_COMPOSITION_H_