blob: 5856946c40ac711efa66e360b529332594ae38b7 [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
3 *
Naseer Ahmed7c958d42012-07-31 18:57:03 -07004 * 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
Naseer Ahmed7c958d42012-07-31 18:57:03 -070028#define DEFAULT_IDLE_TIME 2000
Sushil Chauhan69f2bb22013-02-13 10:50:47 -080029#define MAX_PIPES_PER_MIXER 4
Naseer Ahmed7c958d42012-07-31 18:57:03 -070030
Saurabh Shahacf10202013-02-26 10:15:15 -080031namespace overlay {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080032class Rotator;
Saurabh Shahacf10202013-02-26 10:15:15 -080033};
34
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
Naseer Ahmed54821fe2012-11-28 18:44:38 -050036namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070037
38class MDPComp {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080039public:
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080040 explicit MDPComp(int);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080041 virtual ~MDPComp(){};
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080042 /*sets up mdp comp for the current frame */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080043 int prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080044 /* draw */
45 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list) = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080046 /* dumpsys */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080047 void dump(android::String8& buf);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080048
Saurabh Shah88e4d272013-09-03 13:31:29 -070049 static MDPComp* getObject(hwc_context_t *ctx, const int& dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080050 /* Handler to invoke frame redraw on Idle Timer expiry */
51 static void timeout_handler(void *udata);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080052 /* Initialize MDP comp*/
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080053 static bool init(hwc_context_t *ctx);
Saurabh Shah98acd092013-05-03 10:48:24 -070054 static void resetIdleFallBack() { sIdleFallBack = false; }
Saurabh Shah3c1a6b02013-11-22 11:10:20 -080055 static void reset() { sBwClaimed = 0.0; };
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080056
57protected:
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070058 enum { MAX_SEC_LAYERS = 1 }; //TODO add property support
59
Naseer Ahmed54821fe2012-11-28 18:44:38 -050060 enum ePipeType {
61 MDPCOMP_OV_RGB = ovutils::OV_MDP_PIPE_RGB,
62 MDPCOMP_OV_VG = ovutils::OV_MDP_PIPE_VG,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080063 MDPCOMP_OV_DMA = ovutils::OV_MDP_PIPE_DMA,
Naseer Ahmed54821fe2012-11-28 18:44:38 -050064 MDPCOMP_OV_ANY,
Naseer Ahmed7c958d42012-07-31 18:57:03 -070065 };
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080066
67 /* mdp pipe data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080068 struct MdpPipeInfo {
69 int zOrder;
70 virtual ~MdpPipeInfo(){};
71 };
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080072
73 /* per layer data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080074 struct PipeLayerPair {
75 MdpPipeInfo *pipeInfo;
Saurabh Shahacf10202013-02-26 10:15:15 -080076 overlay::Rotator* rot;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080077 int listIndex;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080078 };
79
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080080 /* per frame data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080081 struct FrameInfo {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080082 /* maps layer list to mdp list */
83 int layerCount;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -070084 int layerToMDP[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080085
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;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -070092 bool isFBComposed[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070093 /* layers lying outside ROI. Will
94 * be dropped off from the composition */
95 int dropCount;
96 bool drop[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080097
98 bool needsRedraw;
99 int fbZ;
100
101 /* c'tor */
102 FrameInfo();
103 /* clear old frame data */
Saurabh Shahaa236822013-04-24 18:07:26 -0700104 void reset(const int& numLayers);
105 void map();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800106 };
107
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800108 /* cached data */
109 struct LayerCache {
110 int layerCount;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700111 buffer_handle_t hnd[MAX_NUM_APP_LAYERS];
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530112 bool isFBComposed[MAX_NUM_APP_LAYERS];
113 bool drop[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800114
115 /* c'tor */
116 LayerCache();
117 /* clear caching info*/
118 void reset();
Saurabh Shahaa236822013-04-24 18:07:26 -0700119 void cacheAll(hwc_display_contents_1_t* list);
120 void updateCounts(const FrameInfo&);
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800121 bool isSameFrame(const FrameInfo& curFrame,
122 hwc_display_contents_1_t* list);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800123 };
124
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800125 /* allocates pipe from pipe book */
126 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800127 hwc_display_contents_1_t* list) = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700128 /* allocate MDP pipes from overlay */
129 ovutils::eDest getMdpPipe(hwc_context_t *ctx, ePipeType type, int mixer);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800130 /* configures MPD pipes */
131 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800132 PipeLayerPair& pipeLayerPair) = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700133 /* Checks for pipes needed versus pipes available */
134 virtual bool arePipesAvailable(hwc_context_t *ctx,
135 hwc_display_contents_1_t* list) = 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800136
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800137 /* set/reset flags for MDPComp */
138 void setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800139 hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800140 /* checks for conditions where mdpcomp is not possible */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800141 bool isFrameDoable(hwc_context_t *ctx);
142 /* checks for conditions where RGB layers cannot be bypassed */
143 bool isFullFrameDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700144 /* checks if full MDP comp can be done */
145 bool fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
146 /* check if we can use layer cache to do at least partial MDP comp */
147 bool partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700148 /* Partial MDP comp that uses caching to save power as primary goal */
149 bool cacheBasedComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
150 /* Partial MDP comp that uses number of pixels to optimize perf goal */
151 bool loadBasedComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
152 /* Checks if its worth doing load based partial comp */
153 bool isLoadBasedCompDoable(hwc_context_t *ctx,
154 hwc_display_contents_1_t* list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700155 /* checks for conditions where only video can be bypassed */
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700156 bool isOnlyVideoDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list,
157 bool secureOnly);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800158 /* checks for conditions where YUV layers cannot be bypassed */
159 bool isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700160 /* calcs bytes read by MDP for a given frame */
161 uint32_t calcMDPBytesRead(hwc_context_t *ctx,
162 hwc_display_contents_1_t* list);
163 /* checks if the required bandwidth exceeds a certain max */
164 bool bandwidthCheck(hwc_context_t *ctx, const uint32_t& size);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700165 /* generates ROI based on the modified area of the frame */
166 void generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list);
167 bool validateAndApplyROI(hwc_context_t *ctx, hwc_display_contents_1_t* list,
168 hwc_rect_t roi);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800169
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800170 /* Is debug enabled */
171 static bool isDebug() { return sDebugLogs ? true : false; };
172 /* Is feature enabled */
173 static bool isEnabled() { return sEnabled; };
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530174 /* checks for mdp comp dimension limitation */
175 bool isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800176 /* tracks non updating layers*/
177 void updateLayerCache(hwc_context_t* ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800178 /* optimize layers for mdp comp*/
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530179 bool markLayersForCaching(hwc_context_t* ctx,
180 hwc_display_contents_1_t* list);
181 int getBatch(hwc_display_contents_1_t* list,
182 int& maxBatchStart, int& maxBatchEnd,
183 int& maxBatchCount);
184 bool canPushBatchToTop(const hwc_display_contents_1_t* list,
185 int fromIndex, int toIndex);
186 bool intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
187 int fromIndex, int toIndex, int targetLayerIndex);
188
189 /* updates cache map with YUV info */
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700190 void updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
191 bool secureOnly);
Saurabh Shahaa236822013-04-24 18:07:26 -0700192 bool programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list);
193 bool programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700194 void reset(const int& numAppLayers, hwc_display_contents_1_t* list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700195 bool isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer);
Saurabh Shah173f4242013-11-20 09:50:12 -0800196 bool resourceCheck(hwc_context_t *ctx, hwc_display_contents_1_t *list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800197
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800198 int mDpy;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199 static bool sEnabled;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700200 static bool sEnableMixedMode;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700201 /* Enables Partial frame composition */
202 static bool sEnablePartialFrameUpdate;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800203 static bool sDebugLogs;
204 static bool sIdleFallBack;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800205 static int sMaxPipesPerMixer;
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700206 //Max bandwidth. Value is in GBPS. For ex: 2.3 means 2.3GBPS
207 static float sMaxBw;
Saurabh Shah3c1a6b02013-11-22 11:10:20 -0800208 //Tracks composition bandwidth claimed. Represented as the total
209 //w*h*bpp*fps (gigabytes-per-second) going to MDP mixers.
210 static double sBwClaimed;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800211 static IdleInvalidator *idleInvalidator;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800212 struct FrameInfo mCurrentFrame;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800213 struct LayerCache mCachedFrame;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800214};
215
Saurabh Shah88e4d272013-09-03 13:31:29 -0700216class MDPCompNonSplit : public MDPComp {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800217public:
Saurabh Shah88e4d272013-09-03 13:31:29 -0700218 explicit MDPCompNonSplit(int dpy):MDPComp(dpy){};
219 virtual ~MDPCompNonSplit(){};
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800221
222private:
Saurabh Shah88e4d272013-09-03 13:31:29 -0700223 struct MdpPipeInfoNonSplit : public MdpPipeInfo {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800224 ovutils::eDest index;
Saurabh Shah88e4d272013-09-03 13:31:29 -0700225 virtual ~MdpPipeInfoNonSplit() {};
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700226 };
227
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700228 /* configure's overlay pipes for the frame */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800229 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230 PipeLayerPair& pipeLayerPair);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800231
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700232 /* allocates pipes to selected candidates */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800233 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234 hwc_display_contents_1_t* list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800235
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700236 /* Checks for pipes needed versus pipes available */
237 virtual bool arePipesAvailable(hwc_context_t *ctx,
238 hwc_display_contents_1_t* list);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700239
240 /* Checks for video pipes needed versus pipes available */
241 virtual bool areVGPipesAvailable(hwc_context_t *ctx,
242 hwc_display_contents_1_t* list);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700243};
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800244
Saurabh Shah88e4d272013-09-03 13:31:29 -0700245class MDPCompSplit : public MDPComp {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800246public:
Saurabh Shah88e4d272013-09-03 13:31:29 -0700247 explicit MDPCompSplit(int dpy):MDPComp(dpy){};
248 virtual ~MDPCompSplit(){};
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800249 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
250private:
Saurabh Shah88e4d272013-09-03 13:31:29 -0700251 struct MdpPipeInfoSplit : public MdpPipeInfo {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800252 ovutils::eDest lIndex;
253 ovutils::eDest rIndex;
Saurabh Shah88e4d272013-09-03 13:31:29 -0700254 virtual ~MdpPipeInfoSplit() {};
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800255 };
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800256
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800257 bool acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah88e4d272013-09-03 13:31:29 -0700258 MdpPipeInfoSplit& pipe_info, ePipeType type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800259
260 /* configure's overlay pipes for the frame */
261 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800262 PipeLayerPair& pipeLayerPair);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800263
264 /* allocates pipes to selected candidates */
265 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800266 hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800267
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700268 /* Checks for pipes needed versus pipes available */
269 virtual bool arePipesAvailable(hwc_context_t *ctx,
270 hwc_display_contents_1_t* list);
271
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700272 /* Checks for video pipes needed versus pipes available */
273 virtual bool areVGPipesAvailable(hwc_context_t *ctx,
274 hwc_display_contents_1_t* list);
275
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700276 int pipesNeeded(hwc_context_t *ctx, hwc_display_contents_1_t* list,
277 int mixer);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800278};
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700279
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700280}; //namespace
281#endif