• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef _EXYNOSDISPLAY_H
18 #define _EXYNOSDISPLAY_H
19 
20 #include <android/hardware/graphics/composer/2.4/types.h>
21 #include <hardware/hwcomposer2.h>
22 #include <system/graphics.h>
23 #include <utils/KeyedVector.h>
24 #include <utils/Vector.h>
25 
26 #include <atomic>
27 #include <chrono>
28 #include <set>
29 
30 #include "DeconHeader.h"
31 #include "ExynosDisplayInterface.h"
32 #include "ExynosHWC.h"
33 #include "ExynosHWCDebug.h"
34 #include "ExynosHWCHelper.h"
35 #include "ExynosHwc3Types.h"
36 #include "ExynosMPP.h"
37 #include "ExynosResourceManager.h"
38 #include "drmeventlistener.h"
39 #include "worker.h"
40 
41 #define HWC_CLEARDISPLAY_WITH_COLORMAP
42 #define HWC_PRINT_FRAME_NUM     10
43 
44 #define LOW_FPS_THRESHOLD     5
45 
46 using ::android::hardware::graphics::composer::V2_4::VsyncPeriodNanos;
47 using namespace std::chrono_literals;
48 
49 #ifndef SECOND_DISPLAY_START_BIT
50 #define SECOND_DISPLAY_START_BIT   4
51 #endif
52 
53 typedef hwc2_composition_t exynos_composition;
54 
55 class BrightnessController;
56 class ExynosLayer;
57 class ExynosDevice;
58 class ExynosMPP;
59 class ExynosMPPSource;
60 class HistogramController;
61 
62 namespace aidl {
63 namespace google {
64 namespace hardware {
65 namespace power {
66 namespace extension {
67 namespace pixel {
68 
69 class IPowerExt;
70 
71 } // namespace pixel
72 } // namespace extension
73 } // namespace power
74 } // namespace hardware
75 } // namespace google
76 } // namespace aidl
77 namespace aidl {
78 namespace android {
79 namespace hardware {
80 namespace power {
81 
82 class IPower;
83 class IPowerHintSession;
84 class WorkDuration;
85 
86 } // namespace power
87 } // namespace hardware
88 } // namespace android
89 } // namespace aidl
90 
91 using WorkDuration = aidl::android::hardware::power::WorkDuration;
92 
93 enum dynamic_recomp_mode {
94     NO_MODE_SWITCH,
95     DEVICE_2_CLIENT,
96     CLIENT_2_DEVICE
97 };
98 
99 enum rendering_state {
100     RENDERING_STATE_NONE = 0,
101     RENDERING_STATE_VALIDATED,
102     RENDERING_STATE_ACCEPTED_CHANGE,
103     RENDERING_STATE_PRESENTED,
104     RENDERING_STATE_MAX
105 };
106 
107 enum composition_type {
108     COMPOSITION_NONE = 0,
109     COMPOSITION_CLIENT,
110     COMPOSITION_EXYNOS,
111     COMPOSITION_MAX
112 };
113 
114 enum {
115     PSR_NONE = 0,
116     PSR_DP,
117     PSR_MIPI,
118     PSR_MAX,
119 };
120 
121 enum {
122     PANEL_LEGACY = 0,
123     PANEL_DSC,
124     PANEL_MIC,
125 };
126 
127 enum {
128     eDisplayNone     = 0x0,
129     ePrimaryDisplay  = 0x00000001,
130     eExternalDisplay = 0x00000002,
131     eVirtualDisplay  = 0x00000004,
132 };
133 
134 // served as extension of hwc2_power_mode_t for use with setPowerMode
135 enum class ext_hwc2_power_mode_t{
136     PAUSE = 10,
137     RESUME,
138 };
139 
140 enum class PanelGammaSource {
141     GAMMA_DEFAULT,     // Resotre gamma table to default
142     GAMMA_CALIBRATION, // Update gamma table from calibration file
143     GAMMA_TYPES,
144 };
145 
146 enum class hwc_request_state_t {
147     SET_CONFIG_STATE_DONE = 0,
148     SET_CONFIG_STATE_PENDING,
149     SET_CONFIG_STATE_REQUESTED,
150 };
151 
152 enum class VrrThrottleRequester : uint32_t {
153     PIXEL_DISP = 0,
154     TEST,
155     LHBM,
156     BRIGHTNESS,
157     MAX,
158 };
159 
160 enum class DispIdleTimerRequester : uint32_t {
161     SF = 0,
162     VRR_THROTTLE,
163     MAX,
164 };
165 
166 #define NUM_SKIP_STATIC_LAYER  5
167 struct ExynosFrameInfo
168 {
169     uint32_t srcNum;
170     exynos_image srcInfo[NUM_SKIP_STATIC_LAYER];
171     exynos_image dstInfo[NUM_SKIP_STATIC_LAYER];
172 };
173 
174 struct exynos_readback_info
175 {
176     buffer_handle_t handle = NULL;
177     /* release sync fence file descriptor,
178      * which will be signaled when it is safe to write to the output buffer.
179      */
180     int rel_fence = -1;
181     /* acquire sync fence file descriptor which will signal when the
182      * buffer provided to setReadbackBuffer has been filled by the device and is
183      * safe for the client to read.
184      */
185     int acq_fence = -1;
186     /* Requested from HWCService */
187     bool requested_from_service = false;
188 };
189 
190 struct exynos_win_config_data
191 {
192     enum {
193         WIN_STATE_DISABLED = 0,
194         WIN_STATE_COLOR,
195         WIN_STATE_BUFFER,
196         WIN_STATE_UPDATE,
197         WIN_STATE_CURSOR,
198         WIN_STATE_RCD,
199     } state = WIN_STATE_DISABLED;
200 
201     uint32_t color = 0;
202     const ExynosLayer* layer = nullptr;
203     uint64_t buffer_id = 0;
204     int fd_idma[3] = {-1, -1, -1};
205     int acq_fence = -1;
206     int rel_fence = -1;
207     float plane_alpha = 1;
208     int32_t blending = HWC2_BLEND_MODE_NONE;
209     ExynosMPP* assignedMPP = NULL;
210     int format = 0;
211     uint32_t transform = 0;
212     android_dataspace dataspace = HAL_DATASPACE_UNKNOWN;
213     bool hdr_enable = false;
214     enum dpp_comp_src comp_src = DPP_COMP_SRC_NONE;
215     uint32_t min_luminance = 0;
216     uint32_t max_luminance = 0;
217     struct decon_win_rect block_area = { 0, 0, 0, 0};
218     struct decon_win_rect transparent_area = {0, 0, 0, 0};
219     struct decon_win_rect opaque_area = {0, 0, 0, 0};
220     struct decon_frame src = {0, 0, 0, 0, 0, 0};
221     struct decon_frame dst = {0, 0, 0, 0, 0, 0};
222     bool protection = false;
223     CompressionInfo compressionInfo;
224     bool needColorTransform = false;
225 
resetexynos_win_config_data226     void reset(){
227         *this = {};
228     };
229 };
230 struct exynos_dpu_data
231 {
232     int retire_fence = -1;
233     std::vector<exynos_win_config_data> configs;
234     std::vector<exynos_win_config_data> rcdConfigs;
235 
236     bool enable_win_update = false;
237     std::atomic<bool> enable_readback = false;
238     struct decon_frame win_update_region = {0, 0, 0, 0, 0, 0};
239     struct exynos_readback_info readback_info;
240 
initexynos_dpu_data241     void init(size_t configNum, size_t rcdConfigNum) {
242         configs.resize(configNum);
243         rcdConfigs.resize(rcdConfigNum);
244     };
245 
resetexynos_dpu_data246     void reset() {
247         retire_fence = -1;
248         for (auto& config : configs) config.reset();
249         for (auto& config : rcdConfigs) config.reset();
250 
251         /*
252          * Should not initialize readback_info
253          * readback_info should be initialized after present
254          */
255     };
256     exynos_dpu_data& operator =(const exynos_dpu_data &configs_data){
257         retire_fence = configs_data.retire_fence;
258         if (configs.size() != configs_data.configs.size()) {
259             HWC_LOGE(NULL, "invalid config, it has different configs size");
260             return *this;
261         }
262         configs = configs_data.configs;
263         if (rcdConfigs.size() != configs_data.rcdConfigs.size()) {
264             HWC_LOGE(NULL, "invalid config, it has different rcdConfigs size");
265             return *this;
266         }
267         rcdConfigs = configs_data.rcdConfigs;
268         return *this;
269     };
270 };
271 
272 class ExynosLowFpsLayerInfo
273 {
274     public:
275         ExynosLowFpsLayerInfo();
276         bool mHasLowFpsLayer;
277         int32_t mFirstIndex;
278         int32_t mLastIndex;
279 
280         void initializeInfos();
281         int32_t addLowFpsLayer(uint32_t layerIndex);
282 };
283 
284 class ExynosSortedLayer : public Vector <ExynosLayer*>
285 {
286     public:
287         ssize_t remove(const ExynosLayer *item);
288         status_t vector_sort();
289         static int compare(ExynosLayer * const *lhs, ExynosLayer *const *rhs);
290 };
291 
292 class DisplayTDMInfo {
293     public:
294         /* Could be extended */
295         typedef struct ResourceAmount {
296             uint32_t totalAmount;
297         } ResourceAmount_t;
298         std::map<tdm_attr_t, ResourceAmount_t> mAmount;
299 
initTDMInfo(ResourceAmount_t amount,tdm_attr_t attr)300         uint32_t initTDMInfo(ResourceAmount_t amount, tdm_attr_t attr) {
301             mAmount[attr] = amount;
302             return 0;
303         }
304 
getAvailableAmount(tdm_attr_t attr)305         ResourceAmount_t getAvailableAmount(tdm_attr_t attr) { return mAmount[attr]; }
306 };
307 
308 class ExynosCompositionInfo : public ExynosMPPSource {
309     public:
ExynosCompositionInfo()310         ExynosCompositionInfo():ExynosCompositionInfo(COMPOSITION_NONE){};
311         ExynosCompositionInfo(uint32_t type);
312         uint32_t mType;
313         bool mHasCompositionLayer;
314         bool mPrevHasCompositionLayer = false;
315         int32_t mFirstIndex;
316         int32_t mLastIndex;
317         buffer_handle_t mTargetBuffer;
318         android_dataspace mDataSpace;
319         int32_t mAcquireFence;
320         int32_t mReleaseFence;
321         bool mEnableSkipStatic;
322         bool mSkipStaticInitFlag;
323         bool mSkipFlag;
324         ExynosFrameInfo mSkipSrcInfo;
325         exynos_win_config_data mLastWinConfigData;
326 
327         int32_t mWindowIndex;
328         CompressionInfo mCompressionInfo;
329 
330         void initializeInfos(ExynosDisplay *display);
331         void initializeInfosComplete(ExynosDisplay *display);
332         void setTargetBuffer(ExynosDisplay *display, buffer_handle_t handle,
333                 int32_t acquireFence, android_dataspace dataspace);
334         void setCompressionType(uint32_t compressionType);
335         void dump(String8& result) const;
336         String8 getTypeStr();
337 };
338 
339 // Prepare multi-resolution
340 struct ResolutionSize {
341     uint32_t w;
342     uint32_t h;
343 };
344 
345 struct ResolutionInfo {
346     uint32_t nNum;
347     ResolutionSize nResolution[3];
348     uint32_t nDSCYSliceSize[3];
349     uint32_t nDSCXSliceSize[3];
350     int      nPanelType[3];
351 };
352 
353 typedef struct displayConfigs {
354     // HWC2_ATTRIBUTE_VSYNC_PERIOD
355     VsyncPeriodNanos vsyncPeriod;
356     // HWC2_ATTRIBUTE_WIDTH
357     uint32_t width;
358     // case HWC2_ATTRIBUTE_HEIGHT
359     uint32_t height;
360     // HWC2_ATTRIBUTE_DPI_X
361     uint32_t Xdpi;
362     // HWC2_ATTRIBUTE_DPI_Y
363     uint32_t Ydpi;
364     // HWC2_ATTRIBUTE_CONFIG_GROUP
365     uint32_t groupId;
366 } displayConfigs_t;
367 
368 struct DisplayControl {
369     /** Composition crop en/disable **/
370     bool enableCompositionCrop;
371     /** Resource assignment optimization for exynos composition **/
372     bool enableExynosCompositionOptimization;
373     /** Resource assignment optimization for client composition **/
374     bool enableClientCompositionOptimization;
375     /** Use G2D as much as possible **/
376     bool useMaxG2DSrc;
377     /** Low fps layer optimization **/
378     bool handleLowFpsLayers;
379     /** start m2mMPP before persentDisplay **/
380     bool earlyStartMPP;
381     /** Adjust display size of the layer having high priority */
382     bool adjustDisplayFrame;
383     /** setCursorPosition support **/
384     bool cursorSupport;
385     /** readback support **/
386     bool readbackSupport = false;
387     /** Reserve MPP regardless of plug state **/
388     bool forceReserveMPP = false;
389     /** Skip M2MMPP processing **/
390     bool skipM2mProcessing = true;
391     /** Enable multi-thread present **/
392     bool multiThreadedPresent = false;
393 };
394 
395 class ExynosDisplay {
396     public:
397         const uint32_t mDisplayId;
398         const uint32_t mType;
399         const uint32_t mIndex;
400         String8 mDeconNodeName;
401         uint32_t mXres;
402         uint32_t mYres;
403         uint32_t mXdpi;
404         uint32_t mYdpi;
405         uint32_t mVsyncPeriod;
406         uint32_t mBtsVsyncPeriod;
407 
408         int                     mPanelType;
409         int                     mPsrMode;
410 
411         /* Constructor */
412         ExynosDisplay(uint32_t type, uint32_t index, ExynosDevice* device,
413                       const std::string& displayName);
414         /* Destructor */
415         virtual ~ExynosDisplay();
416 
417         ExynosDevice *mDevice;
418 
419         const String8 mDisplayName;
420         const String8 mDisplayTraceName;
421         HwcMountOrientation mMountOrientation = HwcMountOrientation::ROT_0;
422         mutable Mutex mDisplayMutex;
423 
424         /** State variables */
425         bool mPlugState;
426         std::optional<hwc2_power_mode_t> mPowerModeState;
427         hwc2_vsync_t mVsyncState;
428         bool mHasSingleBuffer;
429         bool mPauseDisplay = false;
430 
431         DisplayControl mDisplayControl;
432 
433         /**
434          * TODO : Should be defined as ExynosLayer type
435          * Layer list those sorted by z-order
436          */
437         ExynosSortedLayer mLayers;
438         std::vector<ExynosLayer*> mIgnoreLayers;
439 
440         ExynosResourceManager *mResourceManager;
441 
442         /**
443          * Layer index, target buffer information for GLES.
444          */
445         ExynosCompositionInfo mClientCompositionInfo;
446 
447         /**
448          * Layer index, target buffer information for G2D.
449          */
450         ExynosCompositionInfo mExynosCompositionInfo;
451 
452         /**
453          * Geometry change info is described by bit map.
454          * This flag is cleared when resource assignment for all displays
455          * is done.
456          * Geometry changed to layer REFRESH_RATE_INDICATOR will be excluded.
457          */
458         uint64_t  mGeometryChanged;
459 
460         /**
461          * The number of buffer updates in the current frame.
462          * Buffer update for layer REFRESH_RATE_INDICATOR will be excluded.
463          */
464         uint32_t mBufferUpdates;
465 
466         /**
467          * Rendering step information that is seperated by
468          * VALIDATED, ACCEPTED_CHANGE, PRESENTED.
469          */
470         rendering_state  mRenderingState;
471 
472         /**
473          * Rendering step information that is called by client
474          */
475         rendering_state  mHWCRenderingState;
476 
477         /**
478          * Window total bandwidth by enabled window, It's used as dynamic re-composition enable/disable.
479          */
480         uint32_t  mDisplayBW;
481 
482         /**
483          * Mode information Dynamic re-composition feature.
484          * DEVICE_2_CLIENT: All layers are composited by GLES composition.
485          * CLIENT_2_DEVICE: Device composition.
486          */
487         dynamic_recomp_mode mDynamicReCompMode;
488         bool mDREnable;
489         bool mDRDefault;
490         mutable Mutex mDRMutex;
491 
492         nsecs_t  mLastFpsTime;
493         uint64_t mFrameCount;
494         uint64_t mLastFrameCount;
495         uint64_t mErrorFrameCount;
496         uint64_t mLastModeSwitchTimeStamp;
497         uint64_t mLastUpdateTimeStamp;
498         uint64_t mUpdateEventCnt;
499         uint64_t mUpdateCallCnt;
500 
501         /* default DMA for the display */
502         decon_idma_type mDefaultDMA;
503 
504         /**
505          * DECON WIN_CONFIG information.
506          */
507         exynos_dpu_data mDpuData;
508 
509         /**
510          * Last win_config data is used as WIN_CONFIG skip decision or debugging.
511          */
512         exynos_dpu_data mLastDpuData;
513 
514         /**
515          * Restore release fenc from DECON.
516          */
517         int mLastRetireFence;
518 
519         bool mUseDpu;
520 
521         /**
522          * Max Window number, It should be set by display module(chip)
523          */
524         uint32_t mMaxWindowNum;
525         uint32_t mWindowNumUsed;
526         uint32_t mBaseWindowIndex;
527 
528         // Priority
529         uint32_t mNumMaxPriorityAllowed;
530         int32_t mCursorIndex;
531 
532         int32_t mColorTransformHint;
533 
534         ExynosLowFpsLayerInfo mLowFpsLayerInfo;
535 
536         // HDR capabilities
537         std::vector<int32_t> mHdrTypes;
538         float mMaxLuminance;
539         float mMaxAverageLuminance;
540         float mMinLuminance;
541 
542         std::unique_ptr<BrightnessController> mBrightnessController;
543 
544         /* For histogram */
545         std::unique_ptr<HistogramController> mHistogramController;
546 
547         /* For debugging */
548         hwc_display_contents_1_t *mHWC1LayerList;
549 
550         /* Support Multi-resolution scheme */
551         int mOldScalerMode;
552         int mNewScaledWidth;
553         int mNewScaledHeight;
554         int32_t mDeviceXres;
555         int32_t mDeviceYres;
556         ResolutionInfo mResolutionInfo;
557         std::map<uint32_t, displayConfigs_t> mDisplayConfigs;
558 
559         // WCG
560         android_color_mode_t mColorMode;
561 
562         // Skip present frame if there was no validate after power on
563         bool mSkipFrame;
564 
565         hwc_vsync_period_change_constraints_t mVsyncPeriodChangeConstraints;
566         hwc_vsync_period_change_timeline_t mVsyncAppliedTimeLine;
567         hwc_request_state_t mConfigRequestState;
568         hwc2_config_t mDesiredConfig;
569 
570         hwc2_config_t mActiveConfig = UINT_MAX;
571         hwc2_config_t mPendingConfig = UINT_MAX;
572         int64_t mLastVsyncTimestamp = 0;
573 
574         void initDisplay();
575 
576         int getId();
getDisplayMutex()577         Mutex& getDisplayMutex() {return mDisplayMutex; };
578 
579         int32_t setCompositionTargetExynosImage(uint32_t targetType, exynos_image *src_img, exynos_image *dst_img);
580         int32_t initializeValidateInfos();
581         int32_t addClientCompositionLayer(uint32_t layerIndex);
582         int32_t removeClientCompositionLayer(uint32_t layerIndex);
583         bool hasClientComposition();
584         int32_t addExynosCompositionLayer(uint32_t layerIndex, float totalUsedCapa);
585 
586         bool isPowerModeOff() const;
587         bool isSecureContentPresenting() const;
588 
589         /**
590          * Dynamic AFBC Control solution : To get the prepared information is applied to current or not.
591          */
592         bool comparePreferedLayers();
593 
594         /**
595          * @param *outLayer
596          */
597         int32_t destroyLayer(hwc2_layer_t outLayer);
598 
599         void destroyLayers();
600 
601         ExynosLayer *checkLayer(hwc2_layer_t addr);
602 
603         void checkIgnoreLayers();
604         virtual void doPreProcessing();
605 
606         int checkLayerFps();
607 
608         int switchDynamicReCompMode(dynamic_recomp_mode mode);
609 
610         int checkDynamicReCompMode();
611 
612         int handleDynamicReCompMode();
613 
614         void updateBrightnessState();
615 
616         /**
617          * @param compositionType
618          */
619         int skipStaticLayers(ExynosCompositionInfo& compositionInfo);
620         int handleStaticLayers(ExynosCompositionInfo& compositionInfo);
621 
622         int doPostProcessing();
623 
624         int doExynosComposition();
625 
626         int32_t configureOverlay(ExynosLayer *layer, exynos_win_config_data &cfg);
627         int32_t configureOverlay(ExynosCompositionInfo &compositionInfo);
628 
629         int32_t configureHandle(ExynosLayer &layer,  int fence_fd, exynos_win_config_data &cfg);
630 
631         virtual int setWinConfigData();
632 
633         virtual int setDisplayWinConfigData();
634 
635         virtual int32_t validateWinConfigData();
636 
637         virtual int deliverWinConfigData();
638 
639         virtual int setReleaseFences();
640 
641         virtual bool checkFrameValidation();
642 
643         /**
644          * Display Functions for HWC 2.0
645          */
646 
647         /**
648          * Descriptor: HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES
649          * HWC2_PFN_ACCEPT_DISPLAY_CHANGES
650          **/
651         virtual int32_t acceptDisplayChanges();
652 
653         /**
654          * Descriptor: HWC2_FUNCTION_CREATE_LAYER
655          * HWC2_PFN_CREATE_LAYER
656          */
657         virtual int32_t createLayer(hwc2_layer_t* outLayer);
658 
659         /**
660          * Descriptor: HWC2_FUNCTION_GET_ACTIVE_CONFIG
661          * HWC2_PFN_GET_ACTIVE_CONFIG
662          */
663         virtual int32_t getActiveConfig(hwc2_config_t* outConfig);
664 
665         /**
666          * Descriptor: HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES
667          * HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES
668          */
669         virtual int32_t getChangedCompositionTypes(
670                 uint32_t* outNumElements, hwc2_layer_t* outLayers,
671                 int32_t* /*hwc2_composition_t*/ outTypes);
672 
673         /**
674          * Descriptor: HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT
675          * HWC2_PFN_GET_CLIENT_TARGET_SUPPORT
676          */
677         virtual int32_t getClientTargetSupport(
678                 uint32_t width, uint32_t height,
679                 int32_t /*android_pixel_format_t*/ format,
680                 int32_t /*android_dataspace_t*/ dataspace);
681 
682         /**
683          * Descriptor: HWC2_FUNCTION_GET_COLOR_MODES
684          * HWC2_PFN_GET_COLOR_MODES
685          */
686         virtual int32_t getColorModes(
687                 uint32_t* outNumModes,
688                 int32_t* /*android_color_mode_t*/ outModes);
689 
690         /* getDisplayAttribute(..., config, attribute, outValue)
691          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE
692          * HWC2_PFN_GET_DISPLAY_ATTRIBUTE
693          */
694         virtual int32_t getDisplayAttribute(
695                 hwc2_config_t config,
696                 int32_t /*hwc2_attribute_t*/ attribute, int32_t* outValue);
697 
698         /* getDisplayConfigs(..., outNumConfigs, outConfigs)
699          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_CONFIGS
700          * HWC2_PFN_GET_DISPLAY_CONFIGS
701          */
702         virtual int32_t getDisplayConfigs(
703                 uint32_t* outNumConfigs,
704                 hwc2_config_t* outConfigs);
705 
706         /* getDisplayName(..., outSize, outName)
707          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_NAME
708          * HWC2_PFN_GET_DISPLAY_NAME
709          */
710         virtual int32_t getDisplayName(uint32_t* outSize, char* outName);
711 
712         /* getDisplayRequests(..., outDisplayRequests, outNumElements, outLayers,
713          *     outLayerRequests)
714          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_REQUESTS
715          * HWC2_PFN_GET_DISPLAY_REQUESTS
716          */
717         virtual int32_t getDisplayRequests(
718                 int32_t* /*hwc2_display_request_t*/ outDisplayRequests,
719                 uint32_t* outNumElements, hwc2_layer_t* outLayers,
720                 int32_t* /*hwc2_layer_request_t*/ outLayerRequests);
721 
722         /* getDisplayType(..., outType)
723          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_TYPE
724          * HWC2_PFN_GET_DISPLAY_TYPE
725          */
726         virtual int32_t getDisplayType(
727                 int32_t* /*hwc2_display_type_t*/ outType);
728         /* getDozeSupport(..., outSupport)
729          * Descriptor: HWC2_FUNCTION_GET_DOZE_SUPPORT
730          * HWC2_PFN_GET_DOZE_SUPPORT
731          */
732         virtual int32_t getDozeSupport(int32_t* outSupport);
733 
734         /* getReleaseFences(..., outNumElements, outLayers, outFences)
735          * Descriptor: HWC2_FUNCTION_GET_RELEASE_FENCES
736          * HWC2_PFN_GET_RELEASE_FENCES
737          */
738         virtual int32_t getReleaseFences(
739                 uint32_t* outNumElements,
740                 hwc2_layer_t* outLayers, int32_t* outFences);
741 
742         enum {
743             SKIP_ERR_NONE = 0,
744             SKIP_ERR_CONFIG_DISABLED,
745             SKIP_ERR_FIRST_FRAME,
746             SKIP_ERR_GEOMETRY_CHAGNED,
747             SKIP_ERR_HAS_CLIENT_COMP,
748             SKIP_ERR_SKIP_STATIC_CHANGED,
749             SKIP_ERR_HAS_REQUEST,
750             SKIP_ERR_DISP_NOT_CONNECTED,
751             SKIP_ERR_DISP_NOT_POWER_ON,
752             SKIP_ERR_FORCE_VALIDATE,
753             SKIP_ERR_INVALID_CLIENT_TARGET_BUFFER
754         };
755         virtual int32_t canSkipValidate();
756 
757         /* presentDisplay(..., outRetireFence)
758          * Descriptor: HWC2_FUNCTION_PRESENT_DISPLAY
759          * HWC2_PFN_PRESENT_DISPLAY
760          */
761         virtual int32_t presentDisplay(int32_t* outRetireFence);
762         virtual int32_t presentPostProcessing();
763 
764         /* setActiveConfig(..., config)
765          * Descriptor: HWC2_FUNCTION_SET_ACTIVE_CONFIG
766          * HWC2_PFN_SET_ACTIVE_CONFIG
767          */
768         virtual int32_t setActiveConfig(hwc2_config_t config);
769 
770         /* setClientTarget(..., target, acquireFence, dataspace)
771          * Descriptor: HWC2_FUNCTION_SET_CLIENT_TARGET
772          * HWC2_PFN_SET_CLIENT_TARGET
773          */
774         virtual int32_t setClientTarget(
775                 buffer_handle_t target,
776                 int32_t acquireFence, int32_t /*android_dataspace_t*/ dataspace);
777 
778         /* setColorTransform(..., matrix, hint)
779          * Descriptor: HWC2_FUNCTION_SET_COLOR_TRANSFORM
780          * HWC2_PFN_SET_COLOR_TRANSFORM
781          */
782         virtual int32_t setColorTransform(
783                 const float* matrix,
784                 int32_t /*android_color_transform_t*/ hint);
785 
786         /* setColorMode(..., mode)
787          * Descriptor: HWC2_FUNCTION_SET_COLOR_MODE
788          * HWC2_PFN_SET_COLOR_MODE
789          */
790         virtual int32_t setColorMode(
791                 int32_t /*android_color_mode_t*/ mode);
792 
793         /* setOutputBuffer(..., buffer, releaseFence)
794          * Descriptor: HWC2_FUNCTION_SET_OUTPUT_BUFFER
795          * HWC2_PFN_SET_OUTPUT_BUFFER
796          */
797         virtual int32_t setOutputBuffer(
798                 buffer_handle_t buffer,
799                 int32_t releaseFence);
800 
801         virtual int clearDisplay(bool needModeClear = false);
802 
803         /* setPowerMode(..., mode)
804          * Descriptor: HWC2_FUNCTION_SET_POWER_MODE
805          * HWC2_PFN_SET_POWER_MODE
806          */
807         virtual int32_t setPowerMode(
808                 int32_t /*hwc2_power_mode_t*/ mode);
809 
810         /* setVsyncEnabled(..., enabled)
811          * Descriptor: HWC2_FUNCTION_SET_VSYNC_ENABLED
812          * HWC2_PFN_SET_VSYNC_ENABLED
813          */
814         virtual int32_t setVsyncEnabled(
815                 int32_t /*hwc2_vsync_t*/ enabled);
816         int32_t setVsyncEnabledInternal(
817                 int32_t /*hwc2_vsync_t*/ enabled);
818 
819         /* validateDisplay(..., outNumTypes, outNumRequests)
820          * Descriptor: HWC2_FUNCTION_VALIDATE_DISPLAY
821          * HWC2_PFN_VALIDATE_DISPLAY
822          */
823         virtual int32_t validateDisplay(
824                 uint32_t* outNumTypes, uint32_t* outNumRequests);
825 
826         /* getHdrCapabilities(..., outNumTypes, outTypes, outMaxLuminance,
827          *     outMaxAverageLuminance, outMinLuminance)
828          * Descriptor: HWC2_FUNCTION_GET_HDR_CAPABILITIES
829          */
830         virtual int32_t getHdrCapabilities(uint32_t* outNumTypes, int32_t* /*android_hdr_t*/ outTypes, float* outMaxLuminance,
831                 float* outMaxAverageLuminance, float* outMinLuminance);
832 
833         virtual int32_t getRenderIntents(int32_t mode, uint32_t* outNumIntents,
834                 int32_t* /*android_render_intent_v1_1_t*/ outIntents);
835         virtual int32_t setColorModeWithRenderIntent(int32_t /*android_color_mode_t*/ mode,
836                 int32_t /*android_render_intent_v1_1_t */ intent);
837 
838         /* HWC 2.3 APIs */
839 
840         /* getDisplayIdentificationData(..., outPort, outDataSize, outData)
841          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_IDENTIFICATION_DATA
842          * Parameters:
843          *   outPort - the connector to which the display is connected;
844          *             pointer will be non-NULL
845          *   outDataSize - if outData is NULL, the size in bytes of the data which would
846          *       have been returned; if outData is not NULL, the size of outData, which
847          *       must not exceed the value stored in outDataSize prior to the call;
848          *       pointer will be non-NULL
849          *   outData - the EDID 1.3 blob identifying the display
850          *
851          * Returns HWC2_ERROR_NONE or one of the following errors:
852          *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
853          */
854         int32_t getDisplayIdentificationData(uint8_t* outPort,
855                 uint32_t* outDataSize, uint8_t* outData);
856 
857         /* getDisplayCapabilities(..., outCapabilities)
858          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_CAPABILITIES
859          * Parameters:
860          *   outNumCapabilities - if outCapabilities was nullptr, returns the number of capabilities
861          *       if outCapabilities was not nullptr, returns the number of capabilities stored in
862          *       outCapabilities, which must not exceed the value stored in outNumCapabilities prior
863          *       to the call; pointer will be non-NULL
864          *   outCapabilities - a list of supported capabilities.
865          *
866          * Returns HWC2_ERROR_NONE or one of the following errors:
867          *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
868          */
869         /* Capabilities
870            Invalid = HWC2_CAPABILITY_INVALID,
871            SidebandStream = HWC2_CAPABILITY_SIDEBAND_STREAM,
872            SkipClientColorTransform = HWC2_CAPABILITY_SKIP_CLIENT_COLOR_TRANSFORM,
873            PresentFenceIsNotReliable = HWC2_CAPABILITY_PRESENT_FENCE_IS_NOT_RELIABLE,
874            SkipValidate = HWC2_CAPABILITY_SKIP_VALIDATE,
875         */
876         int32_t getDisplayCapabilities(uint32_t* outNumCapabilities,
877                 uint32_t* outCapabilities);
878 
879         /* getDisplayBrightnessSupport(displayToken)
880          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_BRIGHTNESS_SUPPORT
881          * Parameters:
882          *   outSupport - whether the display supports operations.
883          *
884          * Returns HWC2_ERROR_NONE or one of the following errors:
885          *   HWC2_ERROR_BAD_DISPLAY when the display is invalid.
886          */
887         int32_t getDisplayBrightnessSupport(bool* outSupport);
888 
889         /* setDisplayBrightness(displayToken, brightnesss, waitPresent)
890          * Descriptor: HWC2_FUNCTION_SET_DISPLAY_BRIGHTNESS
891          * Parameters:
892          *   brightness - a number between 0.0f (minimum brightness) and 1.0f (maximum brightness), or
893          *          -1.0f to turn the backlight off.
894          *   waitPresent - apply this brightness change at next Present time.
895          *
896          * Returns HWC2_ERROR_NONE or one of the following errors:
897          *   HWC2_ERROR_BAD_DISPLAY   when the display is invalid, or
898          *   HWC2_ERROR_UNSUPPORTED   when brightness operations are not supported, or
899          *   HWC2_ERROR_BAD_PARAMETER when the brightness is invalid, or
900          *   HWC2_ERROR_NO_RESOURCES  when the brightness cannot be applied.
901          */
902         virtual int32_t setDisplayBrightness(float brightness, bool waitPresent = false);
903 
904         /* getDisplayConnectionType(..., outType)
905          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_CONNECTION_TYPE
906          * Optional for all HWC2 devices
907          *
908          * Returns whether the given physical display is internal or external.
909          *
910          * Parameters:
911          * outType - the connection type of the display; pointer will be non-NULL
912          *
913          * Returns HWC2_ERROR_NONE or one of the following errors:
914          * HWC2_ERROR_BAD_DISPLAY when the display is invalid or virtual.
915          */
916         int32_t getDisplayConnectionType(uint32_t* outType);
917 
918         /* getDisplayVsyncPeriod(..., outVsyncPeriods)
919          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_VSYNC_PERIOD
920          * Required for HWC2 devices for composer 2.4
921          *
922          * Retrieves which vsync period the display is currently using.
923          *
924          * If no display configuration is currently active, this function must
925          * return BAD_CONFIG. If a vsync period is about to change due to a
926          * setActiveConfigWithConstraints call, this function must return the current vsync period
927          * until the change has taken place.
928          *
929          * Parameters:
930          *     outVsyncPeriod - the current vsync period of the display.
931          *
932          * Returns HWC2_ERROR_NONE or one of the following errors:
933          *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
934          *   HWC2_ERROR_BAD_CONFIG - no configuration is currently active
935          */
936         int32_t getDisplayVsyncPeriod(hwc2_vsync_period_t* __unused outVsyncPeriod);
937 
938         /* setActiveConfigWithConstraints(...,
939          *                                config,
940          *                                vsyncPeriodChangeConstraints,
941          *                                outTimeline)
942          * Descriptor: HWC2_FUNCTION_SET_ACTIVE_CONFIG_WITH_CONSTRAINTS
943          * Required for HWC2 devices for composer 2.4
944          *
945          * Sets the active configuration and the refresh rate for this display.
946          * If the new config shares the same config group as the current config,
947          * only the vsync period shall change.
948          * Upon returning, the given display configuration, except vsync period, must be active and
949          * remain so until either this function is called again or the display is disconnected.
950          * When the display starts to refresh at the new vsync period, onVsync_2_4 callback must be
951          * called with the new vsync period.
952          *
953          * Parameters:
954          *     config - the new display configuration.
955          *     vsyncPeriodChangeConstraints - constraints required for changing vsync period:
956          *                                    desiredTimeNanos - the time in CLOCK_MONOTONIC after
957          *                                                       which the vsync period may change
958          *                                                       (i.e., the vsync period must not change
959          *                                                       before this time).
960          *                                    seamlessRequired - if true, requires that the vsync period
961          *                                                       change must happen seamlessly without
962          *                                                       a noticeable visual artifact.
963          *                                                       When the conditions change and it may be
964          *                                                       possible to change the vsync period
965          *                                                       seamlessly, HWC2_CALLBACK_SEAMLESS_POSSIBLE
966          *                                                       callback must be called to indicate that
967          *                                                       caller should retry.
968          *     outTimeline - the timeline for the vsync period change.
969          *
970          * Returns HWC2_ERROR_NONE or one of the following errors:
971          *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in.
972          *   HWC2_ERROR_BAD_CONFIG - an invalid configuration handle passed in.
973          *   HWC2_ERROR_SEAMLESS_NOT_ALLOWED - when seamlessRequired was true but config provided doesn't
974          *                                 share the same config group as the current config.
975          *   HWC2_ERROR_SEAMLESS_NOT_POSSIBLE - when seamlessRequired was true but the display cannot
976          *                                      achieve the vsync period change without a noticeable
977          *                                      visual artifact.
978          */
979         int32_t setActiveConfigWithConstraints(hwc2_config_t __unused config,
980                 hwc_vsync_period_change_constraints_t* __unused vsyncPeriodChangeConstraints,
981                 hwc_vsync_period_change_timeline_t* __unused outTimeline);
982 
983         /**
984          * setBootDisplayConfig(..., config)
985          * Descriptor: HWC2_FUNCTION_SET_BOOT_DISPLAY_CONFIG
986          * Optional for HWC2 devices
987          *
988          * Sets the display config in which the device boots.
989          * If the device is unable to boot in this config for any reason (example HDMI display
990          * changed), the implementation should try to find a config which matches the resolution
991          * and refresh-rate of this config. If no such config exists, the implementation's
992          * preferred display config should be used.
993          *
994          * See also:
995          *     getPreferredBootDisplayConfig
996          *
997          * Parameters:
998          *     config - is the new boot time config for the display.
999          *
1000          * Returns HWC2_ERROR_NONE or one of the following errors:
1001          *     HWC2_ERROR_BAD_DISPLAY - when the display is invalid
1002          *     HWC2_ERROR_BAD_CONFIG - when the configuration is invalid
1003          *     HWC2_ERROR_UNSUPPORTED - when the display does not support boot display config
1004          */
1005         virtual int32_t setBootDisplayConfig(int32_t config);
1006 
1007         /**
1008          * clearBootDisplayConfig(...)
1009          * Descriptor: HWC2_FUNCTION_CLEAR_BOOT_DISPLAY_CONFIG
1010          * Optional for HWC2 devices
1011          *
1012          * Clears the boot display config.
1013          * The device should boot in the implementation's preferred display config.
1014          *
1015          * Returns HWC2_ERROR_NONE or one of the following errors:
1016          *     HWC2_ERROR_BAD_DISPLAY - when the display is invalid
1017          *     HWC2_ERROR_UNSUPPORTED - when the display does not support boot display config
1018          */
1019         virtual int32_t clearBootDisplayConfig();
1020 
1021         /**
1022          * getPreferredBootDisplayConfig(..., config*)
1023          * Descriptor: HWC2_FUNCTION_GET_PREFERRED_DISPLAY_CONFIG
1024          * Optional for HWC2 devices
1025          *
1026          * Returns the implementation's preferred display config.
1027          * This is display config used by the implementation at boot time, if the boot
1028          * display config has not been requested yet, or if it has been previously cleared.
1029          *
1030          * See also:
1031          *     setBootDisplayConfig
1032          *
1033          * Parameters:
1034          *     outConfig - is the implementation's preferred display config
1035          *
1036          * Returns HWC2_ERROR_NONE or one of the following errors:
1037          *     HWC2_ERROR_BAD_DISPLAY - when the display is invalid
1038          *     HWC2_ERROR_BAD_CONFIG - when the configuration is invalid
1039          *     HWC2_ERROR_UNSUPPORTED - when the display does not support boot display config
1040          */
1041         int32_t getPreferredBootDisplayConfig(int32_t* outConfig);
1042 
1043         virtual int32_t getPreferredDisplayConfigInternal(int32_t* outConfig);
1044 
1045         /* setAutoLowLatencyMode(displayToken, on)
1046          * Descriptor: HWC2_FUNCTION_SET_AUTO_LOW_LATENCY_MODE
1047          * Optional for HWC2 devices
1048          *
1049          * setAutoLowLatencyMode requests that the display goes into low latency mode. If the display
1050          * is connected via HDMI 2.1, then Auto Low Latency Mode should be triggered. If the display is
1051          * internally connected, then a custom low latency mode should be triggered (if available).
1052          *
1053          * Parameters:
1054          *   on - indicates whether to turn low latency mode on (=true) or off (=false)
1055          *
1056          * Returns HWC2_ERROR_NONE or one of the following errors:
1057          *   HWC2_ERROR_BAD_DISPLAY - when the display is invalid, or
1058          *   HWC2_ERROR_UNSUPPORTED - when the display does not support any low latency mode
1059          */
1060         int32_t setAutoLowLatencyMode(bool __unused on);
1061 
1062         /* getSupportedContentTypes(..., outSupportedContentTypes)
1063          * Descriptor: HWC2_FUNCTION_GET_SUPPORTED_CONTENT_TYPES
1064          * Optional for HWC2 devices
1065          *
1066          * getSupportedContentTypes returns a list of supported content types
1067          * (as described in the definition of ContentType above).
1068          * This list must not change after initialization.
1069          *
1070          * Parameters:
1071          *   outNumSupportedContentTypes - if outSupportedContentTypes was nullptr, returns the number
1072          *       of supported content types; if outSupportedContentTypes was not nullptr, returns the
1073          *       number of capabilities stored in outSupportedContentTypes, which must not exceed the
1074          *       value stored in outNumSupportedContentTypes prior to the call; pointer will be non-NULL
1075          *   outSupportedContentTypes - a list of supported content types.
1076          *
1077          * Returns HWC2_ERROR_NONE or one of the following errors:
1078          *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
1079          */
1080         int32_t getSupportedContentTypes(uint32_t* __unused outNumSupportedContentTypes,
1081                 uint32_t* __unused outSupportedContentTypes);
1082 
1083         /* setContentType(displayToken, contentType)
1084          * Descriptor: HWC2_FUNCTION_SET_CONTENT_TYPE
1085          * Optional for HWC2 devices
1086          *
1087          * setContentType instructs the display that the content being shown is of the given contentType
1088          * (one of GRAPHICS, PHOTO, CINEMA, GAME).
1089          *
1090          * According to the HDMI 1.4 specification, supporting all content types is optional. Whether
1091          * the display supports a given content type is reported by getSupportedContentTypes.
1092          *
1093          * Parameters:
1094          *   contentType - the type of content that is currently being shown on the display
1095          *
1096          * Returns HWC2_ERROR_NONE or one of the following errors:
1097          *   HWC2_ERROR_BAD_DISPLAY - when the display is invalid, or
1098          *   HWC2_ERROR_UNSUPPORTED - when the given content type is a valid content type, but is not
1099          *                            supported on this display, or
1100          *   HWC2_ERROR_BAD_PARAMETER - when the given content type is invalid
1101          */
1102         int32_t setContentType(int32_t /* hwc2_content_type_t */ __unused contentType);
1103 
1104         /* getClientTargetProperty(..., outClientTargetProperty)
1105          * Descriptor: HWC2_FUNCTION_GET_CLIENT_TARGET_PROPERTY
1106          * Optional for HWC2 devices
1107          *
1108          * Retrieves the client target properties for which the hardware composer
1109          * requests after the last call to validateDisplay. The client must set the
1110          * properties of the client target to match the returned values.
1111          * When this API is implemented, if client composition is needed, the hardware
1112          * composer must return meaningful client target property with dataspace not
1113          * setting to UNKNOWN.
1114          * When the returned dataspace is set to UNKNOWN, it means hardware composer
1115          * requests nothing, the client must ignore the returned client target property
1116          * structrue.
1117          *
1118          * Parameters:
1119          *   outClientTargetProperty - the client target properties that hardware
1120          *       composer requests. If dataspace field is set to UNKNOWN, it means
1121          *       the hardware composer requests nothing, the client must ignore the
1122          *       returned client target property structure.
1123          *   outDimmingStage - where should the SDR dimming happen. HWC3 only.
1124          * Returns HWC2_ERROR_NONE or one of the following errors:
1125          *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
1126          *   HWC2_ERROR_NOT_VALIDATED - validateDisplay has not been called for this
1127          *       display
1128          */
1129         virtual int32_t getClientTargetProperty(
1130                 hwc_client_target_property_t* outClientTargetProperty,
1131                 HwcDimmingStage *outDimmingStage = nullptr);
1132 
1133         /*
1134          * HWC3
1135          *
1136          * Execute any pending brightness changes.
1137          */
1138         int32_t flushDisplayBrightnessChange();
1139 
1140         /*
1141          * HWC3
1142          *
1143          * Get display mount orientation.
1144          *
1145          */
1146         int32_t getMountOrientation(HwcMountOrientation *orientation);
1147 
1148         /* setActiveConfig MISCs */
1149         bool isBadConfig(hwc2_config_t config);
1150         bool needNotChangeConfig(hwc2_config_t config);
1151         int32_t updateInternalDisplayConfigVariables(
1152                 hwc2_config_t config, bool updateVsync = true);
1153         int32_t resetConfigRequestStateLocked(hwc2_config_t config);
1154         int32_t updateConfigRequestAppliedTime();
1155         int32_t updateVsyncAppliedTimeLine(int64_t actualChangeTime);
1156         int32_t getDisplayVsyncPeriodInternal(
1157                 hwc2_vsync_period_t* outVsyncPeriod);
1158         virtual int32_t doDisplayConfigInternal(hwc2_config_t config);
1159         int32_t doDisplayConfigPostProcess(ExynosDevice *dev);
1160         int32_t getConfigAppliedTime(const uint64_t desiredTime,
1161                 const uint64_t actualChangeTime,
1162                 int64_t &appliedTime, int64_t &refreshTime);
1163         void updateBtsVsyncPeriod(uint32_t vsyncPeriod, bool configApplied = false);
1164         uint32_t getBtsRefreshRate() const;
checkBtsReassignResource(const uint32_t __unused vsyncPeriod,const uint32_t __unused btsVsyncPeriod)1165         virtual void checkBtsReassignResource(const uint32_t __unused vsyncPeriod,
1166                                               const uint32_t __unused btsVsyncPeriod) {}
1167 
1168         /* TODO : TBD */
1169         int32_t setCursorPositionAsync(uint32_t x_pos, uint32_t y_pos);
1170 
1171         int32_t getReadbackBufferAttributes(int32_t* /*android_pixel_format_t*/ outFormat,
1172                 int32_t* /*android_dataspace_t*/ outDataspace);
1173         int32_t setReadbackBuffer(buffer_handle_t buffer, int32_t releaseFence, bool requestedService = false);
1174         void setReadbackBufferInternal(buffer_handle_t buffer, int32_t releaseFence, bool requestedService = false);
1175         int32_t getReadbackBufferFence(int32_t* outFence);
1176         /* This function is called by ExynosDisplayInterface class to set acquire fence*/
1177         int32_t setReadbackBufferAcqFence(int32_t acqFence);
1178 
1179         virtual void dump(String8& result);
1180 
1181         virtual int32_t startPostProcessing();
1182 
1183         void dumpConfig(const exynos_win_config_data &c);
1184         void dumpConfig(String8 &result, const exynos_win_config_data &c);
1185         void printConfig(exynos_win_config_data &c);
1186 
1187         unsigned int getLayerRegion(ExynosLayer *layer,
1188                 hwc_rect *rect_area, uint32_t regionType);
1189 
1190         int handleWindowUpdate();
1191         bool windowUpdateExceptions();
1192 
1193         /* For debugging */
setHWC1LayerList(hwc_display_contents_1_t * contents)1194         void setHWC1LayerList(hwc_display_contents_1_t *contents) {mHWC1LayerList = contents;};
1195         void traceLayerTypes();
1196 
1197         bool validateExynosCompositionLayer();
1198         void printDebugInfos(String8 &reason);
1199 
1200         bool checkConfigChanged(const exynos_dpu_data &lastConfigsData,
1201                 const exynos_dpu_data &newConfigsData);
1202         int checkConfigDstChanged(const exynos_dpu_data &lastConfigData,
1203                 const exynos_dpu_data &newConfigData, uint32_t index);
1204 
1205         uint32_t getRestrictionIndex(int halFormat);
1206         void closeFences();
1207         void closeFencesForSkipFrame(rendering_state renderingState);
1208 
1209         int32_t getLayerCompositionTypeForValidationType(uint32_t layerIndex);
1210         void setHWCControl(uint32_t ctrl, int32_t val);
1211         void setGeometryChanged(uint64_t changedBit);
1212         void clearGeometryChanged();
1213 
1214         virtual void setDDIScalerEnable(int width, int height);
1215         virtual int getDDIScalerMode(int width, int height);
1216         void increaseMPPDstBufIndex();
1217         virtual void initDisplayInterface(uint32_t interfaceType);
updateColorConversionInfo()1218         virtual int32_t updateColorConversionInfo() { return NO_ERROR; };
resetColorMappingInfo(ExynosMPPSource *)1219         virtual int32_t resetColorMappingInfo(ExynosMPPSource* /*mppSrc*/) { return NO_ERROR; }
updatePresentColorConversionInfo()1220         virtual int32_t updatePresentColorConversionInfo() { return NO_ERROR; };
checkRrCompensationEnabled()1221         virtual bool checkRrCompensationEnabled() { return false; };
isColorCalibratedByDevice()1222         virtual bool isColorCalibratedByDevice() { return false; };
getColorAdjustedDbv(uint32_t &)1223         virtual int32_t getColorAdjustedDbv(uint32_t &) { return NO_ERROR; }
1224 
SetCurrentPanelGammaSource(const displaycolor::DisplayType,const PanelGammaSource &)1225         virtual int32_t SetCurrentPanelGammaSource(const displaycolor::DisplayType /* type */,
1226                                                    const PanelGammaSource& /* source */) {
1227             return HWC2_ERROR_UNSUPPORTED;
1228         }
GetCurrentPanelGammaSource()1229         virtual PanelGammaSource GetCurrentPanelGammaSource() const {
1230             return PanelGammaSource::GAMMA_DEFAULT;
1231         }
initLbe()1232         virtual void initLbe(){};
isLbeSupported()1233         virtual bool isLbeSupported() { return false; }
setLbeState(LbeState __unused state)1234         virtual void setLbeState(LbeState __unused state) {}
setLbeAmbientLight(int __unused value)1235         virtual void setLbeAmbientLight(int __unused value) {}
getLbeState()1236         virtual LbeState getLbeState() { return LbeState::OFF; }
1237 
1238         int32_t checkPowerHalExtHintSupport(const std::string& mode);
1239 
isLhbmSupported()1240         virtual bool isLhbmSupported() { return false; }
setLhbmState(bool __unused enabled)1241         virtual int32_t setLhbmState(bool __unused enabled) { return NO_ERROR; }
getLhbmState()1242         virtual bool getLhbmState() { return false; };
setEarlyWakeupDisplay()1243         virtual void setEarlyWakeupDisplay() {}
setExpectedPresentTime(uint64_t __unused timestamp)1244         virtual void setExpectedPresentTime(uint64_t __unused timestamp) {}
getPendingExpectedPresentTime()1245         virtual uint64_t getPendingExpectedPresentTime() { return 0; }
applyExpectedPresentTime()1246         virtual void applyExpectedPresentTime() {}
1247         virtual int32_t getDisplayIdleTimerSupport(bool& outSupport);
1248         virtual int32_t getDisplayMultiThreadedPresentSupport(bool& outSupport);
setDisplayIdleTimer(const int32_t __unused timeoutMs)1249         virtual int32_t setDisplayIdleTimer(const int32_t __unused timeoutMs) {
1250             return HWC2_ERROR_UNSUPPORTED;
1251         }
handleDisplayIdleEnter(const uint32_t __unused idleTeRefreshRate)1252         virtual void handleDisplayIdleEnter(const uint32_t __unused idleTeRefreshRate) {}
1253 
getPanelCalibrationStatus()1254         virtual PanelCalibrationStatus getPanelCalibrationStatus() {
1255             return PanelCalibrationStatus::UNCALIBRATED;
1256         }
isDbmSupported()1257         virtual bool isDbmSupported() { return false; }
setDbmState(bool __unused enabled)1258         virtual int32_t setDbmState(bool __unused enabled) { return NO_ERROR; }
1259 
1260         /* getDisplayPreAssignBit support mIndex up to 1.
1261            It supports only dual LCD and 2 external displays */
getDisplayPreAssignBit()1262         inline uint32_t getDisplayPreAssignBit() {
1263             uint32_t type = SECOND_DISPLAY_START_BIT * mIndex + mType;
1264             return 1 << type;
1265         }
1266 
1267         void cleanupAfterClientDeath();
1268         int32_t getRCDLayerSupport(bool& outSupport) const;
1269         int32_t setDebugRCDLayerEnabled(bool enable);
1270 
1271         /* ignore / accept brightness update requests */
1272         virtual int32_t ignoreBrightnessUpdateRequests(bool ignore);
1273 
1274         /* set brightness to specific nits value */
1275         virtual int32_t setBrightnessNits(const float nits);
1276 
1277         /* set brightness by dbv value */
1278         virtual int32_t setBrightnessDbv(const uint32_t dbv);
1279 
1280     protected:
1281         virtual bool getHDRException(ExynosLayer *layer);
1282         virtual int32_t getActiveConfigInternal(hwc2_config_t* outConfig);
1283         virtual int32_t setActiveConfigInternal(hwc2_config_t config, bool force);
1284 
1285         void updateRefreshRateHint();
1286         bool isFullScreenComposition();
1287 
1288     public:
1289         /**
1290          * This will be initialized with differnt class
1291          * that inherits ExynosDisplayInterface according to
1292          * interface type.
1293          */
1294         std::unique_ptr<ExynosDisplayInterface> mDisplayInterface;
1295         void requestLhbm(bool on);
1296 
setMinIdleRefreshRate(const int __unused fps,const VrrThrottleRequester __unused requester)1297         virtual int setMinIdleRefreshRate(const int __unused fps,
1298                                           const VrrThrottleRequester __unused requester) {
1299             return NO_ERROR;
1300         }
setRefreshRateThrottleNanos(const int64_t __unused delayNanos,const VrrThrottleRequester __unused requester)1301         virtual int setRefreshRateThrottleNanos(const int64_t __unused delayNanos,
1302                                                 const VrrThrottleRequester __unused requester) {
1303             return NO_ERROR;
1304         }
1305 
updateAppliedActiveConfig(const hwc2_config_t,const int64_t)1306         virtual void updateAppliedActiveConfig(const hwc2_config_t /*newConfig*/,
1307                                                const int64_t /*ts*/) {}
1308 
isConfigSettingEnabled()1309         virtual bool isConfigSettingEnabled() { return true; }
enableConfigSetting(bool)1310         virtual void enableConfigSetting(bool /*en*/) {}
1311 
1312         // is the hint session both enabled and supported
1313         bool usePowerHintSession();
1314 
setPeakRefreshRate(float rr)1315         void setPeakRefreshRate(float rr) { mPeakRefreshRate = rr; }
1316         uint32_t getPeakRefreshRate();
1317         VsyncPeriodNanos getVsyncPeriod(const int32_t config);
1318         uint32_t getRefreshRate(const int32_t config);
1319         uint32_t getConfigId(const int32_t refreshRate, const int32_t width, const int32_t height);
1320 
1321         // check if there are any dimmed layers
1322         bool isMixedComposition();
isPriorFrameMixedCompostion()1323         bool isPriorFrameMixedCompostion() { return mPriorFrameMixedComposition; }
1324         int lookupDisplayConfigs(const int32_t& width,
1325                                  const int32_t& height,
1326                                  const int32_t& fps,
1327                                  int32_t* outConfig);
1328 
1329     private:
1330         bool skipStaticLayerChanged(ExynosCompositionInfo& compositionInfo);
1331 
1332         bool skipSignalIdle();
1333 
1334         /// minimum possible dim rate in the case hbm peak is 1000 nits and norml
1335         // display brightness is 2 nits
1336         static constexpr float kGhbmMinDimRatio = 0.002;
1337 
1338         /// consider HDR as full screen playback when its frame coverage
1339         //exceeds this threshold.
1340         static constexpr float kHdrFullScreen = 0.5;
1341         uint32_t mHdrFullScrenAreaThreshold;
1342 
1343         // peak refresh rate
1344         float mPeakRefreshRate = -1.0f;
1345 
1346         // track if the last frame is a mixed composition, to detect mixed
1347         // composition to non-mixed composition transition.
1348         bool mPriorFrameMixedComposition;
1349 
1350         /* Display hint to notify power hal */
1351         class PowerHalHintWorker : public Worker {
1352         public:
1353             PowerHalHintWorker(uint32_t displayId, const String8& displayTraceName);
1354             virtual ~PowerHalHintWorker();
1355             int Init();
1356 
1357             void signalRefreshRate(hwc2_power_mode_t powerMode, uint32_t vsyncPeriod);
1358             void signalIdle();
1359             void signalActualWorkDuration(nsecs_t actualDurationNanos);
1360             void signalTargetWorkDuration(nsecs_t targetDurationNanos);
1361 
1362             void addBinderTid(pid_t tid);
1363             void removeBinderTid(pid_t tid);
1364 
1365             bool signalStartHintSession();
1366             void trackThisThread();
1367 
1368             // is the hint session both enabled and supported
1369             bool usePowerHintSession();
1370             // is it known if the hint session is enabled + supported yet
1371             bool checkPowerHintSessionReady();
1372 
1373         protected:
1374             void Routine() override;
1375 
1376         private:
1377             static void BinderDiedCallback(void*);
1378             int32_t connectPowerHal();
1379             int32_t connectPowerHalExt();
1380             int32_t checkPowerHalExtHintSupport(const std::string& mode);
1381             int32_t sendPowerHalExtHint(const std::string& mode, bool enabled);
1382 
1383             int32_t checkRefreshRateHintSupport(int refreshRate);
1384             int32_t updateRefreshRateHintInternal(hwc2_power_mode_t powerMode,
1385                                                   uint32_t vsyncPeriod);
1386             int32_t sendRefreshRateHint(int refreshRate, bool enabled);
1387             void forceUpdateHints();
1388 
1389             int32_t checkIdleHintSupport();
1390             int32_t updateIdleHint(int64_t deadlineTime, bool forceUpdate);
1391             bool needUpdateIdleHintLocked(int64_t& timeout) REQUIRES(mutex_);
1392 
1393             // for adpf cpu hints
1394             int32_t sendActualWorkDuration();
1395             int32_t updateTargetWorkDuration();
1396 
1397             // Update checking methods
1398             bool needUpdateTargetWorkDurationLocked() REQUIRES(mutex_);
1399             bool needSendActualWorkDurationLocked() REQUIRES(mutex_);
1400 
1401             // is it known if the hint session is enabled + supported yet
1402             bool checkPowerHintSessionReadyLocked();
1403             // Hint session lifecycle management
1404             int32_t startHintSession();
1405 
1406             int32_t checkPowerHintSessionSupport();
1407             bool mNeedUpdateRefreshRateHint;
1408 
1409             // The last refresh rate hint that is still being enabled
1410             // If all refresh rate hints are disabled, then mLastRefreshRateHint = 0
1411             int mLastRefreshRateHint;
1412 
1413             // support list of refresh rate hints
1414             std::map<int, bool> mRefreshRateHintSupportMap;
1415 
1416             bool mIdleHintIsEnabled;
1417             bool mForceUpdateIdleHint;
1418             int64_t mIdleHintDeadlineTime;
1419 
1420             // whether idle hint support is checked
1421             bool mIdleHintSupportIsChecked;
1422 
1423             // whether idle hint is supported
1424             bool mIdleHintIsSupported;
1425 
1426             String8 mDisplayTraceName;
1427             std::string mIdleHintStr;
1428             std::string mRefreshRateHintPrefixStr;
1429 
1430             hwc2_power_mode_t mPowerModeState;
1431             uint32_t mVsyncPeriod;
1432 
1433             uint32_t mConnectRetryCount;
isPowerHalExist()1434             bool isPowerHalExist() { return mConnectRetryCount < 10; }
1435 
1436             ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
1437 
1438             // for power HAL extension hints
1439             std::shared_ptr<aidl::google::hardware::power::extension::pixel::IPowerExt>
1440                     mPowerHalExtAidl;
1441 
1442             // for normal power HAL hints
1443             std::shared_ptr<aidl::android::hardware::power::IPower> mPowerHalAidl;
1444             // Max amount the error term can vary without causing an actual value report,
1445             // as well as the target durations if not normalized
1446             static constexpr const std::chrono::nanoseconds kAllowedDeviation = 300us;
1447             // Target value used for initialization and normalization,
1448             // the actual value does not really matter
1449             static constexpr const std::chrono::nanoseconds kDefaultTarget = 50ms;
1450             // Whether to normalize all the actual values as error terms relative to a constant
1451             // target. This saves a binder call by not setting the target
1452             static const bool sNormalizeTarget;
1453             // Whether we should emit ATRACE_INT data for hint sessions
1454             static const bool sTraceHintSessionData;
1455             // Whether we use or disable the rate limiter for target and actual values
1456             static const bool sUseRateLimiter;
1457             std::shared_ptr<aidl::android::hardware::power::IPowerHintSession> mPowerHintSession;
1458             // queue of actual durations waiting to be reported
1459             std::vector<WorkDuration> mPowerHintQueue;
1460             // display-specific binder thread tids
1461             std::set<pid_t> mBinderTids;
1462             // indicates that the tid list has changed, so the session must be rebuilt
1463             bool mTidsUpdated = false;
1464 
1465             static std::mutex sSharedDisplayMutex;
1466             struct SharedDisplayData {
1467                 std::optional<bool> hintSessionEnabled;
1468                 std::optional<int32_t> hintSessionSupported;
1469             };
1470             // caches the output of usePowerHintSession to avoid sSharedDisplayMutex
1471             std::atomic<std::optional<bool>> mUsePowerHintSession{std::nullopt};
1472             // this lets us know if we can skip calling checkPowerHintSessionSupport
1473             bool mHintSessionSupportChecked = false;
1474             // used to indicate to all displays whether hint sessions are enabled/supported
1475             static SharedDisplayData sSharedDisplayData GUARDED_BY(sSharedDisplayMutex);
1476             // latest target that was signalled
1477             nsecs_t mTargetWorkDuration = kDefaultTarget.count();
1478             // last target duration reported to PowerHAL
1479             nsecs_t mLastTargetDurationReported = kDefaultTarget.count();
1480             // latest actual duration signalled
1481             std::optional<nsecs_t> mActualWorkDuration;
1482             // last error term reported to PowerHAL, used for rate limiting
1483             std::optional<nsecs_t> mLastErrorSent;
1484             // timestamp of the last report we sent, used to avoid stale sessions
1485             nsecs_t mLastActualReportTimestamp = 0;
1486             // amount of time after the last message was sent before the session goes stale
1487             // actually 100ms but we use 80 here to ideally avoid going stale
1488             static constexpr const std::chrono::nanoseconds kStaleTimeout = 80ms;
1489             // An adjustable safety margin which moves the "target" earlier to allow flinger to
1490             // go a bit over without dropping a frame, especially since we can't measure
1491             // the exact time HWC finishes composition so "actual" durations are measured
1492             // from the end of present() instead, which is a bit later.
1493             static constexpr const std::chrono::nanoseconds kTargetSafetyMargin = 2ms;
1494         };
1495 
1496         // union here permits use as a key in the unordered_map without a custom hash
1497         union AveragesKey {
1498             struct {
1499                 uint16_t layers;
1500                 bool validated;
1501                 bool beforeReleaseFence;
1502             };
1503             uint32_t value;
AveragesKey(size_t layers,bool validated,bool beforeReleaseFence)1504             AveragesKey(size_t layers, bool validated, bool beforeReleaseFence)
1505                   : layers(static_cast<uint16_t>(layers)),
1506                     validated(validated),
1507                     beforeReleaseFence(beforeReleaseFence) {}
uint32_t()1508             operator uint32_t() const { return value; }
1509         };
1510 
1511         static const constexpr int kAveragesBufferSize = 3;
1512         static const constexpr nsecs_t SIGNAL_TIME_PENDING = INT64_MAX;
1513         static const constexpr nsecs_t SIGNAL_TIME_INVALID = -1;
1514         std::unordered_map<uint32_t, RollingAverage<kAveragesBufferSize>> mRollingAverages;
1515         // mPowerHalHint should be declared only after mDisplayId and mDisplayTraceName have been
1516         // declared since mDisplayId and mDisplayTraceName are needed as the parameter of
1517         // PowerHalHintWorker's constructor
1518         PowerHalHintWorker mPowerHalHint;
1519 
1520         std::optional<nsecs_t> mValidateStartTime;
1521         nsecs_t mPresentStartTime;
1522         std::optional<nsecs_t> mValidationDuration;
1523         // cached value used to skip evaluation once set
1524         std::optional<bool> mUsePowerHintSession;
1525         // tracks the time right before we start to wait for the fence
1526         std::optional<nsecs_t> mRetireFenceWaitTime;
1527         // tracks the time right after we finish waiting for the fence
1528         std::optional<nsecs_t> mRetireFenceAcquireTime;
1529         // tracks the time when the retire fence previously signaled
1530         std::optional<nsecs_t> mRetireFencePreviousSignalTime;
1531         // tracks the expected present time of the last frame
1532         std::optional<nsecs_t> mLastExpectedPresentTime;
1533         // tracks the expected present time of the current frame
1534         nsecs_t mExpectedPresentTime;
1535         // set once at the start of composition to ensure consistency
1536         bool mUsePowerHints = false;
1537         nsecs_t getExpectedPresentTime(nsecs_t startTime);
1538         nsecs_t getPredictedPresentTime(nsecs_t startTime);
1539         nsecs_t getSignalTime(int32_t fd) const;
1540         void updateAverages(nsecs_t endTime);
1541         std::optional<nsecs_t> getPredictedDuration(bool duringValidation);
1542         atomic_bool mDebugRCDLayerEnabled = true;
1543 
1544     protected:
getDisplayVsyncPeriodFromConfig(hwc2_config_t config)1545         inline uint32_t getDisplayVsyncPeriodFromConfig(hwc2_config_t config) {
1546             int32_t vsync_period;
1547             getDisplayAttribute(config, HWC2_ATTRIBUTE_VSYNC_PERIOD, &vsync_period);
1548             assert(vsync_period > 0);
1549             return static_cast<uint32_t>(vsync_period);
1550         }
1551 
1552         virtual void calculateTimeline(
1553                 hwc2_config_t config,
1554                 hwc_vsync_period_change_constraints_t* vsyncPeriodChangeConstraints,
1555                 hwc_vsync_period_change_timeline_t* outTimeline);
1556 
1557     public:
1558         /* Override for each display's meaning of 'enabled state'
1559          * Primary : Power on, this function overrided in primary display module
1560          * Exteranal : Plug-in, default */
isEnabled()1561         virtual bool isEnabled() { return mPlugState; }
1562 
1563         // Resource TDM (Time-Division Multiplexing)
1564         std::map<std::pair<int32_t, int32_t>, DisplayTDMInfo> mDisplayTDMInfo;
1565 
1566         class RotatingLogFileWriter {
1567         public:
1568             RotatingLogFileWriter(uint32_t maxFileCount, uint32_t thresholdSizePerFile,
1569                                   std::string extension = ".txt")
mMaxFileCount(maxFileCount)1570                   : mMaxFileCount(maxFileCount),
1571                     mThresholdSizePerFile(thresholdSizePerFile),
1572                     mPrefixName(""),
1573                     mExtension(extension),
1574                     mLastFileIndex(-1),
1575                     mFile(nullptr) {}
1576 
~RotatingLogFileWriter()1577             ~RotatingLogFileWriter() {
1578                 if (mFile) {
1579                     fclose(mFile);
1580                 }
1581             }
1582 
1583             bool chooseOpenedFile();
write(const String8 & content)1584             void write(const String8& content) {
1585                 if (mFile) {
1586                     fwrite(content.string(), 1, content.size(), mFile);
1587                 }
1588             }
flush()1589             void flush() {
1590                 if (mFile) {
1591                     fflush(mFile);
1592                 }
1593             }
setPrefixName(const std::string & prefixName)1594             void setPrefixName(const std::string& prefixName) { mPrefixName = prefixName; }
1595 
1596         private:
1597             FILE* openLogFile(const std::string& filename, const std::string& mode);
1598             std::optional<nsecs_t> getLastModifiedTimestamp(const std::string& filename);
1599 
1600             uint32_t mMaxFileCount;
1601             uint32_t mThresholdSizePerFile;
1602             std::string mPrefixName;
1603             std::string mExtension;
1604             int32_t mLastFileIndex;
1605             FILE* mFile;
1606         };
1607         RotatingLogFileWriter mErrLogFileWriter;
1608         RotatingLogFileWriter mDebugDumpFileWriter;
1609         RotatingLogFileWriter mFenceFileWriter;
1610 
1611     protected:
1612         class OperationRateManager {
1613         public:
OperationRateManager()1614             OperationRateManager() {}
~OperationRateManager()1615             virtual ~OperationRateManager() {}
1616 
onLowPowerMode(bool __unused enabled)1617             virtual int32_t onLowPowerMode(bool __unused enabled) { return 0; }
onPeakRefreshRate(uint32_t __unused rate)1618             virtual int32_t onPeakRefreshRate(uint32_t __unused rate) { return 0; }
onConfig(hwc2_config_t __unused cfg)1619             virtual int32_t onConfig(hwc2_config_t __unused cfg) { return 0; }
onBrightness(uint32_t __unused dbv)1620             virtual int32_t onBrightness(uint32_t __unused dbv) { return 0; }
onPowerMode(int32_t __unused mode)1621             virtual int32_t onPowerMode(int32_t __unused mode) { return 0; }
getTargetOperationRate()1622             virtual int32_t getTargetOperationRate() { return 0; }
1623         };
1624 
1625     public:
1626         std::unique_ptr<OperationRateManager> mOperationRateManager;
isOperationRateSupported()1627         bool isOperationRateSupported() { return mOperationRateManager != nullptr; }
1628         void handleTargetOperationRate();
1629 
1630         bool mHpdStatus;
1631 
1632         void invalidate();
1633         virtual bool checkHotplugEventUpdated(bool &hpdStatus);
1634         virtual void handleHotplugEvent(bool hpdStatus);
1635         virtual void hotplug();
1636 
1637         class RefreshRateIndicatorHandler : public DrmSysfsEventHandler {
1638         public:
1639             RefreshRateIndicatorHandler(ExynosDisplay* display);
1640             int32_t init();
1641             virtual void handleSysfsEvent() override;
getFd()1642             virtual int getFd() override { return mFd.get(); };
isIgnoringLastUpdate()1643             bool isIgnoringLastUpdate() { return mIgnoringLastUpdate; }
1644             void updateRefreshRate(int refreshRate);
1645 
1646         private:
1647             void updateRefreshRateLocked(int refreshRate) REQUIRES(mMutex);
1648 
1649             ExynosDisplay* mDisplay;
1650             int mLastRefreshRate GUARDED_BY(mMutex);
1651             nsecs_t mLastCallbackTime GUARDED_BY(mMutex);
1652             std::atomic_bool mIgnoringLastUpdate = false;
1653             bool mCanIgnoreIncreaseUpdate GUARDED_BY(mMutex) = false;
1654             UniqueFd mFd;
1655             std::mutex mMutex;
1656 
1657             static constexpr auto kRefreshRateStatePathFormat =
1658                     "/sys/class/backlight/panel%d-backlight/state";
1659         };
1660 
1661         std::shared_ptr<RefreshRateIndicatorHandler> mRefreshRateIndicatorHandler;
1662         int32_t setRefreshRateChangedCallbackDebugEnabled(bool enabled);
1663         void updateRefreshRateIndicator();
1664         nsecs_t getLastLayerUpdateTime();
1665         bool needUpdateRRIndicator();
checkPreblendingRequirement()1666         virtual void checkPreblendingRequirement(){};
1667 
1668         void resetColorMappingInfoForClientComp();
1669         void storePrevValidateCompositionType();
1670 };
1671 
1672 #endif //_EXYNOSDISPLAY_H
1673