Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 3 | * Copyright (C) 2012, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <fcntl.h> |
| 19 | #include <errno.h> |
| 20 | |
| 21 | #include <cutils/log.h> |
| 22 | #include <cutils/atomic.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 23 | #include <EGL/egl.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 24 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 25 | #include <overlay.h> |
| 26 | #include <fb_priv.h> |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 27 | #include <mdp_version.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 28 | #include "hwc_utils.h" |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 29 | #include "hwc_video.h" |
Saurabh Shah | 86623d7 | 2012-09-25 19:39:17 -0700 | [diff] [blame] | 30 | #include "hwc_uimirror.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 31 | #include "external.h" |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 32 | #include "hwc_mdpcomp.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 33 | |
| 34 | using namespace qhwc; |
| 35 | |
| 36 | static int hwc_device_open(const struct hw_module_t* module, |
| 37 | const char* name, |
| 38 | struct hw_device_t** device); |
| 39 | |
| 40 | static struct hw_module_methods_t hwc_module_methods = { |
| 41 | open: hwc_device_open |
| 42 | }; |
| 43 | |
| 44 | hwc_module_t HAL_MODULE_INFO_SYM = { |
| 45 | common: { |
| 46 | tag: HARDWARE_MODULE_TAG, |
| 47 | version_major: 2, |
| 48 | version_minor: 0, |
| 49 | id: HWC_HARDWARE_MODULE_ID, |
| 50 | name: "Qualcomm Hardware Composer Module", |
| 51 | author: "CodeAurora Forum", |
| 52 | methods: &hwc_module_methods, |
| 53 | dso: 0, |
| 54 | reserved: {0}, |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | /* |
| 59 | * Save callback functions registered to HWC |
| 60 | */ |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 61 | static void hwc_registerProcs(struct hwc_composer_device_1* dev, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 62 | hwc_procs_t const* procs) |
| 63 | { |
| 64 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 65 | if(!ctx) { |
| 66 | ALOGE("%s: Invalid context", __FUNCTION__); |
| 67 | return; |
| 68 | } |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 69 | ctx->proc = procs; |
| 70 | |
| 71 | // don't start listening for events until we can do something with them |
| 72 | init_uevent_thread(ctx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 75 | //Helper |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 76 | static void reset(hwc_context_t *ctx, int numDisplays) { |
| 77 | memset(ctx->listStats, 0, sizeof(ctx->listStats)); |
| 78 | for(int i = 0; i < numDisplays; i++){ |
| 79 | ctx->listStats[i].yuvIndex = -1; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | static int hwc_prepare_primary(hwc_composer_device_1 *dev, |
| 84 | hwc_display_contents_1_t *list) { |
| 85 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 86 | if (LIKELY(list && list->numHwLayers)) { |
Saurabh Shah | 86623d7 | 2012-09-25 19:39:17 -0700 | [diff] [blame] | 87 | uint32_t last = list->numHwLayers - 1; |
| 88 | hwc_layer_1_t *fblayer = &list->hwLayers[last]; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 89 | setListStats(ctx, list, HWC_DISPLAY_PRIMARY); |
| 90 | if(VideoOverlay::prepare(ctx, list, HWC_DISPLAY_PRIMARY)) { |
| 91 | ctx->overlayInUse = true; |
Saurabh Shah | 86623d7 | 2012-09-25 19:39:17 -0700 | [diff] [blame] | 92 | } else if(UIMirrorOverlay::prepare(ctx, fblayer)) { |
| 93 | ctx->overlayInUse = true; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 94 | } else if(MDPComp::configure(ctx, list)) { |
| 95 | ctx->overlayInUse = true; |
| 96 | } else { |
| 97 | ctx->overlayInUse = false; |
| 98 | } |
| 99 | } |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | static int hwc_prepare_external(hwc_composer_device_1 *dev, |
| 104 | hwc_display_contents_1_t *list) { |
| 105 | |
| 106 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 107 | if (LIKELY(list && list->numHwLayers)) { |
Saurabh Shah | 86623d7 | 2012-09-25 19:39:17 -0700 | [diff] [blame] | 108 | //setListStats(ctx, list, HWC_DISPLAY_EXTERNAL); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 109 | //Nothing to do for now |
| 110 | } |
| 111 | return 0; |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 114 | static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays, |
| 115 | hwc_display_contents_1_t** displays) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 116 | { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 117 | int ret = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 118 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 119 | ctx->overlayInUse = false; |
| 120 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 121 | reset(ctx, numDisplays); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 122 | |
| 123 | //If securing of h/w in progress skip comp using overlay. |
| 124 | if(ctx->mSecuring == true) return 0; |
| 125 | |
Saurabh Shah | 9171ec6 | 2012-09-13 09:33:51 -0700 | [diff] [blame] | 126 | for (uint32_t i = 0; i < numDisplays; i++) { |
| 127 | hwc_display_contents_1_t *list = displays[i]; |
Naseer Ahmed | 6282c95 | 2012-09-26 18:33:58 -0400 | [diff] [blame^] | 128 | if(list && list->numHwLayers) { |
| 129 | uint32_t last = list->numHwLayers - 1; |
| 130 | if(list->hwLayers[last].handle != NULL) { |
| 131 | switch(i) { |
| 132 | case HWC_DISPLAY_PRIMARY: |
| 133 | ret = hwc_prepare_primary(dev, list); |
| 134 | break; |
| 135 | case HWC_DISPLAY_EXTERNAL: |
| 136 | ret = hwc_prepare_external(dev, list); |
| 137 | break; |
| 138 | default: |
| 139 | ret = -EINVAL; |
| 140 | } |
| 141 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 144 | return ret; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 147 | static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy, |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 148 | int event, int enabled) |
| 149 | { |
| 150 | int ret = 0; |
| 151 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 152 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 153 | ctx->mFbDev->common.module); |
| 154 | switch(event) { |
| 155 | case HWC_EVENT_VSYNC: |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 156 | if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_OVERLAY_VSYNC_CTRL, |
| 157 | &enabled) < 0) { |
| 158 | ALOGE("%s: vsync control failed. Dpy=%d, enabled=%d : %s", |
| 159 | __FUNCTION__, dpy, enabled, strerror(errno)); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 160 | ret = -errno; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 161 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 162 | break; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 163 | default: |
| 164 | ret = -EINVAL; |
| 165 | } |
| 166 | return ret; |
| 167 | } |
| 168 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 169 | static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank) |
| 170 | { |
Naseer Ahmed | 934790c | 2012-08-16 18:11:09 -0700 | [diff] [blame] | 171 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 172 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 173 | ctx->mFbDev->common.module); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 174 | int ret = 0; |
| 175 | ALOGD("%s: Doing Dpy=%d, blank=%d", __FUNCTION__, dpy, blank); |
| 176 | switch(dpy) { |
| 177 | case HWC_DISPLAY_PRIMARY: |
| 178 | if(blank) { |
| 179 | ctx->mOverlay->setState(ovutils::OV_CLOSED); |
| 180 | ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN); |
| 181 | } else { |
| 182 | ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK); |
| 183 | } |
| 184 | break; |
| 185 | case HWC_DISPLAY_EXTERNAL: |
| 186 | if(blank) { |
| 187 | //TODO actual |
| 188 | } else { |
| 189 | } |
| 190 | break; |
| 191 | default: |
| 192 | return -EINVAL; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 193 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 194 | |
| 195 | if(ret < 0) { |
| 196 | ALOGE("%s: failed. Dpy=%d, blank=%d : %s", |
| 197 | __FUNCTION__, dpy, blank, strerror(errno)); |
| 198 | return ret; |
| 199 | } |
| 200 | ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank); |
| 201 | ctx->dpyAttr[dpy].isActive = !blank; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | static int hwc_query(struct hwc_composer_device_1* dev, |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 206 | int param, int* value) |
| 207 | { |
| 208 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 209 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 210 | ctx->mFbDev->common.module); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 211 | int supported = HWC_DISPLAY_PRIMARY_BIT; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 212 | |
| 213 | switch (param) { |
| 214 | case HWC_BACKGROUND_LAYER_SUPPORTED: |
| 215 | // Not supported for now |
| 216 | value[0] = 0; |
| 217 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 218 | case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1 |
Saurabh Shah | 2e2798c | 2012-08-30 14:47:10 -0700 | [diff] [blame] | 219 | value[0] = m->fps; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 220 | ALOGI("fps: %d", value[0]); |
| 221 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 222 | case HWC_DISPLAY_TYPES_SUPPORTED: |
Saurabh Shah | 86623d7 | 2012-09-25 19:39:17 -0700 | [diff] [blame] | 223 | //TODO Enable later |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 224 | //if(ctx->mMDP.hasOverlay) |
| 225 | //supported |= HWC_DISPLAY_EXTERNAL_BIT; |
| 226 | value[0] = supported; |
| 227 | break; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 228 | default: |
| 229 | return -EINVAL; |
| 230 | } |
| 231 | return 0; |
| 232 | |
| 233 | } |
| 234 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 235 | static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
| 236 | if (LIKELY(list && list->numHwLayers)) { |
| 237 | VideoOverlay::draw(ctx, list, HWC_DISPLAY_PRIMARY); |
| 238 | MDPComp::draw(ctx, list); |
Saurabh Shah | 86623d7 | 2012-09-25 19:39:17 -0700 | [diff] [blame] | 239 | uint32_t last = list->numHwLayers - 1; |
| 240 | hwc_layer_1_t *fblayer = &list->hwLayers[last]; |
| 241 | if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive) { |
| 242 | UIMirrorOverlay::draw(ctx, fblayer); |
| 243 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 244 | hwc_sync(ctx, list, HWC_DISPLAY_PRIMARY); |
Saurabh Shah | 86623d7 | 2012-09-25 19:39:17 -0700 | [diff] [blame] | 245 | if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive) { |
| 246 | ctx->mExtDisplay->post(); |
| 247 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 248 | //TODO We dont check for SKIP flag on this layer because we need PAN |
| 249 | //always. Last layer is always FB |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 250 | if(list->hwLayers[last].compositionType == HWC_FRAMEBUFFER_TARGET) { |
| 251 | ctx->mFbDev->post(ctx->mFbDev, list->hwLayers[last].handle); |
| 252 | } |
| 253 | } |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static int hwc_set_external(hwc_context_t *ctx, |
| 258 | hwc_display_contents_1_t* list) { |
| 259 | if (LIKELY(list && list->numHwLayers)) { |
Saurabh Shah | 86623d7 | 2012-09-25 19:39:17 -0700 | [diff] [blame] | 260 | //hwc_sync(ctx, list, HWC_DISPLAY_EXTERNAL); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 261 | uint32_t last = list->numHwLayers - 1; |
| 262 | if(list->hwLayers[last].compositionType == HWC_FRAMEBUFFER_TARGET && |
| 263 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive) { |
| 264 | //ctx->mExtDisplay->post(list->hwLayers[last].handle); |
| 265 | } |
| 266 | } |
| 267 | return 0; |
| 268 | } |
| 269 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 270 | static int hwc_set(hwc_composer_device_1 *dev, |
| 271 | size_t numDisplays, |
| 272 | hwc_display_contents_1_t** displays) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 273 | { |
| 274 | int ret = 0; |
| 275 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 276 | for (uint32_t i = 0; i < numDisplays; i++) { |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 277 | hwc_display_contents_1_t* list = displays[i]; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 278 | switch(i) { |
| 279 | case HWC_DISPLAY_PRIMARY: |
| 280 | ret = hwc_set_primary(ctx, list); |
| 281 | case HWC_DISPLAY_EXTERNAL: |
| 282 | ret = hwc_set_external(ctx, list); |
| 283 | default: |
| 284 | ret = -EINVAL; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 285 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 286 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 287 | if(!ctx->overlayInUse) |
| 288 | ctx->mOverlay->setState(ovutils::OV_CLOSED); |
| 289 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 290 | return ret; |
| 291 | } |
| 292 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 293 | int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp, |
| 294 | uint32_t* configs, size_t* numConfigs) { |
| 295 | int ret = 0; |
| 296 | //in 1.1 there is no way to choose a config, report as config id # 0 |
| 297 | //This config is passed to getDisplayAttributes. Ignore for now. |
| 298 | if(*numConfigs == 1) |
| 299 | *configs = 0; |
| 300 | switch(disp) { |
| 301 | case HWC_DISPLAY_PRIMARY: |
| 302 | ret = 0; |
| 303 | break; |
| 304 | case HWC_DISPLAY_EXTERNAL: |
| 305 | //Hack until hotplug is supported. |
| 306 | //This makes framework ignore external display. |
| 307 | ret = -1; |
| 308 | break; |
| 309 | } |
| 310 | return ret; |
| 311 | } |
| 312 | |
| 313 | int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp, |
| 314 | uint32_t config, const uint32_t* attributes, int32_t* values) { |
| 315 | |
| 316 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 317 | //From HWComposer |
| 318 | static const uint32_t DISPLAY_ATTRIBUTES[] = { |
| 319 | HWC_DISPLAY_VSYNC_PERIOD, |
| 320 | HWC_DISPLAY_WIDTH, |
| 321 | HWC_DISPLAY_HEIGHT, |
| 322 | HWC_DISPLAY_DPI_X, |
| 323 | HWC_DISPLAY_DPI_Y, |
| 324 | HWC_DISPLAY_NO_ATTRIBUTE, |
| 325 | }; |
| 326 | |
| 327 | const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) / |
| 328 | sizeof(DISPLAY_ATTRIBUTES)[0]); |
| 329 | |
| 330 | for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) { |
| 331 | switch (attributes[i]) { |
| 332 | case HWC_DISPLAY_VSYNC_PERIOD: |
| 333 | values[i] = ctx->dpyAttr[disp].vsync_period; |
| 334 | break; |
| 335 | case HWC_DISPLAY_WIDTH: |
| 336 | values[i] = ctx->dpyAttr[disp].xres; |
| 337 | ALOGD("%s width = %d",__FUNCTION__, ctx->dpyAttr[disp].xres); |
| 338 | break; |
| 339 | case HWC_DISPLAY_HEIGHT: |
| 340 | values[i] = ctx->dpyAttr[disp].yres; |
| 341 | ALOGD("%s height = %d",__FUNCTION__, ctx->dpyAttr[disp].yres); |
| 342 | break; |
| 343 | case HWC_DISPLAY_DPI_X: |
Naseer Ahmed | 7b80d9c | 2012-09-26 20:14:38 -0400 | [diff] [blame] | 344 | values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 345 | break; |
| 346 | case HWC_DISPLAY_DPI_Y: |
Naseer Ahmed | 7b80d9c | 2012-09-26 20:14:38 -0400 | [diff] [blame] | 347 | values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 348 | break; |
| 349 | default: |
| 350 | ALOGE("Unknown display attribute %d", |
| 351 | attributes[i]); |
| 352 | return -EINVAL; |
| 353 | } |
| 354 | } |
| 355 | return 0; |
| 356 | } |
| 357 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 358 | static int hwc_device_close(struct hw_device_t *dev) |
| 359 | { |
| 360 | if(!dev) { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 361 | ALOGE("%s: NULL device pointer", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 362 | return -1; |
| 363 | } |
| 364 | closeContext((hwc_context_t*)dev); |
| 365 | free(dev); |
| 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | static int hwc_device_open(const struct hw_module_t* module, const char* name, |
| 371 | struct hw_device_t** device) |
| 372 | { |
| 373 | int status = -EINVAL; |
| 374 | |
| 375 | if (!strcmp(name, HWC_HARDWARE_COMPOSER)) { |
| 376 | struct hwc_context_t *dev; |
| 377 | dev = (hwc_context_t*)malloc(sizeof(*dev)); |
| 378 | memset(dev, 0, sizeof(*dev)); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 379 | |
| 380 | //Initialize hwc context |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 381 | initContext(dev); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 382 | |
| 383 | //Setup HWC methods |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 384 | dev->device.common.tag = HARDWARE_DEVICE_TAG; |
| 385 | dev->device.common.version = HWC_DEVICE_API_VERSION_1_1; |
| 386 | dev->device.common.module = const_cast<hw_module_t*>(module); |
| 387 | dev->device.common.close = hwc_device_close; |
| 388 | dev->device.prepare = hwc_prepare; |
| 389 | dev->device.set = hwc_set; |
| 390 | dev->device.eventControl = hwc_eventControl; |
| 391 | dev->device.blank = hwc_blank; |
| 392 | dev->device.query = hwc_query; |
| 393 | dev->device.registerProcs = hwc_registerProcs; |
| 394 | dev->device.dump = NULL; |
| 395 | dev->device.getDisplayConfigs = hwc_getDisplayConfigs; |
| 396 | dev->device.getDisplayAttributes = hwc_getDisplayAttributes; |
| 397 | *device = &dev->device.common; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 398 | status = 0; |
| 399 | } |
| 400 | return status; |
| 401 | } |