Home | History | Annotate | Download | only in libhwcomposer
      1 /*
      2  * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
      3  *
      4  * Not a Contribution, Apache license notifications and license are retained
      5  * for attribution purposes only.
      6  *
      7  * Licensed under the Apache License, Version 2.0 (the "License");
      8  * you may not use this file except in compliance with the License.
      9  * You may obtain a copy of the License at
     10  *
     11  *      http://www.apache.org/licenses/LICENSE-2.0
     12  *
     13  * Unless required by applicable law or agreed to in writing, software
     14  * distributed under the License is distributed on an "AS IS" BASIS,
     15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16  * See the License for the specific language governing permissions and
     17  * limitations under the License.
     18  */
     19 
     20 #ifndef HWC_MDP_COMP
     21 #define HWC_MDP_COMP
     22 
     23 #include <hwc_utils.h>
     24 #include <idle_invalidator.h>
     25 #include <cutils/properties.h>
     26 #include <overlay.h>
     27 
     28 namespace overlay {
     29 class Rotator;
     30 };
     31 
     32 namespace qhwc {
     33 namespace ovutils = overlay::utils;
     34 
     35 class MDPComp {
     36 public:
     37     explicit MDPComp(int);
     38     virtual ~MDPComp(){};
     39     /*sets up mdp comp for the current frame */
     40     int prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list);
     41     /* draw */
     42     virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list) = 0;
     43     //Reset values
     44     void reset();
     45     /* dumpsys */
     46     void dump(android::String8& buf, hwc_context_t *ctx);
     47     bool isGLESOnlyComp() { return (mCurrentFrame.mdpCount == 0); }
     48     int drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t* list);
     49     static MDPComp* getObject(hwc_context_t *ctx, const int& dpy);
     50     /* Handler to invoke frame redraw on Idle Timer expiry */
     51     static void timeout_handler(void *udata);
     52     /* Initialize MDP comp*/
     53     static bool init(hwc_context_t *ctx);
     54     static void resetIdleFallBack() { sIdleFallBack = false; }
     55     static bool isIdleFallback() { return sIdleFallBack; }
     56     static void dynamicDebug(bool enable){ sDebugLogs = enable; }
     57     static void setIdleTimeout(const uint32_t& timeout);
     58     static void setMaxPipesPerMixer(const uint32_t value);
     59     static int setPartialUpdatePref(hwc_context_t *ctx, bool enable);
     60     static bool getPartialUpdatePref(hwc_context_t *ctx);
     61     void setDynRefreshRate(hwc_context_t *ctx, hwc_display_contents_1_t* list);
     62 
     63 protected:
     64     enum ePipeType {
     65         MDPCOMP_OV_RGB = ovutils::OV_MDP_PIPE_RGB,
     66         MDPCOMP_OV_VG = ovutils::OV_MDP_PIPE_VG,
     67         MDPCOMP_OV_DMA = ovutils::OV_MDP_PIPE_DMA,
     68         MDPCOMP_OV_ANY,
     69     };
     70 
     71     //Simulation flags
     72     enum {
     73         MDPCOMP_AVOID_FULL_MDP = 0x001,
     74         MDPCOMP_AVOID_CACHE_MDP = 0x002,
     75         MDPCOMP_AVOID_LOAD_MDP = 0x004,
     76         MDPCOMP_AVOID_VIDEO_ONLY = 0x008,
     77         MDPCOMP_AVOID_MDP_ONLY_LAYERS = 0x010,
     78     };
     79 
     80     /* mdp pipe data */
     81     struct MdpPipeInfo {
     82         int zOrder;
     83         virtual ~MdpPipeInfo(){};
     84     };
     85 
     86     struct MdpYUVPipeInfo : public MdpPipeInfo{
     87         ovutils::eDest lIndex;
     88         ovutils::eDest rIndex;
     89         virtual ~MdpYUVPipeInfo(){};
     90     };
     91 
     92     /* per layer data */
     93     struct PipeLayerPair {
     94         MdpPipeInfo *pipeInfo;
     95         overlay::Rotator* rot;
     96         int listIndex;
     97     };
     98 
     99     /* per frame data */
    100     struct FrameInfo {
    101         /* maps layer list to mdp list */
    102         int layerCount;
    103         int layerToMDP[MAX_NUM_APP_LAYERS];
    104 
    105         /* maps mdp list to layer list */
    106         int mdpCount;
    107         struct PipeLayerPair mdpToLayer[MAX_NUM_BLEND_STAGES];
    108 
    109         /* layer composing on FB? */
    110         int fbCount;
    111         bool isFBComposed[MAX_NUM_APP_LAYERS];
    112         /* layers lying outside ROI. Will
    113          * be dropped off from the composition */
    114         int dropCount;
    115         bool drop[MAX_NUM_APP_LAYERS];
    116 
    117         bool needsRedraw;
    118         int fbZ;
    119 
    120         /* c'tor */
    121         FrameInfo();
    122         /* clear old frame data */
    123         void reset(const int& numLayers);
    124         void map();
    125     };
    126 
    127     /* cached data */
    128     struct LayerCache {
    129         int layerCount;
    130         buffer_handle_t hnd[MAX_NUM_APP_LAYERS];
    131         bool isFBComposed[MAX_NUM_APP_LAYERS];
    132         bool drop[MAX_NUM_APP_LAYERS];
    133 
    134         /* c'tor */
    135         LayerCache();
    136         /* clear caching info*/
    137         void reset();
    138         void cacheAll(hwc_display_contents_1_t* list);
    139         void updateCounts(const FrameInfo&);
    140         bool isSameFrame(const FrameInfo& curFrame,
    141                          hwc_display_contents_1_t* list);
    142     };
    143 
    144     /* allocates pipe from pipe book */
    145     virtual bool allocLayerPipes(hwc_context_t *ctx,
    146                                  hwc_display_contents_1_t* list) = 0;
    147     /* configures MPD pipes */
    148     virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
    149                           PipeLayerPair& pipeLayerPair) = 0;
    150     /* Increments mdpCount if 4k2k yuv layer split is enabled.
    151      * updates framebuffer z order if fb lies above source-split layer */
    152     virtual void adjustForSourceSplit(hwc_context_t *ctx,
    153             hwc_display_contents_1_t* list) = 0;
    154     /* configures 4kx2k yuv layer*/
    155     virtual int configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
    156             PipeLayerPair& PipeLayerPair) = 0;
    157     /* generates ROI based on the modified area of the frame */
    158     virtual void generateROI(hwc_context_t *ctx,
    159             hwc_display_contents_1_t* list) = 0;
    160     /* validates the ROI generated for fallback conditions */
    161     virtual bool validateAndApplyROI(hwc_context_t *ctx,
    162             hwc_display_contents_1_t* list) = 0;
    163     /* Trims fbRect calculated against ROI generated */
    164     virtual void trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) = 0;
    165 
    166     /* set/reset flags for MDPComp */
    167     void setMDPCompLayerFlags(hwc_context_t *ctx,
    168                               hwc_display_contents_1_t* list);
    169     void setRedraw(hwc_context_t *ctx,
    170             hwc_display_contents_1_t* list);
    171     /* checks for conditions where mdpcomp is not possible */
    172     bool isFrameDoable(hwc_context_t *ctx);
    173     /* checks for conditions where RGB layers cannot be bypassed */
    174     bool tryFullFrame(hwc_context_t *ctx, hwc_display_contents_1_t* list);
    175     /* checks if full MDP comp can be done */
    176     bool fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
    177     /* Full MDP Composition with Peripheral Tiny Overlap Removal */
    178     bool fullMDPCompWithPTOR(hwc_context_t *ctx,hwc_display_contents_1_t* list);
    179     /* check if we can use layer cache to do at least partial MDP comp */
    180     bool partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
    181     /* Partial MDP comp that uses caching to save power as primary goal */
    182     bool cacheBasedComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
    183     /* Partial MDP comp that balances the load between MDP and GPU such that
    184      * MDP is loaded to the max of its capacity. The lower z order layers are
    185      * fed to MDP, whereas the upper ones to GPU, because the upper ones have
    186      * lower number of pixels and can reduce GPU processing time */
    187     bool loadBasedComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
    188     /* Checks if its worth doing load based partial comp */
    189     bool isLoadBasedCompDoable(hwc_context_t *ctx);
    190     /* checks for conditions where only video can be bypassed */
    191     bool tryVideoOnly(hwc_context_t *ctx, hwc_display_contents_1_t* list);
    192     bool videoOnlyComp(hwc_context_t *ctx, hwc_display_contents_1_t* list,
    193             bool secureOnly);
    194     /* checks for conditions where only secure RGB and video can be bypassed */
    195     bool tryMDPOnlyLayers(hwc_context_t *ctx, hwc_display_contents_1_t* list);
    196     bool mdpOnlyLayersComp(hwc_context_t *ctx, hwc_display_contents_1_t* list,
    197             bool secureOnly);
    198     /* checks for conditions where YUV layers cannot be bypassed */
    199     bool isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer);
    200     /* checks for conditions where Secure RGB layers cannot be bypassed */
    201     bool isSecureRGBDoable(hwc_context_t* ctx, hwc_layer_1_t* layer);
    202     /* checks if MDP/MDSS can process current list w.r.to HW limitations
    203      * All peculiar HW limitations should go here */
    204     bool hwLimitationsCheck(hwc_context_t* ctx, hwc_display_contents_1_t* list);
    205     /* Is debug enabled */
    206     static bool isDebug() { return sDebugLogs ? true : false; };
    207     /* Is feature enabled */
    208     static bool isEnabled() { return sEnabled; };
    209     /* checks for mdp comp dimension limitation */
    210     bool isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer);
    211     /* tracks non updating layers*/
    212     void updateLayerCache(hwc_context_t* ctx, hwc_display_contents_1_t* list,
    213                           FrameInfo& frame);
    214     /* optimize layers for mdp comp*/
    215     bool markLayersForCaching(hwc_context_t* ctx,
    216             hwc_display_contents_1_t* list);
    217     int getBatch(hwc_display_contents_1_t* list,
    218             int& maxBatchStart, int& maxBatchEnd,
    219             int& maxBatchCount);
    220     bool canPushBatchToTop(const hwc_display_contents_1_t* list,
    221             int fromIndex, int toIndex);
    222     bool intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
    223             int fromIndex, int toIndex, int targetLayerIndex);
    224 
    225     /* drop other non-AIV layers from external display list.*/
    226     void dropNonAIVLayers(hwc_context_t* ctx, hwc_display_contents_1_t* list);
    227 
    228         /* updates cache map with YUV info */
    229     void updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
    230             bool secureOnly, FrameInfo& frame);
    231     /* updates cache map with secure RGB info */
    232     void updateSecureRGB(hwc_context_t* ctx,
    233             hwc_display_contents_1_t* list);
    234     /* Validates if the GPU/MDP layer split chosen by a strategy is supported
    235      * by MDP.
    236      * Sets up MDP comp data structures to reflect covnversion from layers to
    237      * overlay pipes.
    238      * Configures overlay.
    239      * Configures if GPU should redraw.
    240      */
    241     bool postHeuristicsHandling(hwc_context_t *ctx,
    242             hwc_display_contents_1_t* list);
    243     void reset(hwc_context_t *ctx);
    244     bool isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer);
    245     bool resourceCheck(hwc_context_t* ctx, hwc_display_contents_1_t* list);
    246     hwc_rect_t getUpdatingFBRect(hwc_context_t *ctx,
    247             hwc_display_contents_1_t* list);
    248     /* checks for conditions to enable partial udpate */
    249     bool canPartialUpdate(hwc_context_t *ctx, hwc_display_contents_1_t* list);
    250     // Checks if only videocontent is updating
    251     bool onlyVideosUpdating(hwc_context_t *ctx, hwc_display_contents_1_t* list);
    252     static bool loadPerfLib();
    253     void setPerfHint(hwc_context_t *ctx, hwc_display_contents_1_t* list);
    254 
    255     int mDpy;
    256     static bool sEnabled;
    257     static bool sEnableMixedMode;
    258     static int sSimulationFlags;
    259     static bool sDebugLogs;
    260     static bool sIdleFallBack;
    261     /* Handles the timeout event from kernel, if the value is set to true */
    262     static bool sHandleTimeout;
    263     static int sMaxPipesPerMixer;
    264     static bool sSrcSplitEnabled;
    265     static IdleInvalidator *sIdleInvalidator;
    266     static int sMaxSecLayers;
    267     static bool sIsPartialUpdateActive;
    268     struct FrameInfo mCurrentFrame;
    269     struct LayerCache mCachedFrame;
    270     //Enable 4kx2k yuv layer split
    271     static bool sEnableYUVsplit;
    272     bool mModeOn; // if prepare happened
    273     bool allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index);
    274     //Enable Partial Update for MDP3 targets
    275     static bool enablePartialUpdateForMDP3;
    276     static void *sLibPerfHint;
    277     static int sPerfLockHandle;
    278     static int (*sPerfLockAcquire)(int, int, int*, int);
    279     static int (*sPerfLockRelease)(int value);
    280     static int sPerfHintWindow;
    281 
    282 };
    283 
    284 class MDPCompNonSplit : public MDPComp {
    285 public:
    286     explicit MDPCompNonSplit(int dpy):MDPComp(dpy){};
    287     virtual ~MDPCompNonSplit(){};
    288     virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
    289 
    290 private:
    291     struct MdpPipeInfoNonSplit : public MdpPipeInfo {
    292         ovutils::eDest index;
    293         virtual ~MdpPipeInfoNonSplit() {};
    294     };
    295 
    296     /* configure's overlay pipes for the frame */
    297     virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
    298                           PipeLayerPair& pipeLayerPair);
    299 
    300     /* allocates pipes to selected candidates */
    301     virtual bool allocLayerPipes(hwc_context_t *ctx,
    302                                  hwc_display_contents_1_t* list);
    303 
    304     /* Increments mdpCount if 4k2k yuv layer split is enabled.
    305      * updates framebuffer z order if fb lies above source-split layer */
    306     virtual void adjustForSourceSplit(hwc_context_t *ctx,
    307             hwc_display_contents_1_t* list);
    308 
    309     /* configures 4kx2k yuv layer to 2 VG pipes*/
    310     virtual int configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
    311             PipeLayerPair& PipeLayerPair);
    312     /* generates ROI based on the modified area of the frame */
    313     virtual void generateROI(hwc_context_t *ctx,
    314             hwc_display_contents_1_t* list);
    315     /* validates the ROI generated for fallback conditions */
    316     virtual bool validateAndApplyROI(hwc_context_t *ctx,
    317             hwc_display_contents_1_t* list);
    318     /* Trims fbRect calculated against ROI generated */
    319     virtual void trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect);
    320 };
    321 
    322 class MDPCompSplit : public MDPComp {
    323 public:
    324     explicit MDPCompSplit(int dpy):MDPComp(dpy){};
    325     virtual ~MDPCompSplit(){};
    326     virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
    327 
    328 protected:
    329     struct MdpPipeInfoSplit : public MdpPipeInfo {
    330         ovutils::eDest lIndex;
    331         ovutils::eDest rIndex;
    332         virtual ~MdpPipeInfoSplit() {};
    333     };
    334 
    335     virtual bool acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
    336                          MdpPipeInfoSplit& pipe_info);
    337 
    338     /* configure's overlay pipes for the frame */
    339     virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
    340                           PipeLayerPair& pipeLayerPair);
    341 
    342     /* allocates pipes to selected candidates */
    343     virtual bool allocLayerPipes(hwc_context_t *ctx,
    344                                  hwc_display_contents_1_t* list);
    345 private:
    346     /* Increments mdpCount if 4k2k yuv layer split is enabled.
    347      * updates framebuffer z order if fb lies above source-split layer */
    348     virtual void adjustForSourceSplit(hwc_context_t *ctx,
    349             hwc_display_contents_1_t* list);
    350 
    351     /* configures 4kx2k yuv layer*/
    352     virtual int configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
    353             PipeLayerPair& PipeLayerPair);
    354     /* generates ROI based on the modified area of the frame */
    355     virtual void generateROI(hwc_context_t *ctx,
    356             hwc_display_contents_1_t* list);
    357     /* validates the ROI generated for fallback conditions */
    358     virtual bool validateAndApplyROI(hwc_context_t *ctx,
    359             hwc_display_contents_1_t* list);
    360     /* Trims fbRect calculated against ROI generated */
    361     virtual void trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect);
    362 };
    363 
    364 class MDPCompSrcSplit : public MDPCompSplit {
    365 public:
    366     explicit MDPCompSrcSplit(int dpy) : MDPCompSplit(dpy){};
    367     virtual ~MDPCompSrcSplit(){};
    368 private:
    369     virtual bool acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
    370             MdpPipeInfoSplit& pipe_info);
    371 
    372     virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
    373             PipeLayerPair& pipeLayerPair);
    374 };
    375 
    376 }; //namespace
    377 #endif
    378