• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
56 struct hwc_context_t;
57 
58 namespace ovutils = overlay::utils;
59 
60 namespace qmode {
61 class ModeManager;
62 }
63 
64 namespace overlay {
65 class Overlay;
66 class Rotator;
67 class RotMgr;
68 }
69 
70 namespace qhwc {
71 //fwrd decl
72 class QueuedBufferStore;
73 class HDMIDisplay;
74 class VirtualDisplay;
75 class IFBUpdate;
76 class IVideoOverlay;
77 class MDPComp;
78 class CopyBit;
79 class HwcDebug;
80 class AssertiveDisplay;
81 class HWCVirtualVDS;
82 
83 
84 struct MDPInfo {
85     int version;
86     char panel;
87     bool hasOverlay;
88 };
89 
90 struct 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 
129 struct 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
158 struct PtorInfo {
159     int count;
160     int layerIndex[MAX_PTOR_LAYERS];
161     hwc_rect_t displayFrame[MAX_PTOR_LAYERS];
isActivePtorInfo162     bool isActive() { return (count>0); }
getPTORArrayIndexPtorInfo163     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 
173 struct LayerProp {
174     uint32_t mFlags; //qcom specific layer flags
LayerPropLayerProp175     LayerProp():mFlags(0){};
176 };
177 
178 struct VsyncState {
179     bool enable;
180     bool fakevsync;
181     bool debug;
182 };
183 
184 struct 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
191 enum {
192     HWC_MDPCOMP = 0x00000001,
193     HWC_COPYBIT = 0x00000002,
194 };
195 
196 // AIV specific flags
197 enum {
198     HWC_AIV_VIDEO = 0x80000000,
199     HWC_AIV_CC    = 0x40000000,
200 };
201 
202 // HAL specific features
203 enum {
204     HWC_COLOR_FILL = 0x00000008,
205     HWC_FORMAT_RB_SWAP = 0x00000040,
206 };
207 
208 /* External Display states */
209 enum {
210     EXTERNAL_OFFLINE = 0,
211     EXTERNAL_ONLINE,
212     EXTERNAL_PAUSE,
213     EXTERNAL_RESUME,
214     EXTERNAL_MAXSTATES
215 };
216 
217 class LayerRotMap {
218 public:
LayerRotMap()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);
231 private:
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 
getCount()237 inline uint32_t LayerRotMap::getCount() const {
238     return mCount;
239 }
240 
getLayer(uint32_t index)241 inline hwc_layer_1_t* LayerRotMap::getLayer(uint32_t index) const {
242     if(index >= mCount) return NULL;
243     return mLayer[index];
244 }
245 
getRot(uint32_t index)246 inline overlay::Rotator* LayerRotMap::getRot(uint32_t index) const {
247     if(index >= mCount) return NULL;
248     return mRot[index];
249 }
250 
integerizeSourceCrop(const hwc_frect_t & cropF)251 inline 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 
isNonIntegralSourceCrop(const hwc_frect_t & cropF)260 inline 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
272 void dumpLayer(hwc_layer_1_t const* l);
273 void setListStats(hwc_context_t *ctx, hwc_display_contents_1_t *list,
274         int dpy);
275 void initContext(hwc_context_t *ctx);
276 void closeContext(hwc_context_t *ctx);
277 //Crops source buffer against destination and FB boundaries
278 void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
279                          const hwc_rect_t& scissor, int orient);
280 void getNonWormholeRegion(hwc_display_contents_1_t* list,
281                               hwc_rect_t& nwr);
282 bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer);
283 bool isSecureModePolicy(int mdpVersion);
284 // Returns true, if the input layer format is supported by rotator
285 bool isRotatorSupportedFormat(private_handle_t *hnd);
286 //Returns true, if the layer is YUV or the layer has been rendered by CPU
287 bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd);
288 bool isExternalActive(hwc_context_t* ctx);
289 bool isAlphaScaled(hwc_layer_1_t const* layer);
290 bool needsScaling(hwc_layer_1_t const* layer);
291 bool isDownscaleRequired(hwc_layer_1_t const* layer);
292 bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
293                            const int& dpy);
294 void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
295                         private_handle_t *hnd);
296 bool isAlphaPresent(hwc_layer_1_t const* layer);
297 bool isAlphaPresentinFB(hwc_context_t* ctx, int dpy);
298 int hwc_vsync_control(hwc_context_t* ctx, int dpy, int enable);
299 int getBlending(int blending);
300 bool isGLESOnlyComp(hwc_context_t *ctx, const int& dpy);
301 void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers);
302 bool isAbcInUse(hwc_context_t *ctx);
303 
304 void dumpBuffer(private_handle_t *ohnd, char *bufferName);
305 void updateDisplayInfo(hwc_context_t* ctx, int dpy);
306 void resetDisplayInfo(hwc_context_t* ctx, int dpy);
307 void initCompositionResources(hwc_context_t* ctx, int dpy);
308 void destroyCompositionResources(hwc_context_t* ctx, int dpy);
309 void clearPipeResources(hwc_context_t* ctx, int dpy);
310 
311 //Helper function to dump logs
312 void dumpsys_log(android::String8& buf, const char* fmt, ...);
313 
314 int getExtOrientation(hwc_context_t* ctx);
315 bool isValidRect(const hwc_rect_t& rect);
316 hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2);
317 bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2);
318 hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off);
319 hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2);
320 hwc_rect_t getUnion(const hwc_rect_t& rect1, const hwc_rect_t& rect2);
321 void optimizeLayerRects(const hwc_display_contents_1_t *list);
322 bool areLayersIntersecting(const hwc_layer_1_t* layer1,
323         const hwc_layer_1_t* layer2);
324 bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs);
325 bool layerUpdating(const hwc_layer_1_t* layer);
326 /* Calculates the dirtyRegion for the given layer */
327 hwc_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
332 bool isActionSafePresent(hwc_context_t *ctx, int dpy);
333 
334 /* Calculates the destination position based on the action safe rectangle */
335 void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& dst);
336 
337 void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
338                                 hwc_rect_t& inRect, hwc_rect_t& outRect);
339 
340 uint32_t getRefreshRate(hwc_context_t* ctx, uint32_t requestedRefreshRate);
341 
342 uint32_t roundOff(uint32_t refreshRate);
343 
344 void setRefreshRate(hwc_context_t *ctx, int dpy, uint32_t refreshRate);
345 
346 bool isPrimaryPortrait(hwc_context_t *ctx);
347 
348 bool isOrientationPortrait(hwc_context_t *ctx);
349 
350 void 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)
360 int getMirrorModeOrientation(hwc_context_t *ctx);
361 
362 /* Get External State names */
363 const char* getExternalDisplayState(uint32_t external_state);
364 
365 // Resets display ROI to full panel resoluion
366 void resetROI(hwc_context_t *ctx, const int dpy);
367 
368 // Aligns updating ROI to panel restrictions
369 hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary);
370 
371 // Handles wfd Pause and resume events
372 void handle_pause(hwc_context_t *ctx, int dpy);
373 void handle_resume(hwc_context_t *ctx, int dpy);
374 
375 // Handle ONLINE/OFFLINE for HDMI display
376 void handle_online(hwc_context_t* ctx, int dpy);
377 void handle_offline(hwc_context_t* ctx, int dpy);
378 
379 //Close acquireFenceFds of all layers of incoming list
380 void closeAcquireFds(hwc_display_contents_1_t* list);
381 
382 //Sync point impl.
383 int 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.
387 void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
388         ovutils::eMdpFlags &mdpFlags,
389         int rotDownscale, int transform);
390 
391 int 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 
395 int 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 
400 int 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 
404 void updateSource(ovutils::eTransform& orient, ovutils::Whf& whf,
405         hwc_rect_t& crop, overlay::Rotator *rot);
406 
407 bool isZoomModeEnabled(hwc_rect_t crop);
408 void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy);
409 void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& dst, int dpy);
410 void 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)
414 int 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)
420 int 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)
426 int 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.
438 bool canUseRotator(hwc_context_t *ctx, int dpy);
439 
440 int getLeftSplit(hwc_context_t *ctx, const int& dpy);
441 
442 bool isDisplaySplit(hwc_context_t* ctx, int dpy);
443 
444 int 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.
450 void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list);
451 
452 bool loadEglLib(hwc_context_t* ctx);
453 
454 // Returns true if rect1 is peripheral to rect2, false otherwise.
455 bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2);
456 
457 // Checks if boot animation has completed and applies default mode
458 void processBootAnimCompleted(hwc_context_t *ctx);
459 
460 // Inline utility functions
isSkipLayer(const hwc_layer_1_t * l)461 static inline bool isSkipLayer(const hwc_layer_1_t* l) {
462     return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
463 }
464 
isAIVVideoLayer(const hwc_layer_1_t * l)465 static inline bool isAIVVideoLayer(const hwc_layer_1_t* l) {
466     return (UNLIKELY(l && (l->flags & HWC_AIV_VIDEO)));
467 }
468 
isAIVCCLayer(const hwc_layer_1_t * l)469 static 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
isYuvBuffer(const private_handle_t * hnd)474 static 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
isYUVSplitNeeded(const private_handle_t * hnd)479 static 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
isSecureBuffer(const private_handle_t * hnd)486 static inline bool isSecureBuffer(const private_handle_t* hnd) {
487     return (hnd && (private_handle_t::PRIV_FLAGS_SECURE_BUFFER & hnd->flags));
488 }
489 
isTileRendered(const private_handle_t * hnd)490 static inline bool isTileRendered(const private_handle_t* hnd) {
491     return (hnd && (private_handle_t::PRIV_FLAGS_TILE_RENDERED & hnd->flags));
492 }
493 
isCPURendered(const private_handle_t * hnd)494 static 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
isSecureDisplayBuffer(const private_handle_t * hnd)499 static inline bool isSecureDisplayBuffer(const private_handle_t* hnd) {
500     return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_DISPLAY));
501 }
502 
getWidth(const private_handle_t * hnd)503 static 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 
getHeight(const private_handle_t * hnd)511 static 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 
max(T a,T b)519 template<typename T> inline T max(T a, T b) { return (a > b) ? a : b; }
min(T a,T b)520 template<typename T> inline T min(T a, T b) { return (a < b) ? a : b; }
521 
522 // Initialize uevent thread
523 void init_uevent_thread(hwc_context_t* ctx);
524 // Initialize vsync thread
525 void init_vsync_thread(hwc_context_t* ctx);
526 
getLayerResolution(const hwc_layer_1_t * layer,int & width,int & height)527 inline 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 
openFb(int dpy)534 static 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 
543 template <class T>
swap(T & a,T & b)544 inline void swap(T& a, T& b) {
545     T tmp = a;
546     a = b;
547     b = tmp;
548 }
549 
550 }; //qhwc namespace
551 
552 enum eAnimationState{
553     ANIMATION_STOPPED,
554     ANIMATION_STARTED,
555 };
556 
557 enum 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.
564 struct 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
578 struct qdcm_info {
579     qmode::ModeManager *mQdcmMode;
580     void *mQdcmLib;
581     bool  mBootAnimCompleted;
582 };
583 
584 // -----------------------------------------------------------------------------
585 // HWC context
586 // This structure contains overall state
587 struct 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 
673 namespace qhwc {
isSkipPresent(hwc_context_t * ctx,int dpy)674 static inline bool isSkipPresent (hwc_context_t *ctx, int dpy) {
675     return  ctx->listStats[dpy].skipCount;
676 }
677 
isYuvPresent(hwc_context_t * ctx,int dpy)678 static inline bool isYuvPresent (hwc_context_t *ctx, int dpy) {
679     return  ctx->listStats[dpy].yuvCount;
680 }
681 
has90Transform(hwc_layer_1_t const * layer)682 static 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 
isSecurePresent(hwc_context_t * ctx,int dpy)687 inline bool isSecurePresent(hwc_context_t *ctx, int dpy) {
688     return ctx->listStats[dpy].isSecurePresent;
689 }
690 
isSecondaryConfiguring(hwc_context_t * ctx)691 static inline bool isSecondaryConfiguring(hwc_context_t* ctx) {
692     return (ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
693             ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring);
694 }
695 
isSecondaryConnected(hwc_context_t * ctx)696 static inline bool isSecondaryConnected(hwc_context_t* ctx) {
697     return (ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected ||
698             ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected);
699 }
700 
isSecondaryAnimating(hwc_context_t * ctx)701 static 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 */
isVDConnected(hwc_context_t * ctx)712 static 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