1 /*
2  * Copyright (C) 2012 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 #ifndef EXYNOS_VIRTUAL_DISPLAY_DISPLAY_H
17 #define EXYNOS_VIRTUAL_DISPLAY_DISPLAY_H
18 
19 #include "ExynosHWCDebug.h"
20 #include "../libdevice/ExynosDisplay.h"
21 
22 #define VIRTUAL_DISLAY_SKIP_LAYER   0x00000100
23 
24 enum WFDState {
25     DISABLE_WFD,
26     GOOGLEWFD,
27     LLWFD,
28     GOOGLEWFD_TO_LLWFD,
29     LLWFD_TO_GOOGLEWFD,
30 };
31 
32 enum WFDCommand {
33     SET_WFD_MODE,
34     SET_TARGET_DISPLAY_LUMINANCE,
35     SET_TARGET_DISPLAY_DEVICE,
36 };
37 
38 class ExynosVirtualDisplay : public ExynosDisplay {
39 public:
40     enum CompositionType {
41         COMPOSITION_UNKNOWN = 0,
42         COMPOSITION_GLES    = 1,
43         COMPOSITION_HWC     = 2,
44         COMPOSITION_MIXED   = COMPOSITION_GLES | COMPOSITION_HWC
45     };
46 
47     ExynosVirtualDisplay(uint32_t index, ExynosDevice *device);
48     ~ExynosVirtualDisplay();
49 
50     void createVirtualDisplay(uint32_t width, uint32_t height, int32_t* format);
51     void destroyVirtualDisplay();
52 
53     int setWFDMode(unsigned int mode);
54     int getWFDMode();
55     int sendWFDCommand(int32_t cmd, int32_t ext1, int32_t ext2);
56     int setSecureVDSMode(unsigned int mode);
57     int setWFDOutputResolution(unsigned int width, unsigned int height);
58     void getWFDOutputResolution(unsigned int *width, unsigned int *height);
59     void setPresentationMode(bool use);
60     int getPresentationMode(void);
61     int setVDSGlesFormat(int format);
62 
63     /* setOutputBuffer(..., buffer, releaseFence)
64      * Descriptor: HWC2_FUNCTION_SET_OUTPUT_BUFFER
65      * HWC2_PFN_SET_OUTPUT_BUFFER
66      * releaseFence is actually acquireFence
67      * output buffer reader should wait releaseFence
68      */
69     virtual int32_t setOutputBuffer(
70             buffer_handle_t buffer,
71             int32_t releaseFence);
72 
73     virtual int clearDisplay(bool needModeClear = false);
74 
75     /* validateDisplay(..., outNumTypes, outNumRequests)
76      * Descriptor: HWC2_FUNCTION_VALIDATE_DISPLAY
77      * HWC2_PFN_VALIDATE_DISPLAY
78      */
79     virtual int32_t validateDisplay(uint32_t* outNumTypes, uint32_t* outNumRequests);
80 
81     virtual int32_t canSkipValidate();
82 
83     /* presentDisplay(..., outRetireFence)
84      * Descriptor: HWC2_FUNCTION_PRESENT_DISPLAY
85      * HWC2_PFN_PRESENT_DISPLAY
86      */
87     virtual int32_t presentDisplay(int32_t* outRetireFence);
88 
89     /**
90      * set config related DPU window
91      * Only DRM video playback scenario use it.
92      */
93     virtual int setWinConfigData();
94 
95     /**
96      * set config related with DPU WB
97      * Only DRM video playback scenario use it.
98      */
99     virtual int setDisplayWinConfigData();
100 
101     /**
102      * check validation of DPU config
103      * Only DRM video playback scenario use it.
104      */
105     virtual int32_t validateWinConfigData();
106 
107     /**
108      * call ioctl for DPU
109      * Only DRM video playback scenario use it.
110      */
111     virtual int deliverWinConfigData();
112 
113     /**
114      * set release fence of DPU to layers
115      * Only DRM video playback scenario use it.
116      */
117     virtual int setReleaseFences();
118 
119     /**
120      * check output buffer validation
121      * If it is invalid, don't presetnDisplay
122      * And function handle fence of DEVICE composition Layer.
123      */
124     virtual bool checkFrameValidation();
125 
126     virtual int32_t getHdrCapabilities(uint32_t* outNumTypes,
127             int32_t* outTypes, float* outMaxLuminance,
128             float* outMaxAverageLuminance, float* outMinLuminance);
129 
130     /**
131      * If mIsWFDState is true, VirtualDisplaySurface use HWC
132      */
133     int         mIsWFDState;
134 
135 protected:
136     void setSinkBufferUsage();
137 
138     void setCompositionType();
139 
140     void setDrmMode();
141 
142     void initPerFrameData();
143 
144     bool checkSkipFrame();
145 
146     void handleSkipFrame();
147 
148     void handleAcquireFence();
149 
150     /**
151      * Display width, height information set by surfaceflinger
152      */
153     unsigned int mDisplayWidth;
154     unsigned int mDisplayHeight;
155 
156     /**
157      * output buffer and fence are set by setOutputBuffer()
158      */
159     buffer_handle_t mOutputBuffer;
160     int32_t mOutputBufferAcquireFenceFd;
161     int32_t mOutputBufferReleaseFenceFd;
162 
163     /**
164      * If mIsSecureVDSState is true, HWC doesn't change the color format of SINK BQ
165      */
166     bool        mIsSecureVDSState;
167 
168     /**
169      * If mIsSkipFrame is true, TV should not be updated.
170      */
171     bool        mIsSkipFrame;
172 
173     bool        mPresentationMode;
174 
175     /**
176      * If mIsRotationState is true,
177      * VurtualDisplaySurface don't queue graphic buffer
178      */
179     int32_t     mCompositionType;
180 
181     /**
182      * G3D pixel format
183      */
184     int32_t     mGLESFormat;
185 
186     /**
187      * output buffer usage
188      */
189     int32_t     mSinkUsage;
190 
191     /**
192      * If mIsSecureDRM is true, DPU composition is used.
193      * Otherwise, G2D composition is used.
194      */
195     bool mIsSecureDRM;
196     bool mIsNormalDRM;
197 
198     /**
199      * reload the G2D instance to remove the shared buffer for HWFC
200      */
201     bool mNeedReloadResourceForHWFC;
202 
203     /**
204      * the minimum luminance and maximum luminance of the SINK device's display
205      * WFD engine will set this values.
206      */
207     uint16_t mMaxTargetLuminance;
208     uint16_t mMinTargetLuminance;
209 
210     /**
211      * the type of the SINK device
212      * WFD engine will set this values.
213      */
214     int32_t mSinkDeviceType;
215 };
216 
217 #endif
218