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