hwc.cpp revision 8f1c93c4d5c2feb515cde2a6ecc2309188002cbe
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->outbuf && 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 private_handle_t *ohnd = (private_handle_t *)list->outbuf; 232 Writeback::getInstance()->configureDpyInfo(ohnd->width, ohnd->height); 233 setListStats(ctx, list, dpy); 234 235 if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) { 236 const int fbZ = 0; 237 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ); 238 } 239 } 240 return 0; 241} 242 243static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays, 244 hwc_display_contents_1_t** displays) 245{ 246 int ret = 0; 247 hwc_context_t* ctx = (hwc_context_t*)(dev); 248 //Will be unlocked at the end of set 249 ctx->mDrawLock.lock(); 250 reset(ctx, numDisplays, displays); 251 252 ctx->mOverlay->configBegin(); 253 ctx->mRotMgr->configBegin(); 254 overlay::Writeback::configBegin(); 255 256 Overlay::setDMAMode(Overlay::DMA_LINE_MODE); 257 258 //Cleanup virtual display objs, since there is no explicit disconnect 259 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected && 260 (numDisplays <= HWC_NUM_PHYSICAL_DISPLAY_TYPES || 261 displays[HWC_DISPLAY_VIRTUAL] == NULL)) { 262 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false; 263 clearSecondaryObjs(ctx, HWC_DISPLAY_VIRTUAL); 264 } 265 266 for (int32_t i = numDisplays - 1; i >= 0; i--) { 267 hwc_display_contents_1_t *list = displays[i]; 268 switch(i) { 269 case HWC_DISPLAY_PRIMARY: 270 ret = hwc_prepare_primary(dev, list); 271 break; 272 case HWC_DISPLAY_EXTERNAL: 273 ret = hwc_prepare_external(dev, list); 274 break; 275 case HWC_DISPLAY_VIRTUAL: 276 ret = hwc_prepare_virtual(dev, list); 277 break; 278 default: 279 ret = -EINVAL; 280 } 281 } 282 283 ctx->mOverlay->configDone(); 284 ctx->mRotMgr->configDone(); 285 overlay::Writeback::configDone(); 286 287 return ret; 288} 289 290static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy, 291 int event, int enable) 292{ 293 ATRACE_CALL(); 294 int ret = 0; 295 hwc_context_t* ctx = (hwc_context_t*)(dev); 296 switch(event) { 297 case HWC_EVENT_VSYNC: 298 if(!ctx->dpyAttr[dpy].isActive) { 299 ALOGE("Display is blanked - Cannot %s vsync", 300 enable ? "enable" : "disable"); 301 return -EINVAL; 302 } 303 304 if (ctx->vstate.enable == enable) 305 break; 306 ret = hwc_vsync_control(ctx, dpy, enable); 307 if(ret == 0) 308 ctx->vstate.enable = !!enable; 309 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s", 310 (enable)?"ENABLED":"DISABLED"); 311 break; 312 default: 313 ret = -EINVAL; 314 } 315 return ret; 316} 317 318static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank) 319{ 320 ATRACE_CALL(); 321 hwc_context_t* ctx = (hwc_context_t*)(dev); 322 323 Locker::Autolock _l(ctx->mDrawLock); 324 int ret = 0; 325 ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__, 326 blank==1 ? "Blanking":"Unblanking", dpy); 327 if(blank) { 328 // free up all the overlay pipes in use 329 // when we get a blank for either display 330 // makes sure that all pipes are freed 331 ctx->mOverlay->configBegin(); 332 ctx->mOverlay->configDone(); 333 ctx->mRotMgr->clear(); 334 overlay::Writeback::clear(); 335 } 336 switch(dpy) { 337 case HWC_DISPLAY_PRIMARY: 338 if(blank) { 339 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, 340 FB_BLANK_POWERDOWN); 341 } else { 342 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_UNBLANK); 343 } 344 break; 345 case HWC_DISPLAY_EXTERNAL: 346 case HWC_DISPLAY_VIRTUAL: 347 if(blank) { 348 // call external framebuffer commit on blank, 349 // so that any pipe unsets gets committed 350 if (display_commit(ctx, dpy) < 0) { 351 ret = -1; 352 ALOGE("%s:post failed for dpy %d", 353 __FUNCTION__, dpy); 354 } 355 } else { 356 } 357 break; 358 default: 359 return -EINVAL; 360 } 361 if(ret == 0){ 362 ctx->dpyAttr[dpy].isActive = !blank; 363 } else { 364 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__, 365 blank==1 ? "blanking":"unblanking", dpy, strerror(errno)); 366 return ret; 367 } 368 369 ALOGD_IF(BLANK_DEBUG, "%s: Done %s display: %d", __FUNCTION__, 370 blank==1 ? "blanking":"unblanking", dpy); 371 return 0; 372} 373 374static int hwc_query(struct hwc_composer_device_1* dev, 375 int param, int* value) 376{ 377 hwc_context_t* ctx = (hwc_context_t*)(dev); 378 int supported = HWC_DISPLAY_PRIMARY_BIT; 379 380 switch (param) { 381 case HWC_BACKGROUND_LAYER_SUPPORTED: 382 // Not supported for now 383 value[0] = 0; 384 break; 385 case HWC_DISPLAY_TYPES_SUPPORTED: //Unused by f/w 386 if(ctx->mMDP.hasOverlay) { 387 supported |= HWC_DISPLAY_VIRTUAL_BIT; 388 if(!qdutils::MDPVersion::getInstance().is8x26()) 389 supported |= HWC_DISPLAY_EXTERNAL_BIT; 390 } 391 value[0] = supported; 392 break; 393 default: 394 return -EINVAL; 395 } 396 return 0; 397 398} 399 400 401static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) { 402 ATRACE_CALL(); 403 int ret = 0; 404 const int dpy = HWC_DISPLAY_PRIMARY; 405 406 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) { 407 uint32_t last = list->numHwLayers - 1; 408 hwc_layer_1_t *fbLayer = &list->hwLayers[last]; 409 int fd = -1; //FenceFD from the Copybit(valid in async mode) 410 bool copybitDone = false; 411 if(ctx->mCopyBit[dpy]) 412 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd); 413 if(list->numHwLayers > 1) 414 hwc_sync(ctx, list, dpy, fd); 415 416 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) { 417 ALOGE("%s: MDPComp draw failed", __FUNCTION__); 418 ret = -1; 419 } 420 421 //TODO We dont check for SKIP flag on this layer because we need PAN 422 //always. Last layer is always FB 423 private_handle_t *hnd = (private_handle_t *)fbLayer->handle; 424 if(copybitDone) { 425 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer(); 426 } 427 428 if(hnd) { 429 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) { 430 ALOGE("%s: FBUpdate draw failed", __FUNCTION__); 431 ret = -1; 432 } 433 } 434 435 if (display_commit(ctx, dpy) < 0) { 436 ALOGE("%s: display commit fail!", __FUNCTION__); 437 ret = -1; 438 } 439 } 440 441 closeAcquireFds(list, dpy); 442 return ret; 443} 444 445static int hwc_set_external(hwc_context_t *ctx, 446 hwc_display_contents_1_t* list) 447{ 448 ATRACE_CALL(); 449 int ret = 0; 450 const int dpy = HWC_DISPLAY_EXTERNAL; 451 452 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive && 453 !ctx->dpyAttr[dpy].isPause && 454 ctx->dpyAttr[dpy].connected) { 455 uint32_t last = list->numHwLayers - 1; 456 hwc_layer_1_t *fbLayer = &list->hwLayers[last]; 457 int fd = -1; //FenceFD from the Copybit(valid in async mode) 458 bool copybitDone = false; 459 if(ctx->mCopyBit[dpy]) 460 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd); 461 462 if(list->numHwLayers > 1) 463 hwc_sync(ctx, list, dpy, fd); 464 465 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) { 466 ALOGE("%s: MDPComp draw failed", __FUNCTION__); 467 ret = -1; 468 } 469 470 private_handle_t *hnd = (private_handle_t *)fbLayer->handle; 471 if(copybitDone) { 472 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer(); 473 } 474 475 if(hnd) { 476 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) { 477 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__); 478 ret = -1; 479 } 480 } 481 482 if (display_commit(ctx, dpy) < 0) { 483 ALOGE("%s: display commit fail!", __FUNCTION__); 484 ret = -1; 485 } 486 } 487 488 closeAcquireFds(list, dpy); 489 return ret; 490} 491 492static int hwc_set_virtual(hwc_context_t *ctx, 493 hwc_display_contents_1_t* list) { 494 ATRACE_CALL(); 495 int ret = 0; 496 const int dpy = HWC_DISPLAY_VIRTUAL; 497 498 if (list && list->outbuf && list->numHwLayers > 1) { 499 uint32_t last = list->numHwLayers - 1; 500 hwc_layer_1_t *fbLayer = &list->hwLayers[last]; 501 502 if(fbLayer->handle && ctx->dpyAttr[dpy].connected 503#ifndef FORCE_HWC_FOR_VIRTUAL_DISPLAYS 504 //XXX: If we're not forcing virtual via HWC, 505 //full GLES compositions will not be routed through here. 506 && !isGLESOnlyComp(ctx, dpy) 507#endif 508 ) { 509 510 private_handle_t *ohnd = (private_handle_t *)list->outbuf; 511 Writeback::getInstance()->setOutputFormat( 512 utils::getMdpFormat(ohnd->format)); 513 514 int fd = -1; //FenceFD from the Copybit 515 hwc_sync(ctx, list, dpy, fd); 516 517 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) { 518 ALOGE("%s: MDPComp draw failed", __FUNCTION__); 519 ret = -1; 520 } 521 522 if (!ctx->mFBUpdate[dpy]->draw(ctx, 523 (private_handle_t *)fbLayer->handle)) { 524 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__); 525 ret = -1; 526 } 527 528 Writeback::getInstance()->queueBuffer(ohnd->fd, ohnd->offset); 529 if (display_commit(ctx, dpy) < 0) { 530 ALOGE("%s: display commit fail!", __FUNCTION__); 531 ret = -1; 532 } 533 } else if(list->outbufAcquireFenceFd >= 0) { 534 //If we dont handle the frame, set retireFenceFd to outbufFenceFd, 535 //which will make sure, the framework waits on it and closes it. 536 //The other way is to wait on outbufFenceFd ourselves, close it and 537 //set retireFenceFd to -1. Since we want hwc to be async, choosing 538 //the former. 539 //Also dup because, the closeAcquireFds() will close the outbufFence 540 list->retireFenceFd = dup(list->outbufAcquireFenceFd); 541 } 542 } 543 544 closeAcquireFds(list, dpy); 545 return ret; 546} 547 548 549static int hwc_set(hwc_composer_device_1 *dev, 550 size_t numDisplays, 551 hwc_display_contents_1_t** displays) 552{ 553 int ret = 0; 554 hwc_context_t* ctx = (hwc_context_t*)(dev); 555 for (uint32_t i = 0; i < numDisplays; i++) { 556 hwc_display_contents_1_t* list = displays[i]; 557 switch(i) { 558 case HWC_DISPLAY_PRIMARY: 559 ret = hwc_set_primary(ctx, list); 560 break; 561 case HWC_DISPLAY_EXTERNAL: 562 ret = hwc_set_external(ctx, list); 563 break; 564 case HWC_DISPLAY_VIRTUAL: 565 ret = hwc_set_virtual(ctx, list); 566 break; 567 default: 568 ret = -EINVAL; 569 } 570 } 571 // This is only indicative of how many times SurfaceFlinger posts 572 // frames to the display. 573 CALC_FPS(); 574 MDPComp::resetIdleFallBack(); 575 ctx->mVideoTransFlag = false; 576 //Was locked at the beginning of prepare 577 ctx->mDrawLock.unlock(); 578 return ret; 579} 580 581int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp, 582 uint32_t* configs, size_t* numConfigs) { 583 int ret = 0; 584 hwc_context_t* ctx = (hwc_context_t*)(dev); 585 //in 1.1 there is no way to choose a config, report as config id # 0 586 //This config is passed to getDisplayAttributes. Ignore for now. 587 switch(disp) { 588 case HWC_DISPLAY_PRIMARY: 589 if(*numConfigs > 0) { 590 configs[0] = 0; 591 *numConfigs = 1; 592 } 593 ret = 0; //NO_ERROR 594 break; 595 case HWC_DISPLAY_EXTERNAL: 596 ret = -1; //Not connected 597 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) { 598 ret = 0; //NO_ERROR 599 if(*numConfigs > 0) { 600 configs[0] = 0; 601 *numConfigs = 1; 602 } 603 } 604 break; 605 } 606 return ret; 607} 608 609int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp, 610 uint32_t config, const uint32_t* attributes, int32_t* values) { 611 612 hwc_context_t* ctx = (hwc_context_t*)(dev); 613 //If hotpluggable displays are inactive return error 614 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) { 615 return -1; 616 } 617 618 //From HWComposer 619 static const uint32_t DISPLAY_ATTRIBUTES[] = { 620 HWC_DISPLAY_VSYNC_PERIOD, 621 HWC_DISPLAY_WIDTH, 622 HWC_DISPLAY_HEIGHT, 623 HWC_DISPLAY_DPI_X, 624 HWC_DISPLAY_DPI_Y, 625 HWC_DISPLAY_NO_ATTRIBUTE, 626 }; 627 628 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) / 629 sizeof(DISPLAY_ATTRIBUTES)[0]); 630 631 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) { 632 switch (attributes[i]) { 633 case HWC_DISPLAY_VSYNC_PERIOD: 634 values[i] = ctx->dpyAttr[disp].vsync_period; 635 break; 636 case HWC_DISPLAY_WIDTH: 637 values[i] = ctx->dpyAttr[disp].xres; 638 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp, 639 ctx->dpyAttr[disp].xres); 640 break; 641 case HWC_DISPLAY_HEIGHT: 642 values[i] = ctx->dpyAttr[disp].yres; 643 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp, 644 ctx->dpyAttr[disp].yres); 645 break; 646 case HWC_DISPLAY_DPI_X: 647 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0); 648 break; 649 case HWC_DISPLAY_DPI_Y: 650 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0); 651 break; 652 default: 653 ALOGE("Unknown display attribute %d", 654 attributes[i]); 655 return -EINVAL; 656 } 657 } 658 return 0; 659} 660 661void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len) 662{ 663 hwc_context_t* ctx = (hwc_context_t*)(dev); 664 Locker::Autolock _l(ctx->mDrawLock); 665 android::String8 aBuf(""); 666 dumpsys_log(aBuf, "Qualcomm HWC state:\n"); 667 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version); 668 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel); 669 for(int dpy = 0; dpy < MAX_DISPLAYS; dpy++) { 670 if(ctx->mMDPComp[dpy]) 671 ctx->mMDPComp[dpy]->dump(aBuf); 672 } 673 char ovDump[2048] = {'\0'}; 674 ctx->mOverlay->getDump(ovDump, 2048); 675 dumpsys_log(aBuf, ovDump); 676 ovDump[0] = '\0'; 677 ctx->mRotMgr->getDump(ovDump, 1024); 678 dumpsys_log(aBuf, ovDump); 679 ovDump[0] = '\0'; 680 Writeback::getInstance()->getDump(ovDump, 1024); 681 dumpsys_log(aBuf, ovDump); 682 strlcpy(buff, aBuf.string(), buff_len); 683} 684 685static int hwc_device_close(struct hw_device_t *dev) 686{ 687 if(!dev) { 688 ALOGE("%s: NULL device pointer", __FUNCTION__); 689 return -1; 690 } 691 closeContext((hwc_context_t*)dev); 692 free(dev); 693 694 return 0; 695} 696 697static int hwc_device_open(const struct hw_module_t* module, const char* name, 698 struct hw_device_t** device) 699{ 700 int status = -EINVAL; 701 702 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) { 703 struct hwc_context_t *dev; 704 dev = (hwc_context_t*)malloc(sizeof(*dev)); 705 memset(dev, 0, sizeof(*dev)); 706 707 //Initialize hwc context 708 initContext(dev); 709 710 //Setup HWC methods 711 dev->device.common.tag = HARDWARE_DEVICE_TAG; 712 dev->device.common.version = HWC_DEVICE_API_VERSION_1_3; 713 dev->device.common.module = const_cast<hw_module_t*>(module); 714 dev->device.common.close = hwc_device_close; 715 dev->device.prepare = hwc_prepare; 716 dev->device.set = hwc_set; 717 dev->device.eventControl = hwc_eventControl; 718 dev->device.blank = hwc_blank; 719 dev->device.query = hwc_query; 720 dev->device.registerProcs = hwc_registerProcs; 721 dev->device.dump = hwc_dump; 722 dev->device.getDisplayConfigs = hwc_getDisplayConfigs; 723 dev->device.getDisplayAttributes = hwc_getDisplayAttributes; 724 *device = &dev->device.common; 725 status = 0; 726 } 727 return status; 728} 729