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 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 27 | #define DEFAULT_IDLE_TIME 2000 |
| 28 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 29 | namespace qhwc { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 30 | namespace ovutils = overlay::utils; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 31 | |
| 32 | class MDPComp { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 33 | enum eState { |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 34 | MDPCOMP_ON = 0, |
| 35 | MDPCOMP_OFF, |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 38 | enum ePipeType { |
| 39 | MDPCOMP_OV_RGB = ovutils::OV_MDP_PIPE_RGB, |
| 40 | MDPCOMP_OV_VG = ovutils::OV_MDP_PIPE_VG, |
| 41 | MDPCOMP_OV_ANY, |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 44 | struct MdpPipeInfo { |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 45 | int index; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 46 | int zOrder; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 49 | struct PipeLayerPair { |
| 50 | MdpPipeInfo pipeIndex; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 51 | native_handle_t* handle; |
| 52 | }; |
| 53 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 54 | struct FrameInfo { |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 55 | int count; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 56 | struct PipeLayerPair* pipeLayer; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 57 | |
| 58 | }; |
| 59 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 60 | static eState sMDPCompState; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 61 | static IdleInvalidator *idleInvalidator; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 62 | static struct FrameInfo sCurrentFrame; |
| 63 | static bool sEnabled; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 64 | static bool sDebugLogs; |
| 65 | static bool sIdleFallBack; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 66 | static int sActiveMax; |
| 67 | static bool sSecuredVid; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 68 | |
| 69 | public: |
| 70 | /* Handler to invoke frame redraw on Idle Timer expiry */ |
| 71 | static void timeout_handler(void *udata); |
| 72 | |
| 73 | /* configure/tear-down MDPComp params*/ |
| 74 | static bool init(hwc_context_t *ctx); |
| 75 | static bool deinit(); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 76 | static bool isUsed() { return (sMDPCompState == MDPCOMP_ON); }; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 77 | |
| 78 | /*sets up mdp comp for the current frame */ |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 79 | static bool configure(hwc_context_t *ctx, |
| 80 | hwc_display_contents_1_t* list); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 81 | |
| 82 | /* draw */ |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 83 | static bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 84 | |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 85 | static void dump(android::String8& buf); |
| 86 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 87 | private: |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 88 | /* set/reset flags for MDPComp */ |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 89 | static void setMDPCompLayerFlags(hwc_context_t *ctx, |
| 90 | hwc_display_contents_1_t* list); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 91 | static void unsetMDPCompLayerFlags(hwc_context_t* ctx, |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 92 | hwc_display_contents_1_t* list); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 93 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 94 | static void print_info(hwc_layer_1_t* layer); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 95 | |
| 96 | /* configure's overlay pipes for the frame */ |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 97 | static int prepare(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 98 | MdpPipeInfo& mdp_info); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 99 | |
| 100 | /* checks for conditions where mdpcomp is not possible */ |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 101 | static bool isDoable(hwc_context_t *ctx, hwc_display_contents_1_t* list); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 102 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 103 | 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] | 104 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 105 | /* allocates pipes to selected candidates */ |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 106 | static bool allocLayerPipes(hwc_context_t *ctx, |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 107 | hwc_display_contents_1_t* list, |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 108 | FrameInfo& current_frame); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 109 | |
| 110 | /* get/set states */ |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 111 | static eState getState() { return sMDPCompState; }; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 112 | |
| 113 | /* reset state */ |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 114 | 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] | 115 | |
| 116 | /* Is feature enabled */ |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 117 | static bool isEnabled() { return sEnabled; }; |
| 118 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 119 | /* Is debug enabled */ |
| 120 | static bool isDebug() { return sDebugLogs ? true : false; }; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 121 | |
| 122 | /* check layer state */ |
| 123 | static bool isSkipPresent (hwc_context_t *ctx); |
| 124 | static bool isYuvPresent (hwc_context_t *ctx); |
| 125 | |
| 126 | /* configure MDP flags for video buffers */ |
| 127 | static void setVidInfo(hwc_layer_1_t *layer, ovutils::eMdpFlags &mdpFlags); |
| 128 | |
| 129 | /* set up Border fill as Base pipe */ |
| 130 | static bool setupBasePipe(hwc_context_t*); |
| 131 | |
| 132 | /* allocate MDP pipes from overlay */ |
| 133 | static int getMdpPipe(hwc_context_t *ctx, ePipeType type); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 134 | }; |
| 135 | }; //namespace |
| 136 | #endif |