blob: 4aedd775bb1b6c2463a5ec767e9ea041e5f8432f [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
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080049 static MDPComp* getObject(const int& width, 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);
54
55protected:
Naseer Ahmed54821fe2012-11-28 18:44:38 -050056 enum ePipeType {
57 MDPCOMP_OV_RGB = ovutils::OV_MDP_PIPE_RGB,
58 MDPCOMP_OV_VG = ovutils::OV_MDP_PIPE_VG,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080059 MDPCOMP_OV_DMA = ovutils::OV_MDP_PIPE_DMA,
Naseer Ahmed54821fe2012-11-28 18:44:38 -050060 MDPCOMP_OV_ANY,
Naseer Ahmed7c958d42012-07-31 18:57:03 -070061 };
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080062
63 /* mdp pipe data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080064 struct MdpPipeInfo {
65 int zOrder;
66 virtual ~MdpPipeInfo(){};
67 };
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080068
69 /* per layer data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080070 struct PipeLayerPair {
71 MdpPipeInfo *pipeInfo;
Saurabh Shahacf10202013-02-26 10:15:15 -080072 overlay::Rotator* rot;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080073 int listIndex;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080074 };
75
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080076 /* per frame data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080077 struct FrameInfo {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080078 /* maps layer list to mdp list */
79 int layerCount;
80 int layerToMDP[MAX_NUM_LAYERS];
81
82 /* maps mdp list to layer list */
83 int mdpCount;
84 struct PipeLayerPair mdpToLayer[MAX_PIPES_PER_MIXER];
85
86 /* layer composing on FB? */
87 int fbCount;
88 bool isFBComposed[MAX_NUM_LAYERS];
89
90 bool needsRedraw;
91 int fbZ;
92
93 /* c'tor */
94 FrameInfo();
95 /* clear old frame data */
Saurabh Shahaa236822013-04-24 18:07:26 -070096 void reset(const int& numLayers);
97 void map();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080098 };
99
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800100 /* cached data */
101 struct LayerCache {
102 int layerCount;
103 int mdpCount;
104 int cacheCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700105 int fbZ;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800106 buffer_handle_t hnd[MAX_NUM_LAYERS];
107
108 /* c'tor */
109 LayerCache();
110 /* clear caching info*/
111 void reset();
Saurabh Shahaa236822013-04-24 18:07:26 -0700112 void cacheAll(hwc_display_contents_1_t* list);
113 void updateCounts(const FrameInfo&);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800114 };
115
116 /* No of pipes needed for Framebuffer */
117 virtual int pipesForFB() = 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800118 /* calculates pipes needed for the panel */
119 virtual int pipesNeeded(hwc_context_t *ctx,
120 hwc_display_contents_1_t* list) = 0;
121 /* allocates pipe from pipe book */
122 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800123 hwc_display_contents_1_t* list) = 0;
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;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800127
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800128 /* set/reset flags for MDPComp */
129 void setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800130 hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800131 /* allocate MDP pipes from overlay */
132 ovutils::eDest getMdpPipe(hwc_context_t *ctx, ePipeType type);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800133
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);
146
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800147 /* set up Border fill as Base pipe */
148 static bool setupBasePipe(hwc_context_t*);
149 /* Is debug enabled */
150 static bool isDebug() { return sDebugLogs ? true : false; };
151 /* Is feature enabled */
152 static bool isEnabled() { return sEnabled; };
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800153 /* checks for mdp comp width limitation */
154 bool isWidthValid(hwc_context_t *ctx, hwc_layer_1_t *layer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800155 /* tracks non updating layers*/
156 void updateLayerCache(hwc_context_t* ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800157 /* optimize layers for mdp comp*/
158 void batchLayers();
159 /* gets available pipes for mdp comp */
160 int getAvailablePipes(hwc_context_t* ctx);
161 /* updates cache map with YUV info */
162 void updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700163 bool programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list);
164 bool programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800165
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800166 int mDpy;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800167 static bool sEnabled;
168 static bool sDebugLogs;
169 static bool sIdleFallBack;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800170 static int sMaxPipesPerMixer;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800171 static IdleInvalidator *idleInvalidator;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800172 struct FrameInfo mCurrentFrame;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800173 struct LayerCache mCachedFrame;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800174};
175
176class MDPCompLowRes : public MDPComp {
177public:
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800178 explicit MDPCompLowRes(int dpy):MDPComp(dpy){};
179 virtual ~MDPCompLowRes(){};
180 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800181
182private:
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800183 struct MdpPipeInfoLowRes : public MdpPipeInfo {
184 ovutils::eDest index;
185 virtual ~MdpPipeInfoLowRes() {};
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700186 };
187
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800188 virtual int pipesForFB() { return 1; };
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700189 /* configure's overlay pipes for the frame */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800190 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800191 PipeLayerPair& pipeLayerPair);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800192
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700193 /* allocates pipes to selected candidates */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800194 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800195 hwc_display_contents_1_t* list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800196
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 virtual int pipesNeeded(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700198};
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199
200class MDPCompHighRes : public MDPComp {
201public:
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800202 explicit MDPCompHighRes(int dpy):MDPComp(dpy){};
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800203 virtual ~MDPCompHighRes(){};
204 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
205private:
206 struct MdpPipeInfoHighRes : public MdpPipeInfo {
207 ovutils::eDest lIndex;
208 ovutils::eDest rIndex;
209 virtual ~MdpPipeInfoHighRes() {};
210 };
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800211
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800212 bool acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800213 MdpPipeInfoHighRes& pipe_info, ePipeType type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800214
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800215 virtual int pipesForFB() { return 2; };
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800216 /* configure's overlay pipes for the frame */
217 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800218 PipeLayerPair& pipeLayerPair);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800219
220 /* allocates pipes to selected candidates */
221 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800222 hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800223
224 virtual int pipesNeeded(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800225};
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700226}; //namespace
227#endif