Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Arun Kumar K.R | ba9eed5 | 2013-01-04 00:51:29 -0800 | [diff] [blame] | 3 | * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 4 | * |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 5 | * Not a Contribution, Apache license notifications and license are retained |
| 6 | * for attribution purposes only. |
| 7 | * |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 20 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 21 | #include <fcntl.h> |
| 22 | #include <errno.h> |
| 23 | |
| 24 | #include <cutils/log.h> |
| 25 | #include <cutils/atomic.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 26 | #include <EGL/egl.h> |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 27 | #include <utils/Trace.h> |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 28 | #include <sys/ioctl.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 29 | #include <overlay.h> |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 30 | #include <overlayRotator.h> |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 31 | #include <mdp_version.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 32 | #include "hwc_utils.h" |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 33 | #include "hwc_fbupdate.h" |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 34 | #include "hwc_mdpcomp.h" |
Ramkumar Radhakrishnan | d224a1a | 2013-04-05 17:46:55 -0700 | [diff] [blame] | 35 | #include "hwc_dump_layers.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 36 | #include "external.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 37 | #include "hwc_copybit.h" |
Naseer Ahmed | 0d05d4f | 2013-03-28 14:49:07 -0400 | [diff] [blame] | 38 | #include "profiler.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 39 | |
| 40 | using namespace qhwc; |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 41 | using namespace overlay; |
| 42 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 43 | #define VSYNC_DEBUG 0 |
Ramkumar Radhakrishnan | b32a0bc | 2013-04-11 17:57:32 -0700 | [diff] [blame] | 44 | #define BLANK_DEBUG 1 |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 45 | |
| 46 | static int hwc_device_open(const struct hw_module_t* module, |
| 47 | const char* name, |
| 48 | struct hw_device_t** device); |
| 49 | |
| 50 | static struct hw_module_methods_t hwc_module_methods = { |
| 51 | open: hwc_device_open |
| 52 | }; |
| 53 | |
| 54 | hwc_module_t HAL_MODULE_INFO_SYM = { |
| 55 | common: { |
| 56 | tag: HARDWARE_MODULE_TAG, |
| 57 | version_major: 2, |
| 58 | version_minor: 0, |
| 59 | id: HWC_HARDWARE_MODULE_ID, |
| 60 | name: "Qualcomm Hardware Composer Module", |
| 61 | author: "CodeAurora Forum", |
| 62 | methods: &hwc_module_methods, |
| 63 | dso: 0, |
| 64 | reserved: {0}, |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | /* |
| 69 | * Save callback functions registered to HWC |
| 70 | */ |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 71 | static void hwc_registerProcs(struct hwc_composer_device_1* dev, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 72 | hwc_procs_t const* procs) |
| 73 | { |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 74 | ALOGI("%s", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 75 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 76 | if(!ctx) { |
| 77 | ALOGE("%s: Invalid context", __FUNCTION__); |
| 78 | return; |
| 79 | } |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 80 | ctx->proc = procs; |
| 81 | |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 82 | // Now that we have the functions needed, kick off |
| 83 | // the uevent & vsync threads |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 84 | init_uevent_thread(ctx); |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 85 | init_vsync_thread(ctx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 88 | //Helper |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 89 | static void reset(hwc_context_t *ctx, int numDisplays, |
| 90 | hwc_display_contents_1_t** displays) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 91 | memset(ctx->listStats, 0, sizeof(ctx->listStats)); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 92 | for(int i = 0; i < MAX_DISPLAYS; i++) { |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 93 | hwc_display_contents_1_t *list = displays[i]; |
| 94 | // XXX:SurfaceFlinger no longer guarantees that this |
| 95 | // value is reset on every prepare. However, for the layer |
| 96 | // cache we need to reset it. |
| 97 | // We can probably rethink that later on |
| 98 | if (LIKELY(list && list->numHwLayers > 1)) { |
| 99 | for(uint32_t j = 0; j < list->numHwLayers; j++) { |
| 100 | if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET) |
| 101 | list->hwLayers[j].compositionType = HWC_FRAMEBUFFER; |
| 102 | } |
| 103 | } |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 104 | |
| 105 | if(ctx->mFBUpdate[i]) |
| 106 | ctx->mFBUpdate[i]->reset(); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 107 | if(ctx->mCopyBit[i]) |
| 108 | ctx->mCopyBit[i]->reset(); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 112 | //clear prev layer prop flags and realloc for current frame |
Saurabh Shah | 2b03339 | 2013-03-22 11:29:44 -0700 | [diff] [blame] | 113 | static void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 114 | if(ctx->layerProp[dpy]) { |
| 115 | delete[] ctx->layerProp[dpy]; |
| 116 | ctx->layerProp[dpy] = NULL; |
| 117 | } |
Saurabh Shah | 2b03339 | 2013-03-22 11:29:44 -0700 | [diff] [blame] | 118 | ctx->layerProp[dpy] = new LayerProp[numAppLayers]; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 119 | } |
| 120 | |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 121 | static int display_commit(hwc_context_t *ctx, int dpy) { |
| 122 | struct mdp_display_commit commit_info; |
| 123 | memset(&commit_info, 0, sizeof(struct mdp_display_commit)); |
| 124 | commit_info.flags = MDP_DISPLAY_COMMIT_OVERLAY; |
| 125 | if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_DISPLAY_COMMIT, &commit_info) == -1) { |
| 126 | ALOGE("%s: MSMFB_DISPLAY_COMMIT for primary failed", __FUNCTION__); |
| 127 | return -errno; |
| 128 | } |
| 129 | return 0; |
| 130 | } |
| 131 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 132 | static int hwc_prepare_primary(hwc_composer_device_1 *dev, |
| 133 | hwc_display_contents_1_t *list) { |
| 134 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 135 | const int dpy = HWC_DISPLAY_PRIMARY; |
Saurabh Shah | 2b03339 | 2013-03-22 11:29:44 -0700 | [diff] [blame] | 136 | if (LIKELY(list && list->numHwLayers > 1) && |
| 137 | ctx->dpyAttr[dpy].isActive) { |
| 138 | reset_layer_prop(ctx, dpy, list->numHwLayers - 1); |
Saurabh Shah | 86623d7 | 2012-09-25 19:39:17 -0700 | [diff] [blame] | 139 | uint32_t last = list->numHwLayers - 1; |
Saurabh Shah | 1a8cda0 | 2012-10-12 17:00:39 -0700 | [diff] [blame] | 140 | hwc_layer_1_t *fbLayer = &list->hwLayers[last]; |
| 141 | if(fbLayer->handle) { |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 142 | setListStats(ctx, list, dpy); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 143 | int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list); |
| 144 | if(fbZOrder >= 0) |
| 145 | ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder); |
| 146 | |
Terence Hampson | 0124cc7 | 2013-04-18 23:45:56 -0700 | [diff] [blame] | 147 | if (ctx->mMDP.version < qdutils::MDP_V4_0) { |
| 148 | if((fbZOrder >= 0) && ctx->mCopyBit[dpy]) |
| 149 | ctx->mCopyBit[dpy]->prepare(ctx, list, dpy); |
| 150 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static int hwc_prepare_external(hwc_composer_device_1 *dev, |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 157 | hwc_display_contents_1_t *list, int dpy) { |
Raj kamal | e3e68ae | 2013-05-02 17:28:23 +0530 | [diff] [blame] | 158 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 159 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Raj kamal | e3e68ae | 2013-05-02 17:28:23 +0530 | [diff] [blame] | 160 | Locker::Autolock _l(ctx->mExtLock); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 161 | |
Saurabh Shah | 2b03339 | 2013-03-22 11:29:44 -0700 | [diff] [blame] | 162 | if (LIKELY(list && list->numHwLayers > 1) && |
| 163 | ctx->dpyAttr[dpy].isActive && |
| 164 | ctx->dpyAttr[dpy].connected) { |
| 165 | reset_layer_prop(ctx, dpy, list->numHwLayers - 1); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 166 | uint32_t last = list->numHwLayers - 1; |
Saurabh Shah | 2b03339 | 2013-03-22 11:29:44 -0700 | [diff] [blame] | 167 | hwc_layer_1_t *fbLayer = &list->hwLayers[last]; |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 168 | if(!ctx->dpyAttr[dpy].isPause) { |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 169 | if(fbLayer->handle) { |
Saurabh Shah | 2b03339 | 2013-03-22 11:29:44 -0700 | [diff] [blame] | 170 | ctx->mExtDispConfiguring = false; |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 171 | setListStats(ctx, list, dpy); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 172 | int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list); |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 173 | if(ctx->deviceOrientation && |
| 174 | ctx->listStats[dpy].isDisplayAnimating) { |
| 175 | fbZOrder = 0; |
| 176 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 177 | if(fbZOrder >= 0) |
| 178 | ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder); |
| 179 | |
| 180 | /* Temporarily commenting out C2D until we support partial |
| 181 | copybit composition for mixed mode MDP |
| 182 | |
| 183 | if((fbZOrder >= 0) && ctx->mCopyBit[dpy]) |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 184 | ctx->mCopyBit[dpy]->prepare(ctx, list, dpy); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 185 | */ |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 186 | if(ctx->listStats[dpy].isDisplayAnimating) { |
| 187 | // Mark all app layers as HWC_OVERLAY for external during |
| 188 | // animation, so that SF doesnt draw it on FB |
| 189 | for(int i = 0 ;i < ctx->listStats[dpy].numAppLayers; i++) { |
| 190 | hwc_layer_1_t *layer = &list->hwLayers[i]; |
| 191 | layer->compositionType = HWC_OVERLAY; |
| 192 | } |
| 193 | } |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 194 | } |
| 195 | } else { |
| 196 | // External Display is in Pause state. |
| 197 | // ToDo: |
| 198 | // Mark all application layers as OVERLAY so that |
| 199 | // GPU will not compose. This is done for power |
| 200 | // optimization |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 201 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 202 | } |
| 203 | return 0; |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 206 | static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays, |
| 207 | hwc_display_contents_1_t** displays) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 208 | { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 209 | int ret = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 210 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 211 | Locker::Autolock _l(ctx->mBlankLock); |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 212 | reset(ctx, numDisplays, displays); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 213 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 214 | ctx->mOverlay->configBegin(); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 215 | ctx->mRotMgr->configBegin(); |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 216 | Overlay::setDMAMode(Overlay::DMA_LINE_MODE); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 217 | |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 218 | for (int32_t i = numDisplays; i >= 0; i--) { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 219 | hwc_display_contents_1_t *list = displays[i]; |
| 220 | switch(i) { |
| 221 | case HWC_DISPLAY_PRIMARY: |
| 222 | ret = hwc_prepare_primary(dev, list); |
| 223 | break; |
| 224 | case HWC_DISPLAY_EXTERNAL: |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 225 | case HWC_DISPLAY_VIRTUAL: |
| 226 | ret = hwc_prepare_external(dev, list, i); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 227 | break; |
| 228 | default: |
| 229 | ret = -EINVAL; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 230 | } |
| 231 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 232 | |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 233 | ctx->mOverlay->configDone(); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 234 | ctx->mRotMgr->configDone(); |
| 235 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 236 | return ret; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 239 | static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy, |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 240 | int event, int enable) |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 241 | { |
| 242 | int ret = 0; |
| 243 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | 8bb8f9d | 2013-05-11 07:29:45 -0400 | [diff] [blame] | 244 | Locker::Autolock _l(ctx->mBlankLock); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 245 | switch(event) { |
| 246 | case HWC_EVENT_VSYNC: |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 247 | if (ctx->vstate.enable == enable) |
Omprakash Dhyade | 1ef881c | 2012-10-03 02:26:55 -0700 | [diff] [blame] | 248 | break; |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 249 | ret = hwc_vsync_control(ctx, dpy, enable); |
Naseer Ahmed | 8bb8f9d | 2013-05-11 07:29:45 -0400 | [diff] [blame] | 250 | if(ret == 0) |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 251 | ctx->vstate.enable = !!enable; |
Iliyan Malchev | eac8965 | 2012-10-04 10:38:28 -0700 | [diff] [blame] | 252 | ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s", |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 253 | (enable)?"ENABLED":"DISABLED"); |
Iliyan Malchev | eac8965 | 2012-10-04 10:38:28 -0700 | [diff] [blame] | 254 | break; |
Naseer Ahmed | edbe518 | 2013-05-28 19:56:11 -0400 | [diff] [blame] | 255 | #ifdef QCOM_BSP |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 256 | case HWC_EVENT_ORIENTATION: |
| 257 | if(dpy == HWC_DISPLAY_PRIMARY) { |
| 258 | // store the primary display orientation |
| 259 | // will be used in hwc_video::configure to disable |
| 260 | // rotation animation on external display |
| 261 | ctx->deviceOrientation = enable; |
| 262 | } |
| 263 | break; |
Naseer Ahmed | edbe518 | 2013-05-28 19:56:11 -0400 | [diff] [blame] | 264 | #endif |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 265 | default: |
| 266 | ret = -EINVAL; |
| 267 | } |
| 268 | return ret; |
| 269 | } |
| 270 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 271 | static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank) |
| 272 | { |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 273 | ATRACE_CALL(); |
Naseer Ahmed | 934790c | 2012-08-16 18:11:09 -0700 | [diff] [blame] | 274 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 275 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 276 | Locker::Autolock _l(ctx->mBlankLock); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 277 | int ret = 0; |
Naseer Ahmed | e0205b6 | 2013-04-04 13:24:39 -0400 | [diff] [blame] | 278 | ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__, |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 279 | blank==1 ? "Blanking":"Unblanking", dpy); |
Arun Kumar K.R | e740837 | 2013-03-28 18:41:06 -0700 | [diff] [blame] | 280 | if(blank) { |
| 281 | // free up all the overlay pipes in use |
| 282 | // when we get a blank for either display |
| 283 | // makes sure that all pipes are freed |
| 284 | ctx->mOverlay->configBegin(); |
| 285 | ctx->mOverlay->configDone(); |
| 286 | ctx->mRotMgr->clear(); |
| 287 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 288 | switch(dpy) { |
| 289 | case HWC_DISPLAY_PRIMARY: |
| 290 | if(blank) { |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 291 | ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_POWERDOWN); |
Ramkumar Radhakrishnan | 893d6ee | 2013-02-26 10:48:05 -0800 | [diff] [blame] | 292 | |
| 293 | if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) { |
| 294 | // Surfaceflinger does not send Blank/unblank event to hwc |
| 295 | // for virtual display, handle it explicitly when blank for |
| 296 | // primary is invoked, so that any pipes unset get committed |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 297 | if (display_commit(ctx, HWC_DISPLAY_VIRTUAL) < 0) { |
Ramkumar Radhakrishnan | 893d6ee | 2013-02-26 10:48:05 -0800 | [diff] [blame] | 298 | ret = -1; |
| 299 | ALOGE("%s:post failed for virtual display !!", |
| 300 | __FUNCTION__); |
| 301 | } else { |
| 302 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank; |
| 303 | } |
| 304 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 305 | } else { |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 306 | ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, FB_BLANK_UNBLANK); |
Ramkumar Radhakrishnan | 893d6ee | 2013-02-26 10:48:05 -0800 | [diff] [blame] | 307 | if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) { |
| 308 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank; |
| 309 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 310 | } |
| 311 | break; |
| 312 | case HWC_DISPLAY_EXTERNAL: |
| 313 | if(blank) { |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 314 | // call external framebuffer commit on blank, |
| 315 | // so that any pipe unsets gets committed |
| 316 | if (display_commit(ctx, dpy) < 0) { |
Arun Kumar K.R | ba9eed5 | 2013-01-04 00:51:29 -0800 | [diff] [blame] | 317 | ret = -1; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 318 | ALOGE("%s:post failed for external display !! ", |
| 319 | __FUNCTION__); |
Arun Kumar K.R | ba9eed5 | 2013-01-04 00:51:29 -0800 | [diff] [blame] | 320 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 321 | } else { |
| 322 | } |
| 323 | break; |
| 324 | default: |
| 325 | return -EINVAL; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 326 | } |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 327 | // Enable HPD here, as during bootup unblank is called |
| 328 | // when SF is completely initialized |
| 329 | ctx->mExtDisplay->setHPD(1); |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 330 | if(ret == 0){ |
| 331 | ctx->dpyAttr[dpy].isActive = !blank; |
| 332 | } else { |
| 333 | ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__, |
| 334 | blank==1 ? "blanking":"unblanking", dpy, strerror(errno)); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 335 | return ret; |
| 336 | } |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 337 | |
Naseer Ahmed | e0205b6 | 2013-04-04 13:24:39 -0400 | [diff] [blame] | 338 | ALOGD_IF(BLANK_DEBUG, "%s: Done %s display: %d", __FUNCTION__, |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 339 | blank==1 ? "blanking":"unblanking", dpy); |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | static int hwc_query(struct hwc_composer_device_1* dev, |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 344 | int param, int* value) |
| 345 | { |
| 346 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 347 | int supported = HWC_DISPLAY_PRIMARY_BIT; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 348 | |
| 349 | switch (param) { |
| 350 | case HWC_BACKGROUND_LAYER_SUPPORTED: |
| 351 | // Not supported for now |
| 352 | value[0] = 0; |
| 353 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 354 | case HWC_DISPLAY_TYPES_SUPPORTED: |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 355 | if(ctx->mMDP.hasOverlay) |
| 356 | supported |= HWC_DISPLAY_EXTERNAL_BIT; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 357 | value[0] = supported; |
| 358 | break; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 359 | default: |
| 360 | return -EINVAL; |
| 361 | } |
| 362 | return 0; |
| 363 | |
| 364 | } |
| 365 | |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 366 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 367 | static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 368 | ATRACE_CALL(); |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 369 | int ret = 0; |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 370 | const int dpy = HWC_DISPLAY_PRIMARY; |
Amara Venkata Mastan Manoj Kumar | 57e3c81 | 2013-01-11 13:36:33 -0800 | [diff] [blame] | 371 | if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 372 | uint32_t last = list->numHwLayers - 1; |
| 373 | hwc_layer_1_t *fbLayer = &list->hwLayers[last]; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 374 | int fd = -1; //FenceFD from the Copybit(valid in async mode) |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 375 | bool copybitDone = false; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 376 | if(ctx->mCopyBit[dpy]) |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 377 | copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd); |
Amara Venkata Mastan Manoj Kumar | 57e3c81 | 2013-01-11 13:36:33 -0800 | [diff] [blame] | 378 | if(list->numHwLayers > 1) |
| 379 | hwc_sync(ctx, list, dpy, fd); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 380 | |
Ramkumar Radhakrishnan | d224a1a | 2013-04-05 17:46:55 -0700 | [diff] [blame] | 381 | // Dump the layers for primary |
| 382 | if(ctx->mHwcDebug[dpy]) |
| 383 | ctx->mHwcDebug[dpy]->dumpLayers(list); |
| 384 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 385 | if (!ctx->mMDPComp[dpy]->draw(ctx, list)) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 386 | ALOGE("%s: MDPComp draw failed", __FUNCTION__); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 387 | ret = -1; |
| 388 | } |
| 389 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 390 | //TODO We dont check for SKIP flag on this layer because we need PAN |
| 391 | //always. Last layer is always FB |
Saurabh Shah | 2b03339 | 2013-03-22 11:29:44 -0700 | [diff] [blame] | 392 | private_handle_t *hnd = (private_handle_t *)fbLayer->handle; |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 393 | if(copybitDone) { |
| 394 | hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer(); |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 395 | } |
Saurabh Shah | 2b03339 | 2013-03-22 11:29:44 -0700 | [diff] [blame] | 396 | |
| 397 | if(hnd) { |
| 398 | if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) { |
| 399 | ALOGE("%s: FBUpdate draw failed", __FUNCTION__); |
| 400 | ret = -1; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 401 | } |
Saurabh Shah | 4333330 | 2013-02-06 13:30:27 -0800 | [diff] [blame] | 402 | } |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 403 | |
| 404 | if (display_commit(ctx, dpy) < 0) { |
| 405 | ALOGE("%s: display commit fail!", __FUNCTION__); |
Ramkumar Radhakrishnan | 68a5192 | 2013-05-11 16:51:49 -0700 | [diff] [blame] | 406 | ret = -1; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 407 | } |
| 408 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 409 | |
| 410 | closeAcquireFds(list); |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 411 | return ret; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | static int hwc_set_external(hwc_context_t *ctx, |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 415 | hwc_display_contents_1_t* list, int dpy) |
| 416 | { |
| 417 | ATRACE_CALL(); |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 418 | int ret = 0; |
Raj kamal | e3e68ae | 2013-05-02 17:28:23 +0530 | [diff] [blame] | 419 | Locker::Autolock _l(ctx->mExtLock); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 420 | |
Amara Venkata Mastan Manoj Kumar | 57e3c81 | 2013-01-11 13:36:33 -0800 | [diff] [blame] | 421 | if (LIKELY(list) && ctx->dpyAttr[dpy].isActive && |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 422 | !ctx->dpyAttr[dpy].isPause && |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 423 | ctx->dpyAttr[dpy].connected) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 424 | uint32_t last = list->numHwLayers - 1; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 425 | hwc_layer_1_t *fbLayer = &list->hwLayers[last]; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 426 | int fd = -1; //FenceFD from the Copybit(valid in async mode) |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 427 | bool copybitDone = false; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 428 | if(ctx->mCopyBit[dpy]) |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 429 | copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 430 | |
Amara Venkata Mastan Manoj Kumar | 57e3c81 | 2013-01-11 13:36:33 -0800 | [diff] [blame] | 431 | if(list->numHwLayers > 1) |
| 432 | hwc_sync(ctx, list, dpy, fd); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 433 | |
Ramkumar Radhakrishnan | d224a1a | 2013-04-05 17:46:55 -0700 | [diff] [blame] | 434 | // Dump the layers for external |
| 435 | if(ctx->mHwcDebug[dpy]) |
| 436 | ctx->mHwcDebug[dpy]->dumpLayers(list); |
| 437 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 438 | if (!ctx->mMDPComp[dpy]->draw(ctx, list)) { |
| 439 | ALOGE("%s: MDPComp draw failed", __FUNCTION__); |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 440 | ret = -1; |
| 441 | } |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 442 | |
Arun Kumar K.R | a297845 | 2013-02-07 01:34:24 -0800 | [diff] [blame] | 443 | int extOnlyLayerIndex = |
| 444 | ctx->listStats[dpy].extOnlyLayerIndex; |
| 445 | |
Saurabh Shah | 2b03339 | 2013-03-22 11:29:44 -0700 | [diff] [blame] | 446 | private_handle_t *hnd = (private_handle_t *)fbLayer->handle; |
Arun Kumar K.R | a297845 | 2013-02-07 01:34:24 -0800 | [diff] [blame] | 447 | if(extOnlyLayerIndex!= -1) { |
| 448 | hwc_layer_1_t *extLayer = &list->hwLayers[extOnlyLayerIndex]; |
| 449 | hnd = (private_handle_t *)extLayer->handle; |
| 450 | } else if(copybitDone) { |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 451 | hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer(); |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 452 | } |
| 453 | |
Arun Kumar K.R | a297845 | 2013-02-07 01:34:24 -0800 | [diff] [blame] | 454 | if(hnd && !isYuvBuffer(hnd)) { |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 455 | if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 456 | ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__); |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 457 | ret = -1; |
| 458 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 459 | } |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 460 | |
| 461 | if (display_commit(ctx, dpy) < 0) { |
| 462 | ALOGE("%s: display commit fail!", __FUNCTION__); |
Saurabh Shah | 2b03339 | 2013-03-22 11:29:44 -0700 | [diff] [blame] | 463 | ret = -1; |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 464 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 465 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 466 | |
| 467 | closeAcquireFds(list); |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 468 | return ret; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 471 | static int hwc_set(hwc_composer_device_1 *dev, |
| 472 | size_t numDisplays, |
| 473 | hwc_display_contents_1_t** displays) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 474 | { |
| 475 | int ret = 0; |
| 476 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | 32ff225 | 2012-09-29 01:41:21 -0400 | [diff] [blame] | 477 | Locker::Autolock _l(ctx->mBlankLock); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 478 | for (uint32_t i = 0; i <= numDisplays; i++) { |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 479 | hwc_display_contents_1_t* list = displays[i]; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 480 | switch(i) { |
| 481 | case HWC_DISPLAY_PRIMARY: |
| 482 | ret = hwc_set_primary(ctx, list); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 483 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 484 | case HWC_DISPLAY_EXTERNAL: |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 485 | case HWC_DISPLAY_VIRTUAL: |
| 486 | /* ToDo: We are using hwc_set_external path for both External and |
| 487 | Virtual displays on HWC1.1. Eventually, we will have |
| 488 | separate functions when we move to HWC1.2 |
| 489 | */ |
| 490 | ret = hwc_set_external(ctx, list, i); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 491 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 492 | default: |
| 493 | ret = -EINVAL; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 494 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 495 | } |
Naseer Ahmed | 0d05d4f | 2013-03-28 14:49:07 -0400 | [diff] [blame] | 496 | // This is only indicative of how many times SurfaceFlinger posts |
| 497 | // frames to the display. |
| 498 | CALC_FPS(); |
Saurabh Shah | 2d998a9 | 2013-05-14 17:55:58 -0700 | [diff] [blame] | 499 | MDPComp::resetIdleFallBack(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 500 | return ret; |
| 501 | } |
| 502 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 503 | int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp, |
| 504 | uint32_t* configs, size_t* numConfigs) { |
| 505 | int ret = 0; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 506 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 507 | //in 1.1 there is no way to choose a config, report as config id # 0 |
| 508 | //This config is passed to getDisplayAttributes. Ignore for now. |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 509 | switch(disp) { |
| 510 | case HWC_DISPLAY_PRIMARY: |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 511 | if(*numConfigs > 0) { |
| 512 | configs[0] = 0; |
| 513 | *numConfigs = 1; |
| 514 | } |
| 515 | ret = 0; //NO_ERROR |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 516 | break; |
| 517 | case HWC_DISPLAY_EXTERNAL: |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 518 | ret = -1; //Not connected |
| 519 | if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) { |
| 520 | ret = 0; //NO_ERROR |
| 521 | if(*numConfigs > 0) { |
| 522 | configs[0] = 0; |
| 523 | *numConfigs = 1; |
| 524 | } |
| 525 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 526 | break; |
| 527 | } |
| 528 | return ret; |
| 529 | } |
| 530 | |
| 531 | int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp, |
| 532 | uint32_t config, const uint32_t* attributes, int32_t* values) { |
| 533 | |
| 534 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 535 | //If hotpluggable displays are inactive return error |
| 536 | if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) { |
| 537 | return -1; |
| 538 | } |
| 539 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 540 | //From HWComposer |
| 541 | static const uint32_t DISPLAY_ATTRIBUTES[] = { |
| 542 | HWC_DISPLAY_VSYNC_PERIOD, |
| 543 | HWC_DISPLAY_WIDTH, |
| 544 | HWC_DISPLAY_HEIGHT, |
| 545 | HWC_DISPLAY_DPI_X, |
| 546 | HWC_DISPLAY_DPI_Y, |
| 547 | HWC_DISPLAY_NO_ATTRIBUTE, |
| 548 | }; |
| 549 | |
| 550 | const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) / |
| 551 | sizeof(DISPLAY_ATTRIBUTES)[0]); |
| 552 | |
| 553 | for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) { |
| 554 | switch (attributes[i]) { |
| 555 | case HWC_DISPLAY_VSYNC_PERIOD: |
| 556 | values[i] = ctx->dpyAttr[disp].vsync_period; |
| 557 | break; |
| 558 | case HWC_DISPLAY_WIDTH: |
| 559 | values[i] = ctx->dpyAttr[disp].xres; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 560 | ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp, |
| 561 | ctx->dpyAttr[disp].xres); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 562 | break; |
| 563 | case HWC_DISPLAY_HEIGHT: |
| 564 | values[i] = ctx->dpyAttr[disp].yres; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 565 | ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp, |
| 566 | ctx->dpyAttr[disp].yres); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 567 | break; |
| 568 | case HWC_DISPLAY_DPI_X: |
Naseer Ahmed | 7b80d9c | 2012-09-26 20:14:38 -0400 | [diff] [blame] | 569 | values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 570 | break; |
| 571 | case HWC_DISPLAY_DPI_Y: |
Naseer Ahmed | 7b80d9c | 2012-09-26 20:14:38 -0400 | [diff] [blame] | 572 | values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 573 | break; |
| 574 | default: |
| 575 | ALOGE("Unknown display attribute %d", |
| 576 | attributes[i]); |
| 577 | return -EINVAL; |
| 578 | } |
| 579 | } |
| 580 | return 0; |
| 581 | } |
| 582 | |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 583 | void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len) |
| 584 | { |
| 585 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 586 | android::String8 aBuf(""); |
| 587 | dumpsys_log(aBuf, "Qualcomm HWC state:\n"); |
| 588 | dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version); |
| 589 | dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 590 | for(int dpy = 0; dpy < MAX_DISPLAYS; dpy++) { |
| 591 | if(ctx->mMDPComp[dpy]) |
| 592 | ctx->mMDPComp[dpy]->dump(aBuf); |
| 593 | } |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 594 | char ovDump[2048] = {'\0'}; |
| 595 | ctx->mOverlay->getDump(ovDump, 2048); |
| 596 | dumpsys_log(aBuf, ovDump); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 597 | ovDump[0] = '\0'; |
Saurabh Shah | ae61b2b | 2013-04-10 16:37:25 -0700 | [diff] [blame] | 598 | ctx->mRotMgr->getDump(ovDump, 1024); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 599 | dumpsys_log(aBuf, ovDump); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 600 | strlcpy(buff, aBuf.string(), buff_len); |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 601 | } |
| 602 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 603 | static int hwc_device_close(struct hw_device_t *dev) |
| 604 | { |
| 605 | if(!dev) { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 606 | ALOGE("%s: NULL device pointer", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 607 | return -1; |
| 608 | } |
| 609 | closeContext((hwc_context_t*)dev); |
| 610 | free(dev); |
| 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | static int hwc_device_open(const struct hw_module_t* module, const char* name, |
| 616 | struct hw_device_t** device) |
| 617 | { |
| 618 | int status = -EINVAL; |
| 619 | |
| 620 | if (!strcmp(name, HWC_HARDWARE_COMPOSER)) { |
| 621 | struct hwc_context_t *dev; |
| 622 | dev = (hwc_context_t*)malloc(sizeof(*dev)); |
| 623 | memset(dev, 0, sizeof(*dev)); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 624 | |
| 625 | //Initialize hwc context |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 626 | initContext(dev); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 627 | |
| 628 | //Setup HWC methods |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 629 | dev->device.common.tag = HARDWARE_DEVICE_TAG; |
| 630 | dev->device.common.version = HWC_DEVICE_API_VERSION_1_1; |
| 631 | dev->device.common.module = const_cast<hw_module_t*>(module); |
| 632 | dev->device.common.close = hwc_device_close; |
| 633 | dev->device.prepare = hwc_prepare; |
| 634 | dev->device.set = hwc_set; |
| 635 | dev->device.eventControl = hwc_eventControl; |
| 636 | dev->device.blank = hwc_blank; |
| 637 | dev->device.query = hwc_query; |
| 638 | dev->device.registerProcs = hwc_registerProcs; |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 639 | dev->device.dump = hwc_dump; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 640 | dev->device.getDisplayConfigs = hwc_getDisplayConfigs; |
| 641 | dev->device.getDisplayAttributes = hwc_getDisplayAttributes; |
| 642 | *device = &dev->device.common; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 643 | status = 0; |
| 644 | } |
| 645 | return status; |
| 646 | } |