• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
18 #include <cutils/log.h>
19 #include <ui/Rect.h>
20 
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"
28 #include "Hwc2TestProperties.h"
29 
Hwc2TestBufferArea(Hwc2TestCoverage coverage,const Area & displayArea)30 Hwc2TestBufferArea::Hwc2TestBufferArea(Hwc2TestCoverage coverage,
31         const Area& displayArea)
32     : Hwc2TestProperty(mBufferAreas, mCompositionSupport),
33       mScalars((coverage == Hwc2TestCoverage::Complete)? mCompleteScalars:
34             (coverage == Hwc2TestCoverage::Basic)? mBasicScalars:
35             mDefaultScalars),
36       mDisplayArea(displayArea)
37 {
38     update();
39 }
40 
dump() const41 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 
setDependent(Hwc2TestBuffer * buffer)50 void Hwc2TestBufferArea::setDependent(Hwc2TestBuffer* buffer)
51 {
52     mBuffer = buffer;
53     if (buffer) {
54         buffer->updateBufferArea(get());
55     }
56 }
57 
setDependent(Hwc2TestSourceCrop * sourceCrop)58 void Hwc2TestBufferArea::setDependent(Hwc2TestSourceCrop* sourceCrop)
59 {
60     mSourceCrop = sourceCrop;
61     if (mSourceCrop) {
62         mSourceCrop->updateBufferArea(get());
63     }
64 }
65 
setDependent(Hwc2TestSurfaceDamage * surfaceDamage)66 void Hwc2TestBufferArea::setDependent(Hwc2TestSurfaceDamage* surfaceDamage)
67 {
68     mSurfaceDamage = surfaceDamage;
69     if (mSurfaceDamage) {
70         mSurfaceDamage->updateBufferArea(get());
71     }
72 }
73 
update()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 
updateDependents()91 void Hwc2TestBufferArea::updateDependents()
92 {
93     const Area& curr = get();
94 
95     if (mBuffer)
96         mBuffer->updateBufferArea(curr);
97     if (mSourceCrop)
98         mSourceCrop->updateBufferArea(curr);
99     if (mSurfaceDamage)
100         mSurfaceDamage->updateBufferArea(curr);
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 
Hwc2TestBlendMode(Hwc2TestCoverage coverage)116 Hwc2TestBlendMode::Hwc2TestBlendMode(Hwc2TestCoverage coverage)
117     : Hwc2TestProperty(coverage, mCompleteBlendModes, mBasicBlendModes,
118             mDefaultBlendModes, mCompositionSupport) { }
119 
dump() const120 std::string Hwc2TestBlendMode::dump() const
121 {
122     std::stringstream dmp;
123     dmp << "\tblend mode: " << getBlendModeName(get()) << "\n";
124     return dmp.str();
125 }
126 
setDependent(Hwc2TestColor * color)127 void Hwc2TestBlendMode::setDependent(Hwc2TestColor* color)
128 {
129     mColor = color;
130     updateDependents();
131 }
132 
updateDependents()133 void Hwc2TestBlendMode::updateDependents()
134 {
135     if (mColor)
136         mColor->updateBlendMode(get());
137 }
138 
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 
Hwc2TestColor(Hwc2TestCoverage coverage,hwc2_blend_mode_t blendMode)155 Hwc2TestColor::Hwc2TestColor(Hwc2TestCoverage coverage,
156         hwc2_blend_mode_t blendMode)
157     : Hwc2TestProperty(mColors, mCompositionSupport),
158       mBaseColors((coverage == Hwc2TestCoverage::Complete)? mCompleteBaseColors:
159             (coverage == Hwc2TestCoverage::Basic)? mBasicBaseColors:
160             mDefaultBaseColors),
161       mBlendMode(blendMode)
162 {
163     update();
164 }
165 
dump() const166 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 
updateBlendMode(hwc2_blend_mode_t blendMode)176 void Hwc2TestColor::updateBlendMode(hwc2_blend_mode_t blendMode)
177 {
178     mBlendMode = blendMode;
179     update();
180 }
181 
update()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 
Hwc2TestComposition(Hwc2TestCoverage coverage)229 Hwc2TestComposition::Hwc2TestComposition(Hwc2TestCoverage coverage)
230     : Hwc2TestProperty(coverage, mCompleteCompositions, mBasicCompositions,
231             mDefaultCompositions, mCompositionSupport) { }
232 
dump() const233 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 };
256 
257 
Hwc2TestDataspace(Hwc2TestCoverage coverage)258 Hwc2TestDataspace::Hwc2TestDataspace(Hwc2TestCoverage coverage)
259     : Hwc2TestProperty(coverage, completeDataspaces, basicDataspaces,
260             defaultDataspaces, mCompositionSupport) { }
261 
dump() const262 std::string Hwc2TestDataspace::dump() const
263 {
264     std::stringstream dmp;
265     dmp << "\tdataspace: " << static_cast<int32_t>(get()) << "\n";
266     return dmp.str();
267 }
268 
269 const std::vector<android::ui::Dataspace> Hwc2TestDataspace::defaultDataspaces = {
270     android::ui::Dataspace::UNKNOWN,
271 };
272 
273 const std::vector<android::ui::Dataspace> Hwc2TestDataspace::basicDataspaces = {
274     android::ui::Dataspace::UNKNOWN,
275     android::ui::Dataspace::V0_SRGB,
276 };
277 
278 const std::vector<android::ui::Dataspace> Hwc2TestDataspace::completeDataspaces = {
279     android::ui::Dataspace::UNKNOWN,
280     android::ui::Dataspace::ARBITRARY,
281     android::ui::Dataspace::STANDARD_SHIFT,
282     android::ui::Dataspace::STANDARD_MASK,
283     android::ui::Dataspace::STANDARD_UNSPECIFIED,
284     android::ui::Dataspace::STANDARD_BT709,
285     android::ui::Dataspace::STANDARD_BT601_625,
286     android::ui::Dataspace::STANDARD_BT601_625_UNADJUSTED,
287     android::ui::Dataspace::STANDARD_BT601_525,
288     android::ui::Dataspace::STANDARD_BT601_525_UNADJUSTED,
289     android::ui::Dataspace::STANDARD_BT2020,
290     android::ui::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE,
291     android::ui::Dataspace::STANDARD_BT470M,
292     android::ui::Dataspace::STANDARD_FILM,
293     android::ui::Dataspace::TRANSFER_SHIFT,
294     android::ui::Dataspace::TRANSFER_MASK,
295     android::ui::Dataspace::TRANSFER_UNSPECIFIED,
296     android::ui::Dataspace::TRANSFER_LINEAR,
297     android::ui::Dataspace::TRANSFER_SRGB,
298     android::ui::Dataspace::TRANSFER_SMPTE_170M,
299     android::ui::Dataspace::TRANSFER_GAMMA2_2,
300     android::ui::Dataspace::TRANSFER_GAMMA2_8,
301     android::ui::Dataspace::TRANSFER_ST2084,
302     android::ui::Dataspace::TRANSFER_HLG,
303     android::ui::Dataspace::RANGE_SHIFT,
304     android::ui::Dataspace::RANGE_MASK,
305     android::ui::Dataspace::RANGE_UNSPECIFIED,
306     android::ui::Dataspace::RANGE_FULL,
307     android::ui::Dataspace::RANGE_LIMITED,
308     android::ui::Dataspace::SRGB_LINEAR,
309     android::ui::Dataspace::V0_SRGB_LINEAR,
310     android::ui::Dataspace::SRGB,
311     android::ui::Dataspace::V0_SRGB,
312     android::ui::Dataspace::JFIF,
313     android::ui::Dataspace::V0_JFIF,
314     android::ui::Dataspace::BT601_625,
315     android::ui::Dataspace::V0_BT601_625,
316     android::ui::Dataspace::BT601_525,
317     android::ui::Dataspace::V0_BT601_525,
318     android::ui::Dataspace::BT709,
319     android::ui::Dataspace::V0_BT709,
320     android::ui::Dataspace::DEPTH,
321 };
322 
323 
Hwc2TestDisplayDimension(Hwc2TestCoverage coverage)324 Hwc2TestDisplayDimension::Hwc2TestDisplayDimension(Hwc2TestCoverage coverage)
325     : Hwc2TestProperty(
326             (coverage == Hwc2TestCoverage::Complete)? mCompleteDisplayDimensions:
327             (coverage == Hwc2TestCoverage::Basic)? mBasicDisplayDimensions:
328             mDefaultDisplayDimensions, mCompositionSupport) { }
329 
dump() const330 std::string Hwc2TestDisplayDimension::dump() const
331 {
332     std::stringstream dmp;
333     const UnsignedArea& curr = get();
334     dmp << "\tdisplay dimension: " << curr.width<< " x " << curr.height<< "\n";
335     return dmp.str();
336 }
337 
setDependent(Hwc2TestVirtualBuffer * buffer)338 void Hwc2TestDisplayDimension::setDependent(Hwc2TestVirtualBuffer* buffer)
339 {
340     mBuffers.insert(buffer);
341     updateDependents();
342 }
343 
updateDependents()344 void Hwc2TestDisplayDimension::updateDependents()
345 {
346     const UnsignedArea& curr = get();
347 
348     for (Hwc2TestVirtualBuffer* buffer : mBuffers)
349         buffer->updateBufferArea({static_cast<int32_t>(curr.width),
350                 static_cast<int32_t>(curr.height)});
351 }
352 
353 const std::vector<UnsignedArea>
354         Hwc2TestDisplayDimension::mDefaultDisplayDimensions = {
355     {1920, 1080},
356 };
357 
358 const std::vector<UnsignedArea>
359         Hwc2TestDisplayDimension::mBasicDisplayDimensions = {
360     {640, 480},
361     {1280, 720},
362     {1920, 1080},
363     {1920, 1200},
364 };
365 
366 const std::vector<UnsignedArea>
367         Hwc2TestDisplayDimension::mCompleteDisplayDimensions = {
368     {320, 240},
369     {480, 320},
370     {640, 480},
371     {1280, 720},
372     {1920, 1080},
373     {1920, 1200},
374     {2560, 1440},
375     {2560, 1600},
376     {3840, 2160},
377     {4096, 2160},
378 };
379 
380 
Hwc2TestDisplayFrame(Hwc2TestCoverage coverage,const Area & displayArea)381 Hwc2TestDisplayFrame::Hwc2TestDisplayFrame(Hwc2TestCoverage coverage,
382         const Area& displayArea)
383     : Hwc2TestProperty(mDisplayFrames, mCompositionSupport),
384       mFrectScalars((coverage == Hwc2TestCoverage::Complete)? mCompleteFrectScalars:
385             (coverage == Hwc2TestCoverage::Basic)? mBasicFrectScalars:
386             mDefaultFrectScalars),
387       mDisplayArea(displayArea)
388 {
389     update();
390 }
391 
dump() const392 std::string Hwc2TestDisplayFrame::dump() const
393 {
394     std::stringstream dmp;
395     const hwc_rect_t& displayFrame = get();
396     dmp << "\tdisplay frame: left " << displayFrame.left << ", top "
397             << displayFrame.top << ", right " << displayFrame.right
398             << ", bottom " << displayFrame.bottom << "\n";
399     return dmp.str();
400 }
401 
update()402 void Hwc2TestDisplayFrame::update()
403 {
404     mDisplayFrames.clear();
405 
406     if (mDisplayArea.width == 0 && mDisplayArea.height == 0) {
407         mDisplayFrames.push_back({0, 0, 0, 0});
408         return;
409     }
410 
411     for (const auto& frectScalar : mFrectScalars) {
412         mDisplayFrames.push_back({
413                 static_cast<int>(frectScalar.left * mDisplayArea.width),
414                 static_cast<int>(frectScalar.top * mDisplayArea.height),
415                 static_cast<int>(frectScalar.right * mDisplayArea.width),
416                 static_cast<int>(frectScalar.bottom * mDisplayArea.height)});
417     }
418 }
419 
420 const std::vector<hwc_frect_t> Hwc2TestDisplayFrame::mDefaultFrectScalars = {
421     {0.0, 0.0, 1.0, 1.0},
422 };
423 
424 const std::vector<hwc_frect_t> Hwc2TestDisplayFrame::mBasicFrectScalars = {
425     {0.0, 0.0, 1.0, 1.0},
426     {0.0, 0.0, 1.0, 0.05},
427     {0.0, 0.95, 1.0, 1.0},
428 };
429 
430 const std::vector<hwc_frect_t> Hwc2TestDisplayFrame::mCompleteFrectScalars = {
431     {0.0, 0.0, 1.0, 1.0},
432     {0.0, 0.05, 1.0, 0.95},
433     {0.0, 0.05, 1.0, 1.0},
434     {0.0, 0.0, 1.0, 0.05},
435     {0.0, 0.95, 1.0, 1.0},
436     {0.25, 0.0, 0.75, 0.35},
437     {0.25, 0.25, 0.75, 0.75},
438 };
439 
440 
Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage)441 Hwc2TestPlaneAlpha::Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage)
442     : Hwc2TestProperty(coverage, mCompletePlaneAlphas, mBasicPlaneAlphas,
443             mDefaultPlaneAlphas, mCompositionSupport) { }
444 
dump() const445 std::string Hwc2TestPlaneAlpha::dump() const
446 {
447     std::stringstream dmp;
448     dmp << "\tplane alpha: " << get() << "\n";
449     return dmp.str();
450 }
451 
452 const std::vector<float> Hwc2TestPlaneAlpha::mDefaultPlaneAlphas = {
453     1.0f,
454 };
455 
456 const std::vector<float> Hwc2TestPlaneAlpha::mBasicPlaneAlphas = {
457     1.0f, 0.0f,
458 };
459 
460 const std::vector<float> Hwc2TestPlaneAlpha::mCompletePlaneAlphas = {
461     1.0f, 0.75f, 0.5f, 0.25f, 0.0f,
462 };
463 
464 
Hwc2TestSourceCrop(Hwc2TestCoverage coverage,const Area & bufferArea)465 Hwc2TestSourceCrop::Hwc2TestSourceCrop(Hwc2TestCoverage coverage,
466         const Area& bufferArea)
467     : Hwc2TestProperty(mSourceCrops, mCompositionSupport),
468       mFrectScalars((coverage == Hwc2TestCoverage::Complete)? mCompleteFrectScalars:
469             (coverage == Hwc2TestCoverage::Basic)? mBasicFrectScalars:
470             mDefaultFrectScalars),
471       mBufferArea(bufferArea)
472 {
473     update();
474 }
475 
dump() const476 std::string Hwc2TestSourceCrop::dump() const
477 {
478     std::stringstream dmp;
479     const hwc_frect_t& sourceCrop = get();
480     dmp << "\tsource crop: left " << sourceCrop.left << ", top "
481             << sourceCrop.top << ", right " << sourceCrop.right << ", bottom "
482             << sourceCrop.bottom << "\n";
483     return dmp.str();
484 }
485 
updateBufferArea(const Area & bufferArea)486 void Hwc2TestSourceCrop::updateBufferArea(const Area& bufferArea)
487 {
488     mBufferArea = bufferArea;
489     update();
490 }
491 
update()492 void Hwc2TestSourceCrop::update()
493 {
494     mSourceCrops.clear();
495 
496     if (mBufferArea.width == 0 && mBufferArea.height == 0) {
497         mSourceCrops.push_back({0, 0, 0, 0});
498         return;
499     }
500 
501     for (const auto& frectScalar : mFrectScalars) {
502         mSourceCrops.push_back({
503                 frectScalar.left * mBufferArea.width,
504                 frectScalar.top * mBufferArea.height,
505                 frectScalar.right * mBufferArea.width,
506                 frectScalar.bottom * mBufferArea.height});
507     }
508 }
509 
510 const std::vector<hwc_frect_t> Hwc2TestSourceCrop::mDefaultFrectScalars = {
511     {0.0, 0.0, 1.0, 1.0},
512 };
513 
514 const std::vector<hwc_frect_t> Hwc2TestSourceCrop::mBasicFrectScalars = {
515     {0.0, 0.0, 1.0, 1.0},
516     {0.0, 0.0, 0.5, 0.5},
517     {0.5, 0.5, 1.0, 1.0},
518 };
519 
520 const std::vector<hwc_frect_t> Hwc2TestSourceCrop::mCompleteFrectScalars = {
521     {0.0, 0.0, 1.0, 1.0},
522     {0.0, 0.0, 0.5, 0.5},
523     {0.5, 0.5, 1.0, 1.0},
524     {0.0, 0.0, 0.25, 0.25},
525     {0.25, 0.25, 0.75, 0.75},
526 };
527 
528 
Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage)529 Hwc2TestSurfaceDamage::Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage)
530     : Hwc2TestProperty(mSurfaceDamages, mCompositionSupport),
531       mRegionScalars((coverage == Hwc2TestCoverage::Complete)? mCompleteRegionScalars:
532             (coverage == Hwc2TestCoverage::Basic)? mBasicRegionScalars:
533             mDefaultRegionScalars)
534 {
535     update();
536 }
537 
~Hwc2TestSurfaceDamage()538 Hwc2TestSurfaceDamage::~Hwc2TestSurfaceDamage()
539 {
540     freeSurfaceDamages();
541 }
542 
dump() const543 std::string Hwc2TestSurfaceDamage::dump() const
544 {
545     std::stringstream dmp;
546 
547     const hwc_region_t& curr = get();
548     dmp << "\tsurface damage: region count " << curr.numRects << "\n";
549     for (size_t i = 0; i < curr.numRects; i++) {
550         const hwc_rect_t& rect = curr.rects[i];
551         dmp << "\t\trect: left " << rect.left << ", top " << rect.top
552                 << ", right " << rect.right << ", bottom " << rect.bottom << "\n";
553     }
554 
555     return dmp.str();
556 }
557 
updateBufferArea(const Area & bufferArea)558 void Hwc2TestSurfaceDamage::updateBufferArea(const Area& bufferArea)
559 {
560     mBufferArea = bufferArea;
561     update();
562 }
563 
update()564 void Hwc2TestSurfaceDamage::update()
565 {
566     freeSurfaceDamages();
567 
568     if (mBufferArea.width == 0 && mBufferArea.height == 0) {
569         mSurfaceDamages.push_back({0, nullptr});
570         return;
571     }
572 
573     hwc_region_t damage;
574 
575     for (const auto& regionScalar : mRegionScalars) {
576         damage.numRects = regionScalar.size();
577 
578         if (damage.numRects > 0) {
579             hwc_rect_t* rects = new hwc_rect_t[damage.numRects];
580             if (!rects) {
581                 ALOGW("failed to allocate new hwc_rect_t array");
582                 continue;
583             }
584 
585             for (size_t i = 0; i < damage.numRects; i++) {
586                 rects[i].left = regionScalar[i].left * mBufferArea.width;
587                 rects[i].top = regionScalar[i].top * mBufferArea.height;
588                 rects[i].right = regionScalar[i].right * mBufferArea.width;
589                 rects[i].bottom = regionScalar[i].bottom * mBufferArea.height;
590             }
591 
592             damage.rects = static_cast<hwc_rect_t const*>(rects);
593         } else {
594             damage.rects = nullptr;
595         }
596 
597         mSurfaceDamages.push_back(damage);
598     }
599 }
600 
freeSurfaceDamages()601 void Hwc2TestSurfaceDamage::freeSurfaceDamages()
602 {
603     for (const auto& surfaceDamage : mSurfaceDamages) {
604         if (surfaceDamage.numRects > 0 && surfaceDamage.rects)
605             delete[] surfaceDamage.rects;
606     }
607     mSurfaceDamages.clear();
608 }
609 
610 const std::vector<std::vector<hwc_frect_t>> Hwc2TestSurfaceDamage::mDefaultRegionScalars = {
611     {{}},
612 };
613 
614 const std::vector<std::vector<hwc_frect_t>> Hwc2TestSurfaceDamage::mBasicRegionScalars = {
615     {{}},
616     {{0.0, 0.0, 1.0, 1.0}},
617 };
618 
619 const std::vector<std::vector<hwc_frect_t>> Hwc2TestSurfaceDamage::mCompleteRegionScalars = {
620     {{}},
621     {{0.0, 0.0, 1.0, 1.0}},
622     {{0.0, 0.0, 0.5, 0.5}, {0.5, 0.5, 1.0, 1.0}},
623 };
624 
625 
Hwc2TestTransform(Hwc2TestCoverage coverage)626 Hwc2TestTransform::Hwc2TestTransform(Hwc2TestCoverage coverage)
627     : Hwc2TestProperty(coverage, mCompleteTransforms, mBasicTransforms,
628             mDefaultTransforms, mCompositionSupport) { }
629 
dump() const630 std::string Hwc2TestTransform::dump() const
631 {
632     std::stringstream dmp;
633     dmp << "\ttransform: " << getTransformName(get()) << "\n";
634     return dmp.str();
635 }
636 
637 const std::vector<hwc_transform_t> Hwc2TestTransform::mDefaultTransforms = {
638     static_cast<hwc_transform_t>(0),
639 };
640 
641 const std::vector<hwc_transform_t> Hwc2TestTransform::mBasicTransforms = {
642     static_cast<hwc_transform_t>(0),
643     HWC_TRANSFORM_FLIP_H,
644     HWC_TRANSFORM_FLIP_V,
645     HWC_TRANSFORM_ROT_90,
646 };
647 
648 const std::vector<hwc_transform_t> Hwc2TestTransform::mCompleteTransforms = {
649     static_cast<hwc_transform_t>(0),
650     HWC_TRANSFORM_FLIP_H,
651     HWC_TRANSFORM_FLIP_V,
652     HWC_TRANSFORM_ROT_90,
653     HWC_TRANSFORM_ROT_180,
654     HWC_TRANSFORM_ROT_270,
655     HWC_TRANSFORM_FLIP_H_ROT_90,
656     HWC_TRANSFORM_FLIP_V_ROT_90,
657 };
658 
659 
~Hwc2TestVisibleRegion()660 Hwc2TestVisibleRegion::~Hwc2TestVisibleRegion()
661 {
662     release();
663 }
664 
dump() const665 std::string Hwc2TestVisibleRegion::dump() const
666 {
667     std::stringstream dmp;
668 
669     const hwc_region_t& curr = get();
670     dmp << "\tvisible region: region count " << curr.numRects << "\n";
671     for (size_t i = 0; i < curr.numRects; i++) {
672         const hwc_rect_t& rect = curr.rects[i];
673         dmp << "\t\trect: left " << rect.left << ", top " << rect.top
674                 << ", right " << rect.right << ", bottom " << rect.bottom << "\n";
675     }
676 
677     return dmp.str();
678 }
679 
set(const android::Region & visibleRegion)680 void Hwc2TestVisibleRegion::set(const android::Region& visibleRegion)
681 {
682     release();
683 
684     size_t size = 0;
685     const android::Rect* rects = visibleRegion.getArray(&size);
686 
687     mVisibleRegion.numRects = size;
688     mVisibleRegion.rects = nullptr;
689 
690     if (size > 0) {
691         hwc_rect_t* hwcRects = new hwc_rect_t[size];
692         for (size_t i = 0; i < size; i++) {
693             hwcRects[i].left = rects[i].left;
694             hwcRects[i].top = rects[i].top;
695             hwcRects[i].right = rects[i].right;
696             hwcRects[i].bottom = rects[i].bottom;
697         }
698         mVisibleRegion.rects = hwcRects;
699     }
700 }
701 
get() const702 hwc_region_t Hwc2TestVisibleRegion::get() const
703 {
704     return mVisibleRegion;
705 }
706 
release()707 void Hwc2TestVisibleRegion::release()
708 {
709     if (mVisibleRegion.numRects > 0 && mVisibleRegion.rects)
710         delete[] mVisibleRegion.rects;
711     mVisibleRegion.rects = nullptr;
712     mVisibleRegion.numRects = 0;
713 }
714 
715 /* Identifies which layer properties are supported by each composition type.
716  * hwc2_composition_t values range from:
717  *  HWC2_COMPOSITION_INVALID = 0,
718  *  HWC2_COMPOSITION_CLIENT = 1,
719  *  HWC2_COMPOSITION_DEVICE = 2,
720  *  HWC2_COMPOSITION_SOLID_COLOR = 3,
721  *  HWC2_COMPOSITION_CURSOR = 4,
722  *  HWC2_COMPOSITION_SIDEBAND = 5,
723  *
724  * Each property array can be indexed by a hwc2_composition_t value.
725  * By using an array instead of a more complex data structure, runtimes for
726  * some test cases showed a noticeable improvement.
727  */
728 
729 /*  INVALID  CLIENT   DEVICE   COLOR    CURSOR   SIDEBAND */
730 const std::array<bool, 6> Hwc2TestBufferArea::mCompositionSupport = {{
731     false,   true,    true,    false,   true,    true,
732 }};
733 
734 /*  INVALID  CLIENT   DEVICE   COLOR    CURSOR   SIDEBAND */
735 const std::array<bool, 6> Hwc2TestBlendMode::mCompositionSupport = {{
736     false,   true,    true,    false,   true,    true,
737 }};
738 
739 /*  INVALID  CLIENT   DEVICE   COLOR    CURSOR   SIDEBAND */
740 const std::array<bool, 6> Hwc2TestColor::mCompositionSupport = {{
741     false,   false,   false,   true,    false,   false,
742 }};
743 
744 /*  INVALID  CLIENT   DEVICE   COLOR    CURSOR   SIDEBAND */
745 const std::array<bool, 6> Hwc2TestComposition::mCompositionSupport = {{
746     false,   true,    true,    true,    true,    true,
747 }};
748 
749 /*  INVALID  CLIENT   DEVICE   COLOR    CURSOR   SIDEBAND */
750 const std::array<bool, 6> Hwc2TestDataspace::mCompositionSupport = {{
751     false,   true,    true,    true,    true,    false,
752 }};
753 
754 /*  INVALID  CLIENT   DEVICE   COLOR    CURSOR   SIDEBAND */
755 const std::array<bool, 6> Hwc2TestDisplayDimension::mCompositionSupport = {{
756     false,   true,    true,    true,    true,    true,
757 }};
758 
759 /*  INVALID  CLIENT   DEVICE   COLOR    CURSOR   SIDEBAND */
760 const std::array<bool, 6> Hwc2TestDisplayFrame::mCompositionSupport = {{
761     false,   true,    true,    true,    false,   true,
762 }};
763 
764 /*  INVALID  CLIENT   DEVICE   COLOR    CURSOR   SIDEBAND */
765 const std::array<bool, 6> Hwc2TestPlaneAlpha::mCompositionSupport = {{
766     false,   true,    true,    true,    true,    true,
767 }};
768 
769 /*  INVALID  CLIENT   DEVICE   COLOR    CURSOR   SIDEBAND */
770 const std::array<bool, 6> Hwc2TestSourceCrop::mCompositionSupport = {{
771     false,   true,    true,    false,   true,    false,
772 }};
773 
774 /*  INVALID  CLIENT   DEVICE   COLOR    CURSOR   SIDEBAND */
775 const std::array<bool, 6> Hwc2TestSurfaceDamage::mCompositionSupport = {{
776     false,   false,   true,    false,   true,    false,
777 }};
778 
779 /*  INVALID  CLIENT   DEVICE   COLOR    CURSOR   SIDEBAND */
780 const std::array<bool, 6> Hwc2TestTransform::mCompositionSupport = {{
781     false,   true,    true,    false,   true,    true,
782 }};
783