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" |
| 50 | |
| 51 | using namespace android; |
| 52 | |
| 53 | namespace qhwc { |
| 54 | |
| 55 | #define MAX_SYSFS_FILE_PATH 255 |
| 56 | |
| 57 | int VirtualDisplay::configure() { |
| 58 | if(!openFrameBuffer()) |
| 59 | return -1; |
| 60 | |
| 61 | if(ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo) < 0) { |
| 62 | ALOGD("%s: FBIOGET_VSCREENINFO failed with %s", __FUNCTION__, |
| 63 | strerror(errno)); |
| 64 | return -1; |
| 65 | } |
| 66 | setAttributes(); |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | int VirtualDisplay::teardown() { |
| 71 | closeFrameBuffer(); |
| 72 | memset(&mVInfo, 0, sizeof(mVInfo)); |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | VirtualDisplay::VirtualDisplay(hwc_context_t* ctx):mFd(-1), |
| 77 | mHwcContext(ctx) |
| 78 | { |
| 79 | memset(&mVInfo, 0, sizeof(mVInfo)); |
| 80 | } |
| 81 | |
| 82 | VirtualDisplay::~VirtualDisplay() |
| 83 | { |
| 84 | closeFrameBuffer(); |
| 85 | } |
| 86 | |
| 87 | void VirtualDisplay::setAttributes() { |
| 88 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].xres = mVInfo.xres; |
| 89 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].yres = mVInfo.yres; |
| 90 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].vsync_period = |
| 91 | 1000000000l /60; |
| 92 | ALOGD_IF(DEBUG,"%s: Setting Virtual Attr: res(%d x %d)",__FUNCTION__, |
| 93 | mVInfo.xres, mVInfo.yres); |
| 94 | } |
| 95 | |
| 96 | bool VirtualDisplay::openFrameBuffer() |
| 97 | { |
| 98 | if (mFd == -1) { |
| 99 | int fbNum = overlay::Overlay::getInstance()-> |
| 100 | getFbForDpy(HWC_DISPLAY_VIRTUAL); |
| 101 | |
| 102 | char strDevPath[MAX_SYSFS_FILE_PATH]; |
| 103 | sprintf(strDevPath,"/dev/graphics/fb%d", fbNum); |
| 104 | |
| 105 | mFd = open(strDevPath, O_RDWR); |
| 106 | if(mFd < 0) { |
| 107 | ALOGE("%s: Unable to open %s ", __FUNCTION__,strDevPath); |
| 108 | return -1; |
| 109 | } |
| 110 | |
| 111 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].fd = mFd; |
| 112 | } |
| 113 | return 1; |
| 114 | } |
| 115 | |
| 116 | bool VirtualDisplay::closeFrameBuffer() |
| 117 | { |
| 118 | if(mFd >= 0) { |
| 119 | if(close(mFd) < 0 ) { |
| 120 | ALOGE("%s: Unable to close FD(%d)", __FUNCTION__, mFd); |
| 121 | return -1; |
| 122 | } |
| 123 | mFd = -1; |
| 124 | mHwcContext->dpyAttr[HWC_DISPLAY_VIRTUAL].fd = mFd; |
| 125 | } |
| 126 | return 1; |
| 127 | } |
| 128 | }; |