OSDN Git Service

b40bdf3026e4cbc03308a2600822c41492f87d3f
[android-x86/external-IA-Hardware-Composer.git] / common / display / virtualdisplay.h
1 /*
2 // Copyright (c) 2016 Intel Corporation
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 COMMON_DISPLAY_VIRTUALDISPLAY_H_
18 #define COMMON_DISPLAY_VIRTUALDISPLAY_H_
19
20 #include <nativedisplay.h>
21
22 #include <memory>
23 #include <vector>
24
25 #include "compositor.h"
26 #include "resourcemanager.h"
27 #ifdef HYPER_DMABUF_SHARING
28 #include <linux/hyper_dmabuf.h>
29 #include <map>
30 #include "drmbuffer.h"
31 #include "hwctrace.h"
32 #define SURFACE_NAME_LENGTH 64
33 #define HYPER_DMABUF_PATH "/dev/hyper_dmabuf"
34 #endif
35
36 namespace hwcomposer {
37 struct HwcLayer;
38 class FrameBufferManager;
39 class NativeBufferHandler;
40
41 #ifdef HYPER_DMABUF_SHARING
42 struct vm_header {
43   int32_t version;
44   int32_t output;
45   int32_t counter;
46   int32_t n_buffers;
47   int32_t disp_w;
48   int32_t disp_h;
49 };
50
51 struct vm_buffer_info {
52   int32_t surf_index;
53   int32_t width, height;
54   int32_t format;
55   int32_t pitch[3];
56   int32_t offset[3];
57   int32_t tile_format;
58   int32_t rotation;
59   int32_t status;
60   int32_t counter;
61   union {
62     hyper_dmabuf_id_t hyper_dmabuf_id;
63     unsigned long ggtt_offset;
64   };
65   char surface_name[SURFACE_NAME_LENGTH];
66   uint64_t surface_id;
67   int32_t bbox[4];
68 };
69 #endif
70
71 class VirtualDisplay : public NativeDisplay {
72  public:
73   VirtualDisplay(uint32_t gpu_fd, NativeBufferHandler *buffer_handler,
74                  FrameBufferManager *framebuffermanager, uint32_t pipe_id,
75                  uint32_t crtc_id);
76   VirtualDisplay(const VirtualDisplay &) = delete;
77   VirtualDisplay &operator=(const VirtualDisplay &) = delete;
78   ~VirtualDisplay() override;
79
80   void InitVirtualDisplay(uint32_t width, uint32_t height) override;
81
82   bool GetActiveConfig(uint32_t *config) override;
83
84   bool SetActiveConfig(uint32_t config) override;
85
86   bool Present(std::vector<HwcLayer *> &source_layers, int32_t *retire_fence,
87                PixelUploaderCallback *call_back = NULL,
88                bool handle_constraints = false) override;
89
90   void SetOutputBuffer(HWCNativeHandle buffer, int32_t acquire_fence) override;
91
92   bool Initialize(NativeBufferHandler *buffer_handler,
93                   FrameBufferManager *frame_buffer_manager) override;
94
95   DisplayType Type() const override {
96     return DisplayType::kVirtual;
97   }
98
99   uint32_t Width() const override {
100     return width_;
101   }
102
103   uint32_t Height() const override {
104     return height_;
105   }
106
107   uint32_t PowerMode() const override {
108     return 0;
109   }
110
111   bool GetDisplayAttribute(uint32_t config, HWCDisplayAttribute attribute,
112                            int32_t *value) override;
113
114   bool GetDisplayConfigs(uint32_t *num_configs, uint32_t *configs) override;
115   bool GetDisplayName(uint32_t *size, char *name) override;
116   int GetDisplayPipe() override;
117
118   bool SetPowerMode(uint32_t power_mode) override;
119
120   int RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
121                             uint32_t display_id) override;
122
123   void VSyncControl(bool enabled) override;
124   bool CheckPlaneFormat(uint32_t format) override;
125   void SetPAVPSessionStatus(bool enabled, uint32_t pavp_session_id,
126                             uint32_t pavp_instance_id) override {
127     if (enabled) {
128       discard_protected_video_ = false;
129     } else {
130       discard_protected_video_ = true;
131     }
132   }
133
134  private:
135   HWCNativeHandle output_handle_;
136   int32_t acquire_fence_ = -1;
137   Compositor compositor_;
138   uint32_t width_ = 1;
139   uint32_t height_ = 1;
140   std::vector<OverlayLayer> in_flight_layers_;
141   HWCNativeHandle handle_ = 0;
142   std::unique_ptr<ResourceManager> resource_manager_;
143   FrameBufferManager *fb_manager_ = NULL;
144   uint32_t display_index_ = 0;
145   bool discard_protected_video_ = false;
146
147 #ifdef HYPER_DMABUF_SHARING
148   int mHyperDmaBuf_Fd = -1;
149   std::map<uint32_t, vm_buffer_info>
150       mHyperDmaExportedBuffers;  // Track the hyper dmabuf metadata info mapping
151   uint32_t frame_count_ = 0;
152 #endif
153 };
154
155 }  // namespace hwcomposer
156 #endif  // COMMON_DISPLAY_VIRTUALDISPLAY_H_