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