hwc.cpp revision 103c736926cace1ff5a6d154715b375ff1018f8e
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved. 4 * 5 * Not a Contribution, Apache license notifications and license are retained 6 * for attribution purposes only. 7 * 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 */ 20#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL) 21#include <fcntl.h> 22#include <errno.h> 23 24#include <cutils/log.h> 25#include <cutils/atomic.h> 26#include <EGL/egl.h> 27#include <utils/Trace.h> 28#include <sys/ioctl.h> 29#include <overlay.h> 30#include <overlayRotator.h> 31#include <overlayWriteback.h> 32#include <mdp_version.h> 33#include "hwc_utils.h" 34#include "hwc_fbupdate.h" 35#include "hwc_mdpcomp.h" 36#include "external.h" 37#include "hwc_copybit.h" 38#include "hwc_ad.h" 39#include "profiler.h" 40 41using namespace qhwc; 42using namespace overlay; 43 44#define VSYNC_DEBUG 0 45#define BLANK_DEBUG 1 46 47static int hwc_device_open(const struct hw_module_t* module, 48 const char* name, 49 struct hw_device_t** device); 50 51static struct hw_module_methods_t hwc_module_methods = { 52 open: hwc_device_open 53}; 54 55hwc_module_t HAL_MODULE_INFO_SYM = { 56 common: { 57 tag: HARDWARE_MODULE_TAG, 58 version_major: 2, 59 version_minor: 0, 60 id: HWC_HARDWARE_MODULE_ID, 61 name: "Qualcomm Hardware Composer Module", 62 author: "CodeAurora Forum", 63 methods: &hwc_module_methods, 64 dso: 0, 65 reserved: {0}, 66 } 67}; 68 69/* 70 * Save callback functions registered to HWC 71 */ 72static void hwc_registerProcs(struct hwc_composer_device_1* dev, 73 hwc_procs_t const* procs) 74{ 75 ALOGI("%s", __FUNCTION__); 76 hwc_context_t* ctx = (hwc_context_t*)(dev); 77 if(!ctx) { 78 ALOGE("%s: Invalid context", __FUNCTION__); 79 return; 80 } 81 ctx->proc = procs; 82 83 // Now that we have the functions needed, kick off 84 // the uevent & vsync threads 85 init_uevent_thread(ctx); 86 init_vsync_thread(ctx); 87} 88 89//Helper 90static void reset(hwc_context_t *ctx, int numDisplays, 91 hwc_display_contents_1_t** displays) { 92 for(int i = 0; i < MAX_DISPLAYS; i++) { 93 hwc_display_contents_1_t *list = displays[i]; 94 // XXX:SurfaceFlinger no longer guarantees that this 95 // value is reset on every prepare. However, for the layer 96 // cache we need to reset it. 97 // We can probably rethink that later on 98 if (LIKELY(list && list->numHwLayers > 1)) { 99 for(uint32_t j = 0; j < list->numHwLayers; j++) { 100 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET) 101 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER; 102 } 103 } 104 105 if(ctx->mFBUpdate[i]) 106 ctx->mFBUpdate[i]->reset(); 107 if(ctx->mMDPComp[i]) 108 ctx->mMDPComp[i]->reset(); 109 if(ctx->mCopyBit[i]) 110 ctx->mCopyBit[i]->reset(); 111 if(ctx->mLayerRotMap[i]) 112 ctx->mLayerRotMap[i]->reset(); 113 } 114 115 ctx->mAD->reset(); 116} 117 118//clear prev layer prop flags and realloc for current frame 119static void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) { 120 if(ctx->layerProp[dpy]) { 121 delete[] ctx->layerProp[dpy]; 122 ctx->layerProp[dpy] = NULL; 123 } 124 ctx->layerProp[dpy] = new LayerProp[numAppLayers]; 125} 126 127static void handleGeomChange(hwc_context_t *ctx, int dpy, 128 hwc_display_contents_1_t *list) { 129 if(list->flags & HWC_GEOMETRY_CHANGED) { 130 ctx->mOverlay->forceSet(dpy); 131 } 132} 133 134static int display_commit(hwc_context_t *ctx, int dpy) { 135 int fbFd = ctx->dpyAttr[dpy].fd; 136 if(fbFd == -1) { 137 ALOGE("%s: Invalid FB fd for display: %d", __FUNCTION__, dpy); 138 return -1; 139 } 140 141 struct mdp_display_commit commit_info; 142 memset(&commit_info, 0, sizeof(struct mdp_display_commit)); 143 commit_info.flags = MDP_DISPLAY_COMMIT_OVERLAY; 144 if(ioctl(fbFd, MSMFB_DISPLAY_COMMIT, &commit_info) == -1) { 145 ALOGE("%s: MSMFB_DISPLAY_COMMIT for primary failed", __FUNCTION__); 146 return -errno; 147 } 148 return 0; 149} 150 151static int hwc_prepare_primary(hwc_composer_device_1 *dev, 152 hwc_display_contents_1_t *list) { 153 ATRACE_CALL(); 154 hwc_context_t* ctx = (hwc_context_t*)(dev); 155 const int dpy = HWC_DISPLAY_PRIMARY; 156 if (LIKELY(list && list->numHwLayers > 1) && 157 ctx->dpyAttr[dpy].isActive) { 158 reset_layer_prop(ctx, dpy, list->numHwLayers - 1); 159 handleGeomChange(ctx, dpy, list); 160 setListStats(ctx, list, dpy); 161 if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) { 162 const int fbZ = 0; 163 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ); 164 } 165 if (ctx->mMDP.version < qdutils::MDP_V4_0) { 166 if(ctx->mCopyBit[dpy]) 167 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy); 168 } 169 } 170 return 0; 171} 172 173static int hwc_prepare_external(hwc_composer_device_1 *dev, 174 hwc_display_contents_1_t *list) { 175 176 ATRACE_CALL(); 177 hwc_context_t* ctx = (hwc_context_t*)(dev); 178 const int dpy = HWC_DISPLAY_EXTERNAL; 179 180 if (LIKELY(list && list->numHwLayers > 1) && 181 ctx->dpyAttr[dpy].isActive && 182 ctx->dpyAttr[dpy].connected) { 183 reset_layer_prop(ctx, dpy, list->numHwLayers - 1); 184 handleGeomChange(ctx, dpy, list); 185 if(!ctx->dpyAttr[dpy].isPause) { 186 ctx->dpyAttr[dpy].isConfiguring = false; 187 setListStats(ctx, list, dpy); 188 if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) { 189 const int fbZ = 0; 190 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ); 191 } 192 193 /* Temporarily commenting out C2D until we support partial 194 copybit composition for mixed mode MDP 195 196 if((fbZOrder >= 0) && ctx->mCopyBit[dpy]) 197 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy); 198 */ 199 } else { 200 // External Display is in Pause state. 201 // ToDo: 202 // Mark all application layers as OVERLAY so that 203 // GPU will not compose. This is done for power 204 // optimization 205 } 206 } 207 return 0; 208} 209 210static int hwc_prepare_virtual(hwc_composer_device_1 *dev, 211 hwc_display_contents_1_t *list) { 212 ATRACE_CALL(); 213 hwc_context_t* ctx = (hwc_context_t*)(dev); 214 const int dpy = HWC_DISPLAY_VIRTUAL; 215 216 if (list && list->numHwLayers > 1) { 217 reset_layer_prop(ctx, dpy, list->numHwLayers - 1); 218 uint32_t last = list->numHwLayers - 1; 219 hwc_layer_1_t *fbLayer = &list->hwLayers[last]; 220 int fbWidth = 0, fbHeight = 0; 221 getLayerResolution(fbLayer, fbWidth, fbHeight); 222 ctx->dpyAttr[dpy].xres = fbWidth; 223 ctx->dpyAttr[dpy].yres = fbHeight; 224 225 if(ctx->dpyAttr[dpy].connected == false) { 226 ctx->dpyAttr[dpy].connected = true; 227 setupSecondaryObjs(ctx, dpy); 228 } 229 230 ctx->dpyAttr[dpy].fd = Writeback::getInstance()->getFbFd(); 231 Writeback::getInstance()->configureDpyInfo(fbWidth, fbHeight); 232 setListStats(ctx, list, dpy); 233 234 if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) { 235 const int fbZ = 0; 236 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ); 237 } 238 } 239 return 0; 240} 241 242static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays, 243 hwc_display_contents_1_t** displays) 244{ 245 int ret = 0; 246 hwc_context_t* ctx = (hwc_context_t*)(dev); 247 //Will be unlocked at the end of set 248 ctx->mDrawLock.lock(); 249 reset(ctx, numDisplays, displays); 250 251 ctx->mOverlay->configBegin(); 252 ctx->mRotMgr->configBegin(); 253 overlay::Writeback::configBegin(); 254 255 Overlay::setDMAMode(Overlay::DMA_LINE_MODE); 256 257 //Cleanup virtual display objs, since there is no explicit disconnect 258 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected && 259 (numDisplays <= HWC_NUM_PHYSICAL_DISPLAY_TYPES || 260 displays[HWC_DISPLAY_VIRTUAL] == NULL)) { 261 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false; 262 clearSecondaryObjs(ctx, HWC_DISPLAY_VIRTUAL); 263 } 264 265 for (int32_t i = numDisplays - 1; i >= 0; i--) { 266 hwc_display_contents_1_t *list = displays[i]; 267 switch(i) { 268 case HWC_DISPLAY_PRIMARY: 269 ret = hwc_prepare_primary(dev, list); 270 break; 271 case HWC_DISPLAY_EXTERNAL: 272 ret = hwc_prepare_external(dev, list); 273 break; 274 case HWC_DISPLAY_VIRTUAL: 275 ret = hwc_prepare_virtual(dev, list); 276 break; 277 default: 278 ret = -EINVAL; 279 } 280 } 281 282 ctx->mOverlay->configDone(); 283 ctx->mRotMgr->configDone(); 284 overlay::Writeback::configDone(); 285 286 return ret; 287} 288 289static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy, 290 int event, int enable) 291{ 292 ATRACE_CALL(); 293 int ret = 0; 294 hwc_context_t* ctx = (hwc_context_t*)(dev); 295 switch(event) { 296 case HWC_EVENT_VSYNC: 297 if(!ctx->dpyAttr[dpy].isActive) { 298 ALOGE("Display is blanked - Cannot %s vsync", 299 enable ? "enable" : "disable"); 300 return -EINVAL; 301 } 302 303 if (ctx->vstate.enable == enable) 304 break; 305 ret = hwc_vsync_control(ctx, dpy, enable); 306 if(ret == 0) 307 ctx->vstate.enable = !!enable; 308 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s", 309 (enable)?"ENABLED":"DISABLED"); 310 break; 311 default: 312 ret = -EINVAL; 313 } 314 return ret; 315} 316 317static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank) 318{ 319 ATRACE_CALL(); 320 hwc_context_t* ctx = (hwc_context_t*)(dev); 321 322 Locker::Autolock _l(ctx->mDrawLock); 323 int ret = 0; 324 ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__, 325 blank==1 ? "Blanking":"Unblanking", dpy); 326 if(blank) { 327 // free up all the overlay pipes in use 328 // when we get a blank for either display 329 // makes sure that all pipes are freed 330 ctx->mOverlay->configBegin(); 331 ctx->mOverlay->configDone(); 332 ctx->mRotMgr->clear(); 333 overlay::Writeback::clear(); 334 } 335 switch(dpy) { 336 case HWC_DISPLAY_PRIMARY: 337 if(blank) { 338 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, 339 FB_BLANK_POWERDOWN); 340 } else { 341 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_UNBLANK); 342 } 343 break; 344 case HWC_DISPLAY_EXTERNAL: 345 case HWC_DISPLAY_VIRTUAL: 346 if(blank) { 347 // call external framebuffer commit on blank, 348 // so that any pipe unsets gets committed 349 if (display_commit(ctx, dpy) < 0) { 350 ret = -1; 351 ALOGE("%s:post failed for dpy %d", 352 __FUNCTION__, dpy); 353 } 354 } else { 355 } 356 break; 357 default: 358 return -EINVAL; 359 } 360 if(ret == 0){ 361 ctx->dpyAttr[dpy].isActive = !blank; 362 } else { 363 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__, 364 blank==1 ? "blanking":"unblanking", dpy, strerror(errno)); 365 return ret; 366 } 367 368 ALOGD_IF(BLANK_DEBUG, "%s: Done %s display: %d", __FUNCTION__, 369 blank==1 ? "blanking":"unblanking", dpy); 370 return 0; 371} 372 373static int hwc_query(struct hwc_composer_device_1* dev, 374 int param, int* value) 375{ 376 hwc_context_t* ctx = (hwc_context_t*)(dev); 377 int supported = HWC_DISPLAY_PRIMARY_BIT; 378 379 switch (param) { 380 case HWC_BACKGROUND_LAYER_SUPPORTED: 381 // Not supported for now 382 value[0] = 0; 383 break; 384 case HWC_DISPLAY_TYPES_SUPPORTED: //Unused by f/w 385 if(ctx->mMDP.hasOverlay) { 386 supported |= HWC_DISPLAY_VIRTUAL_BIT; 387 if(!qdutils::MDPVersion::getInstance().is8x26()) 388 supported |= HWC_DISPLAY_EXTERNAL_BIT; 389 } 390 value[0] = supported; 391 break; 392 default: 393 return -EINVAL; 394 } 395 return 0; 396 397} 398 399 400static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) { 401 ATRACE_CALL(); 402 int ret = 0; 403 const int dpy = HWC_DISPLAY_PRIMARY; 404 405 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) { 406 uint32_t last = list->numHwLayers - 1; 407 hwc_layer_1_t *fbLayer = &list->hwLayers[last]; 408 int fd = -1; //FenceFD from the Copybit(valid in async mode) 409 bool copybitDone = false; 410 if(ctx->mCopyBit[dpy]) 411 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd); 412 if(list->numHwLayers > 1) 413 hwc_sync(ctx, list, dpy, fd); 414 415 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) { 416 ALOGE("%s: MDPComp draw failed", __FUNCTION__); 417 ret = -1; 418 } 419 420 //TODO We dont check for SKIP flag on this layer because we need PAN 421 //always. Last layer is always FB 422 private_handle_t *hnd = (private_handle_t *)fbLayer->handle; 423 if(copybitDone) { 424 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer(); 425 } 426 427 if(hnd) { 428 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) { 429 ALOGE("%s: FBUpdate draw failed", __FUNCTION__); 430 ret = -1; 431 } 432 } 433 434 if (display_commit(ctx, dpy) < 0) { 435 ALOGE("%s: display commit fail!", __FUNCTION__); 436 ret = -1; 437 } 438 } 439 440 closeAcquireFds(list, dpy); 441 return ret; 442} 443 444static int hwc_set_external(hwc_context_t *ctx, 445 hwc_display_contents_1_t* list) 446{ 447 ATRACE_CALL(); 448 int ret = 0; 449 const int dpy = HWC_DISPLAY_EXTERNAL; 450 451 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive && 452 !ctx->dpyAttr[dpy].isPause && 453 ctx->dpyAttr[dpy].connected) { 454 uint32_t last = list->numHwLayers - 1; 455 hwc_layer_1_t *fbLayer = &list->hwLayers[last]; 456 int fd = -1; //FenceFD from the Copybit(valid in async mode) 457 bool copybitDone = false; 458 if(ctx->mCopyBit[dpy]) 459 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd); 460 461 if(list->numHwLayers > 1) 462 hwc_sync(ctx, list, dpy, fd); 463 464 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) { 465 ALOGE("%s: MDPComp draw failed", __FUNCTION__); 466 ret = -1; 467 } 468 469 private_handle_t *hnd = (private_handle_t *)fbLayer->handle; 470 if(copybitDone) { 471 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer(); 472 } 473 474 if(hnd) { 475 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) { 476 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__); 477 ret = -1; 478 } 479 } 480 481 if (display_commit(ctx, dpy) < 0) { 482 ALOGE("%s: display commit fail!", __FUNCTION__); 483 ret = -1; 484 } 485 } 486 487 closeAcquireFds(list, dpy); 488 return ret; 489} 490 491static int hwc_set_virtual(hwc_context_t *ctx, 492 hwc_display_contents_1_t* list) { 493 ATRACE_CALL(); 494 int ret = 0; 495 const int dpy = HWC_DISPLAY_VIRTUAL; 496 497 if (list && list->outbuf && list->numHwLayers > 1) { 498 uint32_t last = list->numHwLayers - 1; 499 hwc_layer_1_t *fbLayer = &list->hwLayers[last]; 500 501 if(fbLayer->handle && ctx->dpyAttr[dpy].connected 502#ifndef FORCE_HWC_FOR_VIRTUAL_DISPLAYS 503 //XXX: If we're not forcing virtual via HWC, 504 //full GLES compositions will not be routed through here. 505 && !isGLESOnlyComp(ctx, dpy) 506#endif 507 ) { 508 509 private_handle_t *ohnd = (private_handle_t *)list->outbuf; 510 Writeback::getInstance()->setOutputFormat( 511 utils::getMdpFormat(ohnd->format)); 512 513 int fd = -1; //FenceFD from the Copybit 514 hwc_sync(ctx, list, dpy, fd); 515 516 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) { 517 ALOGE("%s: MDPComp draw failed", __FUNCTION__); 518 ret = -1; 519 } 520 521 if (!ctx->mFBUpdate[dpy]->draw(ctx, 522 (private_handle_t *)fbLayer->handle)) { 523 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__); 524 ret = -1; 525 } 526 527 Writeback::getInstance()->queueBuffer(ohnd->fd, ohnd->offset); 528 if (display_commit(ctx, dpy) < 0) { 529 ALOGE("%s: display commit fail!", __FUNCTION__); 530 ret = -1; 531 } 532 } else if(list->outbufAcquireFenceFd >= 0) { 533 //If we dont handle the frame, set retireFenceFd to outbufFenceFd, 534 //which will make sure, the framework waits on it and closes it. 535 //The other way is to wait on outbufFenceFd ourselves, close it and 536 //set retireFenceFd to -1. Since we want hwc to be async, choosing 537 //the former. 538 //Also dup because, the closeAcquireFds() will close the outbufFence 539 list->retireFenceFd = dup(list->outbufAcquireFenceFd); 540 } 541 } 542 543 closeAcquireFds(list, dpy); 544 return ret; 545} 546 547 548static int hwc_set(hwc_composer_device_1 *dev, 549 size_t numDisplays, 550 hwc_display_contents_1_t** displays) 551{ 552 int ret = 0; 553 hwc_context_t* ctx = (hwc_context_t*)(dev); 554 for (uint32_t i = 0; i < numDisplays; i++) { 555 hwc_display_contents_1_t* list = displays[i]; 556 switch(i) { 557 case HWC_DISPLAY_PRIMARY: 558 ret = hwc_set_primary(ctx, list); 559 break; 560 case HWC_DISPLAY_EXTERNAL: 561 ret = hwc_set_external(ctx, list); 562 break; 563 case HWC_DISPLAY_VIRTUAL: 564 ret = hwc_set_virtual(ctx, list); 565 break; 566 default: 567 ret = -EINVAL; 568 } 569 } 570 // This is only indicative of how many times SurfaceFlinger posts 571 // frames to the display. 572 CALC_FPS(); 573 MDPComp::resetIdleFallBack(); 574 ctx->mVideoTransFlag = false; 575 //Was locked at the beginning of prepare 576 ctx->mDrawLock.unlock(); 577 return ret; 578} 579 580int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp, 581 uint32_t* configs, size_t* numConfigs) { 582 int ret = 0; 583 hwc_context_t* ctx = (hwc_context_t*)(dev); 584 //in 1.1 there is no way to choose a config, report as config id # 0 585 //This config is passed to getDisplayAttributes. Ignore for now. 586 switch(disp) { 587 case HWC_DISPLAY_PRIMARY: 588 if(*numConfigs > 0) { 589 configs[0] = 0; 590 *numConfigs = 1; 591 } 592 ret = 0; //NO_ERROR 593 break; 594 case HWC_DISPLAY_EXTERNAL: 595 ret = -1; //Not connected 596 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) { 597 ret = 0; //NO_ERROR 598 if(*numConfigs > 0) { 599 configs[0] = 0; 600 *numConfigs = 1; 601 } 602 } 603 break; 604 } 605 return ret; 606} 607 608int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp, 609 uint32_t config, const uint32_t* attributes, int32_t* values) { 610 611 hwc_context_t* ctx = (hwc_context_t*)(dev); 612 //If hotpluggable displays are inactive return error 613 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) { 614 return -1; 615 } 616 617 //From HWComposer 618 static const uint32_t DISPLAY_ATTRIBUTES[] = { 619 HWC_DISPLAY_VSYNC_PERIOD, 620 HWC_DISPLAY_WIDTH, 621 HWC_DISPLAY_HEIGHT, 622 HWC_DISPLAY_DPI_X, 623 HWC_DISPLAY_DPI_Y, 624 HWC_DISPLAY_NO_ATTRIBUTE, 625 }; 626 627 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) / 628 sizeof(DISPLAY_ATTRIBUTES)[0]); 629 630 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) { 631 switch (attributes[i]) { 632 case HWC_DISPLAY_VSYNC_PERIOD: 633 values[i] = ctx->dpyAttr[disp].vsync_period; 634 break; 635 case HWC_DISPLAY_WIDTH: 636 values[i] = ctx->dpyAttr[disp].xres; 637 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp, 638 ctx->dpyAttr[disp].xres); 639 break; 640 case HWC_DISPLAY_HEIGHT: 641 values[i] = ctx->dpyAttr[disp].yres; 642 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp, 643 ctx->dpyAttr[disp].yres); 644 break; 645 case HWC_DISPLAY_DPI_X: 646 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0); 647 break; 648 case HWC_DISPLAY_DPI_Y: 649 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0); 650 break; 651 default: 652 ALOGE("Unknown display attribute %d", 653 attributes[i]); 654 return -EINVAL; 655 } 656 } 657 return 0; 658} 659 660void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len) 661{ 662 hwc_context_t* ctx = (hwc_context_t*)(dev); 663 Locker::Autolock _l(ctx->mDrawLock); 664 android::String8 aBuf(""); 665 dumpsys_log(aBuf, "Qualcomm HWC state:\n"); 666 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version); 667 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel); 668 for(int dpy = 0; dpy < MAX_DISPLAYS; dpy++) { 669 if(ctx->mMDPComp[dpy]) 670 ctx->mMDPComp[dpy]->dump(aBuf); 671 } 672 char ovDump[2048] = {'\0'}; 673 ctx->mOverlay->getDump(ovDump, 2048); 674 dumpsys_log(aBuf, ovDump); 675 ovDump[0] = '\0'; 676 ctx->mRotMgr->getDump(ovDump, 1024); 677 dumpsys_log(aBuf, ovDump); 678 ovDump[0] = '\0'; 679 Writeback::getInstance()->getDump(ovDump, 1024); 680 dumpsys_log(aBuf, ovDump); 681 strlcpy(buff, aBuf.string(), buff_len); 682} 683 684static int hwc_device_close(struct hw_device_t *dev) 685{ 686 if(!dev) { 687 ALOGE("%s: NULL device pointer", __FUNCTION__); 688 return -1; 689 } 690 closeContext((hwc_context_t*)dev); 691 free(dev); 692 693 return 0; 694} 695 696static int hwc_device_open(const struct hw_module_t* module, const char* name, 697 struct hw_device_t** device) 698{ 699 int status = -EINVAL; 700 701 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) { 702 struct hwc_context_t *dev; 703 dev = (hwc_context_t*)malloc(sizeof(*dev)); 704 memset(dev, 0, sizeof(*dev)); 705 706 //Initialize hwc context 707 initContext(dev); 708 709 //Setup HWC methods 710 dev->device.common.tag = HARDWARE_DEVICE_TAG; 711 dev->device.common.version = HWC_DEVICE_API_VERSION_1_3; 712 dev->device.common.module = const_cast<hw_module_t*>(module); 713 dev->device.common.close = hwc_device_close; 714 dev->device.prepare = hwc_prepare; 715 dev->device.set = hwc_set; 716 dev->device.eventControl = hwc_eventControl; 717 dev->device.blank = hwc_blank; 718 dev->device.query = hwc_query; 719 dev->device.registerProcs = hwc_registerProcs; 720 dev->device.dump = hwc_dump; 721 dev->device.getDisplayConfigs = hwc_getDisplayConfigs; 722 dev->device.getDisplayAttributes = hwc_getDisplayAttributes; 723 *device = &dev->device.common; 724 status = 0; 725 } 726 return status; 727} 728