Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <sstream> |
Marissa Wall | ad76181 | 2016-12-15 12:32:24 -0800 | [diff] [blame] | 18 | #include <cutils/log.h> |
Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame^] | 19 | #include <ui/Rect.h> |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 20 | |
Marissa Wall | 5a240aa | 2016-12-15 12:34:06 -0800 | [diff] [blame] | 21 | #define HWC2_INCLUDE_STRINGIFICATION |
| 22 | #define HWC2_USE_CPP11 |
| 23 | #include <hardware/hwcomposer2.h> |
| 24 | #undef HWC2_INCLUDE_STRINGIFICATION |
| 25 | #undef HWC2_USE_CPP11 |
| 26 | |
| 27 | #include "Hwc2TestBuffer.h" |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 28 | #include "Hwc2TestProperties.h" |
| 29 | |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 30 | Hwc2TestBufferArea::Hwc2TestBufferArea(Hwc2TestCoverage coverage, |
| 31 | const Area& displayArea) |
| 32 | : Hwc2TestProperty(mBufferAreas), |
| 33 | mScalars((coverage == Hwc2TestCoverage::Complete)? mCompleteScalars: |
| 34 | (coverage == Hwc2TestCoverage::Basic)? mBasicScalars: |
| 35 | mDefaultScalars), |
| 36 | mDisplayArea(displayArea) |
| 37 | { |
| 38 | update(); |
| 39 | } |
| 40 | |
| 41 | std::string Hwc2TestBufferArea::dump() const |
| 42 | { |
| 43 | std::stringstream dmp; |
| 44 | const Area& curr = get(); |
| 45 | dmp << "\tbuffer area: width " << curr.width << ", height " << curr.height |
| 46 | << "\n"; |
| 47 | return dmp.str(); |
| 48 | } |
| 49 | |
Marissa Wall | 5a240aa | 2016-12-15 12:34:06 -0800 | [diff] [blame] | 50 | void Hwc2TestBufferArea::setDependent(Hwc2TestBuffer* buffer) |
| 51 | { |
| 52 | mBuffer = buffer; |
| 53 | if (buffer) { |
| 54 | buffer->updateBufferArea(get()); |
| 55 | } |
| 56 | } |
| 57 | |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 58 | void Hwc2TestBufferArea::setDependent(Hwc2TestSourceCrop* sourceCrop) |
| 59 | { |
| 60 | mSourceCrop = sourceCrop; |
Marissa Wall | ad76181 | 2016-12-15 12:32:24 -0800 | [diff] [blame] | 61 | if (mSourceCrop) { |
| 62 | mSourceCrop->updateBufferArea(get()); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | void Hwc2TestBufferArea::setDependent(Hwc2TestSurfaceDamage* surfaceDamage) |
| 67 | { |
| 68 | mSurfaceDamage = surfaceDamage; |
| 69 | if (mSurfaceDamage) { |
| 70 | mSurfaceDamage->updateBufferArea(get()); |
| 71 | } |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void Hwc2TestBufferArea::update() |
| 75 | { |
| 76 | mBufferAreas.clear(); |
| 77 | |
| 78 | if (mDisplayArea.width == 0 && mDisplayArea.height == 0) { |
| 79 | mBufferAreas.push_back({0, 0}); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | for (auto scalar : mScalars) { |
| 84 | mBufferAreas.push_back({static_cast<int32_t>(scalar * mDisplayArea.width), |
| 85 | static_cast<int32_t>(scalar * mDisplayArea.height)}); |
| 86 | } |
| 87 | |
| 88 | updateDependents(); |
| 89 | } |
| 90 | |
| 91 | void Hwc2TestBufferArea::updateDependents() |
| 92 | { |
| 93 | const Area& curr = get(); |
| 94 | |
Marissa Wall | 5a240aa | 2016-12-15 12:34:06 -0800 | [diff] [blame] | 95 | if (mBuffer) |
| 96 | mBuffer->updateBufferArea(curr); |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 97 | if (mSourceCrop) |
| 98 | mSourceCrop->updateBufferArea(curr); |
Marissa Wall | ad76181 | 2016-12-15 12:32:24 -0800 | [diff] [blame] | 99 | if (mSurfaceDamage) |
| 100 | mSurfaceDamage->updateBufferArea(curr); |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | const std::vector<float> Hwc2TestBufferArea::mDefaultScalars = { |
| 104 | 1.0f, |
| 105 | }; |
| 106 | |
| 107 | const std::vector<float> Hwc2TestBufferArea::mBasicScalars = { |
| 108 | 1.0f, 0.5f, |
| 109 | }; |
| 110 | |
| 111 | const std::vector<float> Hwc2TestBufferArea::mCompleteScalars = { |
| 112 | 1.0f, 0.75f, 0.5f |
| 113 | }; |
| 114 | |
| 115 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 116 | Hwc2TestBlendMode::Hwc2TestBlendMode(Hwc2TestCoverage coverage) |
| 117 | : Hwc2TestProperty(coverage, mCompleteBlendModes, mBasicBlendModes, |
| 118 | mDefaultBlendModes) { } |
| 119 | |
| 120 | std::string Hwc2TestBlendMode::dump() const |
| 121 | { |
| 122 | std::stringstream dmp; |
| 123 | dmp << "\tblend mode: " << getBlendModeName(get()) << "\n"; |
| 124 | return dmp.str(); |
| 125 | } |
| 126 | |
Marissa Wall | ee24278 | 2016-12-15 12:30:12 -0800 | [diff] [blame] | 127 | void Hwc2TestBlendMode::setDependent(Hwc2TestColor* color) |
| 128 | { |
| 129 | mColor = color; |
| 130 | updateDependents(); |
| 131 | } |
| 132 | |
| 133 | void Hwc2TestBlendMode::updateDependents() |
| 134 | { |
| 135 | if (mColor) |
| 136 | mColor->updateBlendMode(get()); |
| 137 | } |
| 138 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 139 | const std::vector<hwc2_blend_mode_t> Hwc2TestBlendMode::mDefaultBlendModes = { |
| 140 | HWC2_BLEND_MODE_NONE, |
| 141 | }; |
| 142 | |
| 143 | const std::vector<hwc2_blend_mode_t> Hwc2TestBlendMode::mBasicBlendModes = { |
| 144 | HWC2_BLEND_MODE_NONE, |
| 145 | HWC2_BLEND_MODE_PREMULTIPLIED, |
| 146 | }; |
| 147 | |
| 148 | const std::vector<hwc2_blend_mode_t> Hwc2TestBlendMode::mCompleteBlendModes = { |
| 149 | HWC2_BLEND_MODE_NONE, |
| 150 | HWC2_BLEND_MODE_PREMULTIPLIED, |
| 151 | HWC2_BLEND_MODE_COVERAGE, |
| 152 | }; |
| 153 | |
| 154 | |
Marissa Wall | ee24278 | 2016-12-15 12:30:12 -0800 | [diff] [blame] | 155 | Hwc2TestColor::Hwc2TestColor(Hwc2TestCoverage coverage, |
| 156 | hwc2_blend_mode_t blendMode) |
| 157 | : Hwc2TestProperty(mColors), |
| 158 | mBaseColors((coverage == Hwc2TestCoverage::Complete)? mCompleteBaseColors: |
| 159 | (coverage == Hwc2TestCoverage::Basic)? mBasicBaseColors: |
| 160 | mDefaultBaseColors), |
| 161 | mBlendMode(blendMode) |
| 162 | { |
| 163 | update(); |
| 164 | } |
| 165 | |
| 166 | std::string Hwc2TestColor::dump() const |
| 167 | { |
| 168 | std::stringstream dmp; |
| 169 | const hwc_color_t& color = get(); |
| 170 | dmp << "\tcolor: r " << std::to_string(color.r) << ", g " |
| 171 | << std::to_string(color.g) << ", b " << std::to_string(color.b) |
| 172 | << ", a " << std::to_string(color.a) << "\n"; |
| 173 | return dmp.str(); |
| 174 | } |
| 175 | |
| 176 | void Hwc2TestColor::updateBlendMode(hwc2_blend_mode_t blendMode) |
| 177 | { |
| 178 | mBlendMode = blendMode; |
| 179 | update(); |
| 180 | } |
| 181 | |
| 182 | void Hwc2TestColor::update() |
| 183 | { |
| 184 | if (mBlendMode != HWC2_BLEND_MODE_PREMULTIPLIED) { |
| 185 | mColors = mBaseColors; |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | mColors.clear(); |
| 190 | |
| 191 | for (const hwc_color_t& baseColor : mBaseColors) { |
| 192 | if (baseColor.a >= baseColor.r && baseColor.a >= baseColor.g |
| 193 | && baseColor.a >= baseColor.b) { |
| 194 | mColors.push_back(baseColor); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | } |
| 199 | |
| 200 | const std::vector<hwc_color_t> Hwc2TestColor::mDefaultBaseColors = { |
| 201 | {UINT8_MAX, UINT8_MAX, UINT8_MAX, UINT8_MAX}, |
| 202 | }; |
| 203 | |
| 204 | const std::vector<hwc_color_t> Hwc2TestColor::mBasicBaseColors = { |
| 205 | {UINT8_MAX, UINT8_MAX, UINT8_MAX, UINT8_MAX}, |
| 206 | { 0, 0, 0, 0}, |
| 207 | }; |
| 208 | |
| 209 | const std::vector<hwc_color_t> Hwc2TestColor::mCompleteBaseColors = { |
| 210 | {UINT8_MAX, UINT8_MAX, UINT8_MAX, UINT8_MAX}, |
| 211 | {UINT8_MAX, UINT8_MAX, UINT8_MAX, 0}, |
| 212 | {UINT8_MAX, UINT8_MAX, 0, UINT8_MAX}, |
| 213 | {UINT8_MAX, UINT8_MAX, 0, 0}, |
| 214 | {UINT8_MAX, 0, UINT8_MAX, UINT8_MAX}, |
| 215 | {UINT8_MAX, 0, UINT8_MAX, 0}, |
| 216 | {UINT8_MAX, 0, 0, UINT8_MAX}, |
| 217 | {UINT8_MAX, 0, 0, 0}, |
| 218 | { 0, UINT8_MAX, UINT8_MAX, UINT8_MAX}, |
| 219 | { 0, UINT8_MAX, UINT8_MAX, 0}, |
| 220 | { 0, UINT8_MAX, 0, UINT8_MAX}, |
| 221 | { 0, UINT8_MAX, 0, 0}, |
| 222 | { 0, 0, UINT8_MAX, UINT8_MAX}, |
| 223 | { 0, 0, UINT8_MAX, 0}, |
| 224 | { 0, 0, 0, UINT8_MAX}, |
| 225 | { 0, 0, 0, 0}, |
| 226 | }; |
| 227 | |
| 228 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 229 | Hwc2TestComposition::Hwc2TestComposition(Hwc2TestCoverage coverage) |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 230 | : Hwc2TestProperty(coverage, mCompleteCompositions, mBasicCompositions, |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 231 | mDefaultCompositions) { } |
| 232 | |
| 233 | std::string Hwc2TestComposition::dump() const |
| 234 | { |
| 235 | std::stringstream dmp; |
| 236 | dmp << "\tcomposition: " << getCompositionName(get()) << "\n"; |
| 237 | return dmp.str(); |
| 238 | } |
| 239 | |
| 240 | const std::vector<hwc2_composition_t> Hwc2TestComposition::mDefaultCompositions = { |
| 241 | HWC2_COMPOSITION_DEVICE, |
| 242 | }; |
| 243 | |
| 244 | const std::vector<hwc2_composition_t> Hwc2TestComposition::mBasicCompositions = { |
| 245 | HWC2_COMPOSITION_CLIENT, |
| 246 | HWC2_COMPOSITION_DEVICE, |
| 247 | }; |
| 248 | |
| 249 | const std::vector<hwc2_composition_t> Hwc2TestComposition::mCompleteCompositions = { |
| 250 | HWC2_COMPOSITION_CLIENT, |
| 251 | HWC2_COMPOSITION_DEVICE, |
| 252 | HWC2_COMPOSITION_SOLID_COLOR, |
| 253 | HWC2_COMPOSITION_CURSOR, |
| 254 | HWC2_COMPOSITION_SIDEBAND, |
| 255 | }; |
Marissa Wall | b72b5c9 | 2016-12-15 12:26:39 -0800 | [diff] [blame] | 256 | |
| 257 | |
| 258 | Hwc2TestDataspace::Hwc2TestDataspace(Hwc2TestCoverage coverage) |
| 259 | : Hwc2TestProperty(coverage, completeDataspaces, basicDataspaces, |
| 260 | defaultDataspaces) { } |
| 261 | |
| 262 | std::string Hwc2TestDataspace::dump() const |
| 263 | { |
| 264 | std::stringstream dmp; |
| 265 | dmp << "\tdataspace: " << get() << "\n"; |
| 266 | return dmp.str(); |
| 267 | } |
| 268 | |
| 269 | const std::vector<android_dataspace_t> Hwc2TestDataspace::defaultDataspaces = { |
| 270 | HAL_DATASPACE_UNKNOWN, |
| 271 | }; |
| 272 | |
| 273 | const std::vector<android_dataspace_t> Hwc2TestDataspace::basicDataspaces = { |
| 274 | HAL_DATASPACE_UNKNOWN, |
| 275 | HAL_DATASPACE_V0_SRGB, |
| 276 | }; |
| 277 | |
| 278 | const std::vector<android_dataspace_t> Hwc2TestDataspace::completeDataspaces = { |
| 279 | HAL_DATASPACE_UNKNOWN, |
| 280 | HAL_DATASPACE_ARBITRARY, |
| 281 | HAL_DATASPACE_STANDARD_SHIFT, |
| 282 | HAL_DATASPACE_STANDARD_MASK, |
| 283 | HAL_DATASPACE_STANDARD_UNSPECIFIED, |
| 284 | HAL_DATASPACE_STANDARD_BT709, |
| 285 | HAL_DATASPACE_STANDARD_BT601_625, |
| 286 | HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED, |
| 287 | HAL_DATASPACE_STANDARD_BT601_525, |
| 288 | HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED, |
| 289 | HAL_DATASPACE_STANDARD_BT2020, |
| 290 | HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE, |
| 291 | HAL_DATASPACE_STANDARD_BT470M, |
| 292 | HAL_DATASPACE_STANDARD_FILM, |
| 293 | HAL_DATASPACE_TRANSFER_SHIFT, |
| 294 | HAL_DATASPACE_TRANSFER_MASK, |
| 295 | HAL_DATASPACE_TRANSFER_UNSPECIFIED, |
| 296 | HAL_DATASPACE_TRANSFER_LINEAR, |
| 297 | HAL_DATASPACE_TRANSFER_SRGB, |
| 298 | HAL_DATASPACE_TRANSFER_SMPTE_170M, |
| 299 | HAL_DATASPACE_TRANSFER_GAMMA2_2, |
| 300 | HAL_DATASPACE_TRANSFER_GAMMA2_8, |
| 301 | HAL_DATASPACE_TRANSFER_ST2084, |
| 302 | HAL_DATASPACE_TRANSFER_HLG, |
| 303 | HAL_DATASPACE_RANGE_SHIFT, |
| 304 | HAL_DATASPACE_RANGE_MASK, |
| 305 | HAL_DATASPACE_RANGE_UNSPECIFIED, |
| 306 | HAL_DATASPACE_RANGE_FULL, |
| 307 | HAL_DATASPACE_RANGE_LIMITED, |
| 308 | HAL_DATASPACE_SRGB_LINEAR, |
| 309 | HAL_DATASPACE_V0_SRGB_LINEAR, |
| 310 | HAL_DATASPACE_SRGB, |
| 311 | HAL_DATASPACE_V0_SRGB, |
| 312 | HAL_DATASPACE_JFIF, |
| 313 | HAL_DATASPACE_V0_JFIF, |
| 314 | HAL_DATASPACE_BT601_625, |
| 315 | HAL_DATASPACE_V0_BT601_625, |
| 316 | HAL_DATASPACE_BT601_525, |
| 317 | HAL_DATASPACE_V0_BT601_525, |
| 318 | HAL_DATASPACE_BT709, |
| 319 | HAL_DATASPACE_V0_BT709, |
| 320 | HAL_DATASPACE_DEPTH, |
| 321 | }; |
Marissa Wall | 2b1f530 | 2016-12-15 12:27:20 -0800 | [diff] [blame] | 322 | |
| 323 | |
Marissa Wall | 600a73b | 2016-12-15 12:30:39 -0800 | [diff] [blame] | 324 | Hwc2TestDisplayFrame::Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, |
| 325 | const Area& displayArea) |
| 326 | : Hwc2TestProperty(mDisplayFrames), |
| 327 | mFrectScalars((coverage == Hwc2TestCoverage::Complete)? mCompleteFrectScalars: |
| 328 | (coverage == Hwc2TestCoverage::Basic)? mBasicFrectScalars: |
| 329 | mDefaultFrectScalars), |
| 330 | mDisplayArea(displayArea) |
| 331 | { |
| 332 | update(); |
| 333 | } |
| 334 | |
| 335 | std::string Hwc2TestDisplayFrame::dump() const |
| 336 | { |
| 337 | std::stringstream dmp; |
| 338 | const hwc_rect_t& displayFrame = get(); |
| 339 | dmp << "\tdisplay frame: left " << displayFrame.left << ", top " |
| 340 | << displayFrame.top << ", right " << displayFrame.right |
| 341 | << ", bottom " << displayFrame.bottom << "\n"; |
| 342 | return dmp.str(); |
| 343 | } |
| 344 | |
| 345 | void Hwc2TestDisplayFrame::update() |
| 346 | { |
| 347 | mDisplayFrames.clear(); |
| 348 | |
| 349 | if (mDisplayArea.width == 0 && mDisplayArea.height == 0) { |
| 350 | mDisplayFrames.push_back({0, 0, 0, 0}); |
| 351 | return; |
| 352 | } |
| 353 | |
| 354 | for (const auto& frectScalar : mFrectScalars) { |
| 355 | mDisplayFrames.push_back({ |
| 356 | static_cast<int>(frectScalar.left * mDisplayArea.width), |
| 357 | static_cast<int>(frectScalar.top * mDisplayArea.height), |
| 358 | static_cast<int>(frectScalar.right * mDisplayArea.width), |
| 359 | static_cast<int>(frectScalar.bottom * mDisplayArea.height)}); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | const std::vector<hwc_frect_t> Hwc2TestDisplayFrame::mDefaultFrectScalars = { |
| 364 | {0.0, 0.0, 1.0, 1.0}, |
| 365 | }; |
| 366 | |
| 367 | const std::vector<hwc_frect_t> Hwc2TestDisplayFrame::mBasicFrectScalars = { |
| 368 | {0.0, 0.0, 1.0, 1.0}, |
| 369 | {0.0, 0.0, 1.0, 0.05}, |
| 370 | {0.0, 0.95, 1.0, 1.0}, |
| 371 | }; |
| 372 | |
| 373 | const std::vector<hwc_frect_t> Hwc2TestDisplayFrame::mCompleteFrectScalars = { |
| 374 | {0.0, 0.0, 1.0, 1.0}, |
| 375 | {0.0, 0.05, 1.0, 0.95}, |
| 376 | {0.0, 0.05, 1.0, 1.0}, |
| 377 | {0.0, 0.0, 1.0, 0.05}, |
| 378 | {0.0, 0.95, 1.0, 1.0}, |
| 379 | {0.25, 0.0, 0.75, 0.35}, |
| 380 | {0.25, 0.25, 0.75, 0.75}, |
| 381 | }; |
| 382 | |
| 383 | |
Marissa Wall | 2b1f530 | 2016-12-15 12:27:20 -0800 | [diff] [blame] | 384 | Hwc2TestPlaneAlpha::Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage) |
| 385 | : Hwc2TestProperty(coverage, mCompletePlaneAlphas, mBasicPlaneAlphas, |
| 386 | mDefaultPlaneAlphas) { } |
| 387 | |
| 388 | std::string Hwc2TestPlaneAlpha::dump() const |
| 389 | { |
| 390 | std::stringstream dmp; |
| 391 | dmp << "\tplane alpha: " << get() << "\n"; |
| 392 | return dmp.str(); |
| 393 | } |
| 394 | |
| 395 | const std::vector<float> Hwc2TestPlaneAlpha::mDefaultPlaneAlphas = { |
| 396 | 1.0f, |
| 397 | }; |
| 398 | |
| 399 | const std::vector<float> Hwc2TestPlaneAlpha::mBasicPlaneAlphas = { |
| 400 | 1.0f, 0.0f, |
| 401 | }; |
| 402 | |
| 403 | const std::vector<float> Hwc2TestPlaneAlpha::mCompletePlaneAlphas = { |
| 404 | 1.0f, 0.75f, 0.5f, 0.25f, 0.0f, |
| 405 | }; |
Marissa Wall | ac10819 | 2016-12-15 12:27:48 -0800 | [diff] [blame] | 406 | |
| 407 | |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 408 | Hwc2TestSourceCrop::Hwc2TestSourceCrop(Hwc2TestCoverage coverage, |
| 409 | const Area& bufferArea) |
| 410 | : Hwc2TestProperty(mSourceCrops), |
| 411 | mFrectScalars((coverage == Hwc2TestCoverage::Complete)? mCompleteFrectScalars: |
| 412 | (coverage == Hwc2TestCoverage::Basic)? mBasicFrectScalars: |
| 413 | mDefaultFrectScalars), |
| 414 | mBufferArea(bufferArea) |
| 415 | { |
| 416 | update(); |
| 417 | } |
| 418 | |
| 419 | std::string Hwc2TestSourceCrop::dump() const |
| 420 | { |
| 421 | std::stringstream dmp; |
| 422 | const hwc_frect_t& sourceCrop = get(); |
| 423 | dmp << "\tsource crop: left " << sourceCrop.left << ", top " |
| 424 | << sourceCrop.top << ", right " << sourceCrop.right << ", bottom " |
| 425 | << sourceCrop.bottom << "\n"; |
| 426 | return dmp.str(); |
| 427 | } |
| 428 | |
| 429 | void Hwc2TestSourceCrop::updateBufferArea(const Area& bufferArea) |
| 430 | { |
| 431 | mBufferArea = bufferArea; |
| 432 | update(); |
| 433 | } |
| 434 | |
| 435 | void Hwc2TestSourceCrop::update() |
| 436 | { |
| 437 | mSourceCrops.clear(); |
| 438 | |
| 439 | if (mBufferArea.width == 0 && mBufferArea.height == 0) { |
| 440 | mSourceCrops.push_back({0, 0, 0, 0}); |
| 441 | return; |
| 442 | } |
| 443 | |
| 444 | for (const auto& frectScalar : mFrectScalars) { |
| 445 | mSourceCrops.push_back({ |
| 446 | frectScalar.left * mBufferArea.width, |
| 447 | frectScalar.top * mBufferArea.height, |
| 448 | frectScalar.right * mBufferArea.width, |
| 449 | frectScalar.bottom * mBufferArea.height}); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | const std::vector<hwc_frect_t> Hwc2TestSourceCrop::mDefaultFrectScalars = { |
| 454 | {0.0, 0.0, 1.0, 1.0}, |
| 455 | }; |
| 456 | |
| 457 | const std::vector<hwc_frect_t> Hwc2TestSourceCrop::mBasicFrectScalars = { |
| 458 | {0.0, 0.0, 1.0, 1.0}, |
| 459 | {0.0, 0.0, 0.5, 0.5}, |
| 460 | {0.5, 0.5, 1.0, 1.0}, |
| 461 | }; |
| 462 | |
| 463 | const std::vector<hwc_frect_t> Hwc2TestSourceCrop::mCompleteFrectScalars = { |
| 464 | {0.0, 0.0, 1.0, 1.0}, |
| 465 | {0.0, 0.0, 0.5, 0.5}, |
| 466 | {0.5, 0.5, 1.0, 1.0}, |
| 467 | {0.0, 0.0, 0.25, 0.25}, |
| 468 | {0.25, 0.25, 0.75, 0.75}, |
| 469 | }; |
| 470 | |
| 471 | |
Marissa Wall | ad76181 | 2016-12-15 12:32:24 -0800 | [diff] [blame] | 472 | Hwc2TestSurfaceDamage::Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage) |
| 473 | : Hwc2TestProperty(mSurfaceDamages), |
| 474 | mRegionScalars((coverage == Hwc2TestCoverage::Complete)? mCompleteRegionScalars: |
| 475 | (coverage == Hwc2TestCoverage::Basic)? mBasicRegionScalars: |
| 476 | mDefaultRegionScalars) |
| 477 | { |
| 478 | update(); |
| 479 | } |
| 480 | |
| 481 | Hwc2TestSurfaceDamage::~Hwc2TestSurfaceDamage() |
| 482 | { |
| 483 | freeSurfaceDamages(); |
| 484 | } |
| 485 | |
| 486 | std::string Hwc2TestSurfaceDamage::dump() const |
| 487 | { |
| 488 | std::stringstream dmp; |
| 489 | |
| 490 | const hwc_region_t& curr = get(); |
| 491 | dmp << "\tsurface damage: region count " << curr.numRects << "\n"; |
| 492 | for (size_t i = 0; i < curr.numRects; i++) { |
| 493 | const hwc_rect_t& rect = curr.rects[i]; |
| 494 | dmp << "\t\trect: left " << rect.left << ", top " << rect.top |
| 495 | << ", right " << rect.right << ", bottom " << rect.bottom << "\n"; |
| 496 | } |
| 497 | |
| 498 | return dmp.str(); |
| 499 | } |
| 500 | |
| 501 | void Hwc2TestSurfaceDamage::updateBufferArea(const Area& bufferArea) |
| 502 | { |
| 503 | mBufferArea = bufferArea; |
| 504 | update(); |
| 505 | } |
| 506 | |
| 507 | void Hwc2TestSurfaceDamage::update() |
| 508 | { |
| 509 | freeSurfaceDamages(); |
| 510 | |
| 511 | if (mBufferArea.width == 0 && mBufferArea.height == 0) { |
| 512 | mSurfaceDamages.push_back({0, nullptr}); |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | hwc_region_t damage; |
| 517 | |
| 518 | for (const auto& regionScalar : mRegionScalars) { |
| 519 | damage.numRects = regionScalar.size(); |
| 520 | |
| 521 | if (damage.numRects > 0) { |
| 522 | hwc_rect_t* rects = new hwc_rect_t[damage.numRects]; |
| 523 | if (!rects) { |
| 524 | ALOGW("failed to allocate new hwc_rect_t array"); |
| 525 | continue; |
| 526 | } |
| 527 | |
| 528 | for (size_t i = 0; i < damage.numRects; i++) { |
| 529 | rects[i].left = regionScalar[i].left * mBufferArea.width; |
| 530 | rects[i].top = regionScalar[i].top * mBufferArea.height; |
| 531 | rects[i].right = regionScalar[i].right * mBufferArea.width; |
| 532 | rects[i].bottom = regionScalar[i].bottom * mBufferArea.height; |
| 533 | } |
| 534 | |
| 535 | damage.rects = static_cast<hwc_rect_t const*>(rects); |
| 536 | } else { |
| 537 | damage.rects = nullptr; |
| 538 | } |
| 539 | |
| 540 | mSurfaceDamages.push_back(damage); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | void Hwc2TestSurfaceDamage::freeSurfaceDamages() |
| 545 | { |
| 546 | for (const auto& surfaceDamage : mSurfaceDamages) { |
| 547 | if (surfaceDamage.numRects > 0 && surfaceDamage.rects) |
| 548 | delete[] surfaceDamage.rects; |
| 549 | } |
| 550 | mSurfaceDamages.clear(); |
| 551 | } |
| 552 | |
| 553 | const std::vector<std::vector<hwc_frect_t>> Hwc2TestSurfaceDamage::mDefaultRegionScalars = { |
| 554 | {{}}, |
| 555 | }; |
| 556 | |
| 557 | const std::vector<std::vector<hwc_frect_t>> Hwc2TestSurfaceDamage::mBasicRegionScalars = { |
| 558 | {{}}, |
| 559 | {{0.0, 0.0, 1.0, 1.0}}, |
| 560 | }; |
| 561 | |
| 562 | const std::vector<std::vector<hwc_frect_t>> Hwc2TestSurfaceDamage::mCompleteRegionScalars = { |
| 563 | {{}}, |
| 564 | {{0.0, 0.0, 1.0, 1.0}}, |
| 565 | {{0.0, 0.0, 0.5, 0.5}, {0.5, 0.5, 1.0, 1.0}}, |
| 566 | }; |
| 567 | |
| 568 | |
Marissa Wall | ac10819 | 2016-12-15 12:27:48 -0800 | [diff] [blame] | 569 | Hwc2TestTransform::Hwc2TestTransform(Hwc2TestCoverage coverage) |
| 570 | : Hwc2TestProperty(coverage, mCompleteTransforms, mBasicTransforms, |
| 571 | mDefaultTransforms) { } |
| 572 | |
| 573 | std::string Hwc2TestTransform::dump() const |
| 574 | { |
| 575 | std::stringstream dmp; |
| 576 | dmp << "\ttransform: " << getTransformName(get()) << "\n"; |
| 577 | return dmp.str(); |
| 578 | } |
| 579 | |
| 580 | const std::vector<hwc_transform_t> Hwc2TestTransform::mDefaultTransforms = { |
| 581 | static_cast<hwc_transform_t>(0), |
| 582 | }; |
| 583 | |
| 584 | const std::vector<hwc_transform_t> Hwc2TestTransform::mBasicTransforms = { |
| 585 | static_cast<hwc_transform_t>(0), |
| 586 | HWC_TRANSFORM_FLIP_H, |
| 587 | HWC_TRANSFORM_FLIP_V, |
| 588 | HWC_TRANSFORM_ROT_90, |
| 589 | }; |
| 590 | |
| 591 | const std::vector<hwc_transform_t> Hwc2TestTransform::mCompleteTransforms = { |
| 592 | static_cast<hwc_transform_t>(0), |
| 593 | HWC_TRANSFORM_FLIP_H, |
| 594 | HWC_TRANSFORM_FLIP_V, |
| 595 | HWC_TRANSFORM_ROT_90, |
| 596 | HWC_TRANSFORM_ROT_180, |
| 597 | HWC_TRANSFORM_ROT_270, |
| 598 | HWC_TRANSFORM_FLIP_H_ROT_90, |
| 599 | HWC_TRANSFORM_FLIP_V_ROT_90, |
| 600 | }; |
Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame^] | 601 | |
| 602 | |
| 603 | Hwc2TestVisibleRegion::~Hwc2TestVisibleRegion() |
| 604 | { |
| 605 | release(); |
| 606 | } |
| 607 | |
| 608 | std::string Hwc2TestVisibleRegion::dump() const |
| 609 | { |
| 610 | std::stringstream dmp; |
| 611 | |
| 612 | const hwc_region_t& curr = get(); |
| 613 | dmp << "\tvisible region: region count " << curr.numRects << "\n"; |
| 614 | for (size_t i = 0; i < curr.numRects; i++) { |
| 615 | const hwc_rect_t& rect = curr.rects[i]; |
| 616 | dmp << "\t\trect: left " << rect.left << ", top " << rect.top |
| 617 | << ", right " << rect.right << ", bottom " << rect.bottom << "\n"; |
| 618 | } |
| 619 | |
| 620 | return dmp.str(); |
| 621 | } |
| 622 | |
| 623 | void Hwc2TestVisibleRegion::set(const android::Region& visibleRegion) |
| 624 | { |
| 625 | release(); |
| 626 | |
| 627 | size_t size = 0; |
| 628 | const android::Rect* rects = visibleRegion.getArray(&size); |
| 629 | |
| 630 | mVisibleRegion.numRects = size; |
| 631 | mVisibleRegion.rects = nullptr; |
| 632 | |
| 633 | if (size > 0) { |
| 634 | hwc_rect_t* hwcRects = new hwc_rect_t[size]; |
| 635 | for (size_t i = 0; i < size; i++) { |
| 636 | hwcRects[i].left = rects[i].left; |
| 637 | hwcRects[i].top = rects[i].top; |
| 638 | hwcRects[i].right = rects[i].right; |
| 639 | hwcRects[i].bottom = rects[i].bottom; |
| 640 | } |
| 641 | mVisibleRegion.rects = hwcRects; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | hwc_region_t Hwc2TestVisibleRegion::get() const |
| 646 | { |
| 647 | return mVisibleRegion; |
| 648 | } |
| 649 | |
| 650 | void Hwc2TestVisibleRegion::release() |
| 651 | { |
| 652 | if (mVisibleRegion.numRects > 0 && mVisibleRegion.rects) |
| 653 | delete[] mVisibleRegion.rects; |
| 654 | mVisibleRegion.rects = nullptr; |
| 655 | mVisibleRegion.numRects = 0; |
| 656 | } |