1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 * Copyright (C)2012-2016, The Linux Foundation. All rights reserved.
4 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#ifndef HWC_UTILS_H
22#define HWC_UTILS_H
23
24#define DEBUG_MDPDOWNSCALE 0
25#define HWC_REMOVE_DEPRECATED_VERSIONS 1
26
27#include <fcntl.h>
28#include <math.h>
29#include <hardware/hwcomposer.h>
30#include <gr.h>
31#include <gralloc_priv.h>
32#include <utils/String8.h>
33#include "qdMetaData.h"
34#include "mdp_version.h"
35#include <overlayUtils.h>
36#include <overlayRotator.h>
37#include <EGL/egl.h>
38
39
40#define ALIGN_TO(x, align)     (((x) + ((align)-1)) & ~((align)-1))
41#define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
42#define UNLIKELY( exp )     (__builtin_expect( (exp) != 0, false ))
43#define MAX_NUM_APP_LAYERS 32
44#define MIN_DISPLAY_XRES 200
45#define MIN_DISPLAY_YRES 200
46#define HWC_WFDDISPSYNC_LOG 0
47#define STR(f) #f;
48// Max number of PTOR layers handled
49#define MAX_PTOR_LAYERS 2
50
51#ifdef QTI_BSP
52#include <exhwcomposer_defs.h>
53#endif
54
55//Fwrd decls
56struct hwc_context_t;
57
58namespace ovutils = overlay::utils;
59
60namespace qmode {
61class ModeManager;
62}
63
64namespace overlay {
65class Overlay;
66class Rotator;
67class RotMgr;
68}
69
70namespace qhwc {
71//fwrd decl
72class QueuedBufferStore;
73class HDMIDisplay;
74class VirtualDisplay;
75class IFBUpdate;
76class IVideoOverlay;
77class MDPComp;
78class CopyBit;
79class HwcDebug;
80class AssertiveDisplay;
81class HWCVirtualVDS;
82
83
84struct MDPInfo {
85    int version;
86    char panel;
87    bool hasOverlay;
88};
89
90struct DisplayAttributes {
91    uint32_t refreshRate;
92    uint32_t dynRefreshRate;
93    uint32_t vsync_period; //nanos
94    uint32_t xres;
95    uint32_t yres;
96    uint32_t stride;
97    float xdpi;
98    float ydpi;
99    uint32_t fbformat;
100    int fd;
101    bool connected; //Applies only to pluggable disp.
102    //Connected does not mean it ready to use.
103    //It should be active also. (UNBLANKED)
104    bool isActive;
105    // In pause state, composition is bypassed
106    // used for WFD displays and in QDCM calibration mode
107    bool isPause;
108    // To trigger padding round to clean up mdp
109    // pipes
110    bool isConfiguring;
111    // Indicates whether external/virtual display is in MDP scaling mode
112    bool mMDPScalingMode;
113    // Ext dst Rect
114    hwc_rect_t mDstRect;
115    //Action safe attributes
116    // Flag to indicate the presence of action safe dimensions for external
117    bool mActionSafePresent;
118    int mAsWidthRatio;
119    int mAsHeightRatio;
120
121    //If property fbsize set via adb shell debug.hwc.fbsize = XRESxYRES
122    //following fields are used.
123    bool customFBSize;
124    uint32_t xres_new;
125    uint32_t yres_new;
126
127};
128
129struct ListStats {
130    int numAppLayers; //Total - 1, excluding FB layer.
131    int skipCount;
132    int fbLayerIndex; //Always last for now. = numAppLayers
133    //Video specific
134    int yuvCount;
135    int yuvIndices[MAX_NUM_APP_LAYERS];
136    bool preMultipliedAlpha;
137    int yuv4k2kIndices[MAX_NUM_APP_LAYERS];
138    int yuv4k2kCount;
139    // Notifies hwcomposer about the start and end of animation
140    // This will be set to true during animation, otherwise false.
141    bool isDisplayAnimating;
142    bool secureUI; // Secure display layer
143    bool isSecurePresent;
144    hwc_rect_t lRoi;  //left ROI
145    hwc_rect_t rRoi;  //right ROI. Unused in single DSI panels.
146    //App Buffer Composition index
147    int  renderBufIndexforABC;
148    // Secure RGB specific
149    int secureRGBCount;
150    int secureRGBIndices[MAX_NUM_APP_LAYERS];
151    //dyn refresh rate-Client requested refreshrate
152    uint32_t refreshRateRequest;
153    // Flag related to windowboxing feature
154    bool mAIVVideoMode;
155};
156
157//PTOR Comp info
158struct PtorInfo {
159    int count;
160    int layerIndex[MAX_PTOR_LAYERS];
161    hwc_rect_t displayFrame[MAX_PTOR_LAYERS];
162    bool isActive() { return (count>0); }
163    int getPTORArrayIndex(int index) {
164        int idx = -1;
165        for(int i = 0; i < count; i++) {
166            if(index == layerIndex[i])
167                idx = i;
168        }
169        return idx;
170    }
171};
172
173struct LayerProp {
174    uint32_t mFlags; //qcom specific layer flags
175    LayerProp():mFlags(0){};
176};
177
178struct VsyncState {
179    bool enable;
180    bool fakevsync;
181    bool debug;
182};
183
184struct BwcPM {
185    static void setBwc(const hwc_rect_t& crop, const hwc_rect_t& dst,
186            const int& transform, const int& downscale,
187            ovutils::eMdpFlags& mdpFlags);
188};
189
190// LayerProp::flag values
191enum {
192    HWC_MDPCOMP = 0x00000001,
193    HWC_COPYBIT = 0x00000002,
194};
195
196// AIV specific flags
197enum {
198    HWC_AIV_VIDEO = 0x80000000,
199    HWC_AIV_CC    = 0x40000000,
200};
201
202// HAL specific features
203enum {
204    HWC_COLOR_FILL = 0x00000008,
205    HWC_FORMAT_RB_SWAP = 0x00000040,
206};
207
208/* External Display states */
209enum {
210    EXTERNAL_OFFLINE = 0,
211    EXTERNAL_ONLINE,
212    EXTERNAL_PAUSE,
213    EXTERNAL_RESUME,
214    EXTERNAL_MAXSTATES
215};
216
217class LayerRotMap {
218public:
219    LayerRotMap() { reset(); }
220    void add(hwc_layer_1_t* layer, overlay::Rotator *rot);
221    //Resets the mapping of layer to rotator
222    void reset();
223    //Clears mappings and existing rotator fences
224    //Intended to be used during errors
225    void clear();
226    uint32_t getCount() const;
227    hwc_layer_1_t* getLayer(uint32_t index) const;
228    overlay::Rotator* getRot(uint32_t index) const;
229    bool isRotCached(uint32_t index) const;
230    void setReleaseFd(const int& fence);
231private:
232    hwc_layer_1_t* mLayer[overlay::RotMgr::MAX_ROT_SESS];
233    overlay::Rotator* mRot[overlay::RotMgr::MAX_ROT_SESS];
234    uint32_t mCount;
235};
236
237inline uint32_t LayerRotMap::getCount() const {
238    return mCount;
239}
240
241inline hwc_layer_1_t* LayerRotMap::getLayer(uint32_t index) const {
242    if(index >= mCount) return NULL;
243    return mLayer[index];
244}
245
246inline overlay::Rotator* LayerRotMap::getRot(uint32_t index) const {
247    if(index >= mCount) return NULL;
248    return mRot[index];
249}
250
251inline hwc_rect_t integerizeSourceCrop(const hwc_frect_t& cropF) {
252    hwc_rect_t cropI = {0,0,0,0};
253    cropI.left = int(ceilf(cropF.left));
254    cropI.top = int(ceilf(cropF.top));
255    cropI.right = int(floorf(cropF.right));
256    cropI.bottom = int(floorf(cropF.bottom));
257    return cropI;
258}
259
260inline bool isNonIntegralSourceCrop(const hwc_frect_t& cropF) {
261    if(cropF.left - roundf(cropF.left)     ||
262       cropF.top - roundf(cropF.top)       ||
263       cropF.right - roundf(cropF.right)   ||
264       cropF.bottom - roundf(cropF.bottom))
265        return true;
266    else
267        return false;
268}
269
270// -----------------------------------------------------------------------------
271// Utility functions - implemented in hwc_utils.cpp
272void dumpLayer(hwc_layer_1_t const* l);
273void setListStats(hwc_context_t *ctx, hwc_display_contents_1_t *list,
274        int dpy);
275void initContext(hwc_context_t *ctx);
276void closeContext(hwc_context_t *ctx);
277//Crops source buffer against destination and FB boundaries
278void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
279                         const hwc_rect_t& scissor, int orient);
280void getNonWormholeRegion(hwc_display_contents_1_t* list,
281                              hwc_rect_t& nwr);
282bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer);
283bool isSecureModePolicy(int mdpVersion);
284// Returns true, if the input layer format is supported by rotator
285bool isRotatorSupportedFormat(private_handle_t *hnd);
286//Returns true, if the layer is YUV or the layer has been rendered by CPU
287bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd);
288bool isExternalActive(hwc_context_t* ctx);
289bool isAlphaScaled(hwc_layer_1_t const* layer);
290bool needsScaling(hwc_layer_1_t const* layer);
291bool isDownscaleRequired(hwc_layer_1_t const* layer);
292bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
293                           const int& dpy);
294void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
295                        private_handle_t *hnd);
296bool isAlphaPresent(hwc_layer_1_t const* layer);
297bool isAlphaPresentinFB(hwc_context_t* ctx, int dpy);
298int hwc_vsync_control(hwc_context_t* ctx, int dpy, int enable);
299int getBlending(int blending);
300bool isGLESOnlyComp(hwc_context_t *ctx, const int& dpy);
301void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers);
302bool isAbcInUse(hwc_context_t *ctx);
303
304void dumpBuffer(private_handle_t *ohnd, char *bufferName);
305void updateDisplayInfo(hwc_context_t* ctx, int dpy);
306void resetDisplayInfo(hwc_context_t* ctx, int dpy);
307void initCompositionResources(hwc_context_t* ctx, int dpy);
308void destroyCompositionResources(hwc_context_t* ctx, int dpy);
309void clearPipeResources(hwc_context_t* ctx, int dpy);
310
311//Helper function to dump logs
312void dumpsys_log(android::String8& buf, const char* fmt, ...);
313
314int getExtOrientation(hwc_context_t* ctx);
315bool isValidRect(const hwc_rect_t& rect);
316hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2);
317bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2);
318hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off);
319hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2);
320hwc_rect_t getUnion(const hwc_rect_t& rect1, const hwc_rect_t& rect2);
321void optimizeLayerRects(const hwc_display_contents_1_t *list);
322bool areLayersIntersecting(const hwc_layer_1_t* layer1,
323        const hwc_layer_1_t* layer2);
324bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs);
325bool layerUpdating(const hwc_layer_1_t* layer);
326/* Calculates the dirtyRegion for the given layer */
327hwc_rect_t calculateDirtyRect(const hwc_layer_1_t* layer,
328                                       hwc_rect_t& scissor);
329
330
331// returns true if Action safe dimensions are set and target supports Actionsafe
332bool isActionSafePresent(hwc_context_t *ctx, int dpy);
333
334/* Calculates the destination position based on the action safe rectangle */
335void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& dst);
336
337void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
338                                hwc_rect_t& inRect, hwc_rect_t& outRect);
339
340uint32_t getRefreshRate(hwc_context_t* ctx, uint32_t requestedRefreshRate);
341
342uint32_t roundOff(uint32_t refreshRate);
343
344void setRefreshRate(hwc_context_t *ctx, int dpy, uint32_t refreshRate);
345
346bool isPrimaryPortrait(hwc_context_t *ctx);
347
348bool isOrientationPortrait(hwc_context_t *ctx);
349
350void calcExtDisplayPosition(hwc_context_t *ctx,
351                               private_handle_t *hnd,
352                               int dpy,
353                               hwc_rect_t& sourceCrop,
354                               hwc_rect_t& displayFrame,
355                               int& transform,
356                               ovutils::eTransform& orient);
357
358// Returns the orientation that needs to be set on external for
359// BufferMirrirMode(Sidesync)
360int getMirrorModeOrientation(hwc_context_t *ctx);
361
362/* Get External State names */
363const char* getExternalDisplayState(uint32_t external_state);
364
365// Resets display ROI to full panel resoluion
366void resetROI(hwc_context_t *ctx, const int dpy);
367
368// Aligns updating ROI to panel restrictions
369hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary);
370
371// Handles wfd Pause and resume events
372void handle_pause(hwc_context_t *ctx, int dpy);
373void handle_resume(hwc_context_t *ctx, int dpy);
374
375// Handle ONLINE/OFFLINE for HDMI display
376void handle_online(hwc_context_t* ctx, int dpy);
377void handle_offline(hwc_context_t* ctx, int dpy);
378
379//Close acquireFenceFds of all layers of incoming list
380void closeAcquireFds(hwc_display_contents_1_t* list);
381
382//Sync point impl.
383int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
384        int fd);
385
386//Sets appropriate mdp flags for a layer.
387void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
388        ovutils::eMdpFlags &mdpFlags,
389        int rotDownscale, int transform);
390
391int configRotator(overlay::Rotator *rot, ovutils::Whf& whf,
392        hwc_rect_t& crop, const ovutils::eMdpFlags& mdpFlags,
393        const ovutils::eTransform& orient, const int& downscale);
394
395int configMdp(overlay::Overlay *ov, const ovutils::PipeArgs& parg,
396        const ovutils::eTransform& orient, const hwc_rect_t& crop,
397        const hwc_rect_t& pos, const MetaData_t *metadata,
398        const ovutils::eDest& dest);
399
400int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer, const int& dpy,
401        ovutils::eMdpFlags& mdpFlags, ovutils::eZorder& z,
402        const ovutils::eDest& dest);
403
404void updateSource(ovutils::eTransform& orient, ovutils::Whf& whf,
405        hwc_rect_t& crop, overlay::Rotator *rot);
406
407bool isZoomModeEnabled(hwc_rect_t crop);
408void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy);
409void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& dst, int dpy);
410void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
411                           hwc_rect_t& dst, int dpy);
412
413//Routine to configure low resolution panels (<= 2048 width)
414int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer, const int& dpy,
415        ovutils::eMdpFlags& mdpFlags, ovutils::eZorder& z,
416        const ovutils::eDest& dest,
417        overlay::Rotator **rot);
418
419//Routine to configure high resolution panels (> 2048 width)
420int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer, const int& dpy,
421        ovutils::eMdpFlags& mdpFlags, ovutils::eZorder& z,
422        const ovutils::eDest& lDest,
423        const ovutils::eDest& rDest, overlay::Rotator **rot);
424
425//Routine to split and configure high resolution YUV layer (> 2048 width)
426int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
427        const int& dpy,
428        ovutils::eMdpFlags& mdpFlags, ovutils::eZorder& z,
429        const ovutils::eDest& lDest,
430        const ovutils::eDest& rDest, overlay::Rotator **rot);
431
432//On certain targets DMA pipes are used for rotation and they won't be available
433//for line operations. On a per-target basis we can restrict certain use cases
434//from using rotator, since we know before-hand that such scenarios can lead to
435//extreme unavailability of pipes. This can also be done via hybrid calculations
436//also involving many more variables like number of write-back interfaces etc,
437//but the variety of scenarios is too high to warrant that.
438bool canUseRotator(hwc_context_t *ctx, int dpy);
439
440int getLeftSplit(hwc_context_t *ctx, const int& dpy);
441
442bool isDisplaySplit(hwc_context_t* ctx, int dpy);
443
444int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer);
445
446// Set the GPU hint flag to high for MIXED/GPU composition only for
447// first frame after MDP to GPU/MIXED mode transition.
448// Set the GPU hint to default if the current composition type is GPU
449// due to idle fallback or MDP composition.
450void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list);
451
452bool loadEglLib(hwc_context_t* ctx);
453
454// Returns true if rect1 is peripheral to rect2, false otherwise.
455bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2);
456
457// Checks if boot animation has completed and applies default mode
458void processBootAnimCompleted(hwc_context_t *ctx);
459
460// Inline utility functions
461static inline bool isSkipLayer(const hwc_layer_1_t* l) {
462    return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
463}
464
465static inline bool isAIVVideoLayer(const hwc_layer_1_t* l) {
466    return (UNLIKELY(l && (l->flags & HWC_AIV_VIDEO)));
467}
468
469static inline bool isAIVCCLayer(const hwc_layer_1_t* l) {
470    return (UNLIKELY(l && (l->flags & HWC_AIV_CC)));
471}
472
473// Returns true if the buffer is yuv
474static inline bool isYuvBuffer(const private_handle_t* hnd) {
475    return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
476}
477
478// Returns true if the buffer is yuv and exceeds the mixer width
479static inline bool isYUVSplitNeeded(const private_handle_t* hnd) {
480    int maxMixerWidth = qdutils::MDPVersion::getInstance().getMaxMixerWidth();
481    return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO) &&
482            (hnd->width > maxMixerWidth));
483}
484
485// Returns true if the buffer is secure
486static inline bool isSecureBuffer(const private_handle_t* hnd) {
487    return (hnd && (private_handle_t::PRIV_FLAGS_SECURE_BUFFER & hnd->flags));
488}
489
490static inline bool isTileRendered(const private_handle_t* hnd) {
491    return (hnd && (private_handle_t::PRIV_FLAGS_TILE_RENDERED & hnd->flags));
492}
493
494static inline bool isCPURendered(const private_handle_t* hnd) {
495    return (hnd && (private_handle_t::PRIV_FLAGS_CPU_RENDERED & hnd->flags));
496}
497
498//Return true if the buffer is intended for Secure Display
499static inline bool isSecureDisplayBuffer(const private_handle_t* hnd) {
500    return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_DISPLAY));
501}
502
503static inline int getWidth(const private_handle_t* hnd) {
504    MetaData_t *metadata = reinterpret_cast<MetaData_t*>(hnd->base_metadata);
505    if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
506        return metadata->bufferDim.sliceWidth;
507    }
508    return hnd->width;
509}
510
511static inline int getHeight(const private_handle_t* hnd) {
512    MetaData_t *metadata = reinterpret_cast<MetaData_t*>(hnd->base_metadata);
513    if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
514        return metadata->bufferDim.sliceHeight;
515    }
516    return hnd->height;
517}
518
519template<typename T> inline T max(T a, T b) { return (a > b) ? a : b; }
520template<typename T> inline T min(T a, T b) { return (a < b) ? a : b; }
521
522// Initialize uevent thread
523void init_uevent_thread(hwc_context_t* ctx);
524// Initialize vsync thread
525void init_vsync_thread(hwc_context_t* ctx);
526
527inline void getLayerResolution(const hwc_layer_1_t* layer,
528                               int& width, int& height) {
529    hwc_rect_t displayFrame  = layer->displayFrame;
530    width = displayFrame.right - displayFrame.left;
531    height = displayFrame.bottom - displayFrame.top;
532}
533
534static inline int openFb(int dpy) {
535    int fd = -1;
536    const char *devtmpl = "/dev/graphics/fb%u";
537    char name[64] = {0};
538    snprintf(name, 64, devtmpl, dpy);
539    fd = open(name, O_RDWR);
540    return fd;
541}
542
543template <class T>
544inline void swap(T& a, T& b) {
545    T tmp = a;
546    a = b;
547    b = tmp;
548}
549
550}; //qhwc namespace
551
552enum eAnimationState{
553    ANIMATION_STOPPED,
554    ANIMATION_STARTED,
555};
556
557enum eCompositionState {
558    COMPOSITION_STATE_MDP = 0,        // Set if composition type is MDP
559    COMPOSITION_STATE_GPU,            // Set if composition type is GPU or MIXED
560    COMPOSITION_STATE_IDLE_FALLBACK,  // Set if it is idlefallback
561};
562
563// Structure holds the information about the GPU hint.
564struct gpu_hint_info {
565    // system level flag to enable gpu_perf_mode
566    bool mGpuPerfModeEnable;
567    // Stores the current GPU performance mode DEFAULT/HIGH
568    uint32_t mCurrGPUPerfMode;
569    // Stores the compositon state GPU, MDP or IDLE_FALLBACK
570    bool mCompositionState;
571    // Stores the EGLContext of current process
572    EGLContext mEGLContext;
573    // Stores the EGLDisplay of current process
574    EGLDisplay mEGLDisplay;
575};
576
577//struct holds the information about libmm-qdcm.so
578struct qdcm_info {
579    qmode::ModeManager *mQdcmMode;
580    void *mQdcmLib;
581    bool  mBootAnimCompleted;
582};
583
584// -----------------------------------------------------------------------------
585// HWC context
586// This structure contains overall state
587struct hwc_context_t {
588    hwc_composer_device_1_t device;
589    const hwc_procs_t* proc;
590
591    //CopyBit objects
592    qhwc::CopyBit *mCopyBit[HWC_NUM_DISPLAY_TYPES];
593
594    //Overlay object - NULL for non overlay devices
595    overlay::Overlay *mOverlay;
596    //Holds a few rot objects
597    overlay::RotMgr *mRotMgr;
598
599    //Primary and external FB updater
600    qhwc::IFBUpdate *mFBUpdate[HWC_NUM_DISPLAY_TYPES];
601    // HDMI display related object. Used to configure/teardown
602    // HDMI when it is connected as primary or external.
603    qhwc::HDMIDisplay *mHDMIDisplay;
604    qhwc::MDPInfo mMDP;
605    qhwc::VsyncState vstate;
606    qhwc::DisplayAttributes dpyAttr[HWC_NUM_DISPLAY_TYPES];
607    qhwc::ListStats listStats[HWC_NUM_DISPLAY_TYPES];
608    qhwc::LayerProp *layerProp[HWC_NUM_DISPLAY_TYPES];
609    qhwc::MDPComp *mMDPComp[HWC_NUM_DISPLAY_TYPES];
610    qhwc::HwcDebug *mHwcDebug[HWC_NUM_DISPLAY_TYPES];
611    hwc_rect_t mViewFrame[HWC_NUM_DISPLAY_TYPES];
612    qhwc::AssertiveDisplay *mAD;
613    eAnimationState mAnimationState[HWC_NUM_DISPLAY_TYPES];
614    qhwc::HWCVirtualVDS *mHWCVirtual;
615
616    // stores the #numHwLayers of the previous frame
617    // for each display device
618    int mPrevHwLayerCount[HWC_NUM_DISPLAY_TYPES];
619
620    // stores the primary device orientation
621    int deviceOrientation;
622    //Securing in progress indicator
623    bool mSecuring;
624    //Display in secure mode indicator
625    bool mSecureMode;
626    //Lock to protect drawing data structures
627    mutable Locker mDrawLock;
628    //Drawing round when we use GPU
629    bool isPaddingRound;
630    // External Orientation
631    int mExtOrientation;
632    //Flags the transition of a video session
633    bool mVideoTransFlag;
634    //Used for SideSync feature
635    //which overrides the mExtOrientation
636    bool mBufferMirrorMode;
637    // Used to synchronize between WFD and Display modules
638    mutable Locker mWfdSyncLock;
639
640    qhwc::LayerRotMap *mLayerRotMap[HWC_NUM_DISPLAY_TYPES];
641    // Panel reset flag will be set if BTA check fails
642    bool mPanelResetStatus;
643    // number of active Displays
644    int numActiveDisplays;
645#ifdef QTI_BSP
646    void *mEglLib;
647    EGLBoolean (*mpfn_eglGpuPerfHintQCOM)(EGLDisplay, EGLContext, EGLint *);
648    EGLDisplay (*mpfn_eglGetCurrentDisplay)();
649    EGLContext (*mpfn_eglGetCurrentContext)();
650    struct gpu_hint_info mGPUHintInfo;
651#endif
652    //App Buffer Composition
653    bool enableABC;
654    // PTOR Info
655    qhwc::PtorInfo mPtorInfo;
656    //Running in Thermal burst mode
657    bool mThermalBurstMode;
658    //Layers out of ROI
659    bool copybitDrop[MAX_NUM_APP_LAYERS];
660    // Flag related to windowboxing feature
661    bool mWindowboxFeature;
662    // This denotes the tolerance between video layer and external display
663    // aspect ratio
664    float mAspectRatioToleranceLevel;
665    //Used to notify that boot has completed
666    bool mBootAnimCompleted;
667    // Provides a way for OEM's to disable setting dynfps via metadata.
668    bool mUseMetaDataRefreshRate;
669    //struct holds the information about display tuning service library.
670    struct qdcm_info mQdcmInfo;
671};
672
673namespace qhwc {
674static inline bool isSkipPresent (hwc_context_t *ctx, int dpy) {
675    return  ctx->listStats[dpy].skipCount;
676}
677
678static inline bool isYuvPresent (hwc_context_t *ctx, int dpy) {
679    return  ctx->listStats[dpy].yuvCount;
680}
681
682static inline bool has90Transform(hwc_layer_1_t const* layer) {
683    return ((layer->transform & HWC_TRANSFORM_ROT_90) &&
684            !(layer->flags & HWC_COLOR_FILL));
685}
686
687inline bool isSecurePresent(hwc_context_t *ctx, int dpy) {
688    return ctx->listStats[dpy].isSecurePresent;
689}
690
691static inline bool isSecondaryConfiguring(hwc_context_t* ctx) {
692    return (ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
693            ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring);
694}
695
696static inline bool isSecondaryConnected(hwc_context_t* ctx) {
697    return (ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected ||
698            ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected);
699}
700
701static inline bool isSecondaryAnimating(hwc_context_t* ctx) {
702    return (ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected &&
703            (!ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isPause) &&
704            ctx->listStats[HWC_DISPLAY_EXTERNAL].isDisplayAnimating)
705            ||
706           (ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected &&
707            (!ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) &&
708            ctx->listStats[HWC_DISPLAY_VIRTUAL].isDisplayAnimating);
709}
710
711/* Return Virtual Display connection status */
712static inline bool isVDConnected(hwc_context_t* ctx) {
713    return ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected;
714}
715
716};
717
718#endif //HWC_UTILS_H
719