blob: d872cdfb5c888f4681914f09a4b7c47083a0a618 [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 Shah8c5c8522013-08-29 17:32:49 -070055 static void reset() { sCompBytesClaimed = 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;
111 int mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700112 int fbCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700113 int fbZ;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700114 buffer_handle_t hnd[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800115
116 /* c'tor */
117 LayerCache();
118 /* clear caching info*/
119 void reset();
Saurabh Shahaa236822013-04-24 18:07:26 -0700120 void cacheAll(hwc_display_contents_1_t* list);
121 void updateCounts(const FrameInfo&);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800122 };
123
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800124 /* allocates pipe from pipe book */
125 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800126 hwc_display_contents_1_t* list) = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700127 /* allocate MDP pipes from overlay */
128 ovutils::eDest getMdpPipe(hwc_context_t *ctx, ePipeType type, int mixer);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800129 /* configures MPD pipes */
130 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800131 PipeLayerPair& pipeLayerPair) = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700132 /* Checks for pipes needed versus pipes available */
133 virtual bool arePipesAvailable(hwc_context_t *ctx,
134 hwc_display_contents_1_t* list) = 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800135
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800136 /* set/reset flags for MDPComp */
137 void setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800138 hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800139 /* checks for conditions where mdpcomp is not possible */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800140 bool isFrameDoable(hwc_context_t *ctx);
141 /* checks for conditions where RGB layers cannot be bypassed */
142 bool isFullFrameDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700143 /* checks if full MDP comp can be done */
144 bool fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
145 /* check if we can use layer cache to do at least partial MDP comp */
146 bool partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
147 /* checks for conditions where only video can be bypassed */
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700148 bool isOnlyVideoDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list,
149 bool secureOnly);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800150 /* checks for conditions where YUV layers cannot be bypassed */
151 bool isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700152 /* calcs bytes read by MDP for a given frame */
153 uint32_t calcMDPBytesRead(hwc_context_t *ctx,
154 hwc_display_contents_1_t* list);
155 /* checks if the required bandwidth exceeds a certain max */
156 bool bandwidthCheck(hwc_context_t *ctx, const uint32_t& size);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700157 /* generates ROI based on the modified area of the frame */
158 void generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list);
159 bool validateAndApplyROI(hwc_context_t *ctx, hwc_display_contents_1_t* list,
160 hwc_rect_t roi);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800161
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800162 /* Is debug enabled */
163 static bool isDebug() { return sDebugLogs ? true : false; };
164 /* Is feature enabled */
165 static bool isEnabled() { return sEnabled; };
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530166 /* checks for mdp comp dimension limitation */
167 bool isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800168 /* tracks non updating layers*/
169 void updateLayerCache(hwc_context_t* ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800170 /* optimize layers for mdp comp*/
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700171 bool batchLayers(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800172 /* updates cache map with YUV info */
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700173 void updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
174 bool secureOnly);
Saurabh Shahaa236822013-04-24 18:07:26 -0700175 bool programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list);
176 bool programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700177 void reset(const int& numAppLayers, hwc_display_contents_1_t* list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700178 bool isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800179
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800180 int mDpy;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800181 static bool sEnabled;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700182 static bool sEnableMixedMode;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700183 /* Enables Partial frame composition */
184 static bool sEnablePartialFrameUpdate;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800185 static bool sDebugLogs;
186 static bool sIdleFallBack;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 static int sMaxPipesPerMixer;
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700188 //Max bandwidth. Value is in GBPS. For ex: 2.3 means 2.3GBPS
189 static float sMaxBw;
190 //Tracks composition bytes claimed. Represented as the total w*h*bpp
191 //going to MDP mixers
192 static uint32_t sCompBytesClaimed;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800193 static IdleInvalidator *idleInvalidator;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800194 struct FrameInfo mCurrentFrame;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800195 struct LayerCache mCachedFrame;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800196};
197
Saurabh Shah88e4d272013-09-03 13:31:29 -0700198class MDPCompNonSplit : public MDPComp {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199public:
Saurabh Shah88e4d272013-09-03 13:31:29 -0700200 explicit MDPCompNonSplit(int dpy):MDPComp(dpy){};
201 virtual ~MDPCompNonSplit(){};
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800202 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800203
204private:
Saurabh Shah88e4d272013-09-03 13:31:29 -0700205 struct MdpPipeInfoNonSplit : public MdpPipeInfo {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800206 ovutils::eDest index;
Saurabh Shah88e4d272013-09-03 13:31:29 -0700207 virtual ~MdpPipeInfoNonSplit() {};
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700208 };
209
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700210 /* configure's overlay pipes for the frame */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800211 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800212 PipeLayerPair& pipeLayerPair);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800213
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700214 /* allocates pipes to selected candidates */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800215 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216 hwc_display_contents_1_t* list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800217
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700218 /* Checks for pipes needed versus pipes available */
219 virtual bool arePipesAvailable(hwc_context_t *ctx,
220 hwc_display_contents_1_t* list);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700221
222 /* Checks for video pipes needed versus pipes available */
223 virtual bool areVGPipesAvailable(hwc_context_t *ctx,
224 hwc_display_contents_1_t* list);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700225};
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800226
Saurabh Shah88e4d272013-09-03 13:31:29 -0700227class MDPCompSplit : public MDPComp {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800228public:
Saurabh Shah88e4d272013-09-03 13:31:29 -0700229 explicit MDPCompSplit(int dpy):MDPComp(dpy){};
230 virtual ~MDPCompSplit(){};
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800231 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
232private:
Saurabh Shah88e4d272013-09-03 13:31:29 -0700233 struct MdpPipeInfoSplit : public MdpPipeInfo {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800234 ovutils::eDest lIndex;
235 ovutils::eDest rIndex;
Saurabh Shah88e4d272013-09-03 13:31:29 -0700236 virtual ~MdpPipeInfoSplit() {};
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800237 };
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800238
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800239 bool acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah88e4d272013-09-03 13:31:29 -0700240 MdpPipeInfoSplit& pipe_info, ePipeType type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800241
242 /* configure's overlay pipes for the frame */
243 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800244 PipeLayerPair& pipeLayerPair);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800245
246 /* allocates pipes to selected candidates */
247 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800248 hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800249
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700250 /* Checks for pipes needed versus pipes available */
251 virtual bool arePipesAvailable(hwc_context_t *ctx,
252 hwc_display_contents_1_t* list);
253
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700254 /* Checks for video pipes needed versus pipes available */
255 virtual bool areVGPipesAvailable(hwc_context_t *ctx,
256 hwc_display_contents_1_t* list);
257
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700258 int pipesNeeded(hwc_context_t *ctx, hwc_display_contents_1_t* list,
259 int mixer);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800260};
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700261
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700262}; //namespace
263#endif