1 /*
2  * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
3  *
4  * 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 
28 #define DEFAULT_IDLE_TIME 2000
29 #define MAX_PIPES_PER_MIXER 4
30 
31 namespace overlay {
32 class Rotator;
33 };
34 
35 namespace qhwc {
36 namespace ovutils = overlay::utils;
37 
38 class MDPComp {
39 public:
40     explicit MDPComp(int);
~MDPComp()41     virtual ~MDPComp(){};
42     /*sets up mdp comp for the current frame */
43     int prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list);
44     /* draw */
45     virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list) = 0;
46     /* dumpsys */
47     void dump(android::String8& buf);
48 
49     static MDPComp* getObject(const int& width, const int dpy);
50     /* Handler to invoke frame redraw on Idle Timer expiry */
51     static void timeout_handler(void *udata);
52     /* Initialize MDP comp*/
53     static bool init(hwc_context_t *ctx);
resetIdleFallBack()54     static void resetIdleFallBack() { sIdleFallBack = false; }
55 
56 protected:
57     enum ePipeType {
58         MDPCOMP_OV_RGB = ovutils::OV_MDP_PIPE_RGB,
59         MDPCOMP_OV_VG = ovutils::OV_MDP_PIPE_VG,
60         MDPCOMP_OV_DMA = ovutils::OV_MDP_PIPE_DMA,
61         MDPCOMP_OV_ANY,
62     };
63 
64     /* mdp pipe data */
65     struct MdpPipeInfo {
66         int zOrder;
~MdpPipeInfoMdpPipeInfo67         virtual ~MdpPipeInfo(){};
68     };
69 
70     /* per layer data */
71     struct PipeLayerPair {
72         MdpPipeInfo *pipeInfo;
73         overlay::Rotator* rot;
74         int listIndex;
75     };
76 
77     /* per frame data */
78     struct FrameInfo {
79         /* maps layer list to mdp list */
80         int layerCount;
81         int layerToMDP[MAX_NUM_APP_LAYERS];
82 
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;
89         bool isFBComposed[MAX_NUM_APP_LAYERS];
90 
91         bool needsRedraw;
92         int fbZ;
93 
94         /* c'tor */
95         FrameInfo();
96         /* clear old frame data */
97         void reset(const int& numLayers);
98         void map();
99     };
100 
101     /* cached data */
102     struct LayerCache {
103         int layerCount;
104         int mdpCount;
105         int cacheCount;
106         int fbZ;
107         buffer_handle_t hnd[MAX_NUM_APP_LAYERS];
108 
109         /* c'tor */
110         LayerCache();
111         /* clear caching info*/
112         void reset();
113         void cacheAll(hwc_display_contents_1_t* list);
114         void updateCounts(const FrameInfo&);
115     };
116 
117     /* No of pipes needed for Framebuffer */
118     virtual int pipesForFB() = 0;
119     /* 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,
124                                  hwc_display_contents_1_t* list) = 0;
125     /* configures MPD pipes */
126     virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
127                           PipeLayerPair& pipeLayerPair) = 0;
128 
129     /* set/reset flags for MDPComp */
130     void setMDPCompLayerFlags(hwc_context_t *ctx,
131                               hwc_display_contents_1_t* list);
132     /* allocate MDP pipes from overlay */
133     ovutils::eDest getMdpPipe(hwc_context_t *ctx, ePipeType type);
134 
135     /* checks for conditions where mdpcomp is not possible */
136     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);
139     /* 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);
145     /* checks for conditions where YUV layers cannot be bypassed */
146     bool isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer);
147 
148     /* set up Border fill as Base pipe */
149     static bool setupBasePipe(hwc_context_t*);
150     /* Is debug enabled */
isDebug()151     static bool isDebug() { return sDebugLogs ? true : false; };
152     /* Is feature enabled */
isEnabled()153     static bool isEnabled() { return sEnabled; };
154     /* checks for mdp comp dimension limitation */
155     bool isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer);
156     /* tracks non updating layers*/
157     void updateLayerCache(hwc_context_t* ctx, hwc_display_contents_1_t* list);
158     /* 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);
164     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);
166 
167     int mDpy;
168     static bool sEnabled;
169     static bool sDebugLogs;
170     static bool sIdleFallBack;
171     static int sMaxPipesPerMixer;
172     static IdleInvalidator *idleInvalidator;
173     struct FrameInfo mCurrentFrame;
174     struct LayerCache mCachedFrame;
175 };
176 
177 class MDPCompLowRes : public MDPComp {
178 public:
MDPCompLowRes(int dpy)179     explicit MDPCompLowRes(int dpy):MDPComp(dpy){};
~MDPCompLowRes()180     virtual ~MDPCompLowRes(){};
181     virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
182 
183 private:
184     struct MdpPipeInfoLowRes : public MdpPipeInfo {
185         ovutils::eDest index;
~MdpPipeInfoLowResMdpPipeInfoLowRes186         virtual ~MdpPipeInfoLowRes() {};
187     };
188 
pipesForFB()189     virtual int pipesForFB() { return 1; };
190     /* configure's overlay pipes for the frame */
191     virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
192                           PipeLayerPair& pipeLayerPair);
193 
194     /* allocates pipes to selected candidates */
195     virtual bool allocLayerPipes(hwc_context_t *ctx,
196                                  hwc_display_contents_1_t* list);
197 
198     virtual int pipesNeeded(hwc_context_t *ctx, hwc_display_contents_1_t* list);
199 };
200 
201 class MDPCompHighRes : public MDPComp {
202 public:
MDPCompHighRes(int dpy)203     explicit MDPCompHighRes(int dpy):MDPComp(dpy){};
~MDPCompHighRes()204     virtual ~MDPCompHighRes(){};
205     virtual bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list);
206 private:
207     struct MdpPipeInfoHighRes : public MdpPipeInfo {
208         ovutils::eDest lIndex;
209         ovutils::eDest rIndex;
~MdpPipeInfoHighResMdpPipeInfoHighRes210         virtual ~MdpPipeInfoHighRes() {};
211     };
212 
213     bool acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
214                          MdpPipeInfoHighRes& pipe_info, ePipeType type);
215 
pipesForFB()216     virtual int pipesForFB() { return 2; };
217     /* configure's overlay pipes for the frame */
218     virtual int configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
219                           PipeLayerPair& pipeLayerPair);
220 
221     /* allocates pipes to selected candidates */
222     virtual bool allocLayerPipes(hwc_context_t *ctx,
223                                  hwc_display_contents_1_t* list);
224 
225     virtual int pipesNeeded(hwc_context_t *ctx, hwc_display_contents_1_t* list);
226 };
227 }; //namespace
228 #endif
229