Marissa Wall | 273b1df | 2016-12-15 12:28:47 -0800 | [diff] [blame] | 1 | /* * Copyright (C) 2016 The Android Open Source Project |
| 2 | * |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <sstream> |
| 17 | #include <gtest/gtest.h> |
| 18 | |
| 19 | #include "Hwc2TestLayers.h" |
| 20 | |
| 21 | Hwc2TestLayers::Hwc2TestLayers(const std::vector<hwc2_layer_t>& layers, |
Marissa Wall | 600a73b | 2016-12-15 12:30:39 -0800 | [diff] [blame] | 22 | Hwc2TestCoverage coverage, const Area& displayArea) |
Marissa Wall | 273b1df | 2016-12-15 12:28:47 -0800 | [diff] [blame] | 23 | { |
Marissa Wall | 273b1df | 2016-12-15 12:28:47 -0800 | [diff] [blame] | 24 | for (auto layer : layers) { |
| 25 | mTestLayers.emplace(std::piecewise_construct, |
| 26 | std::forward_as_tuple(layer), |
Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame^] | 27 | std::forward_as_tuple(coverage, displayArea)); |
Marissa Wall | 273b1df | 2016-12-15 12:28:47 -0800 | [diff] [blame] | 28 | } |
Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame^] | 29 | |
| 30 | /* Iterate over the layers in order and assign z orders in the same order. |
| 31 | * This allows us to iterate over z orders in the same way when computing |
| 32 | * visible regions */ |
| 33 | uint32_t nextZOrder = layers.size(); |
| 34 | |
| 35 | for (auto& testLayer : mTestLayers) { |
| 36 | testLayer.second.setZOrder(nextZOrder--); |
| 37 | } |
| 38 | |
| 39 | setVisibleRegions(); |
Marissa Wall | 273b1df | 2016-12-15 12:28:47 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | std::string Hwc2TestLayers::dump() const |
| 43 | { |
| 44 | std::stringstream dmp; |
| 45 | for (auto& testLayer : mTestLayers) { |
| 46 | dmp << testLayer.second.dump(); |
| 47 | } |
| 48 | return dmp.str(); |
| 49 | } |
| 50 | |
| 51 | void Hwc2TestLayers::reset() |
| 52 | { |
| 53 | for (auto& testLayer : mTestLayers) { |
| 54 | testLayer.second.reset(); |
| 55 | } |
Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame^] | 56 | |
| 57 | setVisibleRegions(); |
| 58 | } |
| 59 | |
| 60 | bool Hwc2TestLayers::advanceVisibleRegions() |
| 61 | { |
| 62 | for (auto& testLayer : mTestLayers) { |
| 63 | if (testLayer.second.advanceVisibleRegion()) { |
| 64 | setVisibleRegions(); |
| 65 | return true; |
| 66 | } |
| 67 | testLayer.second.reset(); |
| 68 | } |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | hwc_region_t Hwc2TestLayers::getVisibleRegion(hwc2_layer_t layer) const |
| 73 | { |
| 74 | if (mTestLayers.count(layer) == 0) { |
| 75 | []() { GTEST_FAIL(); }(); |
| 76 | } |
| 77 | return mTestLayers.at(layer).getVisibleRegion(); |
Marissa Wall | 273b1df | 2016-12-15 12:28:47 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | uint32_t Hwc2TestLayers::getZOrder(hwc2_layer_t layer) const |
| 81 | { |
| 82 | if (mTestLayers.count(layer) == 0) { |
| 83 | []() { GTEST_FAIL(); }(); |
| 84 | } |
| 85 | return mTestLayers.at(layer).getZOrder(); |
| 86 | } |
Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame^] | 87 | |
| 88 | void Hwc2TestLayers::setVisibleRegions() |
| 89 | { |
| 90 | /* The region of the display that is covered by layers above the current |
| 91 | * layer */ |
| 92 | android::Region aboveOpaqueLayers; |
| 93 | |
| 94 | /* Iterate over test layers from max z order to min z order. */ |
| 95 | for (auto& testLayer : mTestLayers) { |
| 96 | android::Region visibleRegion; |
| 97 | |
| 98 | /* Set the visible region of this layer */ |
| 99 | const hwc_rect_t displayFrame = testLayer.second.getDisplayFrame(); |
| 100 | |
| 101 | visibleRegion.set(android::Rect(displayFrame.left, displayFrame.top, |
| 102 | displayFrame.right, displayFrame.bottom)); |
| 103 | |
| 104 | /* Remove the area covered by opaque layers above this layer |
| 105 | * from this layer's visible region */ |
| 106 | visibleRegion.subtractSelf(aboveOpaqueLayers); |
| 107 | |
| 108 | testLayer.second.setVisibleRegion(visibleRegion); |
| 109 | |
| 110 | /* If this layer is opaque, store the region it covers */ |
| 111 | if (testLayer.second.getPlaneAlpha() == 1.0f) |
| 112 | aboveOpaqueLayers.orSelf(visibleRegion); |
| 113 | } |
| 114 | } |