2 // Copyright (c) 2016 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef COMMON_DISPLAY_VIRTUALDISPLAY_H_
18 #define COMMON_DISPLAY_VIRTUALDISPLAY_H_
20 #include <nativedisplay.h>
25 #include "compositor.h"
26 #include "resourcemanager.h"
27 #ifdef HYPER_DMABUF_SHARING
28 #include <linux/hyper_dmabuf.h>
30 #include "drmbuffer.h"
32 #define SURFACE_NAME_LENGTH 64
33 #define HYPER_DMABUF_PATH "/dev/hyper_dmabuf"
36 namespace hwcomposer {
38 class FrameBufferManager;
39 class NativeBufferHandler;
41 #ifdef HYPER_DMABUF_SHARING
51 struct vm_buffer_info {
53 int32_t width, height;
62 hyper_dmabuf_id_t hyper_dmabuf_id;
63 unsigned long ggtt_offset;
65 char surface_name[SURFACE_NAME_LENGTH];
71 class VirtualDisplay : public NativeDisplay {
73 VirtualDisplay(uint32_t gpu_fd, NativeBufferHandler *buffer_handler,
74 FrameBufferManager *framebuffermanager, uint32_t pipe_id,
76 VirtualDisplay(const VirtualDisplay &) = delete;
77 VirtualDisplay &operator=(const VirtualDisplay &) = delete;
78 ~VirtualDisplay() override;
80 void InitVirtualDisplay(uint32_t width, uint32_t height) override;
82 bool GetActiveConfig(uint32_t *config) override;
84 bool SetActiveConfig(uint32_t config) override;
86 bool Present(std::vector<HwcLayer *> &source_layers, int32_t *retire_fence,
87 PixelUploaderCallback *call_back = NULL,
88 bool handle_constraints = false) override;
90 void SetOutputBuffer(HWCNativeHandle buffer, int32_t acquire_fence) override;
92 bool Initialize(NativeBufferHandler *buffer_handler,
93 FrameBufferManager *frame_buffer_manager) override;
95 DisplayType Type() const override {
96 return DisplayType::kVirtual;
99 uint32_t Width() const override {
103 uint32_t Height() const override {
107 uint32_t PowerMode() const override {
111 bool GetDisplayAttribute(uint32_t config, HWCDisplayAttribute attribute,
112 int32_t *value) override;
114 bool GetDisplayConfigs(uint32_t *num_configs, uint32_t *configs) override;
115 bool GetDisplayName(uint32_t *size, char *name) override;
116 int GetDisplayPipe() override;
118 bool SetPowerMode(uint32_t power_mode) override;
120 int RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
121 uint32_t display_id) override;
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 {
128 discard_protected_video_ = false;
130 discard_protected_video_ = true;
135 HWCNativeHandle output_handle_;
136 int32_t acquire_fence_ = -1;
137 Compositor compositor_;
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;
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;
155 } // namespace hwcomposer
156 #endif // COMMON_DISPLAY_VIRTUALDISPLAY_H_