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