Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation. nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | |
| 31 | #define DEBUG 0 |
| 32 | #include <ctype.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <media/IAudioPolicyService.h> |
| 35 | #include <media/AudioSystem.h> |
| 36 | #include <utils/threads.h> |
| 37 | #include <utils/Errors.h> |
| 38 | #include <utils/Log.h> |
| 39 | |
| 40 | #include <linux/msm_mdp.h> |
| 41 | #include <linux/fb.h> |
| 42 | #include <sys/ioctl.h> |
| 43 | #include <sys/poll.h> |
| 44 | #include <sys/resource.h> |
| 45 | #include <cutils/properties.h> |
| 46 | #include "hwc_utils.h" |
| 47 | #include "virtual.h" |
| 48 | #include "overlayUtils.h" |
| 49 | #include "overlay.h" |
Amara Venkata Mastan Manoj Kumar | 1291675 | 2013-03-13 19:18:47 -0700 | [diff] [blame^] | 50 | #include "mdp_version.h" |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 51 | |
| 52 | using namespace android; |
| 53 | |
| 54 | namespace qhwc { |
| 55 | |
| 56 | #define MAX_SYSFS_FILE_PATH 255 |
| 57 | |
| 58 | int VirtualDisplay::configure() { |
| 59 | if(!openFrameBuffer()) |
| 60 | return -1; |
| 61 | |
| 62 | if(ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo) < 0) { |
| 63 | ALOGD("%s: FBIOGET_VSCREENINFO failed with %s", __FUNCTION__, |
| 64 | strerror(errno)); |
| 65 | return -1; |
| 66 | } |
| 67 | setAttributes(); |
| 68 | return 0; |
| 69 | } |
| 70 | |
Amara Venkata Mastan Manoj Kumar | 1291675 | 2013-03-13 19:18:47 -0700 | [diff] [blame^] | 71 | void VirtualDisplay::getAttributes(int& width, int& height) { |
| 72 | width = mVInfo.xres; |
| 73 | height = mVInfo.yres; |
| 74 | } |
| 75 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 76 | int VirtualDisplay::teardown() { |
| 77 | closeFrameBuffer(); |
| 78 | memset(&mVInfo, 0, sizeof(mVInfo)); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | VirtualDisplay::VirtualDisplay(hwc_context_t* ctx):mFd(-1), |
| 83 | mHwcContext(ctx) |
| 84 | { |
| 85 | memset(&mVInfo, 0, sizeof(mVInfo)); |
| 86 | } |
| 87 | |
| 88 | VirtualDisplay::~VirtualDisplay() |
| 89 | { |
| 90 | closeFrameBuffer(); |
| 91 | } |
| 92 | |
| 93 | void VirtualDisplay::setAttributes() { |
Amara Venkata Mastan Manoj Kumar | 1291675 | 2013-03-13 19:18:47 -0700 | [diff] [blame^] | 94 | if(mHwcContext) { |
| 95 | // Always set dpyAttr res to mVInfo res |
| 96 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].xres = mVInfo.xres; |
| 97 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].yres = mVInfo.yres; |
| 98 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].mDownScaleMode = false; |
| 99 | if(!qdutils::MDPVersion::getInstance().is8x26()) { |
| 100 | uint32_t priW = mHwcContext->dpyAttr[HWC_DISPLAY_PRIMARY].xres; |
| 101 | uint32_t priH = mHwcContext->dpyAttr[HWC_DISPLAY_PRIMARY].yres; |
| 102 | // if primary resolution is more than the wfd resolution |
| 103 | // configure dpy attr to primary resolution and set |
| 104 | // downscale mode |
| 105 | if((priW * priH) > (mVInfo.xres * mVInfo.yres)) { |
| 106 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].xres = priW; |
| 107 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].yres = priH; |
| 108 | // WFD is always in landscape, so always assign the higher |
| 109 | // dimension to wfd's xres |
| 110 | if(priH > priW) { |
| 111 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].xres = priH; |
| 112 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].yres = priW; |
| 113 | } |
| 114 | // Set External Display MDP Downscale mode indicator |
| 115 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].mDownScaleMode = true; |
| 116 | } |
| 117 | } |
| 118 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].vsync_period = |
| 119 | 1000000000l /60; |
| 120 | ALOGD_IF(DEBUG,"%s: Setting Virtual Attr: res(%d x %d)",__FUNCTION__, |
| 121 | mVInfo.xres, mVInfo.yres); |
| 122 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | bool VirtualDisplay::openFrameBuffer() |
| 126 | { |
| 127 | if (mFd == -1) { |
| 128 | int fbNum = overlay::Overlay::getInstance()-> |
| 129 | getFbForDpy(HWC_DISPLAY_VIRTUAL); |
| 130 | |
| 131 | char strDevPath[MAX_SYSFS_FILE_PATH]; |
| 132 | sprintf(strDevPath,"/dev/graphics/fb%d", fbNum); |
| 133 | |
| 134 | mFd = open(strDevPath, O_RDWR); |
| 135 | if(mFd < 0) { |
| 136 | ALOGE("%s: Unable to open %s ", __FUNCTION__,strDevPath); |
| 137 | return -1; |
| 138 | } |
| 139 | |
| 140 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].fd = mFd; |
| 141 | } |
| 142 | return 1; |
| 143 | } |
| 144 | |
| 145 | bool VirtualDisplay::closeFrameBuffer() |
| 146 | { |
| 147 | if(mFd >= 0) { |
| 148 | if(close(mFd) < 0 ) { |
| 149 | ALOGE("%s: Unable to close FD(%d)", __FUNCTION__, mFd); |
| 150 | return -1; |
| 151 | } |
| 152 | mFd = -1; |
| 153 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].fd = mFd; |
| 154 | } |
| 155 | return 1; |
| 156 | } |
| 157 | }; |