ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2022, 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 | #pragma once |
| 17 | |
| 18 | #include <aidl/android/hardware/graphics/common/BlendMode.h> |
| 19 | #include <aidl/android/hardware/graphics/common/BufferUsage.h> |
| 20 | #include <aidl/android/hardware/graphics/common/FRect.h> |
| 21 | #include <aidl/android/hardware/graphics/common/Rect.h> |
| 22 | #include <aidl/android/hardware/graphics/composer3/Composition.h> |
| 23 | #include <aidl/android/hardware/graphics/composer3/IComposer.h> |
| 24 | #include <android-base/properties.h> |
| 25 | #include <android/binder_manager.h> |
| 26 | #include <android/binder_process.h> |
| 27 | #include <android/hardware/graphics/composer3/ComposerClientReader.h> |
| 28 | #include <binder/ProcessState.h> |
| 29 | #include <gtest/gtest.h> |
| 30 | #include <ui/Fence.h> |
| 31 | #include <ui/GraphicBuffer.h> |
| 32 | #include <ui/PixelFormat.h> |
| 33 | #include <algorithm> |
| 34 | #include <numeric> |
| 35 | #include <string> |
| 36 | #include <thread> |
| 37 | #include <unordered_map> |
Leon Scroggins III | c3d695d | 2022-09-16 15:34:59 -0400 | [diff] [blame] | 38 | #include <unordered_set> |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 39 | #include "GraphicsComposerCallback.h" |
| 40 | |
| 41 | using aidl::android::hardware::graphics::common::Dataspace; |
Leon Scroggins III | de05758 | 2022-01-13 12:26:00 -0500 | [diff] [blame] | 42 | using aidl::android::hardware::graphics::common::DisplayDecorationSupport; |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 43 | using aidl::android::hardware::graphics::common::FRect; |
| 44 | using aidl::android::hardware::graphics::common::PixelFormat; |
| 45 | using aidl::android::hardware::graphics::common::Rect; |
| 46 | using namespace ::ndk; |
| 47 | |
| 48 | namespace aidl::android::hardware::graphics::composer3::vts { |
| 49 | |
| 50 | class VtsDisplay; |
| 51 | /** |
| 52 | * A wrapper to IComposerClient. |
| 53 | * This wrapper manages the IComposerClient instance and manages the resources for |
| 54 | * the tests with respect to the IComposerClient calls. |
| 55 | */ |
| 56 | class VtsComposerClient { |
| 57 | public: |
| 58 | VtsComposerClient(const std::string& name); |
| 59 | |
| 60 | ScopedAStatus createClient(); |
| 61 | |
| 62 | bool tearDown(); |
| 63 | |
ramindani | 02fe477 | 2023-06-30 18:04:41 -0700 | [diff] [blame] | 64 | std::pair<ScopedAStatus, int32_t> getInterfaceVersion() const; |
Brian Lindahl | 78ff2d6 | 2022-12-18 11:21:41 -0700 | [diff] [blame] | 65 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 66 | std::pair<ScopedAStatus, VirtualDisplay> createVirtualDisplay(int32_t width, int32_t height, |
| 67 | PixelFormat pixelFormat, |
| 68 | int32_t bufferSlotCount); |
| 69 | |
| 70 | ScopedAStatus destroyVirtualDisplay(int64_t display); |
| 71 | |
| 72 | std::pair<ScopedAStatus, int64_t> createLayer(int64_t display, int32_t bufferSlotCount); |
| 73 | |
| 74 | ScopedAStatus destroyLayer(int64_t display, int64_t layer); |
| 75 | |
| 76 | std::pair<ScopedAStatus, int32_t> getActiveConfig(int64_t display); |
| 77 | |
| 78 | ScopedAStatus setActiveConfig(VtsDisplay* vtsDisplay, int32_t config); |
| 79 | |
ramindani | 9dd8c48 | 2023-02-21 18:07:56 -0800 | [diff] [blame] | 80 | ScopedAStatus setPeakRefreshRateConfig(VtsDisplay* vtsDisplay); |
| 81 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 82 | std::pair<ScopedAStatus, int32_t> getDisplayAttribute(int64_t display, int32_t config, |
| 83 | DisplayAttribute displayAttribute); |
| 84 | |
| 85 | ScopedAStatus setPowerMode(int64_t display, PowerMode powerMode); |
| 86 | |
| 87 | ScopedAStatus setVsync(int64_t display, bool enable); |
| 88 | |
| 89 | void setVsyncAllowed(bool isAllowed); |
| 90 | |
| 91 | std::pair<ScopedAStatus, std::vector<float>> getDataspaceSaturationMatrix(Dataspace dataspace); |
| 92 | |
| 93 | std::pair<ScopedAStatus, std::vector<CommandResultPayload>> executeCommands( |
| 94 | const std::vector<DisplayCommand>& commands); |
| 95 | |
| 96 | std::optional<VsyncPeriodChangeTimeline> takeLastVsyncPeriodChangeTimeline(); |
| 97 | |
| 98 | ScopedAStatus setContentType(int64_t display, ContentType contentType); |
| 99 | |
| 100 | std::pair<ScopedAStatus, VsyncPeriodChangeTimeline> setActiveConfigWithConstraints( |
| 101 | VtsDisplay* vtsDisplay, int32_t config, |
| 102 | const VsyncPeriodChangeConstraints& constraints); |
| 103 | |
| 104 | std::pair<ScopedAStatus, std::vector<DisplayCapability>> getDisplayCapabilities( |
| 105 | int64_t display); |
| 106 | |
| 107 | ScopedAStatus dumpDebugInfo(); |
| 108 | |
| 109 | std::pair<ScopedAStatus, DisplayIdentification> getDisplayIdentificationData(int64_t display); |
| 110 | |
| 111 | std::pair<ScopedAStatus, HdrCapabilities> getHdrCapabilities(int64_t display); |
| 112 | |
| 113 | std::pair<ScopedAStatus, std::vector<PerFrameMetadataKey>> getPerFrameMetadataKeys( |
| 114 | int64_t display); |
| 115 | |
| 116 | std::pair<ScopedAStatus, ReadbackBufferAttributes> getReadbackBufferAttributes(int64_t display); |
| 117 | |
| 118 | ScopedAStatus setReadbackBuffer(int64_t display, const native_handle_t* buffer, |
| 119 | const ScopedFileDescriptor& releaseFence); |
| 120 | |
| 121 | std::pair<ScopedAStatus, ScopedFileDescriptor> getReadbackBufferFence(int64_t display); |
| 122 | |
| 123 | std::pair<ScopedAStatus, std::vector<ColorMode>> getColorModes(int64_t display); |
| 124 | |
| 125 | std::pair<ScopedAStatus, std::vector<RenderIntent>> getRenderIntents(int64_t display, |
| 126 | ColorMode colorMode); |
| 127 | |
| 128 | ScopedAStatus setColorMode(int64_t display, ColorMode colorMode, RenderIntent renderIntent); |
| 129 | |
| 130 | std::pair<ScopedAStatus, DisplayContentSamplingAttributes> |
| 131 | getDisplayedContentSamplingAttributes(int64_t display); |
| 132 | |
| 133 | ScopedAStatus setDisplayedContentSamplingEnabled(int64_t display, bool isEnabled, |
| 134 | FormatColorComponent formatColorComponent, |
| 135 | int64_t maxFrames); |
| 136 | |
| 137 | std::pair<ScopedAStatus, DisplayContentSample> getDisplayedContentSample(int64_t display, |
| 138 | int64_t maxFrames, |
| 139 | int64_t timestamp); |
| 140 | |
| 141 | std::pair<ScopedAStatus, DisplayConnectionType> getDisplayConnectionType(int64_t display); |
| 142 | |
| 143 | std::pair<ScopedAStatus, std::vector<int32_t>> getDisplayConfigs(int64_t display); |
| 144 | |
ramindani | 02fe477 | 2023-06-30 18:04:41 -0700 | [diff] [blame] | 145 | std::pair<ScopedAStatus, std::vector<DisplayConfiguration>> getDisplayConfigurations( |
| 146 | int64_t display); |
| 147 | |
ramindani | 2704c5f | 2023-07-18 20:53:24 -0700 | [diff] [blame] | 148 | ScopedAStatus notifyExpectedPresent(int64_t display, |
| 149 | ClockMonotonicTimestamp expectedPresentTime, |
| 150 | int frameIntervalNs); |
| 151 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 152 | std::pair<ScopedAStatus, int32_t> getDisplayVsyncPeriod(int64_t display); |
| 153 | |
| 154 | ScopedAStatus setAutoLowLatencyMode(int64_t display, bool isEnabled); |
| 155 | |
| 156 | std::pair<ScopedAStatus, std::vector<ContentType>> getSupportedContentTypes(int64_t display); |
| 157 | |
Leon Scroggins III | de05758 | 2022-01-13 12:26:00 -0500 | [diff] [blame] | 158 | std::pair<ScopedAStatus, std::optional<DisplayDecorationSupport>> getDisplayDecorationSupport( |
| 159 | int64_t display); |
| 160 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 161 | std::pair<ScopedAStatus, int32_t> getMaxVirtualDisplayCount(); |
| 162 | |
| 163 | std::pair<ScopedAStatus, std::string> getDisplayName(int64_t display); |
| 164 | |
| 165 | ScopedAStatus setClientTargetSlotCount(int64_t display, int32_t bufferSlotCount); |
| 166 | |
| 167 | std::pair<ScopedAStatus, std::vector<Capability>> getCapabilities(); |
| 168 | |
| 169 | ScopedAStatus setBootDisplayConfig(int64_t display, int32_t config); |
| 170 | |
| 171 | ScopedAStatus clearBootDisplayConfig(int64_t display); |
| 172 | |
| 173 | std::pair<ScopedAStatus, int32_t> getPreferredBootDisplayConfig(int64_t display); |
| 174 | |
Kriti Dang | 3793ebd | 2022-12-05 13:03:49 +0100 | [diff] [blame] | 175 | std::pair<ScopedAStatus, std::vector<common::HdrConversionCapability>> |
| 176 | getHdrConversionCapabilities(); |
| 177 | |
Kriti Dang | 3762276 | 2023-02-09 18:15:37 +0100 | [diff] [blame] | 178 | std::pair<ScopedAStatus, common::Hdr> setHdrConversionStrategy( |
| 179 | const common::HdrConversionStrategy& conversionStrategy); |
Kriti Dang | 3793ebd | 2022-12-05 13:03:49 +0100 | [diff] [blame] | 180 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 181 | std::pair<ScopedAStatus, common::Transform> getDisplayPhysicalOrientation(int64_t display); |
| 182 | |
| 183 | ScopedAStatus setIdleTimerEnabled(int64_t display, int32_t timeoutMs); |
| 184 | |
| 185 | int32_t getVsyncIdleCount(); |
| 186 | |
| 187 | int64_t getVsyncIdleTime(); |
| 188 | |
| 189 | int64_t getInvalidDisplayId(); |
| 190 | |
| 191 | std::pair<ScopedAStatus, std::vector<VtsDisplay>> getDisplays(); |
| 192 | |
Sally Qi | 2600d34 | 2022-08-16 12:46:17 -0700 | [diff] [blame] | 193 | std::pair<ScopedAStatus, OverlayProperties> getOverlaySupport(); |
| 194 | |
ramindani | 9dd8c48 | 2023-02-21 18:07:56 -0800 | [diff] [blame] | 195 | ndk::ScopedAStatus setRefreshRateChangedCallbackDebugEnabled(int64_t display, bool enabled); |
| 196 | |
| 197 | std::vector<RefreshRateChangedDebugData> takeListOfRefreshRateChangedDebugData(); |
| 198 | |
ramindani | 2704c5f | 2023-07-18 20:53:24 -0700 | [diff] [blame] | 199 | static constexpr int32_t kMaxFrameIntervalNs = 50000000; // 20fps |
| 200 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 201 | private: |
ramindani | 02fe477 | 2023-06-30 18:04:41 -0700 | [diff] [blame] | 202 | void addDisplayConfigs(VtsDisplay*, const std::vector<DisplayConfiguration>&); |
| 203 | ScopedAStatus addDisplayConfigLegacy(VtsDisplay*, int32_t config); |
| 204 | bool getDisplayConfigurationSupported() const; |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 205 | ScopedAStatus updateDisplayProperties(VtsDisplay* vtsDisplay, int32_t config); |
| 206 | |
| 207 | ScopedAStatus addDisplayToDisplayResources(int64_t display, bool isVirtual); |
| 208 | |
| 209 | ScopedAStatus addLayerToDisplayResources(int64_t display, int64_t layer); |
| 210 | |
| 211 | void removeLayerFromDisplayResources(int64_t display, int64_t layer); |
| 212 | |
| 213 | bool destroyAllLayers(); |
| 214 | |
| 215 | bool verifyComposerCallbackParams(); |
| 216 | |
| 217 | // Keep track of displays and layers. When a test fails/ends, |
| 218 | // the VtsComposerClient::tearDown should be called from the |
| 219 | // test tearDown to clean up the resources for the test. |
| 220 | struct DisplayResource { |
| 221 | DisplayResource(bool isVirtual_) : isVirtual(isVirtual_) {} |
| 222 | |
| 223 | bool isVirtual; |
| 224 | std::unordered_set<int64_t> layers; |
| 225 | }; |
| 226 | |
| 227 | std::shared_ptr<IComposer> mComposer; |
| 228 | std::shared_ptr<IComposerClient> mComposerClient; |
| 229 | std::shared_ptr<GraphicsComposerCallback> mComposerCallback; |
| 230 | std::unordered_map<int64_t, DisplayResource> mDisplayResources; |
| 231 | }; |
| 232 | |
| 233 | class VtsDisplay { |
| 234 | public: |
Greg Kaiser | c20d70e | 2022-02-09 07:11:33 -0800 | [diff] [blame] | 235 | VtsDisplay(int64_t displayId) : mDisplayId(displayId), mDisplayWidth(0), mDisplayHeight(0) {} |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 236 | |
| 237 | int64_t getDisplayId() const { return mDisplayId; } |
| 238 | |
| 239 | FRect getCrop() const { |
| 240 | return {0, 0, static_cast<float>(mDisplayWidth), static_cast<float>(mDisplayHeight)}; |
| 241 | } |
| 242 | |
| 243 | Rect getFrameRect() const { return {0, 0, mDisplayWidth, mDisplayHeight}; } |
| 244 | |
| 245 | void setDimensions(int32_t displayWidth, int32_t displayHeight) { |
| 246 | mDisplayWidth = displayWidth; |
| 247 | mDisplayHeight = displayHeight; |
| 248 | } |
| 249 | |
| 250 | int32_t getDisplayWidth() const { return mDisplayWidth; } |
| 251 | |
| 252 | int32_t getDisplayHeight() const { return mDisplayHeight; } |
| 253 | |
| 254 | struct DisplayConfig { |
| 255 | DisplayConfig(int32_t vsyncPeriod_, int32_t configGroup_) |
| 256 | : vsyncPeriod(vsyncPeriod_), configGroup(configGroup_) {} |
| 257 | int32_t vsyncPeriod; |
| 258 | int32_t configGroup; |
| 259 | }; |
| 260 | |
| 261 | void addDisplayConfig(int32_t config, DisplayConfig displayConfig) { |
ramindani | 9dd8c48 | 2023-02-21 18:07:56 -0800 | [diff] [blame] | 262 | mDisplayConfigs.insert({config, displayConfig}); |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 263 | } |
| 264 | |
ramindani | 9dd8c48 | 2023-02-21 18:07:56 -0800 | [diff] [blame] | 265 | DisplayConfig getDisplayConfig(int32_t config) { return mDisplayConfigs.find(config)->second; } |
| 266 | |
| 267 | std::unordered_map<int32_t, DisplayConfig> getDisplayConfigs() { return mDisplayConfigs; } |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 268 | |
| 269 | private: |
| 270 | int64_t mDisplayId; |
| 271 | int32_t mDisplayWidth; |
| 272 | int32_t mDisplayHeight; |
ramindani | 9dd8c48 | 2023-02-21 18:07:56 -0800 | [diff] [blame] | 273 | std::unordered_map<int32_t, DisplayConfig> mDisplayConfigs; |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 274 | }; |
Greg Kaiser | c20d70e | 2022-02-09 07:11:33 -0800 | [diff] [blame] | 275 | } // namespace aidl::android::hardware::graphics::composer3::vts |