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