blob: e2800d242672b232ba71e5baab6d5eabaeb51050 [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);
Saurabh Shah98acd092013-05-03 10:48:24 -070054 static void resetIdleFallBack() { sIdleFallBack = false; }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080055
56protected:
Naseer Ahmed54821fe2012-11-28 18:44:38 -050057 enum ePipeType {
58 MDPCOMP_OV_RGB = ovutils::OV_MDP_PIPE_RGB,
59 MDPCOMP_OV_VG = ovutils::OV_MDP_PIPE_VG,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080060 MDPCOMP_OV_DMA = ovutils::OV_MDP_PIPE_DMA,
Naseer Ahmed54821fe2012-11-28 18:44:38 -050061 MDPCOMP_OV_ANY,
Naseer Ahmed7c958d42012-07-31 18:57:03 -070062 };
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080063
64 /* mdp pipe data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080065 struct MdpPipeInfo {
66 int zOrder;
67 virtual ~MdpPipeInfo(){};
68 };
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080069
70 /* per layer data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080071 struct PipeLayerPair {
72 MdpPipeInfo *pipeInfo;
Saurabh Shahacf10202013-02-26 10:15:15 -080073 overlay::Rotator* rot;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080074 int listIndex;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080075 };
76
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080077 /* per frame data */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080078 struct FrameInfo {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080079 /* maps layer list to mdp list */
80 int layerCount;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -070081 int layerToMDP[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080082
83 /* maps mdp list to layer list */
84 int mdpCount;
85 struct PipeLayerPair mdpToLayer[MAX_PIPES_PER_MIXER];
86
87 /* layer composing on FB? */
88 int fbCount;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -070089 bool isFBComposed[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080090
91 bool needsRedraw;
92 int fbZ;
93
94 /* c'tor */
95 FrameInfo();
96 /* clear old frame data */
Saurabh Shahaa236822013-04-24 18:07:26 -070097 void reset(const int& numLayers);
98 void map();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080099 };
100
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800101 /* cached data */
102 struct LayerCache {
103 int layerCount;
104 int mdpCount;
105 int cacheCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700106 int fbZ;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700107 buffer_handle_t hnd[MAX_NUM_APP_LAYERS];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800108
109 /* c'tor */
110 LayerCache();
111 /* clear caching info*/
112 void reset();
Saurabh Shahaa236822013-04-24 18:07:26 -0700113 void cacheAll(hwc_display_contents_1_t* list);
114 void updateCounts(const FrameInfo&);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800115 };
116
117 /* No of pipes needed for Framebuffer */
118 virtual int pipesForFB() = 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800119 /* calculates pipes needed for the panel */
120 virtual int pipesNeeded(hwc_context_t *ctx,
121 hwc_display_contents_1_t* list) = 0;
122 /* allocates pipe from pipe book */
123 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800124 hwc_display_contents_1_t* list) = 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800125 /* configures MPD pipes */
126 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800127 PipeLayerPair& pipeLayerPair) = 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800128
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800129 /* set/reset flags for MDPComp */
130 void setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800131 hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800132 /* allocate MDP pipes from overlay */
133 ovutils::eDest getMdpPipe(hwc_context_t *ctx, ePipeType type);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800134
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800135 /* checks for conditions where mdpcomp is not possible */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800136 bool isFrameDoable(hwc_context_t *ctx);
137 /* checks for conditions where RGB layers cannot be bypassed */
138 bool isFullFrameDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700139 /* checks if full MDP comp can be done */
140 bool fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
141 /* check if we can use layer cache to do at least partial MDP comp */
142 bool partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list);
143 /* checks for conditions where only video can be bypassed */
144 bool isOnlyVideoDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800145 /* checks for conditions where YUV layers cannot be bypassed */
146 bool isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer);
147
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800148 /* set up Border fill as Base pipe */
149 static bool setupBasePipe(hwc_context_t*);
150 /* Is debug enabled */
151 static bool isDebug() { return sDebugLogs ? true : false; };
152 /* Is feature enabled */
153 static bool isEnabled() { return sEnabled; };
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530154 /* checks for mdp comp dimension limitation */
155 bool isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800156 /* tracks non updating layers*/
157 void updateLayerCache(hwc_context_t* ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800158 /* optimize layers for mdp comp*/
159 void batchLayers();
160 /* gets available pipes for mdp comp */
161 int getAvailablePipes(hwc_context_t* ctx);
162 /* updates cache map with YUV info */
163 void updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700164 bool programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list);
165 bool programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800166
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800167 int mDpy;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800168 static bool sEnabled;
169 static bool sDebugLogs;
170 static bool sIdleFallBack;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800171 static int sMaxPipesPerMixer;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800172 static IdleInvalidator *idleInvalidator;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800173 struct FrameInfo mCurrentFrame;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800174 struct LayerCache mCachedFrame;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800175};
176
177class MDPCompLowRes : public MDPComp {
178public:
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800179 explicit MDPCompLowRes(int dpy):MDPComp(dpy){};
180 virtual ~MDPCompLowRes(){};
181 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800182
183private:
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800184 struct MdpPipeInfoLowRes : public MdpPipeInfo {
185 ovutils::eDest index;
186 virtual ~MdpPipeInfoLowRes() {};
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700187 };
188
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800189 virtual int pipesForFB() { return 1; };
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700190 /* configure's overlay pipes for the frame */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800191 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800192 PipeLayerPair& pipeLayerPair);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800193
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700194 /* allocates pipes to selected candidates */
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800195 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800196 hwc_display_contents_1_t* list);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800197
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800198 virtual int pipesNeeded(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700199};
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800200
201class MDPCompHighRes : public MDPComp {
202public:
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800203 explicit MDPCompHighRes(int dpy):MDPComp(dpy){};
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800204 virtual ~MDPCompHighRes(){};
205 virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
206private:
207 struct MdpPipeInfoHighRes : public MdpPipeInfo {
208 ovutils::eDest lIndex;
209 ovutils::eDest rIndex;
210 virtual ~MdpPipeInfoHighRes() {};
211 };
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800212
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800213 bool acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800214 MdpPipeInfoHighRes& pipe_info, ePipeType type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800215
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216 virtual int pipesForFB() { return 2; };
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800217 /* configure's overlay pipes for the frame */
218 virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800219 PipeLayerPair& pipeLayerPair);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800220
221 /* allocates pipes to selected candidates */
222 virtual bool allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223 hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800224
225 virtual int pipesNeeded(hwc_context_t *ctx, hwc_display_contents_1_t* list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800226};
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700227}; //namespace
228#endif