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