Manoj Kumar AVM | b86bc17 | 2015-01-28 21:20:04 -0800 | [diff] [blame] | 1 | /* |
Namit Solanki | 6d0d806 | 2017-11-30 17:29:48 +0530 | [diff] [blame^] | 2 | * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. |
Manoj Kumar AVM | b86bc17 | 2015-01-28 21:20:04 -0800 | [diff] [blame] | 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 | |
Tatenda Chipeperekwa | 2ba9789 | 2015-02-10 12:18:34 -0800 | [diff] [blame] | 30 | #include <math.h> |
Manoj Kumar AVM | b86bc17 | 2015-01-28 21:20:04 -0800 | [diff] [blame] | 31 | #include <utils/rect.h> |
Tatenda Chipeperekwa | 2ba9789 | 2015-02-10 12:18:34 -0800 | [diff] [blame] | 32 | #include <utils/constants.h> |
Dileep Marchya | 7290bd2 | 2016-06-09 11:37:20 +0530 | [diff] [blame] | 33 | #include <algorithm> |
Tatenda Chipeperekwa | 2ba9789 | 2015-02-10 12:18:34 -0800 | [diff] [blame] | 34 | |
| 35 | #define __CLASS__ "RectUtils" |
Manoj Kumar AVM | b86bc17 | 2015-01-28 21:20:04 -0800 | [diff] [blame] | 36 | |
Dileep Marchya | 73d002e | 2015-05-08 18:58:33 -0700 | [diff] [blame] | 37 | namespace sdm { |
Manoj Kumar AVM | b86bc17 | 2015-01-28 21:20:04 -0800 | [diff] [blame] | 38 | |
Manoj Kumar AVM | 351c928 | 2015-03-18 16:34:38 -0700 | [diff] [blame] | 39 | bool IsValid(const LayerRect &rect) { |
Manoj Kumar AVM | b86bc17 | 2015-01-28 21:20:04 -0800 | [diff] [blame] | 40 | return ((rect.bottom > rect.top) && (rect.right > rect.left)); |
| 41 | } |
| 42 | |
Manoj Kumar AVM | 351c928 | 2015-03-18 16:34:38 -0700 | [diff] [blame] | 43 | bool IsCongruent(const LayerRect &rect1, const LayerRect &rect2) { |
| 44 | return ((rect1.left == rect2.left) && |
| 45 | (rect1.top == rect2.top) && |
| 46 | (rect1.right == rect2.right) && |
| 47 | (rect1.bottom == rect2.bottom)); |
| 48 | } |
Manoj Kumar AVM | b86bc17 | 2015-01-28 21:20:04 -0800 | [diff] [blame] | 49 | |
Saurabh Dubey | d90a6a4 | 2017-10-24 16:28:01 +0530 | [diff] [blame] | 50 | void LogI(DebugTag debug_tag, const char *prefix, const LayerRect &roi) { |
| 51 | DLOGI_IF(debug_tag, "%s: left = %.0f, top = %.0f, right = %.0f, bottom = %.0f", |
| 52 | prefix, roi.left, roi.top, roi.right, roi.bottom); |
| 53 | } |
| 54 | |
Manoj Kumar AVM | 351c928 | 2015-03-18 16:34:38 -0700 | [diff] [blame] | 55 | void Log(DebugTag debug_tag, const char *prefix, const LayerRect &roi) { |
| 56 | DLOGV_IF(debug_tag, "%s: left = %.0f, top = %.0f, right = %.0f, bottom = %.0f", |
| 57 | prefix, roi.left, roi.top, roi.right, roi.bottom); |
| 58 | } |
| 59 | |
| 60 | void Normalize(const uint32_t &align_x, const uint32_t &align_y, LayerRect *rect) { |
| 61 | rect->left = ROUND_UP_ALIGN_UP(rect->left, align_x); |
| 62 | rect->right = ROUND_UP_ALIGN_DOWN(rect->right, align_x); |
| 63 | rect->top = ROUND_UP_ALIGN_UP(rect->top, align_y); |
| 64 | rect->bottom = ROUND_UP_ALIGN_DOWN(rect->bottom, align_y); |
| 65 | } |
| 66 | |
| 67 | LayerRect Intersection(const LayerRect &rect1, const LayerRect &rect2) { |
Manoj Kumar AVM | b86bc17 | 2015-01-28 21:20:04 -0800 | [diff] [blame] | 68 | LayerRect res; |
| 69 | |
Manoj Kumar AVM | 351c928 | 2015-03-18 16:34:38 -0700 | [diff] [blame] | 70 | if (!IsValid(rect1) || !IsValid(rect2)) { |
Manoj Kumar AVM | b86bc17 | 2015-01-28 21:20:04 -0800 | [diff] [blame] | 71 | return LayerRect(); |
| 72 | } |
| 73 | |
Dileep Marchya | 7290bd2 | 2016-06-09 11:37:20 +0530 | [diff] [blame] | 74 | res.left = std::max(rect1.left, rect2.left); |
| 75 | res.top = std::max(rect1.top, rect2.top); |
| 76 | res.right = std::min(rect1.right, rect2.right); |
| 77 | res.bottom = std::min(rect1.bottom, rect2.bottom); |
Manoj Kumar AVM | b86bc17 | 2015-01-28 21:20:04 -0800 | [diff] [blame] | 78 | |
Manoj Kumar AVM | 351c928 | 2015-03-18 16:34:38 -0700 | [diff] [blame] | 79 | if (!IsValid(res)) { |
Manoj Kumar AVM | b86bc17 | 2015-01-28 21:20:04 -0800 | [diff] [blame] | 80 | return LayerRect(); |
| 81 | } |
| 82 | |
| 83 | return res; |
| 84 | } |
| 85 | |
Manoj Kumar AVM | 351c928 | 2015-03-18 16:34:38 -0700 | [diff] [blame] | 86 | LayerRect Reposition(const LayerRect &rect, const int &x_offset, const int &y_offset) { |
| 87 | LayerRect res; |
| 88 | |
| 89 | if (!IsValid(rect)) { |
| 90 | return LayerRect(); |
| 91 | } |
| 92 | |
| 93 | res.left = rect.left + FLOAT(x_offset); |
| 94 | res.top = rect.top + FLOAT(y_offset); |
| 95 | res.right = rect.right + FLOAT(x_offset); |
| 96 | res.bottom = rect.bottom + FLOAT(y_offset); |
| 97 | |
| 98 | return res; |
Tatenda Chipeperekwa | 2ba9789 | 2015-02-10 12:18:34 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Namit Solanki | 6d0d806 | 2017-11-30 17:29:48 +0530 | [diff] [blame^] | 101 | // Is rect2 completely inside rect1? |
| 102 | bool Contains(const LayerRect &rect1, const LayerRect &rect2) { |
| 103 | if (!IsValid(rect1) || !IsValid(rect2)) { |
| 104 | return false; |
| 105 | } |
| 106 | return (rect1.top <= rect2.top && rect1.bottom >= rect2.bottom && |
| 107 | rect1.left <= rect2.left && rect1.right >= rect2.right); |
| 108 | } |
| 109 | |
| 110 | // subtracts 2 rects iff result of subtraction is 2 rects. |
| 111 | void Subtract(const LayerRect &rect1, const LayerRect &rect2, LayerRect *res) { |
| 112 | if (!res) { |
| 113 | return; |
| 114 | } |
| 115 | if (!IsValid(rect1) || !IsValid(rect2)) { |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | if (rect1.left != rect2.left || rect1.right != rect2.right) { |
| 120 | return; |
| 121 | } |
| 122 | res[0].left = rect1.left; |
| 123 | res[0].right = rect1.right; |
| 124 | if (rect1.top < rect2.top) { |
| 125 | res[0].top = rect1.top; |
| 126 | res[0].bottom = rect2.top; |
| 127 | } else { |
| 128 | res[0].top = rect2.top; |
| 129 | res[0].bottom = rect1.top; |
| 130 | } |
| 131 | res[1].left = rect1.left; |
| 132 | res[1].right = rect1.right; |
| 133 | if (rect1.bottom < rect2.bottom) { |
| 134 | res[1].top = rect1.bottom; |
| 135 | res[1].bottom = rect2.bottom; |
| 136 | } else { |
| 137 | res[1].top = rect2.bottom; |
| 138 | res[1].bottom = rect1.bottom; |
| 139 | } |
| 140 | } |
| 141 | |
Manoj Kumar AVM | 351c928 | 2015-03-18 16:34:38 -0700 | [diff] [blame] | 142 | // Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results a single rect |
| 143 | LayerRect Subtract(const LayerRect &rect1, const LayerRect &rect2) { |
| 144 | LayerRect res; |
| 145 | |
| 146 | res = rect1; |
| 147 | |
| 148 | if ((rect1.left == rect2.left) && (rect1.right == rect2.right)) { |
| 149 | if ((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom)) { |
| 150 | res.top = rect2.bottom; |
| 151 | } else if ((rect1.bottom == rect2.bottom) && (rect2.top >= rect1.top)) { |
| 152 | res.bottom = rect2.top; |
| 153 | } |
| 154 | } else if ((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) { |
| 155 | if ((rect1.left == rect2.left) && (rect2.right <= rect1.right)) { |
| 156 | res.left = rect2.right; |
| 157 | } else if ((rect1.right == rect2.right) && (rect2.left >= rect1.left)) { |
| 158 | res.right = rect2.left; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | return res; |
| 163 | } |
| 164 | |
| 165 | LayerRect Union(const LayerRect &rect1, const LayerRect &rect2) { |
| 166 | LayerRect res; |
| 167 | |
| 168 | if (!IsValid(rect1) && !IsValid(rect2)) { |
| 169 | return LayerRect(); |
| 170 | } |
| 171 | |
Manoj Kumar AVM | 2405ce5 | 2015-04-02 23:13:19 -0700 | [diff] [blame] | 172 | if (!IsValid(rect1)) { |
Manoj Kumar AVM | 351c928 | 2015-03-18 16:34:38 -0700 | [diff] [blame] | 173 | return rect2; |
| 174 | } |
| 175 | |
Manoj Kumar AVM | 2405ce5 | 2015-04-02 23:13:19 -0700 | [diff] [blame] | 176 | if (!IsValid(rect2)) { |
Manoj Kumar AVM | 351c928 | 2015-03-18 16:34:38 -0700 | [diff] [blame] | 177 | return rect1; |
| 178 | } |
| 179 | |
Dileep Marchya | 7290bd2 | 2016-06-09 11:37:20 +0530 | [diff] [blame] | 180 | res.left = std::min(rect1.left, rect2.left); |
| 181 | res.top = std::min(rect1.top, rect2.top); |
| 182 | res.right = std::max(rect1.right, rect2.right); |
| 183 | res.bottom = std::max(rect1.bottom, rect2.bottom); |
Manoj Kumar AVM | 351c928 | 2015-03-18 16:34:38 -0700 | [diff] [blame] | 184 | |
| 185 | return res; |
Tatenda Chipeperekwa | 2ba9789 | 2015-02-10 12:18:34 -0800 | [diff] [blame] | 186 | } |
| 187 | |
Ramkumar Radhakrishnan | 3450811 | 2015-05-28 19:02:05 -0700 | [diff] [blame] | 188 | void SplitLeftRight(const LayerRect &in_rect, uint32_t split_count, uint32_t align_x, |
Tatenda Chipeperekwa | a866864 | 2015-07-23 15:36:24 -0700 | [diff] [blame] | 189 | bool flip_horizontal, LayerRect *out_rects) { |
Ramkumar Radhakrishnan | 3450811 | 2015-05-28 19:02:05 -0700 | [diff] [blame] | 190 | LayerRect rect_temp = in_rect; |
| 191 | |
| 192 | uint32_t split_width = UINT32(rect_temp.right - rect_temp.left) / split_count; |
Tatenda Chipeperekwa | a866864 | 2015-07-23 15:36:24 -0700 | [diff] [blame] | 193 | float aligned_width = FLOAT(CeilToMultipleOf(split_width, align_x)); |
Ramkumar Radhakrishnan | 3450811 | 2015-05-28 19:02:05 -0700 | [diff] [blame] | 194 | |
| 195 | for (uint32_t count = 0; count < split_count; count++) { |
Tatenda Chipeperekwa | a866864 | 2015-07-23 15:36:24 -0700 | [diff] [blame] | 196 | float aligned_right = rect_temp.left + aligned_width; |
Ramkumar Radhakrishnan | 3450811 | 2015-05-28 19:02:05 -0700 | [diff] [blame] | 197 | out_rects[count].left = rect_temp.left; |
Dileep Marchya | 7290bd2 | 2016-06-09 11:37:20 +0530 | [diff] [blame] | 198 | out_rects[count].right = std::min(rect_temp.right, aligned_right); |
Ramkumar Radhakrishnan | 3450811 | 2015-05-28 19:02:05 -0700 | [diff] [blame] | 199 | out_rects[count].top = rect_temp.top; |
| 200 | out_rects[count].bottom = rect_temp.bottom; |
| 201 | |
| 202 | rect_temp.left = out_rects[count].right; |
| 203 | |
| 204 | Log(kTagRotator, "SplitLeftRight", out_rects[count]); |
| 205 | } |
Tatenda Chipeperekwa | a866864 | 2015-07-23 15:36:24 -0700 | [diff] [blame] | 206 | |
| 207 | // If we have a horizontal flip, then we should be splitting the source from right to left |
| 208 | // to ensure that the right split will have an aligned width that matches the alignment on the |
| 209 | // destination. |
| 210 | if (flip_horizontal && split_count > 1) { |
| 211 | out_rects[0].right = out_rects[0].left + (out_rects[1].right - out_rects[1].left); |
| 212 | out_rects[1].left = out_rects[0].right; |
| 213 | Log(kTagRotator, "Adjusted Left", out_rects[0]); |
| 214 | Log(kTagRotator, "Adjusted Right", out_rects[1]); |
| 215 | } |
Ramkumar Radhakrishnan | 3450811 | 2015-05-28 19:02:05 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | void SplitTopBottom(const LayerRect &in_rect, uint32_t split_count, uint32_t align_y, |
Tatenda Chipeperekwa | a866864 | 2015-07-23 15:36:24 -0700 | [diff] [blame] | 219 | bool flip_horizontal, LayerRect *out_rects) { |
Ramkumar Radhakrishnan | 3450811 | 2015-05-28 19:02:05 -0700 | [diff] [blame] | 220 | LayerRect rect_temp = in_rect; |
| 221 | |
| 222 | uint32_t split_height = UINT32(rect_temp.bottom - rect_temp.top) / split_count; |
Tatenda Chipeperekwa | a866864 | 2015-07-23 15:36:24 -0700 | [diff] [blame] | 223 | float aligned_height = FLOAT(CeilToMultipleOf(split_height, align_y)); |
Ramkumar Radhakrishnan | 3450811 | 2015-05-28 19:02:05 -0700 | [diff] [blame] | 224 | |
| 225 | for (uint32_t count = 0; count < split_count; count++) { |
Tatenda Chipeperekwa | a866864 | 2015-07-23 15:36:24 -0700 | [diff] [blame] | 226 | float aligned_bottom = rect_temp.top + aligned_height; |
Ramkumar Radhakrishnan | 3450811 | 2015-05-28 19:02:05 -0700 | [diff] [blame] | 227 | out_rects[count].top = rect_temp.top; |
Dileep Marchya | 7290bd2 | 2016-06-09 11:37:20 +0530 | [diff] [blame] | 228 | out_rects[count].bottom = std::min(rect_temp.bottom, aligned_bottom); |
Ramkumar Radhakrishnan | 3450811 | 2015-05-28 19:02:05 -0700 | [diff] [blame] | 229 | out_rects[count].left = rect_temp.left; |
| 230 | out_rects[count].right = rect_temp.right; |
| 231 | |
| 232 | rect_temp.top = out_rects[count].bottom; |
| 233 | |
| 234 | Log(kTagRotator, "SplitTopBottom", out_rects[count]); |
| 235 | } |
Tatenda Chipeperekwa | a866864 | 2015-07-23 15:36:24 -0700 | [diff] [blame] | 236 | |
| 237 | // If we have a horizontal flip, then we should be splitting the destination from bottom to top |
| 238 | // to ensure that the bottom split's y-offset is aligned correctly after we swap the destinations |
| 239 | // while accounting for the flip. |
| 240 | if (flip_horizontal && split_count > 1) { |
| 241 | out_rects[0].bottom = out_rects[0].top + (out_rects[1].bottom - out_rects[1].top); |
| 242 | out_rects[1].top = out_rects[0].bottom; |
| 243 | Log(kTagRotator, "Adjusted Top", out_rects[0]); |
| 244 | Log(kTagRotator, "Adjusted Bottom", out_rects[1]); |
| 245 | } |
Ramkumar Radhakrishnan | 3450811 | 2015-05-28 19:02:05 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Ramkumar Radhakrishnan | b27735f | 2016-08-26 22:37:23 -0700 | [diff] [blame] | 248 | void MapRect(const LayerRect &src_domain, const LayerRect &dst_domain, const LayerRect &in_rect, |
| 249 | LayerRect *out_rect) { |
Ramkumar Radhakrishnan | 6884047 | 2016-05-09 13:01:25 -0700 | [diff] [blame] | 250 | if (!IsValid(src_domain) || !IsValid(dst_domain) || !IsValid(in_rect)) { |
| 251 | return; |
| 252 | } |
| 253 | |
Prabhanjan Kandula | 6064cad | 2016-11-02 16:55:19 -0700 | [diff] [blame] | 254 | int x_offset = INT(src_domain.left); |
| 255 | int y_offset = INT(src_domain.top); |
| 256 | |
| 257 | LayerRect modified_in_rect = Reposition(in_rect, -x_offset, -y_offset); |
Ramkumar Radhakrishnan | 6884047 | 2016-05-09 13:01:25 -0700 | [diff] [blame] | 258 | float src_domain_width = src_domain.right - src_domain.left; |
| 259 | float src_domain_height = src_domain.bottom - src_domain.top; |
| 260 | float dst_domain_width = dst_domain.right - dst_domain.left; |
| 261 | float dst_domain_height = dst_domain.bottom - dst_domain.top; |
| 262 | |
| 263 | float width_ratio = dst_domain_width / src_domain_width; |
| 264 | float height_ratio = dst_domain_height / src_domain_height; |
| 265 | |
Prabhanjan Kandula | 6064cad | 2016-11-02 16:55:19 -0700 | [diff] [blame] | 266 | out_rect->left = dst_domain.left + (width_ratio * modified_in_rect.left); |
| 267 | out_rect->top = dst_domain.top + (height_ratio * modified_in_rect.top); |
| 268 | out_rect->right = dst_domain.left + (width_ratio * modified_in_rect.right); |
| 269 | out_rect->bottom = dst_domain.top + (height_ratio * modified_in_rect.bottom); |
Ramkumar Radhakrishnan | 6884047 | 2016-05-09 13:01:25 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Pullakavi Srinivas | 5de9c63 | 2017-01-30 20:30:39 +0530 | [diff] [blame] | 272 | void TransformHV(const LayerRect &src_domain, const LayerRect &in_rect, |
| 273 | const LayerTransform &transform, LayerRect *out_rect) { |
Pullakavi Srinivas | 1494a93 | 2016-12-30 12:51:06 +0530 | [diff] [blame] | 274 | if (!IsValid(src_domain) || !IsValid(in_rect)) { |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | float in_width = in_rect.right - in_rect.left; |
| 279 | float in_height = in_rect.bottom - in_rect.top; |
Pullakavi Srinivas | 5de9c63 | 2017-01-30 20:30:39 +0530 | [diff] [blame] | 280 | float x_offset = in_rect.left - src_domain.left; |
| 281 | float y_offset = in_rect.top - src_domain.top; |
| 282 | *out_rect = in_rect; |
Pullakavi Srinivas | 1494a93 | 2016-12-30 12:51:06 +0530 | [diff] [blame] | 283 | |
Pullakavi Srinivas | 5de9c63 | 2017-01-30 20:30:39 +0530 | [diff] [blame] | 284 | if (transform.flip_horizontal) { |
| 285 | out_rect->right = src_domain.right - x_offset; |
| 286 | out_rect->left = out_rect->right - in_width; |
| 287 | } |
| 288 | |
| 289 | if (transform.flip_vertical) { |
| 290 | out_rect->bottom = src_domain.bottom - y_offset; |
| 291 | out_rect->top = out_rect->bottom - in_height; |
| 292 | } |
Pullakavi Srinivas | 1494a93 | 2016-12-30 12:51:06 +0530 | [diff] [blame] | 293 | } |
| 294 | |
Ramkumar Radhakrishnan | 6884047 | 2016-05-09 13:01:25 -0700 | [diff] [blame] | 295 | RectOrientation GetOrientation(const LayerRect &in_rect) { |
| 296 | if (!IsValid(in_rect)) { |
| 297 | return kOrientationUnknown; |
| 298 | } |
| 299 | |
| 300 | float input_width = in_rect.right - in_rect.left; |
| 301 | float input_height = in_rect.bottom - in_rect.top; |
| 302 | |
| 303 | if (input_width < input_height) { |
| 304 | return kOrientationPortrait; |
| 305 | } |
| 306 | |
| 307 | return kOrientationLandscape; |
| 308 | } |
| 309 | |
Rohit Kulkarni | 8622e36 | 2017-01-30 18:14:10 -0800 | [diff] [blame] | 310 | DisplayError GetCropAndDestination(const LayerRect &crop, const LayerRect &dst, |
| 311 | const bool rotated90, float *crop_width, |
| 312 | float *crop_height, float *dst_width, |
| 313 | float *dst_height) { |
| 314 | if (!IsValid(crop)) { |
| 315 | Log(kTagResources, "Invalid crop rect", crop); |
| 316 | return kErrorNotSupported; |
| 317 | } |
| 318 | |
| 319 | if (!IsValid(dst)) { |
| 320 | Log(kTagResources, "Invalid dst rect", dst); |
| 321 | return kErrorNotSupported; |
| 322 | } |
| 323 | |
| 324 | *crop_width = crop.right - crop.left; |
| 325 | *crop_height = crop.bottom - crop.top; |
| 326 | if (rotated90) { |
| 327 | std::swap(*crop_width, *crop_height); |
| 328 | } |
| 329 | |
| 330 | *dst_width = dst.right - dst.left; |
| 331 | *dst_height = dst.bottom - dst.top; |
| 332 | |
| 333 | return kErrorNone; |
| 334 | } |
| 335 | |
| 336 | DisplayError GetScaleFactor(const LayerRect &crop, const LayerRect &dst, |
| 337 | bool rotated90, float *scale_x, float *scale_y) { |
| 338 | float crop_width = 1.0f, crop_height = 1.0f, dst_width = 1.0f, dst_height = 1.0f; |
| 339 | |
| 340 | DisplayError error = GetCropAndDestination(crop, dst, rotated90, &crop_width, &crop_height, |
| 341 | &dst_width, &dst_height); |
| 342 | if (error != kErrorNone) { |
| 343 | return error; |
| 344 | } |
| 345 | |
| 346 | *scale_x = crop_width / dst_width; |
| 347 | *scale_y = crop_height / dst_height; |
| 348 | |
| 349 | return kErrorNone; |
| 350 | } |
| 351 | |
Dileep Marchya | 73d002e | 2015-05-08 18:58:33 -0700 | [diff] [blame] | 352 | } // namespace sdm |
Manoj Kumar AVM | b86bc17 | 2015-01-28 21:20:04 -0800 | [diff] [blame] | 353 | |