| 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> | 
|  | 18 |  | 
|  | 19 | #include "Hwc2TestLayer.h" | 
|  | 20 |  | 
| Marissa Wall | 563030b | 2017-02-21 14:01:05 -0800 | [diff] [blame] | 21 | Hwc2TestCoverage getCoverage(Hwc2TestPropertyName property, | 
|  | 22 | Hwc2TestCoverage coverage, const std::unordered_map<Hwc2TestPropertyName, | 
|  | 23 | Hwc2TestCoverage>& coverageExceptions) { | 
|  | 24 | auto exception = coverageExceptions.find(property); | 
|  | 25 | return (exception != coverageExceptions.end())? exception->second : coverage; | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | Hwc2TestLayer::Hwc2TestLayer(Hwc2TestCoverage coverage, | 
|  | 29 | const Area& displayArea) | 
|  | 30 | : Hwc2TestLayer(coverage, displayArea, | 
|  | 31 | std::unordered_map<Hwc2TestPropertyName, Hwc2TestCoverage>()) { } | 
|  | 32 |  | 
|  | 33 | Hwc2TestLayer::Hwc2TestLayer(Hwc2TestCoverage coverage, | 
|  | 34 | const Area& displayArea, const std::unordered_map<Hwc2TestPropertyName, | 
|  | 35 | Hwc2TestCoverage>& coverageExceptions) | 
|  | 36 | : mBlendMode(getCoverage(Hwc2TestPropertyName::BlendMode, coverage, | 
|  | 37 | coverageExceptions)), | 
|  | 38 | mBufferArea(getCoverage(Hwc2TestPropertyName::BufferArea, coverage, | 
|  | 39 | coverageExceptions), displayArea), | 
|  | 40 | mColor(getCoverage(Hwc2TestPropertyName::Color, coverage, | 
|  | 41 | coverageExceptions)), | 
|  | 42 | mComposition(getCoverage(Hwc2TestPropertyName::Composition, coverage, | 
|  | 43 | coverageExceptions)), | 
|  | 44 | mDataspace(getCoverage(Hwc2TestPropertyName::Dataspace, coverage, | 
|  | 45 | coverageExceptions)), | 
|  | 46 | mDisplayFrame(getCoverage(Hwc2TestPropertyName::DisplayFrame, coverage, | 
|  | 47 | coverageExceptions), displayArea), | 
|  | 48 | mPlaneAlpha(getCoverage(Hwc2TestPropertyName::PlaneAlpha, coverage, | 
|  | 49 | coverageExceptions)), | 
|  | 50 | mSourceCrop(getCoverage(Hwc2TestPropertyName::SourceCrop, coverage, | 
|  | 51 | coverageExceptions)), | 
|  | 52 | mSurfaceDamage(getCoverage(Hwc2TestPropertyName::SurfaceDamage, coverage, | 
|  | 53 | coverageExceptions)), | 
|  | 54 | mTransform(getCoverage(Hwc2TestPropertyName::Transform, coverage, | 
|  | 55 | coverageExceptions)) | 
| Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 56 | { | 
| Marissa Wall | 5a240aa | 2016-12-15 12:34:06 -0800 | [diff] [blame] | 57 | mBufferArea.setDependent(&mBuffer); | 
| Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 58 | mBufferArea.setDependent(&mSourceCrop); | 
| Marissa Wall | ad76181 | 2016-12-15 12:32:24 -0800 | [diff] [blame] | 59 | mBufferArea.setDependent(&mSurfaceDamage); | 
| Marissa Wall | ee24278 | 2016-12-15 12:30:12 -0800 | [diff] [blame] | 60 | mBlendMode.setDependent(&mColor); | 
| Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 61 | } | 
| Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 62 |  | 
|  | 63 | std::string Hwc2TestLayer::dump() const | 
|  | 64 | { | 
|  | 65 | std::stringstream dmp; | 
|  | 66 |  | 
|  | 67 | dmp << "layer: \n"; | 
| Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 68 |  | 
|  | 69 | for (auto property : mProperties) { | 
|  | 70 | dmp << property->dump(); | 
|  | 71 | } | 
| Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 72 |  | 
| Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame] | 73 | dmp << mVisibleRegion.dump(); | 
| Marissa Wall | 273b1df | 2016-12-15 12:28:47 -0800 | [diff] [blame] | 74 | dmp << "\tz order: " << mZOrder << "\n"; | 
|  | 75 |  | 
| Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 76 | return dmp.str(); | 
|  | 77 | } | 
|  | 78 |  | 
| Marissa Wall | 5a240aa | 2016-12-15 12:34:06 -0800 | [diff] [blame] | 79 | int Hwc2TestLayer::getBuffer(buffer_handle_t* outHandle, | 
|  | 80 | android::base::unique_fd* outAcquireFence) | 
|  | 81 | { | 
|  | 82 | int32_t acquireFence; | 
|  | 83 | int ret = mBuffer.get(outHandle, &acquireFence); | 
|  | 84 | outAcquireFence->reset(acquireFence); | 
|  | 85 | return ret; | 
|  | 86 | } | 
|  | 87 |  | 
| Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 88 | int Hwc2TestLayer::getBuffer(buffer_handle_t* outHandle, | 
|  | 89 | int32_t* outAcquireFence) | 
|  | 90 | { | 
|  | 91 | return mBuffer.get(outHandle, outAcquireFence); | 
|  | 92 | } | 
|  | 93 |  | 
| Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame] | 94 | void Hwc2TestLayer::setZOrder(uint32_t zOrder) | 
|  | 95 | { | 
|  | 96 | mZOrder = zOrder; | 
|  | 97 | } | 
|  | 98 |  | 
|  | 99 | void Hwc2TestLayer::setVisibleRegion(const android::Region& region) | 
|  | 100 | { | 
|  | 101 | return mVisibleRegion.set(region); | 
|  | 102 | } | 
|  | 103 |  | 
| Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 104 | void Hwc2TestLayer::reset() | 
|  | 105 | { | 
| Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame] | 106 | mVisibleRegion.release(); | 
|  | 107 |  | 
| Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 108 | for (auto property : mProperties) { | 
|  | 109 | property->reset(); | 
|  | 110 | } | 
|  | 111 | } | 
|  | 112 |  | 
| Marissa Wall | 1cd789c | 2017-01-27 12:55:36 -0800 | [diff] [blame] | 113 | bool Hwc2TestLayer::advance() | 
|  | 114 | { | 
|  | 115 | for (auto property : mProperties) { | 
|  | 116 | if (property->isSupported(mComposition.get())) | 
|  | 117 | if (property->advance()) | 
|  | 118 | return true; | 
|  | 119 | } | 
|  | 120 | return false; | 
|  | 121 | } | 
|  | 122 |  | 
| Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 123 | hwc2_blend_mode_t Hwc2TestLayer::getBlendMode() const | 
|  | 124 | { | 
|  | 125 | return mBlendMode.get(); | 
| Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 126 | } | 
|  | 127 |  | 
| Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame] | 128 | Area Hwc2TestLayer::getBufferArea() const | 
|  | 129 | { | 
|  | 130 | return mBufferArea.get(); | 
|  | 131 | } | 
|  | 132 |  | 
| Marissa Wall | ee24278 | 2016-12-15 12:30:12 -0800 | [diff] [blame] | 133 | hwc_color_t Hwc2TestLayer::getColor() const | 
|  | 134 | { | 
|  | 135 | return mColor.get(); | 
|  | 136 | } | 
|  | 137 |  | 
| Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 138 | hwc2_composition_t Hwc2TestLayer::getComposition() const | 
|  | 139 | { | 
|  | 140 | return mComposition.get(); | 
|  | 141 | } | 
|  | 142 |  | 
| Marissa Wall | 2a0aaf9 | 2016-12-15 12:31:37 -0800 | [diff] [blame] | 143 | /* The cursor position corresponds to {displayFrame.left, displayFrame.top} */ | 
|  | 144 | hwc_rect_t Hwc2TestLayer::getCursorPosition() const | 
|  | 145 | { | 
|  | 146 | return mDisplayFrame.get(); | 
|  | 147 | } | 
|  | 148 |  | 
| Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 149 | android::ui::Dataspace Hwc2TestLayer::getDataspace() const | 
| Marissa Wall | b72b5c9 | 2016-12-15 12:26:39 -0800 | [diff] [blame] | 150 | { | 
|  | 151 | return mDataspace.get(); | 
|  | 152 | } | 
|  | 153 |  | 
| Marissa Wall | 600a73b | 2016-12-15 12:30:39 -0800 | [diff] [blame] | 154 | hwc_rect_t Hwc2TestLayer::getDisplayFrame() const | 
|  | 155 | { | 
|  | 156 | return mDisplayFrame.get(); | 
|  | 157 | } | 
|  | 158 |  | 
| Marissa Wall | 2b1f530 | 2016-12-15 12:27:20 -0800 | [diff] [blame] | 159 | float Hwc2TestLayer::getPlaneAlpha() const | 
|  | 160 | { | 
|  | 161 | return mPlaneAlpha.get(); | 
|  | 162 | } | 
|  | 163 |  | 
| Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 164 | hwc_frect_t Hwc2TestLayer::getSourceCrop() const | 
|  | 165 | { | 
|  | 166 | return mSourceCrop.get(); | 
|  | 167 | } | 
|  | 168 |  | 
| Marissa Wall | ad76181 | 2016-12-15 12:32:24 -0800 | [diff] [blame] | 169 | hwc_region_t Hwc2TestLayer::getSurfaceDamage() const | 
|  | 170 | { | 
|  | 171 | return mSurfaceDamage.get(); | 
|  | 172 | } | 
|  | 173 |  | 
| Marissa Wall | ac10819 | 2016-12-15 12:27:48 -0800 | [diff] [blame] | 174 | hwc_transform_t Hwc2TestLayer::getTransform() const | 
|  | 175 | { | 
|  | 176 | return mTransform.get(); | 
|  | 177 | } | 
|  | 178 |  | 
| Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame] | 179 | hwc_region_t Hwc2TestLayer::getVisibleRegion() const | 
|  | 180 | { | 
|  | 181 | return mVisibleRegion.get(); | 
|  | 182 | } | 
|  | 183 |  | 
| Marissa Wall | 273b1df | 2016-12-15 12:28:47 -0800 | [diff] [blame] | 184 | uint32_t Hwc2TestLayer::getZOrder() const | 
|  | 185 | { | 
|  | 186 | return mZOrder; | 
|  | 187 | } | 
|  | 188 |  | 
| Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 189 | bool Hwc2TestLayer::advanceBlendMode() | 
|  | 190 | { | 
|  | 191 | return mBlendMode.advance(); | 
|  | 192 | } | 
|  | 193 |  | 
| Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 194 | bool Hwc2TestLayer::advanceBufferArea() | 
|  | 195 | { | 
|  | 196 | return mBufferArea.advance(); | 
|  | 197 | } | 
|  | 198 |  | 
| Marissa Wall | ee24278 | 2016-12-15 12:30:12 -0800 | [diff] [blame] | 199 | bool Hwc2TestLayer::advanceColor() | 
|  | 200 | { | 
|  | 201 | return mColor.advance(); | 
|  | 202 | } | 
|  | 203 |  | 
| Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 204 | bool Hwc2TestLayer::advanceComposition() | 
|  | 205 | { | 
|  | 206 | return mComposition.advance(); | 
|  | 207 | } | 
| Marissa Wall | b72b5c9 | 2016-12-15 12:26:39 -0800 | [diff] [blame] | 208 |  | 
| Marissa Wall | 2a0aaf9 | 2016-12-15 12:31:37 -0800 | [diff] [blame] | 209 | bool Hwc2TestLayer::advanceCursorPosition() | 
|  | 210 | { | 
|  | 211 | return mDisplayFrame.advance(); | 
|  | 212 | } | 
|  | 213 |  | 
| Marissa Wall | b72b5c9 | 2016-12-15 12:26:39 -0800 | [diff] [blame] | 214 | bool Hwc2TestLayer::advanceDataspace() | 
|  | 215 | { | 
|  | 216 | return mDataspace.advance(); | 
|  | 217 | } | 
| Marissa Wall | 2b1f530 | 2016-12-15 12:27:20 -0800 | [diff] [blame] | 218 |  | 
| Marissa Wall | 600a73b | 2016-12-15 12:30:39 -0800 | [diff] [blame] | 219 | bool Hwc2TestLayer::advanceDisplayFrame() | 
|  | 220 | { | 
|  | 221 | return mDisplayFrame.advance(); | 
|  | 222 | } | 
|  | 223 |  | 
| Marissa Wall | 2b1f530 | 2016-12-15 12:27:20 -0800 | [diff] [blame] | 224 | bool Hwc2TestLayer::advancePlaneAlpha() | 
|  | 225 | { | 
|  | 226 | return mPlaneAlpha.advance(); | 
|  | 227 | } | 
| Marissa Wall | ac10819 | 2016-12-15 12:27:48 -0800 | [diff] [blame] | 228 |  | 
| Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 229 | bool Hwc2TestLayer::advanceSourceCrop() | 
|  | 230 | { | 
|  | 231 | return mSourceCrop.advance(); | 
|  | 232 | } | 
|  | 233 |  | 
| Marissa Wall | ad76181 | 2016-12-15 12:32:24 -0800 | [diff] [blame] | 234 | bool Hwc2TestLayer::advanceSurfaceDamage() | 
|  | 235 | { | 
|  | 236 | return mSurfaceDamage.advance(); | 
|  | 237 | } | 
|  | 238 |  | 
| Marissa Wall | ac10819 | 2016-12-15 12:27:48 -0800 | [diff] [blame] | 239 | bool Hwc2TestLayer::advanceTransform() | 
|  | 240 | { | 
|  | 241 | return mTransform.advance(); | 
|  | 242 | } | 
| Marissa Wall | f7618ed | 2016-12-15 12:34:39 -0800 | [diff] [blame] | 243 |  | 
|  | 244 | bool Hwc2TestLayer::advanceVisibleRegion() | 
|  | 245 | { | 
|  | 246 | if (mPlaneAlpha.advance()) | 
|  | 247 | return true; | 
|  | 248 | return mDisplayFrame.advance(); | 
|  | 249 | } |