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 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 21 | #include <sstream> |
Marissa Wall | ad76181 | 2016-12-15 12:32:24 -0800 | [diff] [blame] | 22 | #include <cutils/log.h> |
Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame] | 23 | #include <ui/Rect.h> |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 24 | |
Marissa Wall | 5a240aa | 2016-12-15 12:34:06 -0800 | [diff] [blame] | 25 | #define HWC2_INCLUDE_STRINGIFICATION |
| 26 | #define HWC2_USE_CPP11 |
| 27 | #include <hardware/hwcomposer2.h> |
| 28 | #undef HWC2_INCLUDE_STRINGIFICATION |
| 29 | #undef HWC2_USE_CPP11 |
| 30 | |
| 31 | #include "Hwc2TestBuffer.h" |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 32 | #include "Hwc2TestProperties.h" |
| 33 | |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 34 | Hwc2TestBufferArea::Hwc2TestBufferArea(Hwc2TestCoverage coverage, |
| 35 | const Area& displayArea) |
Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 36 | : Hwc2TestProperty(mBufferAreas, mCompositionSupport), |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 37 | mScalars((coverage == Hwc2TestCoverage::Complete)? mCompleteScalars: |
| 38 | (coverage == Hwc2TestCoverage::Basic)? mBasicScalars: |
| 39 | mDefaultScalars), |
| 40 | mDisplayArea(displayArea) |
| 41 | { |
| 42 | update(); |
| 43 | } |
| 44 | |
| 45 | std::string Hwc2TestBufferArea::dump() const |
| 46 | { |
| 47 | std::stringstream dmp; |
| 48 | const Area& curr = get(); |
| 49 | dmp << "\tbuffer area: width " << curr.width << ", height " << curr.height |
| 50 | << "\n"; |
| 51 | return dmp.str(); |
| 52 | } |
| 53 | |
Marissa Wall | 5a240aa | 2016-12-15 12:34:06 -0800 | [diff] [blame] | 54 | void Hwc2TestBufferArea::setDependent(Hwc2TestBuffer* buffer) |
| 55 | { |
| 56 | mBuffer = buffer; |
| 57 | if (buffer) { |
| 58 | buffer->updateBufferArea(get()); |
| 59 | } |
| 60 | } |
| 61 | |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 62 | void Hwc2TestBufferArea::setDependent(Hwc2TestSourceCrop* sourceCrop) |
| 63 | { |
| 64 | mSourceCrop = sourceCrop; |
Marissa Wall | ad76181 | 2016-12-15 12:32:24 -0800 | [diff] [blame] | 65 | if (mSourceCrop) { |
| 66 | mSourceCrop->updateBufferArea(get()); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | void Hwc2TestBufferArea::setDependent(Hwc2TestSurfaceDamage* surfaceDamage) |
| 71 | { |
| 72 | mSurfaceDamage = surfaceDamage; |
| 73 | if (mSurfaceDamage) { |
| 74 | mSurfaceDamage->updateBufferArea(get()); |
| 75 | } |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void Hwc2TestBufferArea::update() |
| 79 | { |
| 80 | mBufferAreas.clear(); |
| 81 | |
| 82 | if (mDisplayArea.width == 0 && mDisplayArea.height == 0) { |
| 83 | mBufferAreas.push_back({0, 0}); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | for (auto scalar : mScalars) { |
| 88 | mBufferAreas.push_back({static_cast<int32_t>(scalar * mDisplayArea.width), |
| 89 | static_cast<int32_t>(scalar * mDisplayArea.height)}); |
| 90 | } |
| 91 | |
| 92 | updateDependents(); |
| 93 | } |
| 94 | |
| 95 | void Hwc2TestBufferArea::updateDependents() |
| 96 | { |
| 97 | const Area& curr = get(); |
| 98 | |
Marissa Wall | 5a240aa | 2016-12-15 12:34:06 -0800 | [diff] [blame] | 99 | if (mBuffer) |
| 100 | mBuffer->updateBufferArea(curr); |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 101 | if (mSourceCrop) |
| 102 | mSourceCrop->updateBufferArea(curr); |
Marissa Wall | ad76181 | 2016-12-15 12:32:24 -0800 | [diff] [blame] | 103 | if (mSurfaceDamage) |
| 104 | mSurfaceDamage->updateBufferArea(curr); |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | const std::vector<float> Hwc2TestBufferArea::mDefaultScalars = { |
| 108 | 1.0f, |
| 109 | }; |
| 110 | |
| 111 | const std::vector<float> Hwc2TestBufferArea::mBasicScalars = { |
| 112 | 1.0f, 0.5f, |
| 113 | }; |
| 114 | |
| 115 | const std::vector<float> Hwc2TestBufferArea::mCompleteScalars = { |
| 116 | 1.0f, 0.75f, 0.5f |
| 117 | }; |
| 118 | |
| 119 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 120 | Hwc2TestBlendMode::Hwc2TestBlendMode(Hwc2TestCoverage coverage) |
| 121 | : Hwc2TestProperty(coverage, mCompleteBlendModes, mBasicBlendModes, |
Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 122 | mDefaultBlendModes, mCompositionSupport) { } |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 123 | |
| 124 | std::string Hwc2TestBlendMode::dump() const |
| 125 | { |
| 126 | std::stringstream dmp; |
| 127 | dmp << "\tblend mode: " << getBlendModeName(get()) << "\n"; |
| 128 | return dmp.str(); |
| 129 | } |
| 130 | |
Marissa Wall | ee24278 | 2016-12-15 12:30:12 -0800 | [diff] [blame] | 131 | void Hwc2TestBlendMode::setDependent(Hwc2TestColor* color) |
| 132 | { |
| 133 | mColor = color; |
| 134 | updateDependents(); |
| 135 | } |
| 136 | |
| 137 | void Hwc2TestBlendMode::updateDependents() |
| 138 | { |
| 139 | if (mColor) |
| 140 | mColor->updateBlendMode(get()); |
| 141 | } |
| 142 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 143 | const std::vector<hwc2_blend_mode_t> Hwc2TestBlendMode::mDefaultBlendModes = { |
| 144 | HWC2_BLEND_MODE_NONE, |
| 145 | }; |
| 146 | |
| 147 | const std::vector<hwc2_blend_mode_t> Hwc2TestBlendMode::mBasicBlendModes = { |
| 148 | HWC2_BLEND_MODE_NONE, |
| 149 | HWC2_BLEND_MODE_PREMULTIPLIED, |
| 150 | }; |
| 151 | |
| 152 | const std::vector<hwc2_blend_mode_t> Hwc2TestBlendMode::mCompleteBlendModes = { |
| 153 | HWC2_BLEND_MODE_NONE, |
| 154 | HWC2_BLEND_MODE_PREMULTIPLIED, |
| 155 | HWC2_BLEND_MODE_COVERAGE, |
| 156 | }; |
| 157 | |
| 158 | |
Marissa Wall | ee24278 | 2016-12-15 12:30:12 -0800 | [diff] [blame] | 159 | Hwc2TestColor::Hwc2TestColor(Hwc2TestCoverage coverage, |
| 160 | hwc2_blend_mode_t blendMode) |
Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 161 | : Hwc2TestProperty(mColors, mCompositionSupport), |
Marissa Wall | ee24278 | 2016-12-15 12:30:12 -0800 | [diff] [blame] | 162 | mBaseColors((coverage == Hwc2TestCoverage::Complete)? mCompleteBaseColors: |
| 163 | (coverage == Hwc2TestCoverage::Basic)? mBasicBaseColors: |
| 164 | mDefaultBaseColors), |
| 165 | mBlendMode(blendMode) |
| 166 | { |
| 167 | update(); |
| 168 | } |
| 169 | |
| 170 | std::string Hwc2TestColor::dump() const |
| 171 | { |
| 172 | std::stringstream dmp; |
| 173 | const hwc_color_t& color = get(); |
| 174 | dmp << "\tcolor: r " << std::to_string(color.r) << ", g " |
| 175 | << std::to_string(color.g) << ", b " << std::to_string(color.b) |
| 176 | << ", a " << std::to_string(color.a) << "\n"; |
| 177 | return dmp.str(); |
| 178 | } |
| 179 | |
| 180 | void Hwc2TestColor::updateBlendMode(hwc2_blend_mode_t blendMode) |
| 181 | { |
| 182 | mBlendMode = blendMode; |
| 183 | update(); |
| 184 | } |
| 185 | |
| 186 | void Hwc2TestColor::update() |
| 187 | { |
| 188 | if (mBlendMode != HWC2_BLEND_MODE_PREMULTIPLIED) { |
| 189 | mColors = mBaseColors; |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | mColors.clear(); |
| 194 | |
| 195 | for (const hwc_color_t& baseColor : mBaseColors) { |
| 196 | if (baseColor.a >= baseColor.r && baseColor.a >= baseColor.g |
| 197 | && baseColor.a >= baseColor.b) { |
| 198 | mColors.push_back(baseColor); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | } |
| 203 | |
| 204 | const std::vector<hwc_color_t> Hwc2TestColor::mDefaultBaseColors = { |
| 205 | {UINT8_MAX, UINT8_MAX, UINT8_MAX, UINT8_MAX}, |
| 206 | }; |
| 207 | |
| 208 | const std::vector<hwc_color_t> Hwc2TestColor::mBasicBaseColors = { |
| 209 | {UINT8_MAX, UINT8_MAX, UINT8_MAX, UINT8_MAX}, |
| 210 | { 0, 0, 0, 0}, |
| 211 | }; |
| 212 | |
| 213 | const std::vector<hwc_color_t> Hwc2TestColor::mCompleteBaseColors = { |
| 214 | {UINT8_MAX, UINT8_MAX, UINT8_MAX, UINT8_MAX}, |
| 215 | {UINT8_MAX, UINT8_MAX, UINT8_MAX, 0}, |
| 216 | {UINT8_MAX, UINT8_MAX, 0, UINT8_MAX}, |
| 217 | {UINT8_MAX, UINT8_MAX, 0, 0}, |
| 218 | {UINT8_MAX, 0, UINT8_MAX, UINT8_MAX}, |
| 219 | {UINT8_MAX, 0, UINT8_MAX, 0}, |
| 220 | {UINT8_MAX, 0, 0, UINT8_MAX}, |
| 221 | {UINT8_MAX, 0, 0, 0}, |
| 222 | { 0, UINT8_MAX, UINT8_MAX, UINT8_MAX}, |
| 223 | { 0, UINT8_MAX, UINT8_MAX, 0}, |
| 224 | { 0, UINT8_MAX, 0, UINT8_MAX}, |
| 225 | { 0, UINT8_MAX, 0, 0}, |
| 226 | { 0, 0, UINT8_MAX, UINT8_MAX}, |
| 227 | { 0, 0, UINT8_MAX, 0}, |
| 228 | { 0, 0, 0, UINT8_MAX}, |
| 229 | { 0, 0, 0, 0}, |
| 230 | }; |
| 231 | |
| 232 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 233 | Hwc2TestComposition::Hwc2TestComposition(Hwc2TestCoverage coverage) |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 234 | : Hwc2TestProperty(coverage, mCompleteCompositions, mBasicCompositions, |
Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 235 | mDefaultCompositions, mCompositionSupport) { } |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 236 | |
| 237 | std::string Hwc2TestComposition::dump() const |
| 238 | { |
| 239 | std::stringstream dmp; |
| 240 | dmp << "\tcomposition: " << getCompositionName(get()) << "\n"; |
| 241 | return dmp.str(); |
| 242 | } |
| 243 | |
| 244 | const std::vector<hwc2_composition_t> Hwc2TestComposition::mDefaultCompositions = { |
| 245 | HWC2_COMPOSITION_DEVICE, |
| 246 | }; |
| 247 | |
| 248 | const std::vector<hwc2_composition_t> Hwc2TestComposition::mBasicCompositions = { |
| 249 | HWC2_COMPOSITION_CLIENT, |
| 250 | HWC2_COMPOSITION_DEVICE, |
| 251 | }; |
| 252 | |
| 253 | const std::vector<hwc2_composition_t> Hwc2TestComposition::mCompleteCompositions = { |
| 254 | HWC2_COMPOSITION_CLIENT, |
| 255 | HWC2_COMPOSITION_DEVICE, |
| 256 | HWC2_COMPOSITION_SOLID_COLOR, |
| 257 | HWC2_COMPOSITION_CURSOR, |
| 258 | HWC2_COMPOSITION_SIDEBAND, |
| 259 | }; |
Marissa Wall | b72b5c9 | 2016-12-15 12:26:39 -0800 | [diff] [blame] | 260 | |
| 261 | |
| 262 | Hwc2TestDataspace::Hwc2TestDataspace(Hwc2TestCoverage coverage) |
| 263 | : Hwc2TestProperty(coverage, completeDataspaces, basicDataspaces, |
Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 264 | defaultDataspaces, mCompositionSupport) { } |
Marissa Wall | b72b5c9 | 2016-12-15 12:26:39 -0800 | [diff] [blame] | 265 | |
| 266 | std::string Hwc2TestDataspace::dump() const |
| 267 | { |
| 268 | std::stringstream dmp; |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 269 | dmp << "\tdataspace: " << static_cast<int32_t>(get()) << "\n"; |
Marissa Wall | b72b5c9 | 2016-12-15 12:26:39 -0800 | [diff] [blame] | 270 | return dmp.str(); |
| 271 | } |
| 272 | |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 273 | const std::vector<android::ui::Dataspace> Hwc2TestDataspace::defaultDataspaces = { |
| 274 | android::ui::Dataspace::UNKNOWN, |
Marissa Wall | b72b5c9 | 2016-12-15 12:26:39 -0800 | [diff] [blame] | 275 | }; |
| 276 | |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 277 | const std::vector<android::ui::Dataspace> Hwc2TestDataspace::basicDataspaces = { |
| 278 | android::ui::Dataspace::UNKNOWN, |
| 279 | android::ui::Dataspace::V0_SRGB, |
Marissa Wall | b72b5c9 | 2016-12-15 12:26:39 -0800 | [diff] [blame] | 280 | }; |
| 281 | |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 282 | const std::vector<android::ui::Dataspace> Hwc2TestDataspace::completeDataspaces = { |
| 283 | android::ui::Dataspace::UNKNOWN, |
| 284 | android::ui::Dataspace::ARBITRARY, |
| 285 | android::ui::Dataspace::STANDARD_SHIFT, |
| 286 | android::ui::Dataspace::STANDARD_MASK, |
| 287 | android::ui::Dataspace::STANDARD_UNSPECIFIED, |
| 288 | android::ui::Dataspace::STANDARD_BT709, |
| 289 | android::ui::Dataspace::STANDARD_BT601_625, |
| 290 | android::ui::Dataspace::STANDARD_BT601_625_UNADJUSTED, |
| 291 | android::ui::Dataspace::STANDARD_BT601_525, |
| 292 | android::ui::Dataspace::STANDARD_BT601_525_UNADJUSTED, |
| 293 | android::ui::Dataspace::STANDARD_BT2020, |
| 294 | android::ui::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE, |
| 295 | android::ui::Dataspace::STANDARD_BT470M, |
| 296 | android::ui::Dataspace::STANDARD_FILM, |
| 297 | android::ui::Dataspace::TRANSFER_SHIFT, |
| 298 | android::ui::Dataspace::TRANSFER_MASK, |
| 299 | android::ui::Dataspace::TRANSFER_UNSPECIFIED, |
| 300 | android::ui::Dataspace::TRANSFER_LINEAR, |
| 301 | android::ui::Dataspace::TRANSFER_SRGB, |
| 302 | android::ui::Dataspace::TRANSFER_SMPTE_170M, |
| 303 | android::ui::Dataspace::TRANSFER_GAMMA2_2, |
| 304 | android::ui::Dataspace::TRANSFER_GAMMA2_8, |
| 305 | android::ui::Dataspace::TRANSFER_ST2084, |
| 306 | android::ui::Dataspace::TRANSFER_HLG, |
| 307 | android::ui::Dataspace::RANGE_SHIFT, |
| 308 | android::ui::Dataspace::RANGE_MASK, |
| 309 | android::ui::Dataspace::RANGE_UNSPECIFIED, |
| 310 | android::ui::Dataspace::RANGE_FULL, |
| 311 | android::ui::Dataspace::RANGE_LIMITED, |
| 312 | android::ui::Dataspace::SRGB_LINEAR, |
| 313 | android::ui::Dataspace::V0_SRGB_LINEAR, |
| 314 | android::ui::Dataspace::SRGB, |
| 315 | android::ui::Dataspace::V0_SRGB, |
| 316 | android::ui::Dataspace::JFIF, |
| 317 | android::ui::Dataspace::V0_JFIF, |
| 318 | android::ui::Dataspace::BT601_625, |
| 319 | android::ui::Dataspace::V0_BT601_625, |
| 320 | android::ui::Dataspace::BT601_525, |
| 321 | android::ui::Dataspace::V0_BT601_525, |
| 322 | android::ui::Dataspace::BT709, |
| 323 | android::ui::Dataspace::V0_BT709, |
| 324 | android::ui::Dataspace::DEPTH, |
Marissa Wall | b72b5c9 | 2016-12-15 12:26:39 -0800 | [diff] [blame] | 325 | }; |
Marissa Wall | 2b1f530 | 2016-12-15 12:27:20 -0800 | [diff] [blame] | 326 | |
| 327 | |
Marissa Wall | bad1bc7 | 2017-02-21 14:33:46 -0800 | [diff] [blame] | 328 | Hwc2TestDisplayDimension::Hwc2TestDisplayDimension(Hwc2TestCoverage coverage) |
| 329 | : Hwc2TestProperty( |
| 330 | (coverage == Hwc2TestCoverage::Complete)? mCompleteDisplayDimensions: |
| 331 | (coverage == Hwc2TestCoverage::Basic)? mBasicDisplayDimensions: |
| 332 | mDefaultDisplayDimensions, mCompositionSupport) { } |
| 333 | |
| 334 | std::string Hwc2TestDisplayDimension::dump() const |
| 335 | { |
| 336 | std::stringstream dmp; |
| 337 | const UnsignedArea& curr = get(); |
| 338 | dmp << "\tdisplay dimension: " << curr.width<< " x " << curr.height<< "\n"; |
| 339 | return dmp.str(); |
| 340 | } |
| 341 | |
David Hanna Jr | 3f05602 | 2017-07-27 19:19:15 -0700 | [diff] [blame] | 342 | void Hwc2TestDisplayDimension::setDependent(Hwc2TestVirtualBuffer* buffer) |
Marissa Wall | bad1bc7 | 2017-02-21 14:33:46 -0800 | [diff] [blame] | 343 | { |
David Hanna Jr | 3f05602 | 2017-07-27 19:19:15 -0700 | [diff] [blame] | 344 | mBuffers.insert(buffer); |
Marissa Wall | bad1bc7 | 2017-02-21 14:33:46 -0800 | [diff] [blame] | 345 | updateDependents(); |
| 346 | } |
| 347 | |
| 348 | void Hwc2TestDisplayDimension::updateDependents() |
| 349 | { |
| 350 | const UnsignedArea& curr = get(); |
| 351 | |
David Hanna Jr | 3f05602 | 2017-07-27 19:19:15 -0700 | [diff] [blame] | 352 | for (Hwc2TestVirtualBuffer* buffer : mBuffers) |
| 353 | buffer->updateBufferArea({static_cast<int32_t>(curr.width), |
Marissa Wall | bad1bc7 | 2017-02-21 14:33:46 -0800 | [diff] [blame] | 354 | static_cast<int32_t>(curr.height)}); |
| 355 | } |
| 356 | |
| 357 | const std::vector<UnsignedArea> |
| 358 | Hwc2TestDisplayDimension::mDefaultDisplayDimensions = { |
| 359 | {1920, 1080}, |
| 360 | }; |
| 361 | |
| 362 | const std::vector<UnsignedArea> |
| 363 | Hwc2TestDisplayDimension::mBasicDisplayDimensions = { |
| 364 | {640, 480}, |
| 365 | {1280, 720}, |
| 366 | {1920, 1080}, |
| 367 | {1920, 1200}, |
| 368 | }; |
| 369 | |
| 370 | const std::vector<UnsignedArea> |
| 371 | Hwc2TestDisplayDimension::mCompleteDisplayDimensions = { |
| 372 | {320, 240}, |
| 373 | {480, 320}, |
| 374 | {640, 480}, |
| 375 | {1280, 720}, |
| 376 | {1920, 1080}, |
| 377 | {1920, 1200}, |
| 378 | {2560, 1440}, |
| 379 | {2560, 1600}, |
| 380 | {3840, 2160}, |
| 381 | {4096, 2160}, |
| 382 | }; |
| 383 | |
| 384 | |
Marissa Wall | 600a73b | 2016-12-15 12:30:39 -0800 | [diff] [blame] | 385 | Hwc2TestDisplayFrame::Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, |
| 386 | const Area& displayArea) |
Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 387 | : Hwc2TestProperty(mDisplayFrames, mCompositionSupport), |
Marissa Wall | 600a73b | 2016-12-15 12:30:39 -0800 | [diff] [blame] | 388 | mFrectScalars((coverage == Hwc2TestCoverage::Complete)? mCompleteFrectScalars: |
| 389 | (coverage == Hwc2TestCoverage::Basic)? mBasicFrectScalars: |
| 390 | mDefaultFrectScalars), |
| 391 | mDisplayArea(displayArea) |
| 392 | { |
| 393 | update(); |
| 394 | } |
| 395 | |
| 396 | std::string Hwc2TestDisplayFrame::dump() const |
| 397 | { |
| 398 | std::stringstream dmp; |
| 399 | const hwc_rect_t& displayFrame = get(); |
| 400 | dmp << "\tdisplay frame: left " << displayFrame.left << ", top " |
| 401 | << displayFrame.top << ", right " << displayFrame.right |
| 402 | << ", bottom " << displayFrame.bottom << "\n"; |
| 403 | return dmp.str(); |
| 404 | } |
| 405 | |
| 406 | void Hwc2TestDisplayFrame::update() |
| 407 | { |
| 408 | mDisplayFrames.clear(); |
| 409 | |
| 410 | if (mDisplayArea.width == 0 && mDisplayArea.height == 0) { |
| 411 | mDisplayFrames.push_back({0, 0, 0, 0}); |
| 412 | return; |
| 413 | } |
| 414 | |
| 415 | for (const auto& frectScalar : mFrectScalars) { |
| 416 | mDisplayFrames.push_back({ |
| 417 | static_cast<int>(frectScalar.left * mDisplayArea.width), |
| 418 | static_cast<int>(frectScalar.top * mDisplayArea.height), |
| 419 | static_cast<int>(frectScalar.right * mDisplayArea.width), |
| 420 | static_cast<int>(frectScalar.bottom * mDisplayArea.height)}); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | const std::vector<hwc_frect_t> Hwc2TestDisplayFrame::mDefaultFrectScalars = { |
| 425 | {0.0, 0.0, 1.0, 1.0}, |
| 426 | }; |
| 427 | |
| 428 | const std::vector<hwc_frect_t> Hwc2TestDisplayFrame::mBasicFrectScalars = { |
| 429 | {0.0, 0.0, 1.0, 1.0}, |
| 430 | {0.0, 0.0, 1.0, 0.05}, |
| 431 | {0.0, 0.95, 1.0, 1.0}, |
| 432 | }; |
| 433 | |
| 434 | const std::vector<hwc_frect_t> Hwc2TestDisplayFrame::mCompleteFrectScalars = { |
| 435 | {0.0, 0.0, 1.0, 1.0}, |
| 436 | {0.0, 0.05, 1.0, 0.95}, |
| 437 | {0.0, 0.05, 1.0, 1.0}, |
| 438 | {0.0, 0.0, 1.0, 0.05}, |
| 439 | {0.0, 0.95, 1.0, 1.0}, |
| 440 | {0.25, 0.0, 0.75, 0.35}, |
| 441 | {0.25, 0.25, 0.75, 0.75}, |
| 442 | }; |
| 443 | |
| 444 | |
Marissa Wall | 2b1f530 | 2016-12-15 12:27:20 -0800 | [diff] [blame] | 445 | Hwc2TestPlaneAlpha::Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage) |
| 446 | : Hwc2TestProperty(coverage, mCompletePlaneAlphas, mBasicPlaneAlphas, |
Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 447 | mDefaultPlaneAlphas, mCompositionSupport) { } |
Marissa Wall | 2b1f530 | 2016-12-15 12:27:20 -0800 | [diff] [blame] | 448 | |
| 449 | std::string Hwc2TestPlaneAlpha::dump() const |
| 450 | { |
| 451 | std::stringstream dmp; |
| 452 | dmp << "\tplane alpha: " << get() << "\n"; |
| 453 | return dmp.str(); |
| 454 | } |
| 455 | |
| 456 | const std::vector<float> Hwc2TestPlaneAlpha::mDefaultPlaneAlphas = { |
| 457 | 1.0f, |
| 458 | }; |
| 459 | |
| 460 | const std::vector<float> Hwc2TestPlaneAlpha::mBasicPlaneAlphas = { |
| 461 | 1.0f, 0.0f, |
| 462 | }; |
| 463 | |
| 464 | const std::vector<float> Hwc2TestPlaneAlpha::mCompletePlaneAlphas = { |
| 465 | 1.0f, 0.75f, 0.5f, 0.25f, 0.0f, |
| 466 | }; |
Marissa Wall | ac10819 | 2016-12-15 12:27:48 -0800 | [diff] [blame] | 467 | |
| 468 | |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 469 | Hwc2TestSourceCrop::Hwc2TestSourceCrop(Hwc2TestCoverage coverage, |
| 470 | const Area& bufferArea) |
Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 471 | : Hwc2TestProperty(mSourceCrops, mCompositionSupport), |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 472 | mFrectScalars((coverage == Hwc2TestCoverage::Complete)? mCompleteFrectScalars: |
| 473 | (coverage == Hwc2TestCoverage::Basic)? mBasicFrectScalars: |
| 474 | mDefaultFrectScalars), |
| 475 | mBufferArea(bufferArea) |
| 476 | { |
| 477 | update(); |
| 478 | } |
| 479 | |
| 480 | std::string Hwc2TestSourceCrop::dump() const |
| 481 | { |
| 482 | std::stringstream dmp; |
| 483 | const hwc_frect_t& sourceCrop = get(); |
| 484 | dmp << "\tsource crop: left " << sourceCrop.left << ", top " |
| 485 | << sourceCrop.top << ", right " << sourceCrop.right << ", bottom " |
| 486 | << sourceCrop.bottom << "\n"; |
| 487 | return dmp.str(); |
| 488 | } |
| 489 | |
| 490 | void Hwc2TestSourceCrop::updateBufferArea(const Area& bufferArea) |
| 491 | { |
| 492 | mBufferArea = bufferArea; |
| 493 | update(); |
| 494 | } |
| 495 | |
| 496 | void Hwc2TestSourceCrop::update() |
| 497 | { |
| 498 | mSourceCrops.clear(); |
| 499 | |
| 500 | if (mBufferArea.width == 0 && mBufferArea.height == 0) { |
| 501 | mSourceCrops.push_back({0, 0, 0, 0}); |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | for (const auto& frectScalar : mFrectScalars) { |
| 506 | mSourceCrops.push_back({ |
| 507 | frectScalar.left * mBufferArea.width, |
| 508 | frectScalar.top * mBufferArea.height, |
| 509 | frectScalar.right * mBufferArea.width, |
| 510 | frectScalar.bottom * mBufferArea.height}); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | const std::vector<hwc_frect_t> Hwc2TestSourceCrop::mDefaultFrectScalars = { |
| 515 | {0.0, 0.0, 1.0, 1.0}, |
| 516 | }; |
| 517 | |
| 518 | const std::vector<hwc_frect_t> Hwc2TestSourceCrop::mBasicFrectScalars = { |
| 519 | {0.0, 0.0, 1.0, 1.0}, |
| 520 | {0.0, 0.0, 0.5, 0.5}, |
| 521 | {0.5, 0.5, 1.0, 1.0}, |
| 522 | }; |
| 523 | |
| 524 | const std::vector<hwc_frect_t> Hwc2TestSourceCrop::mCompleteFrectScalars = { |
| 525 | {0.0, 0.0, 1.0, 1.0}, |
| 526 | {0.0, 0.0, 0.5, 0.5}, |
| 527 | {0.5, 0.5, 1.0, 1.0}, |
| 528 | {0.0, 0.0, 0.25, 0.25}, |
| 529 | {0.25, 0.25, 0.75, 0.75}, |
| 530 | }; |
| 531 | |
| 532 | |
Marissa Wall | ad76181 | 2016-12-15 12:32:24 -0800 | [diff] [blame] | 533 | Hwc2TestSurfaceDamage::Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage) |
Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 534 | : Hwc2TestProperty(mSurfaceDamages, mCompositionSupport), |
Marissa Wall | ad76181 | 2016-12-15 12:32:24 -0800 | [diff] [blame] | 535 | mRegionScalars((coverage == Hwc2TestCoverage::Complete)? mCompleteRegionScalars: |
| 536 | (coverage == Hwc2TestCoverage::Basic)? mBasicRegionScalars: |
| 537 | mDefaultRegionScalars) |
| 538 | { |
| 539 | update(); |
| 540 | } |
| 541 | |
| 542 | Hwc2TestSurfaceDamage::~Hwc2TestSurfaceDamage() |
| 543 | { |
| 544 | freeSurfaceDamages(); |
| 545 | } |
| 546 | |
| 547 | std::string Hwc2TestSurfaceDamage::dump() const |
| 548 | { |
| 549 | std::stringstream dmp; |
| 550 | |
| 551 | const hwc_region_t& curr = get(); |
| 552 | dmp << "\tsurface damage: region count " << curr.numRects << "\n"; |
| 553 | for (size_t i = 0; i < curr.numRects; i++) { |
| 554 | const hwc_rect_t& rect = curr.rects[i]; |
| 555 | dmp << "\t\trect: left " << rect.left << ", top " << rect.top |
| 556 | << ", right " << rect.right << ", bottom " << rect.bottom << "\n"; |
| 557 | } |
| 558 | |
| 559 | return dmp.str(); |
| 560 | } |
| 561 | |
| 562 | void Hwc2TestSurfaceDamage::updateBufferArea(const Area& bufferArea) |
| 563 | { |
| 564 | mBufferArea = bufferArea; |
| 565 | update(); |
| 566 | } |
| 567 | |
| 568 | void Hwc2TestSurfaceDamage::update() |
| 569 | { |
| 570 | freeSurfaceDamages(); |
| 571 | |
| 572 | if (mBufferArea.width == 0 && mBufferArea.height == 0) { |
| 573 | mSurfaceDamages.push_back({0, nullptr}); |
| 574 | return; |
| 575 | } |
| 576 | |
| 577 | hwc_region_t damage; |
| 578 | |
| 579 | for (const auto& regionScalar : mRegionScalars) { |
| 580 | damage.numRects = regionScalar.size(); |
| 581 | |
| 582 | if (damage.numRects > 0) { |
| 583 | hwc_rect_t* rects = new hwc_rect_t[damage.numRects]; |
| 584 | if (!rects) { |
| 585 | ALOGW("failed to allocate new hwc_rect_t array"); |
| 586 | continue; |
| 587 | } |
| 588 | |
| 589 | for (size_t i = 0; i < damage.numRects; i++) { |
| 590 | rects[i].left = regionScalar[i].left * mBufferArea.width; |
| 591 | rects[i].top = regionScalar[i].top * mBufferArea.height; |
| 592 | rects[i].right = regionScalar[i].right * mBufferArea.width; |
| 593 | rects[i].bottom = regionScalar[i].bottom * mBufferArea.height; |
| 594 | } |
| 595 | |
| 596 | damage.rects = static_cast<hwc_rect_t const*>(rects); |
| 597 | } else { |
| 598 | damage.rects = nullptr; |
| 599 | } |
| 600 | |
| 601 | mSurfaceDamages.push_back(damage); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | void Hwc2TestSurfaceDamage::freeSurfaceDamages() |
| 606 | { |
| 607 | for (const auto& surfaceDamage : mSurfaceDamages) { |
| 608 | if (surfaceDamage.numRects > 0 && surfaceDamage.rects) |
| 609 | delete[] surfaceDamage.rects; |
| 610 | } |
| 611 | mSurfaceDamages.clear(); |
| 612 | } |
| 613 | |
| 614 | const std::vector<std::vector<hwc_frect_t>> Hwc2TestSurfaceDamage::mDefaultRegionScalars = { |
| 615 | {{}}, |
| 616 | }; |
| 617 | |
| 618 | const std::vector<std::vector<hwc_frect_t>> Hwc2TestSurfaceDamage::mBasicRegionScalars = { |
| 619 | {{}}, |
| 620 | {{0.0, 0.0, 1.0, 1.0}}, |
| 621 | }; |
| 622 | |
| 623 | const std::vector<std::vector<hwc_frect_t>> Hwc2TestSurfaceDamage::mCompleteRegionScalars = { |
| 624 | {{}}, |
| 625 | {{0.0, 0.0, 1.0, 1.0}}, |
| 626 | {{0.0, 0.0, 0.5, 0.5}, {0.5, 0.5, 1.0, 1.0}}, |
| 627 | }; |
| 628 | |
| 629 | |
Marissa Wall | ac10819 | 2016-12-15 12:27:48 -0800 | [diff] [blame] | 630 | Hwc2TestTransform::Hwc2TestTransform(Hwc2TestCoverage coverage) |
| 631 | : Hwc2TestProperty(coverage, mCompleteTransforms, mBasicTransforms, |
Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 632 | mDefaultTransforms, mCompositionSupport) { } |
Marissa Wall | ac10819 | 2016-12-15 12:27:48 -0800 | [diff] [blame] | 633 | |
| 634 | std::string Hwc2TestTransform::dump() const |
| 635 | { |
| 636 | std::stringstream dmp; |
| 637 | dmp << "\ttransform: " << getTransformName(get()) << "\n"; |
| 638 | return dmp.str(); |
| 639 | } |
| 640 | |
| 641 | const std::vector<hwc_transform_t> Hwc2TestTransform::mDefaultTransforms = { |
| 642 | static_cast<hwc_transform_t>(0), |
| 643 | }; |
| 644 | |
| 645 | const std::vector<hwc_transform_t> Hwc2TestTransform::mBasicTransforms = { |
| 646 | static_cast<hwc_transform_t>(0), |
| 647 | HWC_TRANSFORM_FLIP_H, |
| 648 | HWC_TRANSFORM_FLIP_V, |
| 649 | HWC_TRANSFORM_ROT_90, |
| 650 | }; |
| 651 | |
| 652 | const std::vector<hwc_transform_t> Hwc2TestTransform::mCompleteTransforms = { |
| 653 | static_cast<hwc_transform_t>(0), |
| 654 | HWC_TRANSFORM_FLIP_H, |
| 655 | HWC_TRANSFORM_FLIP_V, |
| 656 | HWC_TRANSFORM_ROT_90, |
| 657 | HWC_TRANSFORM_ROT_180, |
| 658 | HWC_TRANSFORM_ROT_270, |
| 659 | HWC_TRANSFORM_FLIP_H_ROT_90, |
| 660 | HWC_TRANSFORM_FLIP_V_ROT_90, |
| 661 | }; |
Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame] | 662 | |
| 663 | |
| 664 | Hwc2TestVisibleRegion::~Hwc2TestVisibleRegion() |
| 665 | { |
| 666 | release(); |
| 667 | } |
| 668 | |
| 669 | std::string Hwc2TestVisibleRegion::dump() const |
| 670 | { |
| 671 | std::stringstream dmp; |
| 672 | |
| 673 | const hwc_region_t& curr = get(); |
| 674 | dmp << "\tvisible region: region count " << curr.numRects << "\n"; |
| 675 | for (size_t i = 0; i < curr.numRects; i++) { |
| 676 | const hwc_rect_t& rect = curr.rects[i]; |
| 677 | dmp << "\t\trect: left " << rect.left << ", top " << rect.top |
| 678 | << ", right " << rect.right << ", bottom " << rect.bottom << "\n"; |
| 679 | } |
| 680 | |
| 681 | return dmp.str(); |
| 682 | } |
| 683 | |
| 684 | void Hwc2TestVisibleRegion::set(const android::Region& visibleRegion) |
| 685 | { |
| 686 | release(); |
| 687 | |
| 688 | size_t size = 0; |
| 689 | const android::Rect* rects = visibleRegion.getArray(&size); |
| 690 | |
| 691 | mVisibleRegion.numRects = size; |
| 692 | mVisibleRegion.rects = nullptr; |
| 693 | |
| 694 | if (size > 0) { |
| 695 | hwc_rect_t* hwcRects = new hwc_rect_t[size]; |
| 696 | for (size_t i = 0; i < size; i++) { |
| 697 | hwcRects[i].left = rects[i].left; |
| 698 | hwcRects[i].top = rects[i].top; |
| 699 | hwcRects[i].right = rects[i].right; |
| 700 | hwcRects[i].bottom = rects[i].bottom; |
| 701 | } |
| 702 | mVisibleRegion.rects = hwcRects; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | hwc_region_t Hwc2TestVisibleRegion::get() const |
| 707 | { |
| 708 | return mVisibleRegion; |
| 709 | } |
| 710 | |
| 711 | void Hwc2TestVisibleRegion::release() |
| 712 | { |
| 713 | if (mVisibleRegion.numRects > 0 && mVisibleRegion.rects) |
| 714 | delete[] mVisibleRegion.rects; |
| 715 | mVisibleRegion.rects = nullptr; |
| 716 | mVisibleRegion.numRects = 0; |
| 717 | } |
Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 718 | |
| 719 | /* Identifies which layer properties are supported by each composition type. |
| 720 | * hwc2_composition_t values range from: |
| 721 | * HWC2_COMPOSITION_INVALID = 0, |
| 722 | * HWC2_COMPOSITION_CLIENT = 1, |
| 723 | * HWC2_COMPOSITION_DEVICE = 2, |
| 724 | * HWC2_COMPOSITION_SOLID_COLOR = 3, |
| 725 | * HWC2_COMPOSITION_CURSOR = 4, |
| 726 | * HWC2_COMPOSITION_SIDEBAND = 5, |
| 727 | * |
| 728 | * Each property array can be indexed by a hwc2_composition_t value. |
| 729 | * By using an array instead of a more complex data structure, runtimes for |
| 730 | * some test cases showed a noticeable improvement. |
| 731 | */ |
| 732 | |
| 733 | /* INVALID CLIENT DEVICE COLOR CURSOR SIDEBAND */ |
| 734 | const std::array<bool, 6> Hwc2TestBufferArea::mCompositionSupport = {{ |
| 735 | false, true, true, false, true, true, |
| 736 | }}; |
| 737 | |
| 738 | /* INVALID CLIENT DEVICE COLOR CURSOR SIDEBAND */ |
| 739 | const std::array<bool, 6> Hwc2TestBlendMode::mCompositionSupport = {{ |
| 740 | false, true, true, false, true, true, |
| 741 | }}; |
| 742 | |
| 743 | /* INVALID CLIENT DEVICE COLOR CURSOR SIDEBAND */ |
| 744 | const std::array<bool, 6> Hwc2TestColor::mCompositionSupport = {{ |
| 745 | false, false, false, true, false, false, |
| 746 | }}; |
| 747 | |
| 748 | /* INVALID CLIENT DEVICE COLOR CURSOR SIDEBAND */ |
| 749 | const std::array<bool, 6> Hwc2TestComposition::mCompositionSupport = {{ |
| 750 | false, true, true, true, true, true, |
| 751 | }}; |
| 752 | |
| 753 | /* INVALID CLIENT DEVICE COLOR CURSOR SIDEBAND */ |
| 754 | const std::array<bool, 6> Hwc2TestDataspace::mCompositionSupport = {{ |
| 755 | false, true, true, true, true, false, |
| 756 | }}; |
| 757 | |
| 758 | /* INVALID CLIENT DEVICE COLOR CURSOR SIDEBAND */ |
Marissa Wall | bad1bc7 | 2017-02-21 14:33:46 -0800 | [diff] [blame] | 759 | const std::array<bool, 6> Hwc2TestDisplayDimension::mCompositionSupport = {{ |
| 760 | false, true, true, true, true, true, |
| 761 | }}; |
| 762 | |
| 763 | /* INVALID CLIENT DEVICE COLOR CURSOR SIDEBAND */ |
Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 764 | const std::array<bool, 6> Hwc2TestDisplayFrame::mCompositionSupport = {{ |
| 765 | false, true, true, true, false, true, |
| 766 | }}; |
| 767 | |
| 768 | /* INVALID CLIENT DEVICE COLOR CURSOR SIDEBAND */ |
| 769 | const std::array<bool, 6> Hwc2TestPlaneAlpha::mCompositionSupport = {{ |
| 770 | false, true, true, true, true, true, |
| 771 | }}; |
| 772 | |
| 773 | /* INVALID CLIENT DEVICE COLOR CURSOR SIDEBAND */ |
| 774 | const std::array<bool, 6> Hwc2TestSourceCrop::mCompositionSupport = {{ |
| 775 | false, true, true, false, true, false, |
| 776 | }}; |
| 777 | |
| 778 | /* INVALID CLIENT DEVICE COLOR CURSOR SIDEBAND */ |
| 779 | const std::array<bool, 6> Hwc2TestSurfaceDamage::mCompositionSupport = {{ |
| 780 | false, false, true, false, true, false, |
| 781 | }}; |
| 782 | |
| 783 | /* INVALID CLIENT DEVICE COLOR CURSOR SIDEBAND */ |
| 784 | const std::array<bool, 6> Hwc2TestTransform::mCompositionSupport = {{ |
| 785 | false, true, true, false, true, true, |
| 786 | }}; |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 787 | |
| 788 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 789 | #pragma clang diagnostic pop // ignored "-Wconversion" |