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 "ExynosDisplayInterface.h"
27 #include "ExynosHWC.h"
28 #include "ExynosHWCDebug.h"
29 #include "ExynosHWCHelper.h"
30 #include "ExynosMPP.h"
31 #include "ExynosResourceManager.h"
32 #include "worker.h"
33 
34 #define HWC_CLEARDISPLAY_WITH_COLORMAP
35 #define HWC_PRINT_FRAME_NUM     10
36 
37 #define LOW_FPS_THRESHOLD     5
38 #define MAX_BRIGHTNESS_LEN 5
39 
40 using ::android::hardware::graphics::composer::V2_4::VsyncPeriodNanos;
41 
42 #ifndef SECOND_DISPLAY_START_BIT
43 #define SECOND_DISPLAY_START_BIT   4
44 #endif
45 
46 typedef hwc2_composition_t exynos_composition;
47 
48 class ExynosLayer;
49 class ExynosDevice;
50 class ExynosMPP;
51 class ExynosMPPSource;
52 
53 namespace aidl {
54 namespace google {
55 namespace hardware {
56 namespace power {
57 namespace extension {
58 namespace pixel {
59 
60 class IPowerExt;
61 
62 } // namespace pixel
63 } // namespace extension
64 } // namespace power
65 } // namespace hardware
66 } // namespace google
67 } // namespace aidl
68 
69 enum dynamic_recomp_mode {
70     NO_MODE_SWITCH,
71     DEVICE_2_CLIENT,
72     CLIENT_2_DEVICE
73 };
74 
75 enum rendering_state {
76     RENDERING_STATE_NONE = 0,
77     RENDERING_STATE_VALIDATED,
78     RENDERING_STATE_ACCEPTED_CHANGE,
79     RENDERING_STATE_PRESENTED,
80     RENDERING_STATE_MAX
81 };
82 
83 enum composition_type {
84     COMPOSITION_NONE = 0,
85     COMPOSITION_CLIENT,
86     COMPOSITION_EXYNOS,
87     COMPOSITION_MAX
88 };
89 
90 enum {
91     PSR_NONE = 0,
92     PSR_DP,
93     PSR_MIPI,
94     PSR_MAX,
95 };
96 
97 enum {
98     PANEL_LEGACY = 0,
99     PANEL_DSC,
100     PANEL_MIC,
101 };
102 
103 enum {
104     eDisplayNone     = 0x0,
105     ePrimaryDisplay  = 0x00000001,
106     eExternalDisplay = 0x00000002,
107     eVirtualDisplay  = 0x00000004,
108 };
109 
110 // served as extension of hwc2_power_mode_t for use with setPowerMode
111 enum class ext_hwc2_power_mode_t{
112     PAUSE = 10,
113     RESUME,
114 };
115 
116 enum class PanelGammaSource {
117     GAMMA_DEFAULT,     // Resotre gamma table to default
118     GAMMA_CALIBRATION, // Update gamma table from calibration file
119     GAMMA_TYPES,
120 };
121 
122 enum class hwc_request_state_t {
123     SET_CONFIG_STATE_NONE = 0,
124     SET_CONFIG_STATE_PENDING,
125     SET_CONFIG_STATE_REQUESTED,
126 };
127 
128 #define NUM_SKIP_STATIC_LAYER  5
129 struct ExynosFrameInfo
130 {
131     uint32_t srcNum;
132     exynos_image srcInfo[NUM_SKIP_STATIC_LAYER];
133     exynos_image dstInfo[NUM_SKIP_STATIC_LAYER];
134 };
135 
136 struct exynos_readback_info
137 {
138     buffer_handle_t handle = NULL;
139     /* release sync fence file descriptor,
140      * which will be signaled when it is safe to write to the output buffer.
141      */
142     int rel_fence = -1;
143     /* acquire sync fence file descriptor which will signal when the
144      * buffer provided to setReadbackBuffer has been filled by the device and is
145      * safe for the client to read.
146      */
147     int acq_fence = -1;
148     /* Requested from HWCService */
149     bool requested_from_service = false;
150 };
151 
152 struct exynos_win_config_data
153 {
154     enum {
155         WIN_STATE_DISABLED = 0,
156         WIN_STATE_COLOR,
157         WIN_STATE_BUFFER,
158         WIN_STATE_UPDATE,
159         WIN_STATE_CURSOR,
160     } state = WIN_STATE_DISABLED;
161 
162     uint32_t color = 0;
163     const ExynosLayer* layer = nullptr;
164     uint64_t buffer_id = 0;
165     int fd_idma[3] = {-1, -1, -1};
166     int acq_fence = -1;
167     int rel_fence = -1;
168     float plane_alpha = 1;
169     int32_t blending = HWC2_BLEND_MODE_NONE;
170     ExynosMPP* assignedMPP = NULL;
171     int format = 0;
172     uint32_t transform = 0;
173     android_dataspace dataspace = HAL_DATASPACE_UNKNOWN;
174     bool hdr_enable = false;
175     enum dpp_comp_src comp_src = DPP_COMP_SRC_NONE;
176     uint32_t min_luminance = 0;
177     uint32_t max_luminance = 0;
178     struct decon_win_rect block_area = { 0, 0, 0, 0};
179     struct decon_win_rect transparent_area = {0, 0, 0, 0};
180     struct decon_win_rect opaque_area = {0, 0, 0, 0};
181     struct decon_frame src = {0, 0, 0, 0, 0, 0};
182     struct decon_frame dst = {0, 0, 0, 0, 0, 0};
183     bool protection = false;
184     bool compression = false;
185     bool needColorTransform = false;
186 
resetexynos_win_config_data187     void reset(){
188         *this = {};
189     };
190 };
191 struct exynos_dpu_data
192 {
193     int retire_fence = -1;
194     std::vector<exynos_win_config_data> configs;
195     bool enable_win_update = false;
196     std::atomic<bool> enable_readback = false;
197     struct decon_frame win_update_region = {0, 0, 0, 0, 0, 0};
198     struct exynos_readback_info readback_info;
199 
initexynos_dpu_data200     void init(uint32_t configNum) {
201         for(uint32_t i = 0; i < configNum; i++)
202         {
203             exynos_win_config_data config_data;
204             configs.push_back(config_data);
205         }
206     };
207 
resetexynos_dpu_data208     void reset() {
209         retire_fence = -1;
210         for (uint32_t i = 0; i < configs.size(); i++)
211             configs[i].reset();
212 
213         /*
214          * Should not initialize readback_info
215          * readback_info should be initialized after present
216          */
217     };
218     exynos_dpu_data& operator =(const exynos_dpu_data &configs_data){
219         retire_fence = configs_data.retire_fence;
220         if (configs.size() != configs_data.configs.size()) {
221             HWC_LOGE(NULL, "invalid config, it has different configs size");
222             return *this;
223         }
224         configs = configs_data.configs;
225         return *this;
226     };
227 };
228 
229 class ExynosLowFpsLayerInfo
230 {
231     public:
232         ExynosLowFpsLayerInfo();
233         bool mHasLowFpsLayer;
234         int32_t mFirstIndex;
235         int32_t mLastIndex;
236 
237         void initializeInfos();
238         int32_t addLowFpsLayer(uint32_t layerIndex);
239 };
240 
241 class ExynosSortedLayer : public Vector <ExynosLayer*>
242 {
243     public:
244         ssize_t remove(const ExynosLayer *item);
245         status_t vector_sort();
246         static int compare(ExynosLayer * const *lhs, ExynosLayer *const *rhs);
247 };
248 
249 class ExynosCompositionInfo : public ExynosMPPSource {
250     public:
ExynosCompositionInfo()251         ExynosCompositionInfo():ExynosCompositionInfo(COMPOSITION_NONE){};
252         ExynosCompositionInfo(uint32_t type);
253         uint32_t mType;
254         bool mHasCompositionLayer;
255         int32_t mFirstIndex;
256         int32_t mLastIndex;
257         buffer_handle_t mTargetBuffer;
258         android_dataspace mDataSpace;
259         int32_t mAcquireFence;
260         int32_t mReleaseFence;
261         bool mEnableSkipStatic;
262         bool mSkipStaticInitFlag;
263         bool mSkipFlag;
264         ExynosFrameInfo mSkipSrcInfo;
265         exynos_win_config_data mLastWinConfigData;
266 
267         int32_t mWindowIndex;
268         bool mCompressed;
269 
270         void initializeInfos(ExynosDisplay *display);
271         void setTargetBuffer(ExynosDisplay *display, buffer_handle_t handle,
272                 int32_t acquireFence, android_dataspace dataspace);
273         void setCompressed(bool compressed);
274         bool getCompressed();
275         void dump(String8& result);
276         String8 getTypeStr();
277 };
278 
279 // Prepare multi-resolution
280 struct ResolutionSize {
281     uint32_t w;
282     uint32_t h;
283 };
284 
285 struct ResolutionInfo {
286     uint32_t nNum;
287     ResolutionSize nResolution[3];
288     uint32_t nDSCYSliceSize[3];
289     uint32_t nDSCXSliceSize[3];
290     int      nPanelType[3];
291 };
292 
293 typedef struct displayConfigs {
294     // HWC2_ATTRIBUTE_VSYNC_PERIOD
295     VsyncPeriodNanos vsyncPeriod;
296     // HWC2_ATTRIBUTE_WIDTH
297     uint32_t width;
298     // case HWC2_ATTRIBUTE_HEIGHT
299     uint32_t height;
300     // HWC2_ATTRIBUTE_DPI_X
301     uint32_t Xdpi;
302     // HWC2_ATTRIBUTE_DPI_Y
303     uint32_t Ydpi;
304     // HWC2_ATTRIBUTE_CONFIG_GROUP
305     uint32_t groupId;
306 } displayConfigs_t;
307 
308 struct DisplayControl {
309     /** Composition crop en/disable **/
310     bool enableCompositionCrop;
311     /** Resource assignment optimization for exynos composition **/
312     bool enableExynosCompositionOptimization;
313     /** Resource assignment optimization for client composition **/
314     bool enableClientCompositionOptimization;
315     /** Use G2D as much as possible **/
316     bool useMaxG2DSrc;
317     /** Low fps layer optimization **/
318     bool handleLowFpsLayers;
319     /** start m2mMPP before persentDisplay **/
320     bool earlyStartMPP;
321     /** Adjust display size of the layer having high priority */
322     bool adjustDisplayFrame;
323     /** setCursorPosition support **/
324     bool cursorSupport;
325     /** readback support **/
326     bool readbackSupport = false;
327     /** Reserve MPP regardless of plug state **/
328     bool forceReserveMPP = false;
329     /** Skip M2MMPP processing **/
330     bool skipM2mProcessing = true;
331 };
332 
333 typedef struct brightnessState {
334     enum MipiSyncType {
335         MIPI_SYNC_NONE,
336         MIPI_SYNC_GHBM_ON,
337         MIPI_SYNC_GHBM_OFF,
338         MIPI_SYNC_LHBM_ON,
339         MIPI_SYNC_LHBM_OFF,
340     };
341     static constexpr size_t kNumofBrightnessState = 3;
342     static constexpr float kSdrDimRatioNone = 1.0;
343     union {
344         std::array<bool, kNumofBrightnessState> mData;
345         struct {
346             bool instant_hbm;
347             bool peak_hbm;
348             bool local_hbm;
349         };
350     };
351     /** dim ratio calculated from current layer stack but will be delayed to apply **/
352     float dim_sdr_target_ratio = kSdrDimRatioNone;
353     /** dim ratio to apply to current frame and is 'dim_delay' frames behind
354      * dim_sdr_target_ratio **/
355     float dim_sdr_ratio = kSdrDimRatioNone;
356 
357     // current Brightness value
358     float brightness_value;
359 
360     // HDR layer is covering most of the screen
361     bool hdr_full_screen;
362 
363     bool enhanced_hbm;
364 
resetbrightnessState365     void reset() {
366         mData = {false, false, false};
367         dim_sdr_target_ratio = kSdrDimRatioNone;
368         hdr_full_screen = false;
369     }
dimSdrTransitionbrightnessState370     bool dimSdrTransition() {
371         return dim_sdr_target_ratio != dim_sdr_ratio &&
372             (dim_sdr_target_ratio == kSdrDimRatioNone || dim_sdr_ratio == kSdrDimRatioNone);
373     }
374     brightnessState& operator=(const brightnessState& a) {
375         mData = a.mData;
376         dim_sdr_target_ratio = a.dim_sdr_target_ratio;
377         dim_sdr_ratio = a.dim_sdr_ratio;
378         brightness_value = a.brightness_value;
379         enhanced_hbm = a.enhanced_hbm;
380         return *this;
381     }
382     // TODO: add hdr_full_screen comparison
383     bool operator==(const brightnessState& a) const {
384         return a.mData == mData && a.dim_sdr_ratio == dim_sdr_ratio &&
385                 a.dim_sdr_target_ratio == dim_sdr_target_ratio &&
386                 a.brightness_value == brightness_value && a.enhanced_hbm == enhanced_hbm;
387     }
388 } brightnessState_t;
389 
390 class ExynosDisplay {
391     public:
392         uint32_t mDisplayId;
393         uint32_t mType;
394         uint32_t mIndex;
395         String8 mDeconNodeName;
396         uint32_t mXres;
397         uint32_t mYres;
398         uint32_t mXdpi;
399         uint32_t mYdpi;
400         uint32_t mVsyncPeriod;
401         uint32_t mBtsVsyncPeriod;
402 
403         int                     mPanelType;
404         int                     mPsrMode;
405 
406         /* Constructor */
407         ExynosDisplay(uint32_t index, ExynosDevice *device);
408         /* Destructor */
409         virtual ~ExynosDisplay();
410 
411         ExynosDevice *mDevice;
412 
413         String8 mDisplayName;
414 
415         Mutex mDisplayMutex;
416 
417         /** State variables */
418         bool mPlugState;
419         hwc2_power_mode_t mPowerModeState;
420         hwc2_vsync_t mVsyncState;
421         bool mHasSingleBuffer;
422         bool mPauseDisplay = false;
423 
424         DisplayControl mDisplayControl;
425 
426         /**
427          * TODO : Should be defined as ExynosLayer type
428          * Layer list those sorted by z-order
429          */
430         ExynosSortedLayer mLayers;
431         std::vector<ExynosLayer*> mIgnoreLayers;
432 
433         ExynosResourceManager *mResourceManager;
434 
435         /**
436          * Layer index, target buffer information for GLES.
437          */
438         ExynosCompositionInfo mClientCompositionInfo;
439 
440         /**
441          * Layer index, target buffer information for G2D.
442          */
443         ExynosCompositionInfo mExynosCompositionInfo;
444 
445         /**
446          * Geometry change info is described by bit map.
447          * This flag is cleared when resource assignment for all displays
448          * is done.
449          */
450         uint64_t  mGeometryChanged;
451 
452         /**
453          * Rendering step information that is seperated by
454          * VALIDATED, ACCEPTED_CHANGE, PRESENTED.
455          */
456         rendering_state  mRenderingState;
457 
458         /**
459          * Rendering step information that is called by client
460          */
461         rendering_state  mHWCRenderingState;
462 
463         /**
464          * Window total bandwidth by enabled window, It's used as dynamic re-composition enable/disable.
465          */
466         uint32_t  mDisplayBW;
467 
468         /**
469          * Mode information Dynamic re-composition feature.
470          * DEVICE_2_CLIENT: All layers are composited by GLES composition.
471          * CLIENT_2_DEVICE: Device composition.
472          */
473         dynamic_recomp_mode mDynamicReCompMode;
474         bool mDREnable;
475         bool mDRDefault;
476         Mutex mDRMutex;
477 
478         nsecs_t  mLastFpsTime;
479         uint64_t mFrameCount;
480         uint64_t mLastFrameCount;
481         uint64_t mErrorFrameCount;
482         uint64_t mLastModeSwitchTimeStamp;
483         uint64_t mLastUpdateTimeStamp;
484         uint64_t mUpdateEventCnt;
485         uint64_t mUpdateCallCnt;
486 
487         /* default DMA for the display */
488         decon_idma_type mDefaultDMA;
489 
490         /**
491          * DECON WIN_CONFIG information.
492          */
493         exynos_dpu_data mDpuData;
494 
495         /**
496          * Last win_config data is used as WIN_CONFIG skip decision or debugging.
497          */
498         exynos_dpu_data mLastDpuData;
499 
500         /**
501          * Restore release fenc from DECON.
502          */
503         int mLastRetireFence;
504 
505         bool mUseDpu;
506 
507         /**
508          * Max Window number, It should be set by display module(chip)
509          */
510         uint32_t mMaxWindowNum;
511         uint32_t mWindowNumUsed;
512         uint32_t mBaseWindowIndex;
513 
514         // Priority
515         uint32_t mNumMaxPriorityAllowed;
516         int32_t mCursorIndex;
517 
518         int32_t mColorTransformHint;
519 
520         ExynosLowFpsLayerInfo mLowFpsLayerInfo;
521 
522         // HDR capabilities
523         std::vector<int32_t> mHdrTypes;
524         float mMaxLuminance;
525         float mMaxAverageLuminance;
526         float mMinLuminance;
527 
528         /* For debugging */
529         hwc_display_contents_1_t *mHWC1LayerList;
530 
531         /* Support Multi-resolution scheme */
532         int mOldScalerMode;
533         int mNewScaledWidth;
534         int mNewScaledHeight;
535         int32_t mDeviceXres;
536         int32_t mDeviceYres;
537         ResolutionInfo mResolutionInfo;
538         std::map<uint32_t, displayConfigs_t> mDisplayConfigs;
539 
540         // WCG
541         android_color_mode_t mColorMode;
542 
543         // Skip present frame if there was no validate after power on
544         bool mSkipFrame;
545 
546         FILE *mBrightnessFd;
547         FILE *mEarlyWakeupFd;
548         uint32_t mMaxBrightness;
549 
550         hwc_vsync_period_change_constraints_t mVsyncPeriodChangeConstraints;
551         hwc_vsync_period_change_timeline_t mVsyncAppliedTimeLine;
552         hwc_request_state_t mConfigRequestState;
553         hwc2_config_t mDesiredConfig;
554 
555         hwc2_config_t mActiveConfig = UINT_MAX;
556 
557         void initDisplay();
558 
559         int getId();
getDisplayMutex()560         Mutex& getDisplayMutex() {return mDisplayMutex; };
561 
562         int32_t setCompositionTargetExynosImage(uint32_t targetType, exynos_image *src_img, exynos_image *dst_img);
563         int32_t initializeValidateInfos();
564         int32_t addClientCompositionLayer(uint32_t layerIndex);
565         int32_t removeClientCompositionLayer(uint32_t layerIndex);
566         int32_t addExynosCompositionLayer(uint32_t layerIndex);
567 
568         /**
569          * Dynamic AFBC Control solution : To get the prepared information is applied to current or not.
570          */
571         bool comparePreferedLayers();
572 
573         /**
574          * @param *outLayer
575          */
576         int32_t destroyLayer(hwc2_layer_t outLayer);
577 
578         void destroyLayers();
579 
580         ExynosLayer *checkLayer(hwc2_layer_t addr);
581 
582         void checkIgnoreLayers();
583         virtual void doPreProcessing();
584 
585         int checkLayerFps();
586 
587         int checkDynamicReCompMode();
588 
589         int handleDynamicReCompMode();
590 
591         void updateBrightnessState();
592 
593         /**
594          * @param compositionType
595          */
596         int skipStaticLayers(ExynosCompositionInfo& compositionInfo);
597         int handleStaticLayers(ExynosCompositionInfo& compositionInfo);
598 
599         int doPostProcessing();
600 
601         int doExynosComposition();
602 
603         int32_t configureOverlay(ExynosLayer *layer, exynos_win_config_data &cfg);
604         int32_t configureOverlay(ExynosCompositionInfo &compositionInfo);
605 
606         int32_t configureHandle(ExynosLayer &layer,  int fence_fd, exynos_win_config_data &cfg);
607 
608         virtual int setWinConfigData();
609 
610         virtual int setDisplayWinConfigData();
611 
612         virtual int32_t validateWinConfigData();
613 
614         virtual int deliverWinConfigData();
615 
616         virtual int setReleaseFences();
617 
618         virtual bool checkFrameValidation();
619 
620         /**
621          * Display Functions for HWC 2.0
622          */
623 
624         /**
625          * Descriptor: HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES
626          * HWC2_PFN_ACCEPT_DISPLAY_CHANGES
627          **/
628         virtual int32_t acceptDisplayChanges();
629 
630         /**
631          * Descriptor: HWC2_FUNCTION_CREATE_LAYER
632          * HWC2_PFN_CREATE_LAYER
633          */
634         virtual int32_t createLayer(hwc2_layer_t* outLayer);
635 
636         /**
637          * Descriptor: HWC2_FUNCTION_GET_ACTIVE_CONFIG
638          * HWC2_PFN_GET_ACTIVE_CONFIG
639          */
640         virtual int32_t getActiveConfig(hwc2_config_t* outConfig);
641 
642         /**
643          * Descriptor: HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES
644          * HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES
645          */
646         virtual int32_t getChangedCompositionTypes(
647                 uint32_t* outNumElements, hwc2_layer_t* outLayers,
648                 int32_t* /*hwc2_composition_t*/ outTypes);
649 
650         /**
651          * Descriptor: HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT
652          * HWC2_PFN_GET_CLIENT_TARGET_SUPPORT
653          */
654         virtual int32_t getClientTargetSupport(
655                 uint32_t width, uint32_t height,
656                 int32_t /*android_pixel_format_t*/ format,
657                 int32_t /*android_dataspace_t*/ dataspace);
658 
659         /**
660          * Descriptor: HWC2_FUNCTION_GET_COLOR_MODES
661          * HWC2_PFN_GET_COLOR_MODES
662          */
663         virtual int32_t getColorModes(
664                 uint32_t* outNumModes,
665                 int32_t* /*android_color_mode_t*/ outModes);
666 
667         /* getDisplayAttribute(..., config, attribute, outValue)
668          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE
669          * HWC2_PFN_GET_DISPLAY_ATTRIBUTE
670          */
671         virtual int32_t getDisplayAttribute(
672                 hwc2_config_t config,
673                 int32_t /*hwc2_attribute_t*/ attribute, int32_t* outValue);
674 
675         /* getDisplayConfigs(..., outNumConfigs, outConfigs)
676          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_CONFIGS
677          * HWC2_PFN_GET_DISPLAY_CONFIGS
678          */
679         virtual int32_t getDisplayConfigs(
680                 uint32_t* outNumConfigs,
681                 hwc2_config_t* outConfigs);
682 
683         /* getDisplayName(..., outSize, outName)
684          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_NAME
685          * HWC2_PFN_GET_DISPLAY_NAME
686          */
687         virtual int32_t getDisplayName(uint32_t* outSize, char* outName);
688 
689         /* getDisplayRequests(..., outDisplayRequests, outNumElements, outLayers,
690          *     outLayerRequests)
691          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_REQUESTS
692          * HWC2_PFN_GET_DISPLAY_REQUESTS
693          */
694         virtual int32_t getDisplayRequests(
695                 int32_t* /*hwc2_display_request_t*/ outDisplayRequests,
696                 uint32_t* outNumElements, hwc2_layer_t* outLayers,
697                 int32_t* /*hwc2_layer_request_t*/ outLayerRequests);
698 
699         /* getDisplayType(..., outType)
700          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_TYPE
701          * HWC2_PFN_GET_DISPLAY_TYPE
702          */
703         virtual int32_t getDisplayType(
704                 int32_t* /*hwc2_display_type_t*/ outType);
705         /* getDozeSupport(..., outSupport)
706          * Descriptor: HWC2_FUNCTION_GET_DOZE_SUPPORT
707          * HWC2_PFN_GET_DOZE_SUPPORT
708          */
709         virtual int32_t getDozeSupport(int32_t* outSupport);
710 
711         /* getReleaseFences(..., outNumElements, outLayers, outFences)
712          * Descriptor: HWC2_FUNCTION_GET_RELEASE_FENCES
713          * HWC2_PFN_GET_RELEASE_FENCES
714          */
715         virtual int32_t getReleaseFences(
716                 uint32_t* outNumElements,
717                 hwc2_layer_t* outLayers, int32_t* outFences);
718 
719         enum {
720             SKIP_ERR_NONE = 0,
721             SKIP_ERR_CONFIG_DISABLED,
722             SKIP_ERR_FIRST_FRAME,
723             SKIP_ERR_GEOMETRY_CHAGNED,
724             SKIP_ERR_HAS_CLIENT_COMP,
725             SKIP_ERR_SKIP_STATIC_CHANGED,
726             SKIP_ERR_HAS_REQUEST,
727             SKIP_ERR_DISP_NOT_CONNECTED,
728             SKIP_ERR_DISP_NOT_POWER_ON,
729             SKIP_ERR_FORCE_VALIDATE,
730             SKIP_ERR_INVALID_CLIENT_TARGET_BUFFER
731         };
732         virtual int32_t canSkipValidate();
733 
734         /* presentDisplay(..., outRetireFence)
735          * Descriptor: HWC2_FUNCTION_PRESENT_DISPLAY
736          * HWC2_PFN_PRESENT_DISPLAY
737          */
738         virtual int32_t presentDisplay(int32_t* outRetireFence);
739         virtual int32_t presentPostProcessing();
740 
741         /* setActiveConfig(..., config)
742          * Descriptor: HWC2_FUNCTION_SET_ACTIVE_CONFIG
743          * HWC2_PFN_SET_ACTIVE_CONFIG
744          */
745         virtual int32_t setActiveConfig(hwc2_config_t config);
746 
747         /* setClientTarget(..., target, acquireFence, dataspace)
748          * Descriptor: HWC2_FUNCTION_SET_CLIENT_TARGET
749          * HWC2_PFN_SET_CLIENT_TARGET
750          */
751         virtual int32_t setClientTarget(
752                 buffer_handle_t target,
753                 int32_t acquireFence, int32_t /*android_dataspace_t*/ dataspace);
754 
755         /* setColorTransform(..., matrix, hint)
756          * Descriptor: HWC2_FUNCTION_SET_COLOR_TRANSFORM
757          * HWC2_PFN_SET_COLOR_TRANSFORM
758          */
759         virtual int32_t setColorTransform(
760                 const float* matrix,
761                 int32_t /*android_color_transform_t*/ hint);
762 
763         /* setColorMode(..., mode)
764          * Descriptor: HWC2_FUNCTION_SET_COLOR_MODE
765          * HWC2_PFN_SET_COLOR_MODE
766          */
767         virtual int32_t setColorMode(
768                 int32_t /*android_color_mode_t*/ mode);
769 
770         /* setOutputBuffer(..., buffer, releaseFence)
771          * Descriptor: HWC2_FUNCTION_SET_OUTPUT_BUFFER
772          * HWC2_PFN_SET_OUTPUT_BUFFER
773          */
774         virtual int32_t setOutputBuffer(
775                 buffer_handle_t buffer,
776                 int32_t releaseFence);
777 
778         virtual int clearDisplay(bool needModeClear = false);
779 
780         /* setPowerMode(..., mode)
781          * Descriptor: HWC2_FUNCTION_SET_POWER_MODE
782          * HWC2_PFN_SET_POWER_MODE
783          */
784         virtual int32_t setPowerMode(
785                 int32_t /*hwc2_power_mode_t*/ mode);
786 
787         /* setVsyncEnabled(..., enabled)
788          * Descriptor: HWC2_FUNCTION_SET_VSYNC_ENABLED
789          * HWC2_PFN_SET_VSYNC_ENABLED
790          */
791         virtual int32_t setVsyncEnabled(
792                 int32_t /*hwc2_vsync_t*/ enabled);
793         int32_t setVsyncEnabledInternal(
794                 int32_t /*hwc2_vsync_t*/ enabled);
795 
796         /* validateDisplay(..., outNumTypes, outNumRequests)
797          * Descriptor: HWC2_FUNCTION_VALIDATE_DISPLAY
798          * HWC2_PFN_VALIDATE_DISPLAY
799          */
800         virtual int32_t validateDisplay(
801                 uint32_t* outNumTypes, uint32_t* outNumRequests);
802 
803         /* getHdrCapabilities(..., outNumTypes, outTypes, outMaxLuminance,
804          *     outMaxAverageLuminance, outMinLuminance)
805          * Descriptor: HWC2_FUNCTION_GET_HDR_CAPABILITIES
806          */
807         virtual int32_t getHdrCapabilities(uint32_t* outNumTypes, int32_t* /*android_hdr_t*/ outTypes, float* outMaxLuminance,
808                 float* outMaxAverageLuminance, float* outMinLuminance);
809 
810         virtual int32_t getRenderIntents(int32_t mode, uint32_t* outNumIntents,
811                 int32_t* /*android_render_intent_v1_1_t*/ outIntents);
812         virtual int32_t setColorModeWithRenderIntent(int32_t /*android_color_mode_t*/ mode,
813                 int32_t /*android_render_intent_v1_1_t */ intent);
814 
815         /* HWC 2.3 APIs */
816 
817         /* getDisplayIdentificationData(..., outPort, outDataSize, outData)
818          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_IDENTIFICATION_DATA
819          * Parameters:
820          *   outPort - the connector to which the display is connected;
821          *             pointer will be non-NULL
822          *   outDataSize - if outData is NULL, the size in bytes of the data which would
823          *       have been returned; if outData is not NULL, the size of outData, which
824          *       must not exceed the value stored in outDataSize prior to the call;
825          *       pointer will be non-NULL
826          *   outData - the EDID 1.3 blob identifying the display
827          *
828          * Returns HWC2_ERROR_NONE or one of the following errors:
829          *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
830          */
831         int32_t getDisplayIdentificationData(uint8_t* outPort,
832                 uint32_t* outDataSize, uint8_t* outData);
833 
834         /* getDisplayCapabilities(..., outCapabilities)
835          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_CAPABILITIES
836          * Parameters:
837          *   outNumCapabilities - if outCapabilities was nullptr, returns the number of capabilities
838          *       if outCapabilities was not nullptr, returns the number of capabilities stored in
839          *       outCapabilities, which must not exceed the value stored in outNumCapabilities prior
840          *       to the call; pointer will be non-NULL
841          *   outCapabilities - a list of supported capabilities.
842          *
843          * Returns HWC2_ERROR_NONE or one of the following errors:
844          *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
845          */
846         /* Capabilities
847            Invalid = HWC2_CAPABILITY_INVALID,
848            SidebandStream = HWC2_CAPABILITY_SIDEBAND_STREAM,
849            SkipClientColorTransform = HWC2_CAPABILITY_SKIP_CLIENT_COLOR_TRANSFORM,
850            PresentFenceIsNotReliable = HWC2_CAPABILITY_PRESENT_FENCE_IS_NOT_RELIABLE,
851            SkipValidate = HWC2_CAPABILITY_SKIP_VALIDATE,
852         */
853         int32_t getDisplayCapabilities(uint32_t* outNumCapabilities,
854                 uint32_t* outCapabilities);
855 
856         /* getDisplayBrightnessSupport(displayToken)
857          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_BRIGHTNESS_SUPPORT
858          * Parameters:
859          *   outSupport - whether the display supports operations.
860          *
861          * Returns HWC2_ERROR_NONE or one of the following errors:
862          *   HWC2_ERROR_BAD_DISPLAY when the display is invalid.
863          */
864         int32_t getDisplayBrightnessSupport(bool* outSupport);
865 
866         /* setDisplayBrightness(displayToken, brightnesss)
867          * Descriptor: HWC2_FUNCTION_SET_DISPLAY_BRIGHTNESS
868          * Parameters:
869          *   brightness - a number between 0.0f (minimum brightness) and 1.0f (maximum brightness), or
870          *          -1.0f to turn the backlight off.
871          *
872          * Returns HWC2_ERROR_NONE or one of the following errors:
873          *   HWC2_ERROR_BAD_DISPLAY   when the display is invalid, or
874          *   HWC2_ERROR_UNSUPPORTED   when brightness operations are not supported, or
875          *   HWC2_ERROR_BAD_PARAMETER when the brightness is invalid, or
876          *   HWC2_ERROR_NO_RESOURCES  when the brightness cannot be applied.
877          */
878         virtual int32_t setDisplayBrightness(float brightness);
879 
880         /* getDisplayConnectionType(..., outType)
881          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_CONNECTION_TYPE
882          * Optional for all HWC2 devices
883          *
884          * Returns whether the given physical display is internal or external.
885          *
886          * Parameters:
887          * outType - the connection type of the display; pointer will be non-NULL
888          *
889          * Returns HWC2_ERROR_NONE or one of the following errors:
890          * HWC2_ERROR_BAD_DISPLAY when the display is invalid or virtual.
891          */
892         int32_t getDisplayConnectionType(uint32_t* outType);
893 
894         /* getDisplayVsyncPeriod(..., outVsyncPeriods)
895          * Descriptor: HWC2_FUNCTION_GET_DISPLAY_VSYNC_PERIOD
896          * Required for HWC2 devices for composer 2.4
897          *
898          * Retrieves which vsync period the display is currently using.
899          *
900          * If no display configuration is currently active, this function must
901          * return BAD_CONFIG. If a vsync period is about to change due to a
902          * setActiveConfigWithConstraints call, this function must return the current vsync period
903          * until the change has taken place.
904          *
905          * Parameters:
906          *     outVsyncPeriod - the current vsync period of the display.
907          *
908          * Returns HWC2_ERROR_NONE or one of the following errors:
909          *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
910          *   HWC2_ERROR_BAD_CONFIG - no configuration is currently active
911          */
912         int32_t getDisplayVsyncPeriod(hwc2_vsync_period_t* __unused outVsyncPeriod);
913 
914         /* setActiveConfigWithConstraints(...,
915          *                                config,
916          *                                vsyncPeriodChangeConstraints,
917          *                                outTimeline)
918          * Descriptor: HWC2_FUNCTION_SET_ACTIVE_CONFIG_WITH_CONSTRAINTS
919          * Required for HWC2 devices for composer 2.4
920          *
921          * Sets the active configuration and the refresh rate for this display.
922          * If the new config shares the same config group as the current config,
923          * only the vsync period shall change.
924          * Upon returning, the given display configuration, except vsync period, must be active and
925          * remain so until either this function is called again or the display is disconnected.
926          * When the display starts to refresh at the new vsync period, onVsync_2_4 callback must be
927          * called with the new vsync period.
928          *
929          * Parameters:
930          *     config - the new display configuration.
931          *     vsyncPeriodChangeConstraints - constraints required for changing vsync period:
932          *                                    desiredTimeNanos - the time in CLOCK_MONOTONIC after
933          *                                                       which the vsync period may change
934          *                                                       (i.e., the vsync period must not change
935          *                                                       before this time).
936          *                                    seamlessRequired - if true, requires that the vsync period
937          *                                                       change must happen seamlessly without
938          *                                                       a noticeable visual artifact.
939          *                                                       When the conditions change and it may be
940          *                                                       possible to change the vsync period
941          *                                                       seamlessly, HWC2_CALLBACK_SEAMLESS_POSSIBLE
942          *                                                       callback must be called to indicate that
943          *                                                       caller should retry.
944          *     outTimeline - the timeline for the vsync period change.
945          *
946          * Returns HWC2_ERROR_NONE or one of the following errors:
947          *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in.
948          *   HWC2_ERROR_BAD_CONFIG - an invalid configuration handle passed in.
949          *   HWC2_ERROR_SEAMLESS_NOT_ALLOWED - when seamlessRequired was true but config provided doesn't
950          *                                 share the same config group as the current config.
951          *   HWC2_ERROR_SEAMLESS_NOT_POSSIBLE - when seamlessRequired was true but the display cannot
952          *                                      achieve the vsync period change without a noticeable
953          *                                      visual artifact.
954          */
955         int32_t setActiveConfigWithConstraints(hwc2_config_t __unused config,
956                 hwc_vsync_period_change_constraints_t* __unused vsyncPeriodChangeConstraints,
957                 hwc_vsync_period_change_timeline_t* __unused outTimeline);
958 
959         /* setAutoLowLatencyMode(displayToken, on)
960          * Descriptor: HWC2_FUNCTION_SET_AUTO_LOW_LATENCY_MODE
961          * Optional for HWC2 devices
962          *
963          * setAutoLowLatencyMode requests that the display goes into low latency mode. If the display
964          * is connected via HDMI 2.1, then Auto Low Latency Mode should be triggered. If the display is
965          * internally connected, then a custom low latency mode should be triggered (if available).
966          *
967          * Parameters:
968          *   on - indicates whether to turn low latency mode on (=true) or off (=false)
969          *
970          * Returns HWC2_ERROR_NONE or one of the following errors:
971          *   HWC2_ERROR_BAD_DISPLAY - when the display is invalid, or
972          *   HWC2_ERROR_UNSUPPORTED - when the display does not support any low latency mode
973          */
974         int32_t setAutoLowLatencyMode(bool __unused on);
975 
976         /* getSupportedContentTypes(..., outSupportedContentTypes)
977          * Descriptor: HWC2_FUNCTION_GET_SUPPORTED_CONTENT_TYPES
978          * Optional for HWC2 devices
979          *
980          * getSupportedContentTypes returns a list of supported content types
981          * (as described in the definition of ContentType above).
982          * This list must not change after initialization.
983          *
984          * Parameters:
985          *   outNumSupportedContentTypes - if outSupportedContentTypes was nullptr, returns the number
986          *       of supported content types; if outSupportedContentTypes was not nullptr, returns the
987          *       number of capabilities stored in outSupportedContentTypes, which must not exceed the
988          *       value stored in outNumSupportedContentTypes prior to the call; pointer will be non-NULL
989          *   outSupportedContentTypes - a list of supported content types.
990          *
991          * Returns HWC2_ERROR_NONE or one of the following errors:
992          *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
993          */
994         int32_t getSupportedContentTypes(uint32_t* __unused outNumSupportedContentTypes,
995                 uint32_t* __unused outSupportedContentTypes);
996 
997         /* setContentType(displayToken, contentType)
998          * Descriptor: HWC2_FUNCTION_SET_CONTENT_TYPE
999          * Optional for HWC2 devices
1000          *
1001          * setContentType instructs the display that the content being shown is of the given contentType
1002          * (one of GRAPHICS, PHOTO, CINEMA, GAME).
1003          *
1004          * According to the HDMI 1.4 specification, supporting all content types is optional. Whether
1005          * the display supports a given content type is reported by getSupportedContentTypes.
1006          *
1007          * Parameters:
1008          *   contentType - the type of content that is currently being shown on the display
1009          *
1010          * Returns HWC2_ERROR_NONE or one of the following errors:
1011          *   HWC2_ERROR_BAD_DISPLAY - when the display is invalid, or
1012          *   HWC2_ERROR_UNSUPPORTED - when the given content type is a valid content type, but is not
1013          *                            supported on this display, or
1014          *   HWC2_ERROR_BAD_PARAMETER - when the given content type is invalid
1015          */
1016         int32_t setContentType(int32_t /* hwc2_content_type_t */ __unused contentType);
1017 
1018         /* getClientTargetProperty(..., outClientTargetProperty)
1019          * Descriptor: HWC2_FUNCTION_GET_CLIENT_TARGET_PROPERTY
1020          * Optional for HWC2 devices
1021          *
1022          * Retrieves the client target properties for which the hardware composer
1023          * requests after the last call to validateDisplay. The client must set the
1024          * properties of the client target to match the returned values.
1025          * When this API is implemented, if client composition is needed, the hardware
1026          * composer must return meaningful client target property with dataspace not
1027          * setting to UNKNOWN.
1028          * When the returned dataspace is set to UNKNOWN, it means hardware composer
1029          * requests nothing, the client must ignore the returned client target property
1030          * structrue.
1031          *
1032          * Parameters:
1033          *   outClientTargetProperty - the client target properties that hardware
1034          *       composer requests. If dataspace field is set to UNKNOWN, it means
1035          *       the hardware composer requests nothing, the client must ignore the
1036          *       returned client target property structure.
1037          *
1038          * Returns HWC2_ERROR_NONE or one of the following errors:
1039          *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
1040          *   HWC2_ERROR_NOT_VALIDATED - validateDisplay has not been called for this
1041          *       display
1042          */
1043         int32_t getClientTargetProperty(hwc_client_target_property_t* outClientTargetProperty);
1044 
1045         /* setActiveConfig MISCs */
1046         bool isBadConfig(hwc2_config_t config);
1047         bool needNotChangeConfig(hwc2_config_t config);
1048         int32_t updateInternalDisplayConfigVariables(
1049                 hwc2_config_t config, bool updateVsync = true);
1050         int32_t resetConfigRequestStateLocked();
1051         int32_t updateConfigRequestAppliedTime();
1052         int32_t updateVsyncAppliedTimeLine(int64_t actualChangeTime);
1053         int32_t getDisplayVsyncPeriodInternal(
1054                 hwc2_vsync_period_t* outVsyncPeriod);
1055         virtual int32_t doDisplayConfigInternal(hwc2_config_t config);
1056         int32_t doDisplayConfigPostProcess(ExynosDevice *dev);
1057         int32_t getConfigAppliedTime(const uint64_t desiredTime,
1058                 const uint64_t actualChangeTime,
1059                 int64_t &appliedTime, int64_t &refreshTime);
1060         void updateBtsVsyncPeriod(uint32_t vsyncPeriod, bool forceUpdate = false);
1061         uint32_t getBtsRefreshRate() const;
1062 
1063         /* TODO : TBD */
1064         int32_t setCursorPositionAsync(uint32_t x_pos, uint32_t y_pos);
1065 
1066         int32_t getReadbackBufferAttributes(int32_t* /*android_pixel_format_t*/ outFormat,
1067                 int32_t* /*android_dataspace_t*/ outDataspace);
1068         int32_t setReadbackBuffer(buffer_handle_t buffer, int32_t releaseFence, bool requestedService = false);
1069         void setReadbackBufferInternal(buffer_handle_t buffer, int32_t releaseFence, bool requestedService = false);
1070         int32_t getReadbackBufferFence(int32_t* outFence);
1071         /* This function is called by ExynosDisplayInterface class to set acquire fence*/
1072         int32_t setReadbackBufferAcqFence(int32_t acqFence);
1073 
1074         virtual void dump(String8& result);
1075 
1076         virtual int32_t startPostProcessing();
1077 
1078         void dumpConfig(const exynos_win_config_data &c);
1079         void dumpConfig(String8 &result, const exynos_win_config_data &c);
1080         void printConfig(exynos_win_config_data &c);
1081 
1082         unsigned int getLayerRegion(ExynosLayer *layer,
1083                 hwc_rect *rect_area, uint32_t regionType);
1084 
1085         int handleWindowUpdate();
1086         bool windowUpdateExceptions();
1087 
1088         /* For debugging */
setHWC1LayerList(hwc_display_contents_1_t * contents)1089         void setHWC1LayerList(hwc_display_contents_1_t *contents) {mHWC1LayerList = contents;};
1090         void traceLayerTypes();
1091 
1092         bool validateExynosCompositionLayer();
1093         void printDebugInfos(String8 &reason);
1094 
1095         bool checkConfigChanged(const exynos_dpu_data &lastConfigsData,
1096                 const exynos_dpu_data &newConfigsData);
1097         int checkConfigDstChanged(const exynos_dpu_data &lastConfigData,
1098                 const exynos_dpu_data &newConfigData, uint32_t index);
1099 
1100         uint32_t getRestrictionIndex(int halFormat);
1101         void closeFences();
1102         void closeFencesForSkipFrame(rendering_state renderingState);
1103 
1104         int32_t getLayerCompositionTypeForValidationType(uint32_t layerIndex);
1105         void setHWCControl(uint32_t ctrl, int32_t val);
1106         void setGeometryChanged(uint64_t changedBit);
1107         void clearGeometryChanged();
1108 
1109         virtual void setDDIScalerEnable(int width, int height);
1110         virtual int getDDIScalerMode(int width, int height);
1111         void increaseMPPDstBufIndex();
1112         virtual void initDisplayInterface(uint32_t interfaceType);
updateColorConversionInfo()1113         virtual int32_t updateColorConversionInfo() { return NO_ERROR; };
updatePresentColorConversionInfo()1114         virtual int32_t updatePresentColorConversionInfo() { return NO_ERROR; };
checkRrCompensationEnabled()1115         virtual bool checkRrCompensationEnabled() { return false; };
isColorCalibratedByDevice()1116         virtual bool isColorCalibratedByDevice() { return false; };
getColorAdjustedDbv(uint32_t &)1117         virtual int32_t getColorAdjustedDbv(uint32_t &) { return NO_ERROR; }
SetCurrentPanelGammaSource(const displaycolor::DisplayType,const PanelGammaSource &)1118         virtual int32_t SetCurrentPanelGammaSource(const displaycolor::DisplayType /* type */,
1119                                                    const PanelGammaSource& /* source */) {
1120             return HWC2_ERROR_UNSUPPORTED;
1121         }
GetCurrentPanelGammaSource()1122         virtual PanelGammaSource GetCurrentPanelGammaSource() const {
1123             return PanelGammaSource::GAMMA_DEFAULT;
1124         }
initLbe()1125         virtual void initLbe(){};
setLbeState(LbeState __unused state)1126         virtual void setLbeState(LbeState __unused state) {}
setLbeAmbientLight(int __unused value)1127         virtual void setLbeAmbientLight(int __unused value) {}
getLbeState()1128         virtual LbeState getLbeState() { return LbeState::OFF; }
1129 
1130         int32_t checkPowerHalExtHintSupport(const std::string& mode);
1131 
isLhbmSupported()1132         virtual bool isLhbmSupported() { return false; }
setLhbmState(bool __unused enabled)1133         virtual int32_t setLhbmState(bool __unused enabled) { return NO_ERROR; }
getLhbmState()1134         virtual bool getLhbmState() { return false; };
notifyLhbmState(bool __unused enabled)1135         virtual void notifyLhbmState(bool __unused enabled) {}
setWakeupDisplay()1136         virtual void setWakeupDisplay() {}
1137 
1138         /* getDisplayPreAssignBit support mIndex up to 1.
1139            It supports only dual LCD and 2 external displays */
getDisplayPreAssignBit()1140         inline uint32_t getDisplayPreAssignBit() {
1141             uint32_t type = SECOND_DISPLAY_START_BIT * mIndex + mType;
1142             return 1 << type;
1143         }
requestEnhancedHbm(bool on)1144         void requestEnhancedHbm(bool on) { mBrightnessState.enhanced_hbm = on; };
1145 
1146         void cleanupAfterClientDeath();
1147 
1148     protected:
1149         virtual bool getHDRException(ExynosLayer *layer);
1150         virtual int32_t getActiveConfigInternal(hwc2_config_t* outConfig);
1151         virtual int32_t setActiveConfigInternal(hwc2_config_t config, bool force);
1152 
1153         void updateRefreshRateHint();
1154 
1155     public:
1156         /**
1157          * This will be initialized with differnt class
1158          * that inherits ExynosDisplayInterface according to
1159          * interface type.
1160          */
1161         std::unique_ptr<ExynosDisplayInterface> mDisplayInterface;
1162 
getBrightnessState()1163         const brightnessState_t& getBrightnessState() const { return mBrightnessState; }
updateForMipiSync(brightnessState_t::MipiSyncType type)1164         void updateForMipiSync(brightnessState_t::MipiSyncType type) {
1165             if (type == brightnessState_t::MIPI_SYNC_GHBM_ON ||
1166                 type == brightnessState_t::MIPI_SYNC_GHBM_OFF) {
1167                 mBrightnessState.dim_sdr_ratio = mBrightnessState.dim_sdr_target_ratio;
1168             }
1169         }
getBrightnessValue()1170         float getBrightnessValue() const { return mBrightnessState.brightness_value; }
requestLhbm(bool on)1171         void requestLhbm(bool on) {
1172             mReqLhbm = on;
1173             mDevice->invalidate();
1174         }
1175 
setMinIdleRefreshRate(const int __unused fps)1176         virtual int setMinIdleRefreshRate(const int __unused fps) { return NO_ERROR; }
setRefreshRateThrottleNanos(const int64_t __unused delayNanos)1177         virtual int setRefreshRateThrottleNanos(const int64_t __unused delayNanos) {
1178             return NO_ERROR;
1179         }
1180 
updateAppliedActiveConfig(const hwc2_config_t,const int64_t)1181         virtual void updateAppliedActiveConfig(const hwc2_config_t /*newConfig*/,
1182                                                const int64_t /*ts*/) {}
1183 
1184     private:
1185         bool skipStaticLayerChanged(ExynosCompositionInfo& compositionInfo);
1186 
1187         bool skipSignalIdleForVideoLayer();
1188 
1189         /// minimum possible dim rate in the case hbm peak is 1000 nits and norml
1190         // display brightness is 2 nits
1191         static constexpr float kGhbmMinDimRatio = 0.002;
1192 
1193         /// consider HDR as full screen playback when its frame coverage
1194         //exceeds this threshold.
1195         static constexpr float kHdrFullScreen = 0.5;
1196         uint32_t mHdrFullScrenAreaThreshold;
1197 
1198        // Brightness state
1199         brightnessState_t mBrightnessState;
1200 
1201         // request lhbm state
1202         bool mReqLhbm = false;
1203 
1204         /* Display hint to notify power hal */
1205         class PowerHalHintWorker : public Worker {
1206         public:
1207             PowerHalHintWorker();
1208             virtual ~PowerHalHintWorker();
1209             int Init();
1210 
1211             void signalRefreshRate(hwc2_power_mode_t powerMode, uint32_t vsyncPeriod);
1212             void signalIdle();
1213 
1214         protected:
1215             void Routine() override;
1216 
1217         private:
1218             static void BinderDiedCallback(void*);
1219             int32_t connectPowerHalExt();
1220             int32_t checkPowerHalExtHintSupport(const std::string& mode);
1221             int32_t sendPowerHalExtHint(const std::string& mode, bool enabled);
1222 
1223             int32_t checkRefreshRateHintSupport(int refreshRate);
1224             int32_t updateRefreshRateHintInternal(hwc2_power_mode_t powerMode,
1225                                                   uint32_t vsyncPeriod);
1226             int32_t sendRefreshRateHint(int refreshRate, bool enabled);
1227             void forceUpdateHints();
1228 
1229             int32_t checkIdleHintSupport();
1230             int32_t updateIdleHint(int64_t deadlineTime, bool forceUpdate);
1231             bool needUpdateIdleHintLocked(int64_t& timeout) REQUIRES(mutex_);
1232 
1233             bool mNeedUpdateRefreshRateHint;
1234 
1235             // previous refresh rate
1236             int mPrevRefreshRate;
1237 
1238             // the refresh rate whose hint failed to be disabled
1239             int mPendingPrevRefreshRate;
1240 
1241             // support list of refresh rate hints
1242             std::map<int, bool> mRefreshRateHintSupportMap;
1243 
1244             bool mIdleHintIsEnabled;
1245             bool mForceUpdateIdleHint;
1246             int64_t mIdleHintDeadlineTime;
1247 
1248             // whether idle hint support is checked
1249             bool mIdleHintSupportIsChecked;
1250 
1251             // whether idle hint is supported
1252             bool mIdleHintIsSupported;
1253 
1254             hwc2_power_mode_t mPowerModeState;
1255             uint32_t mVsyncPeriod;
1256 
1257             // for power HAL extension hints
1258             std::shared_ptr<aidl::google::hardware::power::extension::pixel::IPowerExt>
1259                     mPowerHalExtAidl;
1260             ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
1261         };
1262 
1263         PowerHalHintWorker mPowerHalHint;
1264 
1265     protected:
getDisplayVsyncPeriodFromConfig(hwc2_config_t config)1266         inline uint32_t getDisplayVsyncPeriodFromConfig(hwc2_config_t config) {
1267             int32_t vsync_period;
1268             getDisplayAttribute(config, HWC2_ATTRIBUTE_VSYNC_PERIOD, &vsync_period);
1269             assert(vsync_period > 0);
1270             return static_cast<uint32_t>(vsync_period);
1271         }
1272 
1273         virtual void calculateTimeline(
1274                 hwc2_config_t config,
1275                 hwc_vsync_period_change_constraints_t* vsyncPeriodChangeConstraints,
1276                 hwc_vsync_period_change_timeline_t* outTimeline);
1277 };
1278 
1279 #endif //_EXYNOSDISPLAY_H
1280