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