Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012, Code Aurora Forum. All rights reserved. |
| 3 | * Not a Contribution, Apache license notifications and license are retained |
| 4 | * for attribution purposes only. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | #ifndef HWC_MDP_COMP |
| 20 | #define HWC_MDP_COMP |
| 21 | |
| 22 | #include <hwc_utils.h> |
| 23 | #include <idle_invalidator.h> |
| 24 | #include <cutils/properties.h> |
| 25 | #include <overlay.h> |
| 26 | |
| 27 | #define MAX_STATIC_PIPES 3 |
| 28 | #define MDPCOMP_INDEX_OFFSET 4 |
| 29 | #define DEFAULT_IDLE_TIME 2000 |
| 30 | |
| 31 | #define MAX_VG 2 |
| 32 | #define MAX_RGB 2 |
| 33 | #define VAR_INDEX 3 |
| 34 | #define MAX_PIPES (MAX_VG + MAX_RGB) |
| 35 | #define HWC_MDPCOMP_INDEX_MASK 0x00000030 |
| 36 | |
| 37 | |
| 38 | //struct hwc_context_t; |
| 39 | |
| 40 | namespace qhwc { |
| 41 | |
| 42 | // pipe status |
| 43 | enum { |
| 44 | PIPE_UNASSIGNED = 0, |
| 45 | PIPE_IN_FB_MODE, |
| 46 | PIPE_IN_COMP_MODE, |
| 47 | }; |
| 48 | |
| 49 | // pipe request |
| 50 | enum { |
| 51 | PIPE_NONE = 0, |
| 52 | PIPE_REQ_VG, |
| 53 | PIPE_REQ_RGB, |
| 54 | PIPE_REQ_FB, |
| 55 | }; |
| 56 | |
| 57 | // MDP Comp Status |
| 58 | enum { |
| 59 | MDPCOMP_SUCCESS = 0, |
| 60 | MDPCOMP_FAILURE, |
| 61 | MDPCOMP_ABORT, |
| 62 | }; |
| 63 | |
| 64 | //This class manages the status of 4 MDP pipes and keeps |
| 65 | //track of Variable pipe mode. |
| 66 | class PipeMgr { |
| 67 | |
| 68 | public: |
| 69 | PipeMgr() { reset();} |
| 70 | //reset pipemgr params |
| 71 | void reset(); |
| 72 | |
| 73 | //Based on the preference received, pipe mgr |
| 74 | //allocates the best available pipe to handle |
| 75 | //the case |
| 76 | int req_for_pipe(int pipe_req); |
| 77 | |
| 78 | //Allocate requested pipe and update availablity |
| 79 | int assign_pipe(int pipe_pref); |
| 80 | |
| 81 | // Get/Set pipe status |
| 82 | void setStatus(int pipe_index, int pipe_status) { |
| 83 | mStatus[pipe_index] = pipe_status; |
| 84 | } |
| 85 | int getStatus(int pipe_index) { |
| 86 | return mStatus[pipe_index]; |
| 87 | } |
| 88 | private: |
| 89 | int mVGPipes; |
| 90 | int mVGUsed; |
| 91 | int mVGIndex; |
| 92 | int mRGBPipes; |
| 93 | int mRGBUsed; |
| 94 | int mRGBIndex; |
| 95 | int mTotalAvail; |
| 96 | int mStatus[MAX_PIPES]; |
| 97 | }; |
| 98 | |
| 99 | |
| 100 | class MDPComp { |
| 101 | enum State { |
| 102 | MDPCOMP_ON = 0, |
| 103 | MDPCOMP_OFF, |
| 104 | MDPCOMP_OFF_PENDING, |
| 105 | }; |
| 106 | |
| 107 | enum { |
| 108 | MDPCOMP_LAYER_BLEND = 1, |
| 109 | MDPCOMP_LAYER_DOWNSCALE = 2, |
| 110 | MDPCOMP_LAYER_SKIP = 4, |
| 111 | MDPCOMP_LAYER_UNSUPPORTED_MEM = 8, |
| 112 | }; |
| 113 | |
| 114 | struct mdp_pipe_info { |
| 115 | int index; |
| 116 | int z_order; |
| 117 | bool isVG; |
| 118 | bool isFG; |
| 119 | bool vsync_wait; |
| 120 | }; |
| 121 | |
| 122 | struct pipe_layer_pair { |
| 123 | int layer_index; |
| 124 | mdp_pipe_info pipe_index; |
| 125 | native_handle_t* handle; |
| 126 | }; |
| 127 | |
| 128 | struct frame_info { |
| 129 | int count; |
| 130 | struct pipe_layer_pair* pipe_layer; |
| 131 | |
| 132 | }; |
| 133 | |
| 134 | struct layer_mdp_info { |
| 135 | bool can_use_mdp; |
| 136 | int pipe_pref; |
| 137 | }; |
| 138 | |
| 139 | static State sMDPCompState; |
| 140 | static IdleInvalidator *idleInvalidator; |
| 141 | static struct frame_info sCurrentFrame; |
| 142 | static PipeMgr sPipeMgr; |
| 143 | static int sSkipCount; |
| 144 | static int sMaxLayers; |
| 145 | static bool sDebugLogs; |
| 146 | static bool sIdleFallBack; |
| 147 | |
| 148 | public: |
| 149 | /* Handler to invoke frame redraw on Idle Timer expiry */ |
| 150 | static void timeout_handler(void *udata); |
| 151 | |
| 152 | /* configure/tear-down MDPComp params*/ |
| 153 | static bool init(hwc_context_t *ctx); |
| 154 | static bool deinit(); |
| 155 | |
| 156 | /*sets up mdp comp for the current frame */ |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 157 | static bool configure(hwc_context_t *ctx, hwc_display_contents_1_t* list); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 158 | |
| 159 | /* draw */ |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 160 | static int draw(hwc_context_t *ctx, hwc_display_contents_1_t *list); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 161 | |
| 162 | /* store frame stats */ |
| 163 | static void setStats(int skipCt) { sSkipCount = skipCt;}; |
| 164 | |
| 165 | private: |
| 166 | |
| 167 | /* get/set pipe index associated with overlay layers */ |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 168 | static void setLayerIndex(hwc_layer_1_t* layer, const int pipe_index); |
| 169 | static int getLayerIndex(hwc_layer_1_t* layer); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 170 | |
| 171 | /* set/reset flags for MDPComp */ |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 172 | static void setMDPCompLayerFlags(hwc_display_contents_1_t* list); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 173 | static void unsetMDPCompLayerFlags(hwc_context_t* ctx, |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 174 | hwc_display_contents_1_t* list); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 175 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 176 | static void print_info(hwc_layer_1_t* layer); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 177 | |
| 178 | /* configure's overlay pipes for the frame */ |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 179 | static int prepare(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 180 | mdp_pipe_info& mdp_info); |
| 181 | |
| 182 | /* checks for conditions where mdpcomp is not possible */ |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 183 | static bool is_doable(hwc_context_t *ctx, hwc_display_contents_1_t* list); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 184 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 185 | static bool setup(hwc_context_t* ctx, hwc_display_contents_1_t* list); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 186 | |
| 187 | /* parses layer for properties affecting mdp comp */ |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 188 | static void get_layer_info(hwc_layer_1_t* layer, int& flags); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 189 | |
| 190 | /* iterates through layer list to choose candidate to use overlay */ |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 191 | static int mark_layers(hwc_context_t *ctx, hwc_display_contents_1_t* list, |
| 192 | layer_mdp_info* layer_info, frame_info& current_frame); |
| 193 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 194 | static bool parse_and_allocate(hwc_context_t* ctx, hwc_display_contents_1_t* list, |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 195 | frame_info& current_frame ); |
| 196 | |
| 197 | /* clears layer info struct */ |
| 198 | static void reset_layer_mdp_info(layer_mdp_info* layer_mdp_info,int count); |
| 199 | |
| 200 | /* allocates pipes to selected candidates */ |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 201 | static bool alloc_layer_pipes(hwc_context_t *ctx, |
| 202 | hwc_display_contents_1_t* list, |
| 203 | layer_mdp_info* layer_info, |
| 204 | frame_info& current_frame); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 205 | /* updates variable pipe mode for the current frame */ |
| 206 | static int configure_var_pipe(hwc_context_t* ctx); |
| 207 | |
| 208 | /* get/set states */ |
| 209 | static State get_state() { return sMDPCompState; }; |
| 210 | static void set_state(State state) { sMDPCompState = state; }; |
| 211 | |
| 212 | /* reset state */ |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 213 | static void reset( hwc_context_t *ctx, hwc_display_contents_1_t* list ); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 214 | |
| 215 | /* Is feature enabled */ |
| 216 | static bool isEnabled() { return sMaxLayers ? true : false; }; |
| 217 | /* Is debug enabled */ |
| 218 | static bool isDebug() { return sDebugLogs ? true : false; }; |
| 219 | }; |
| 220 | }; //namespace |
| 221 | #endif |