hwc_mdpcomp.h revision b5199b08a351177e2d572b29d04f5a05069b3c2a
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#define DEFAULT_IDLE_TIME 2000 29#define MAX_PIPES_PER_MIXER 4 30 31namespace overlay { 32class Rotator; 33}; 34 35namespace qhwc { 36namespace ovutils = overlay::utils; 37 38class MDPComp { 39public: 40 explicit MDPComp(int); 41 virtual ~MDPComp(){}; 42 /*sets up mdp comp for the current frame */ 43 int prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list); 44 /* draw */ 45 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list) = 0; 46 /* dumpsys */ 47 void dump(android::String8& buf); 48 49 static MDPComp* getObject(const int& width, const int& rightSplit, 50 const int& dpy); 51 /* Handler to invoke frame redraw on Idle Timer expiry */ 52 static void timeout_handler(void *udata); 53 /* Initialize MDP comp*/ 54 static bool init(hwc_context_t *ctx); 55 static void resetIdleFallBack() { sIdleFallBack = false; } 56 57protected: 58 enum { MAX_SEC_LAYERS = 1 }; //TODO add property support 59 60 enum ePipeType { 61 MDPCOMP_OV_RGB = ovutils::OV_MDP_PIPE_RGB, 62 MDPCOMP_OV_VG = ovutils::OV_MDP_PIPE_VG, 63 MDPCOMP_OV_DMA = ovutils::OV_MDP_PIPE_DMA, 64 MDPCOMP_OV_ANY, 65 }; 66 67 /* mdp pipe data */ 68 struct MdpPipeInfo { 69 int zOrder; 70 virtual ~MdpPipeInfo(){}; 71 }; 72 73 /* per layer data */ 74 struct PipeLayerPair { 75 MdpPipeInfo *pipeInfo; 76 overlay::Rotator* rot; 77 int listIndex; 78 }; 79 80 /* per frame data */ 81 struct FrameInfo { 82 /* maps layer list to mdp list */ 83 int layerCount; 84 int layerToMDP[MAX_NUM_APP_LAYERS]; 85 86 /* maps mdp list to layer list */ 87 int mdpCount; 88 struct PipeLayerPair mdpToLayer[MAX_PIPES_PER_MIXER]; 89 90 /* layer composing on FB? */ 91 int fbCount; 92 bool isFBComposed[MAX_NUM_APP_LAYERS]; 93 94 bool needsRedraw; 95 int fbZ; 96 97 /* c'tor */ 98 FrameInfo(); 99 /* clear old frame data */ 100 void reset(const int& numLayers); 101 void map(); 102 }; 103 104 /* cached data */ 105 struct LayerCache { 106 int layerCount; 107 int mdpCount; 108 int fbCount; 109 int fbZ; 110 buffer_handle_t hnd[MAX_NUM_APP_LAYERS]; 111 112 /* c'tor */ 113 LayerCache(); 114 /* clear caching info*/ 115 void reset(); 116 void cacheAll(hwc_display_contents_1_t* list); 117 void updateCounts(const FrameInfo&); 118 }; 119 120 /* allocates pipe from pipe book */ 121 virtual bool allocLayerPipes(hwc_context_t *ctx, 122 hwc_display_contents_1_t* list) = 0; 123 /* allocate MDP pipes from overlay */ 124 ovutils::eDest getMdpPipe(hwc_context_t *ctx, ePipeType type, int mixer); 125 /* configures MPD pipes */ 126 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer, 127 PipeLayerPair& pipeLayerPair) = 0; 128 /* Checks for pipes needed versus pipes available */ 129 virtual bool arePipesAvailable(hwc_context_t *ctx, 130 hwc_display_contents_1_t* list) = 0; 131 132 /* set/reset flags for MDPComp */ 133 void setMDPCompLayerFlags(hwc_context_t *ctx, 134 hwc_display_contents_1_t* list); 135 /* checks for conditions where mdpcomp is not possible */ 136 bool isFrameDoable(hwc_context_t *ctx); 137 /* checks for conditions where RGB layers cannot be bypassed */ 138 bool isFullFrameDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list); 139 /* checks if full MDP comp can be done */ 140 bool fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list); 141 /* check if we can use layer cache to do at least partial MDP comp */ 142 bool partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list); 143 /* Partial MDP comp that uses caching to save power as primary goal */ 144 bool cacheBasedComp(hwc_context_t *ctx, hwc_display_contents_1_t* list); 145 /* Partial MDP comp that uses number of pixels to optimize perf goal */ 146 bool loadBasedComp(hwc_context_t *ctx, hwc_display_contents_1_t* list); 147 /* Checks if its worth doing load based partial comp */ 148 bool isLoadBasedCompDoable(hwc_context_t *ctx, 149 hwc_display_contents_1_t* list); 150 /* checks for conditions where only video can be bypassed */ 151 bool isOnlyVideoDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list); 152 /* checks for conditions where YUV layers cannot be bypassed */ 153 bool isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer); 154 155 /* Is debug enabled */ 156 static bool isDebug() { return sDebugLogs ? true : false; }; 157 /* Is feature enabled */ 158 static bool isEnabled() { return sEnabled; }; 159 /* checks for mdp comp dimension limitation */ 160 bool isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer); 161 /* tracks non updating layers*/ 162 void updateLayerCache(hwc_context_t* ctx, hwc_display_contents_1_t* list); 163 /* optimize layers for mdp comp*/ 164 bool batchLayers(hwc_context_t *ctx, hwc_display_contents_1_t* list); 165 /* updates cache map with YUV info */ 166 void updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list); 167 bool programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list); 168 bool programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list); 169 void reset(const int& numAppLayers, hwc_display_contents_1_t* list); 170 bool isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer); 171 172 int mDpy; 173 static bool sEnabled; 174 static bool sEnableMixedMode; 175 static bool sDebugLogs; 176 static bool sIdleFallBack; 177 static int sMaxPipesPerMixer; 178 static IdleInvalidator *idleInvalidator; 179 struct FrameInfo mCurrentFrame; 180 struct LayerCache mCachedFrame; 181}; 182 183class MDPCompLowRes : public MDPComp { 184public: 185 explicit MDPCompLowRes(int dpy):MDPComp(dpy){}; 186 virtual ~MDPCompLowRes(){}; 187 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list); 188 189private: 190 struct MdpPipeInfoLowRes : public MdpPipeInfo { 191 ovutils::eDest index; 192 virtual ~MdpPipeInfoLowRes() {}; 193 }; 194 195 /* configure's overlay pipes for the frame */ 196 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer, 197 PipeLayerPair& pipeLayerPair); 198 199 /* allocates pipes to selected candidates */ 200 virtual bool allocLayerPipes(hwc_context_t *ctx, 201 hwc_display_contents_1_t* list); 202 203 /* Checks for pipes needed versus pipes available */ 204 virtual bool arePipesAvailable(hwc_context_t *ctx, 205 hwc_display_contents_1_t* list); 206}; 207 208class MDPCompHighRes : public MDPComp { 209public: 210 explicit MDPCompHighRes(int dpy):MDPComp(dpy){}; 211 virtual ~MDPCompHighRes(){}; 212 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list); 213private: 214 struct MdpPipeInfoHighRes : public MdpPipeInfo { 215 ovutils::eDest lIndex; 216 ovutils::eDest rIndex; 217 virtual ~MdpPipeInfoHighRes() {}; 218 }; 219 220 bool acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer, 221 MdpPipeInfoHighRes& pipe_info, ePipeType type); 222 223 /* configure's overlay pipes for the frame */ 224 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer, 225 PipeLayerPair& pipeLayerPair); 226 227 /* allocates pipes to selected candidates */ 228 virtual bool allocLayerPipes(hwc_context_t *ctx, 229 hwc_display_contents_1_t* list); 230 231 /* Checks for pipes needed versus pipes available */ 232 virtual bool arePipesAvailable(hwc_context_t *ctx, 233 hwc_display_contents_1_t* list); 234 235 int pipesNeeded(hwc_context_t *ctx, hwc_display_contents_1_t* list, 236 int mixer); 237}; 238 239}; //namespace 240#endif 241