blob: 1e374aa6f78fd1bea2e8c91a49e18ea854533c5b [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 Shah67a38c32013-06-10 16:23:15 -070049 static MDPComp* getObject(const int& width, const int& rightSplit,
50 const int& dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080051 /* Handler to invoke frame redraw on Idle Timer expiry */
52 static void timeout_handler(void *udata);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080053 /* Initialize MDP comp*/
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080054 static bool init(hwc_context_t *ctx);
Saurabh Shah98acd092013-05-03 10:48:24 -070055 static void resetIdleFallBack() { sIdleFallBack = false; }
Saurabh Shah8c5c8522013-08-29 17:32:49 -070056 static void reset() { sCompBytesClaimed = 0; };
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080057
58protected:
Naseer Ahmed54821fe2012-11-28 18:44:38 -050059 enum ePipeType {
60 MDPCOMP_OV_RGB = ovutils::OV_MDP_PIPE_RGB,
61 MDPCOMP_OV_VG = ovutils::OV_MDP_PIPE_VG,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080062 MDPCOMP_OV_DMA = ovutils::OV_MDP_PIPE_DMA,
Naseer Ahmed54821fe2012-11-28 18:44:38 -050063 MDPCOMP_OV_ANY,
Naseer Ahmed7c958d42012-07-31 18:57:03 -070064 };
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080065
66 /* mdp pipe data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080067 struct MdpPipeInfo {
68 int zOrder;
69 virtual ~MdpPipeInfo(){};
70 };
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080071
72 /* per layer data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080073 struct PipeLayerPair {
74 MdpPipeInfo *pipeInfo;
Saurabh Shahacf10202013-02-26 10:15:15 -080075 overlay::Rotator* rot;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080076 int listIndex;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080077 };
78
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080079 /* per frame data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080080 struct FrameInfo {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080081 /* maps layer list to mdp list */
82 int layerCount;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -070083 int layerToMDP[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080084
85 /* maps mdp list to layer list */
86 int mdpCount;
87 struct PipeLayerPair mdpToLayer[MAX_PIPES_PER_MIXER];
88
89 /* layer composing on FB? */
90 int fbCount;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -070091 bool isFBComposed[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080092
93 bool needsRedraw;
94 int fbZ;
95
96 /* c'tor */
97 FrameInfo();
98 /* clear old frame data */
Saurabh Shahaa236822013-04-24 18:07:26 -070099 void reset(const int& numLayers);
100 void map();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800101 };
102
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800103 /* cached data */
104 struct LayerCache {
105 int layerCount;
106 int mdpCount;
107 int cacheCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700108 int fbZ;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700109 buffer_handle_t hnd[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800110
111 /* c'tor */
112 LayerCache();
113 /* clear caching info*/
114 void reset();
Saurabh Shahaa236822013-04-24 18:07:26 -0700115 void cacheAll(hwc_display_contents_1_t* list);
116 void updateCounts(const FrameInfo&);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800117 };
118
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800119 /* allocates pipe from pipe book */
120 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800121 hwc_display_contents_1_t* list) = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700122 /* allocate MDP pipes from overlay */
123 ovutils::eDest getMdpPipe(hwc_context_t *ctx, ePipeType type, int mixer);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800124 /* configures MPD pipes */
125 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800126 PipeLayerPair& pipeLayerPair) = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700127 /* Checks for pipes needed versus pipes available */
128 virtual bool arePipesAvailable(hwc_context_t *ctx,
129 hwc_display_contents_1_t* list) = 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800130
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800131 /* set/reset flags for MDPComp */
132 void setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800133 hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800134 /* checks for conditions where mdpcomp is not possible */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800135 bool isFrameDoable(hwc_context_t *ctx);
136 /* checks for conditions where RGB layers cannot be bypassed */
137 bool isFullFrameDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700138 /* checks if full MDP comp can be done */
139 bool fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
140 /* check if we can use layer cache to do at least partial MDP comp */
141 bool partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
142 /* checks for conditions where only video can be bypassed */
143 bool isOnlyVideoDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800144 /* checks for conditions where YUV layers cannot be bypassed */
145 bool isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700146 /* calcs bytes read by MDP for a given frame */
147 uint32_t calcMDPBytesRead(hwc_context_t *ctx,
148 hwc_display_contents_1_t* list);
149 /* checks if the required bandwidth exceeds a certain max */
150 bool bandwidthCheck(hwc_context_t *ctx, const uint32_t& size);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800151
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800152 /* set up Border fill as Base pipe */
153 static bool setupBasePipe(hwc_context_t*);
154 /* Is debug enabled */
155 static bool isDebug() { return sDebugLogs ? true : false; };
156 /* Is feature enabled */
157 static bool isEnabled() { return sEnabled; };
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530158 /* checks for mdp comp dimension limitation */
159 bool isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800160 /* tracks non updating layers*/
161 void updateLayerCache(hwc_context_t* ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800162 /* optimize layers for mdp comp*/
163 void batchLayers();
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800164 /* updates cache map with YUV info */
165 void updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700166 bool programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list);
167 bool programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700168 void reset(const int& numAppLayers, hwc_display_contents_1_t* list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800169
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800170 int mDpy;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800171 static bool sEnabled;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700172 static bool sEnableMixedMode;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800173 static bool sDebugLogs;
174 static bool sIdleFallBack;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800175 static int sMaxPipesPerMixer;
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700176 //Max bandwidth. Value is in GBPS. For ex: 2.3 means 2.3GBPS
177 static float sMaxBw;
178 //Tracks composition bytes claimed. Represented as the total w*h*bpp
179 //going to MDP mixers
180 static uint32_t sCompBytesClaimed;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800181 static IdleInvalidator *idleInvalidator;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800182 struct FrameInfo mCurrentFrame;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800183 struct LayerCache mCachedFrame;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800184};
185
186class MDPCompLowRes : public MDPComp {
187public:
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800188 explicit MDPCompLowRes(int dpy):MDPComp(dpy){};
189 virtual ~MDPCompLowRes(){};
190 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800191
192private:
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800193 struct MdpPipeInfoLowRes : public MdpPipeInfo {
194 ovutils::eDest index;
195 virtual ~MdpPipeInfoLowRes() {};
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700196 };
197
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700198 /* configure's overlay pipes for the frame */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800199 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800200 PipeLayerPair& pipeLayerPair);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800201
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700202 /* allocates pipes to selected candidates */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800203 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800204 hwc_display_contents_1_t* list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800205
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700206 /* Checks for pipes needed versus pipes available */
207 virtual bool arePipesAvailable(hwc_context_t *ctx,
208 hwc_display_contents_1_t* list);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700209};
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800210
211class MDPCompHighRes : public MDPComp {
212public:
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800213 explicit MDPCompHighRes(int dpy):MDPComp(dpy){};
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800214 virtual ~MDPCompHighRes(){};
215 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
216private:
217 struct MdpPipeInfoHighRes : public MdpPipeInfo {
218 ovutils::eDest lIndex;
219 ovutils::eDest rIndex;
220 virtual ~MdpPipeInfoHighRes() {};
221 };
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800222
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800223 bool acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800224 MdpPipeInfoHighRes& pipe_info, ePipeType type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800225
226 /* configure's overlay pipes for the frame */
227 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800228 PipeLayerPair& pipeLayerPair);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800229
230 /* allocates pipes to selected candidates */
231 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800232 hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800233
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700234 /* Checks for pipes needed versus pipes available */
235 virtual bool arePipesAvailable(hwc_context_t *ctx,
236 hwc_display_contents_1_t* list);
237
238 int pipesNeeded(hwc_context_t *ctx, hwc_display_contents_1_t* list,
239 int mixer);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800240};
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700241
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700242}; //namespace
243#endif