Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 3 | * Copyright (c) 2010-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 <cutils/properties.h> |
| 19 | #include "overlayCtrlData.h" |
| 20 | #include "fb_priv.h" |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 21 | #include "gralloc_priv.h" //for interlace |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 22 | |
| 23 | namespace overlay{ |
| 24 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 25 | bool Ctrl::init(uint32_t fbnum) { |
| 26 | // MDP/FD init |
| 27 | if(!mMdp.init(fbnum)) { |
| 28 | ALOGE("Ctrl failed to init fbnum=%d", fbnum); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 29 | return false; |
| 30 | } |
| 31 | |
| 32 | if(!getScreenInfo(mInfo)) { |
| 33 | ALOGE("Ctrl failed to getScreenInfo"); |
| 34 | return false; |
| 35 | } |
| 36 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 37 | return true; |
| 38 | } |
| 39 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 40 | bool Ctrl::setSource(const utils::PipeArgs& args) |
| 41 | { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 42 | return mMdp.setSource(args); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | bool Ctrl::setPosition(const utils::Dim& dim) |
| 46 | { |
| 47 | if(!dim.check(mInfo.mFBWidth, mInfo.mFBHeight)) { |
| 48 | ALOGE("Ctrl setPosition error in dim"); |
| 49 | dim.dump(); |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | if(!mMdp.setPosition(dim, mInfo.mFBWidth, mInfo.mFBHeight)) { |
| 54 | ALOGE("Ctrl failed MDP setPosition"); |
| 55 | return false; |
| 56 | } |
| 57 | return true; |
| 58 | } |
| 59 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 60 | bool Ctrl::setTransform(const utils::eTransform& orient, const bool& rotUsed) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 61 | { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 62 | if(!mMdp.setTransform(orient, rotUsed)) { |
| 63 | ALOGE("Ctrl setTransform failed for Mdp"); |
| 64 | return false; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 65 | } |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | bool Ctrl::setCrop(const utils::Dim& d) |
| 70 | { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 71 | if(!mMdp.setCrop(d)) { |
| 72 | ALOGE("Data setCrop failed in MDP setCrop"); |
| 73 | return false; |
| 74 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 75 | return true; |
| 76 | } |
| 77 | |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 78 | utils::ActionSafe* utils::ActionSafe::sActionSafe = NULL; |
| 79 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 80 | utils::Dim Ctrl::getAspectRatio(const utils::Whf& whf) const |
| 81 | { |
| 82 | utils::Whf inWhf(whf.w, whf.h, mMdp.getSrcWhf().format); |
| 83 | utils::Whf tmpwhf(inWhf); |
| 84 | uint32_t fbWidth = mInfo.mFBWidth; |
| 85 | uint32_t fbHeight = mInfo.mFBHeight; |
| 86 | |
| 87 | /* Calculate the width and height if it is YUV TILE format*/ |
| 88 | if (inWhf.format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) { |
| 89 | tmpwhf.w = whf.w - (utils::alignup(whf.w, 64) - whf.w); |
| 90 | tmpwhf.h = whf.h - (utils::alignup(whf.h, 32) - whf.h); |
| 91 | } |
| 92 | if (inWhf.w * fbHeight > fbWidth * inWhf.h) { |
| 93 | inWhf.h = fbWidth * inWhf.h / inWhf.w; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 94 | inWhf.w = fbWidth; |
| 95 | } else if (inWhf.w * fbHeight < fbWidth * inWhf.h) { |
| 96 | inWhf.w = fbHeight * inWhf.w / inWhf.h; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 97 | inWhf.h = fbHeight; |
| 98 | } else { |
| 99 | inWhf.w = fbWidth; |
| 100 | inWhf.h = fbHeight; |
| 101 | } |
| 102 | /* Scaling of upto a max of 8 times supported */ |
| 103 | if (inWhf.w > (tmpwhf.w * utils::HW_OV_MAGNIFICATION_LIMIT)){ |
| 104 | inWhf.w = utils::HW_OV_MAGNIFICATION_LIMIT * tmpwhf.w; |
| 105 | } |
| 106 | if(inWhf.h > (tmpwhf.h * utils::HW_OV_MAGNIFICATION_LIMIT)) { |
| 107 | inWhf.h = utils::HW_OV_MAGNIFICATION_LIMIT * tmpwhf.h; |
| 108 | } |
| 109 | if (inWhf.w > fbWidth) inWhf.w = fbWidth; |
| 110 | if (inWhf.h > fbHeight) inWhf.h = fbHeight; |
| 111 | |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 112 | float asWidth = utils::ActionSafe::getInstance()->getHeight(); |
| 113 | float asHeight = utils::ActionSafe::getInstance()->getWidth(); |
| 114 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 115 | inWhf.w = inWhf.w * (1.0f - asWidth / 100.0f); |
| 116 | inWhf.h = inWhf.h * (1.0f - asHeight / 100.0f); |
| 117 | |
| 118 | uint32_t x = (fbWidth - inWhf.w) / 2.0; |
| 119 | uint32_t y = (fbHeight - inWhf.h) / 2.0; |
| 120 | return utils::Dim(x, y, inWhf.w, inWhf.h); |
| 121 | } |
| 122 | |
| 123 | utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0; |
| 124 | |
| 125 | // This function gets the destination position for external display |
| 126 | // based on the position and aspect ratio of the primary |
| 127 | utils::Dim Ctrl::getAspectRatio(const utils::Dim& dim) const { |
| 128 | float priWidth = utils::FrameBufferInfo::getInstance()->getWidth(); |
| 129 | float priHeight = utils::FrameBufferInfo::getInstance()->getHeight(); |
| 130 | float fbWidth = mInfo.mFBWidth; |
| 131 | float fbHeight = mInfo.mFBHeight; |
| 132 | float wRatio = 1.0; |
| 133 | float hRatio = 1.0; |
| 134 | float xRatio = 1.0; |
| 135 | float yRatio = 1.0; |
| 136 | utils::Dim inDim(dim); |
| 137 | |
| 138 | int xPos = 0; |
| 139 | int yPos = 0; |
| 140 | int tmp = 0; |
| 141 | utils::Dim tmpDim; |
| 142 | switch(inDim.o) { |
| 143 | case MDP_ROT_NOP: |
| 144 | case MDP_ROT_180: |
| 145 | { |
| 146 | utils::Whf whf((uint32_t) priWidth, (uint32_t) priHeight, 0); |
| 147 | tmpDim = getAspectRatio(whf); |
| 148 | xPos = tmpDim.x; |
| 149 | yPos = tmpDim.y; |
| 150 | fbWidth = tmpDim.w; |
| 151 | fbHeight = tmpDim.h; |
| 152 | |
| 153 | if (inDim.o == MDP_ROT_180) { |
| 154 | inDim.x = priWidth - (inDim.x + inDim.w); |
| 155 | inDim.y = priHeight - (inDim.y + inDim.h); |
| 156 | } |
| 157 | break; |
| 158 | } |
| 159 | case MDP_ROT_90: |
| 160 | case MDP_ROT_270: |
| 161 | { |
| 162 | if(inDim.o == MDP_ROT_90) { |
| 163 | tmp = inDim.y; |
| 164 | inDim.y = priWidth - (inDim.x + inDim.w); |
| 165 | inDim.x = tmp; |
| 166 | } |
| 167 | else if (inDim.o == MDP_ROT_270) { |
| 168 | tmp = inDim.x; |
| 169 | inDim.x = priHeight - (inDim.y + inDim.h); |
| 170 | inDim.y = tmp; |
| 171 | } |
| 172 | |
| 173 | // Swap the destination width/height |
| 174 | utils::swapWidthHeight(inDim.w, inDim.h); |
| 175 | // Swap width/height for primary |
| 176 | utils::swapWidthHeight(priWidth, priHeight); |
| 177 | utils::Whf whf((uint32_t) priWidth, (uint32_t) priHeight, 0); |
| 178 | tmpDim = getAspectRatio(whf); |
| 179 | xPos = tmpDim.x; |
| 180 | yPos = tmpDim.y; |
| 181 | fbWidth = tmpDim.w; |
| 182 | fbHeight = tmpDim.h; |
| 183 | break; |
| 184 | } |
| 185 | default: |
| 186 | ALOGE("%s: Unknown Orientation", __FUNCTION__); |
| 187 | break; |
| 188 | } |
| 189 | |
| 190 | // Calculate the position |
| 191 | xRatio = inDim.x/priWidth; |
| 192 | yRatio = inDim.y/priHeight; |
| 193 | wRatio = inDim.w/priWidth; |
| 194 | hRatio = inDim.h/priHeight; |
| 195 | |
| 196 | return utils::Dim((xRatio * fbWidth) + xPos, // x |
| 197 | (yRatio * fbHeight) + yPos, // y |
| 198 | (wRatio * fbWidth), // width |
| 199 | (hRatio * fbHeight), // height |
| 200 | inDim.o); // orientation |
| 201 | } |
| 202 | |
| 203 | void Ctrl::dump() const { |
| 204 | ALOGE("== Dump Ctrl start =="); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 205 | mInfo.dump("mInfo"); |
| 206 | mMdp.dump(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 207 | ALOGE("== Dump Ctrl end =="); |
| 208 | } |
| 209 | |
| 210 | } // overlay |