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