blob: cc4b76af2488a86b16cbf9695e55ecd98868f881 [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 Shahcbf7ccc2012-12-19 16:45:51 -080056
57protected:
Naseer Ahmed54821fe2012-11-28 18:44:38 -050058 enum ePipeType {
59 MDPCOMP_OV_RGB = ovutils::OV_MDP_PIPE_RGB,
60 MDPCOMP_OV_VG = ovutils::OV_MDP_PIPE_VG,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080061 MDPCOMP_OV_DMA = ovutils::OV_MDP_PIPE_DMA,
Naseer Ahmed54821fe2012-11-28 18:44:38 -050062 MDPCOMP_OV_ANY,
Naseer Ahmed7c958d42012-07-31 18:57:03 -070063 };
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080064
65 /* mdp pipe data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080066 struct MdpPipeInfo {
67 int zOrder;
68 virtual ~MdpPipeInfo(){};
69 };
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080070
71 /* per layer data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080072 struct PipeLayerPair {
73 MdpPipeInfo *pipeInfo;
Saurabh Shahacf10202013-02-26 10:15:15 -080074 overlay::Rotator* rot;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080075 int listIndex;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080076 };
77
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080078 /* per frame data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080079 struct FrameInfo {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080080 /* maps layer list to mdp list */
81 int layerCount;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -070082 int layerToMDP[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083
84 /* maps mdp list to layer list */
85 int mdpCount;
86 struct PipeLayerPair mdpToLayer[MAX_PIPES_PER_MIXER];
87
88 /* layer composing on FB? */
89 int fbCount;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -070090 bool isFBComposed[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080091
92 bool needsRedraw;
93 int fbZ;
94
95 /* c'tor */
96 FrameInfo();
97 /* clear old frame data */
Saurabh Shahaa236822013-04-24 18:07:26 -070098 void reset(const int& numLayers);
99 void map();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800100 };
101
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800102 /* cached data */
103 struct LayerCache {
104 int layerCount;
105 int mdpCount;
106 int cacheCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700107 int fbZ;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700108 buffer_handle_t hnd[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800109
110 /* c'tor */
111 LayerCache();
112 /* clear caching info*/
113 void reset();
Saurabh Shahaa236822013-04-24 18:07:26 -0700114 void cacheAll(hwc_display_contents_1_t* list);
115 void updateCounts(const FrameInfo&);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800116 };
117
118 /* No of pipes needed for Framebuffer */
119 virtual int pipesForFB() = 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800120 /* calculates pipes needed for the panel */
121 virtual int pipesNeeded(hwc_context_t *ctx,
122 hwc_display_contents_1_t* list) = 0;
123 /* allocates pipe from pipe book */
124 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800125 hwc_display_contents_1_t* list) = 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800126 /* configures MPD pipes */
127 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800128 PipeLayerPair& pipeLayerPair) = 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800129
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800130 /* set/reset flags for MDPComp */
131 void setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800132 hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800133 /* allocate MDP pipes from overlay */
134 ovutils::eDest getMdpPipe(hwc_context_t *ctx, ePipeType type);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800135
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800136 /* checks for conditions where mdpcomp is not possible */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800137 bool isFrameDoable(hwc_context_t *ctx);
138 /* checks for conditions where RGB layers cannot be bypassed */
139 bool isFullFrameDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700140 /* checks if full MDP comp can be done */
141 bool fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
142 /* check if we can use layer cache to do at least partial MDP comp */
143 bool partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
144 /* checks for conditions where only video can be bypassed */
145 bool isOnlyVideoDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800146 /* checks for conditions where YUV layers cannot be bypassed */
147 bool isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer);
148
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800149 /* set up Border fill as Base pipe */
150 static bool setupBasePipe(hwc_context_t*);
151 /* Is debug enabled */
152 static bool isDebug() { return sDebugLogs ? true : false; };
153 /* Is feature enabled */
154 static bool isEnabled() { return sEnabled; };
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530155 /* checks for mdp comp dimension limitation */
156 bool isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800157 /* tracks non updating layers*/
158 void updateLayerCache(hwc_context_t* ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800159 /* optimize layers for mdp comp*/
160 void batchLayers();
161 /* gets available pipes for mdp comp */
162 int getAvailablePipes(hwc_context_t* ctx);
163 /* updates cache map with YUV info */
164 void updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700165 bool programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list);
166 bool programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700167 void reset(const int& numAppLayers, hwc_display_contents_1_t* list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800168
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800169 int mDpy;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800170 static bool sEnabled;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700171 static bool sEnableMixedMode;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800172 static bool sDebugLogs;
173 static bool sIdleFallBack;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800174 static int sMaxPipesPerMixer;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800175 static IdleInvalidator *idleInvalidator;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800176 struct FrameInfo mCurrentFrame;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800177 struct LayerCache mCachedFrame;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530178 mutable Locker mMdpCompLock;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800179};
180
181class MDPCompLowRes : public MDPComp {
182public:
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800183 explicit MDPCompLowRes(int dpy):MDPComp(dpy){};
184 virtual ~MDPCompLowRes(){};
185 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800186
187private:
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800188 struct MdpPipeInfoLowRes : public MdpPipeInfo {
189 ovutils::eDest index;
190 virtual ~MdpPipeInfoLowRes() {};
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700191 };
192
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800193 virtual int pipesForFB() { return 1; };
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700194 /* configure's overlay pipes for the frame */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800195 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800196 PipeLayerPair& pipeLayerPair);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800197
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700198 /* allocates pipes to selected candidates */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800199 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800200 hwc_display_contents_1_t* list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800201
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800202 virtual int pipesNeeded(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700203};
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800204
205class MDPCompHighRes : public MDPComp {
206public:
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800207 explicit MDPCompHighRes(int dpy):MDPComp(dpy){};
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800208 virtual ~MDPCompHighRes(){};
209 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
210private:
211 struct MdpPipeInfoHighRes : public MdpPipeInfo {
212 ovutils::eDest lIndex;
213 ovutils::eDest rIndex;
214 virtual ~MdpPipeInfoHighRes() {};
215 };
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800216
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800217 bool acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800218 MdpPipeInfoHighRes& pipe_info, ePipeType type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800219
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220 virtual int pipesForFB() { return 2; };
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800221 /* configure's overlay pipes for the frame */
222 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223 PipeLayerPair& pipeLayerPair);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800224
225 /* allocates pipes to selected candidates */
226 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800227 hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800228
229 virtual int pipesNeeded(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800230};
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700231
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700232}; //namespace
233#endif