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 | |
Brian Lindahl | 78ff2d6 | 2022-12-18 11:21:41 -0700 | [diff] [blame] | 64 | std::pair<ScopedAStatus, int32_t> getInterfaceVersion(); |
| 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 | |
| 80 | std::pair<ScopedAStatus, int32_t> getDisplayAttribute(int64_t display, int32_t config, |
| 81 | DisplayAttribute displayAttribute); |
| 82 | |
| 83 | ScopedAStatus setPowerMode(int64_t display, PowerMode powerMode); |
| 84 | |
| 85 | ScopedAStatus setVsync(int64_t display, bool enable); |
| 86 | |
| 87 | void setVsyncAllowed(bool isAllowed); |
| 88 | |
| 89 | std::pair<ScopedAStatus, std::vector<float>> getDataspaceSaturationMatrix(Dataspace dataspace); |
| 90 | |
| 91 | std::pair<ScopedAStatus, std::vector<CommandResultPayload>> executeCommands( |
| 92 | const std::vector<DisplayCommand>& commands); |
| 93 | |
| 94 | std::optional<VsyncPeriodChangeTimeline> takeLastVsyncPeriodChangeTimeline(); |
| 95 | |
| 96 | ScopedAStatus setContentType(int64_t display, ContentType contentType); |
| 97 | |
| 98 | std::pair<ScopedAStatus, VsyncPeriodChangeTimeline> setActiveConfigWithConstraints( |
| 99 | VtsDisplay* vtsDisplay, int32_t config, |
| 100 | const VsyncPeriodChangeConstraints& constraints); |
| 101 | |
| 102 | std::pair<ScopedAStatus, std::vector<DisplayCapability>> getDisplayCapabilities( |
| 103 | int64_t display); |
| 104 | |
| 105 | ScopedAStatus dumpDebugInfo(); |
| 106 | |
| 107 | std::pair<ScopedAStatus, DisplayIdentification> getDisplayIdentificationData(int64_t display); |
| 108 | |
| 109 | std::pair<ScopedAStatus, HdrCapabilities> getHdrCapabilities(int64_t display); |
| 110 | |
| 111 | std::pair<ScopedAStatus, std::vector<PerFrameMetadataKey>> getPerFrameMetadataKeys( |
| 112 | int64_t display); |
| 113 | |
| 114 | std::pair<ScopedAStatus, ReadbackBufferAttributes> getReadbackBufferAttributes(int64_t display); |
| 115 | |
| 116 | ScopedAStatus setReadbackBuffer(int64_t display, const native_handle_t* buffer, |
| 117 | const ScopedFileDescriptor& releaseFence); |
| 118 | |
| 119 | std::pair<ScopedAStatus, ScopedFileDescriptor> getReadbackBufferFence(int64_t display); |
| 120 | |
| 121 | std::pair<ScopedAStatus, std::vector<ColorMode>> getColorModes(int64_t display); |
| 122 | |
| 123 | std::pair<ScopedAStatus, std::vector<RenderIntent>> getRenderIntents(int64_t display, |
| 124 | ColorMode colorMode); |
| 125 | |
| 126 | ScopedAStatus setColorMode(int64_t display, ColorMode colorMode, RenderIntent renderIntent); |
| 127 | |
| 128 | std::pair<ScopedAStatus, DisplayContentSamplingAttributes> |
| 129 | getDisplayedContentSamplingAttributes(int64_t display); |
| 130 | |
| 131 | ScopedAStatus setDisplayedContentSamplingEnabled(int64_t display, bool isEnabled, |
| 132 | FormatColorComponent formatColorComponent, |
| 133 | int64_t maxFrames); |
| 134 | |
| 135 | std::pair<ScopedAStatus, DisplayContentSample> getDisplayedContentSample(int64_t display, |
| 136 | int64_t maxFrames, |
| 137 | int64_t timestamp); |
| 138 | |
| 139 | std::pair<ScopedAStatus, DisplayConnectionType> getDisplayConnectionType(int64_t display); |
| 140 | |
| 141 | std::pair<ScopedAStatus, std::vector<int32_t>> getDisplayConfigs(int64_t display); |
| 142 | |
| 143 | std::pair<ScopedAStatus, int32_t> getDisplayVsyncPeriod(int64_t display); |
| 144 | |
| 145 | ScopedAStatus setAutoLowLatencyMode(int64_t display, bool isEnabled); |
| 146 | |
| 147 | std::pair<ScopedAStatus, std::vector<ContentType>> getSupportedContentTypes(int64_t display); |
| 148 | |
Leon Scroggins III | de05758 | 2022-01-13 12:26:00 -0500 | [diff] [blame] | 149 | std::pair<ScopedAStatus, std::optional<DisplayDecorationSupport>> getDisplayDecorationSupport( |
| 150 | int64_t display); |
| 151 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 152 | std::pair<ScopedAStatus, int32_t> getMaxVirtualDisplayCount(); |
| 153 | |
| 154 | std::pair<ScopedAStatus, std::string> getDisplayName(int64_t display); |
| 155 | |
| 156 | ScopedAStatus setClientTargetSlotCount(int64_t display, int32_t bufferSlotCount); |
| 157 | |
| 158 | std::pair<ScopedAStatus, std::vector<Capability>> getCapabilities(); |
| 159 | |
| 160 | ScopedAStatus setBootDisplayConfig(int64_t display, int32_t config); |
| 161 | |
| 162 | ScopedAStatus clearBootDisplayConfig(int64_t display); |
| 163 | |
| 164 | std::pair<ScopedAStatus, int32_t> getPreferredBootDisplayConfig(int64_t display); |
| 165 | |
Kriti Dang | 3793ebd | 2022-12-05 13:03:49 +0100 | [diff] [blame] | 166 | std::pair<ScopedAStatus, std::vector<common::HdrConversionCapability>> |
| 167 | getHdrConversionCapabilities(); |
| 168 | |
Kriti Dang | 3762276 | 2023-02-09 18:15:37 +0100 | [diff] [blame^] | 169 | std::pair<ScopedAStatus, common::Hdr> setHdrConversionStrategy( |
| 170 | const common::HdrConversionStrategy& conversionStrategy); |
Kriti Dang | 3793ebd | 2022-12-05 13:03:49 +0100 | [diff] [blame] | 171 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 172 | std::pair<ScopedAStatus, common::Transform> getDisplayPhysicalOrientation(int64_t display); |
| 173 | |
| 174 | ScopedAStatus setIdleTimerEnabled(int64_t display, int32_t timeoutMs); |
| 175 | |
| 176 | int32_t getVsyncIdleCount(); |
| 177 | |
| 178 | int64_t getVsyncIdleTime(); |
| 179 | |
| 180 | int64_t getInvalidDisplayId(); |
| 181 | |
| 182 | std::pair<ScopedAStatus, std::vector<VtsDisplay>> getDisplays(); |
| 183 | |
Sally Qi | 2600d34 | 2022-08-16 12:46:17 -0700 | [diff] [blame] | 184 | std::pair<ScopedAStatus, OverlayProperties> getOverlaySupport(); |
| 185 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 186 | private: |
HyunKyoung | 4775bdc | 2022-11-09 20:43:34 +0900 | [diff] [blame] | 187 | ScopedAStatus addDisplayConfig(VtsDisplay* vtsDisplay, int32_t config); |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 188 | ScopedAStatus updateDisplayProperties(VtsDisplay* vtsDisplay, int32_t config); |
| 189 | |
| 190 | ScopedAStatus addDisplayToDisplayResources(int64_t display, bool isVirtual); |
| 191 | |
| 192 | ScopedAStatus addLayerToDisplayResources(int64_t display, int64_t layer); |
| 193 | |
| 194 | void removeLayerFromDisplayResources(int64_t display, int64_t layer); |
| 195 | |
| 196 | bool destroyAllLayers(); |
| 197 | |
| 198 | bool verifyComposerCallbackParams(); |
| 199 | |
ramindani | 8345034 | 2023-02-03 12:52:08 -0800 | [diff] [blame] | 200 | ndk::ScopedAStatus setRefreshRateChangedCallbackDebugEnabled(int64_t /* display */, |
| 201 | bool /* enabled */); |
| 202 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 203 | // Keep track of displays and layers. When a test fails/ends, |
| 204 | // the VtsComposerClient::tearDown should be called from the |
| 205 | // test tearDown to clean up the resources for the test. |
| 206 | struct DisplayResource { |
| 207 | DisplayResource(bool isVirtual_) : isVirtual(isVirtual_) {} |
| 208 | |
| 209 | bool isVirtual; |
| 210 | std::unordered_set<int64_t> layers; |
| 211 | }; |
| 212 | |
| 213 | std::shared_ptr<IComposer> mComposer; |
| 214 | std::shared_ptr<IComposerClient> mComposerClient; |
| 215 | std::shared_ptr<GraphicsComposerCallback> mComposerCallback; |
| 216 | std::unordered_map<int64_t, DisplayResource> mDisplayResources; |
| 217 | }; |
| 218 | |
| 219 | class VtsDisplay { |
| 220 | public: |
Greg Kaiser | c20d70e | 2022-02-09 07:11:33 -0800 | [diff] [blame] | 221 | VtsDisplay(int64_t displayId) : mDisplayId(displayId), mDisplayWidth(0), mDisplayHeight(0) {} |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 222 | |
| 223 | int64_t getDisplayId() const { return mDisplayId; } |
| 224 | |
| 225 | FRect getCrop() const { |
| 226 | return {0, 0, static_cast<float>(mDisplayWidth), static_cast<float>(mDisplayHeight)}; |
| 227 | } |
| 228 | |
| 229 | Rect getFrameRect() const { return {0, 0, mDisplayWidth, mDisplayHeight}; } |
| 230 | |
| 231 | void setDimensions(int32_t displayWidth, int32_t displayHeight) { |
| 232 | mDisplayWidth = displayWidth; |
| 233 | mDisplayHeight = displayHeight; |
| 234 | } |
| 235 | |
| 236 | int32_t getDisplayWidth() const { return mDisplayWidth; } |
| 237 | |
| 238 | int32_t getDisplayHeight() const { return mDisplayHeight; } |
| 239 | |
| 240 | struct DisplayConfig { |
| 241 | DisplayConfig(int32_t vsyncPeriod_, int32_t configGroup_) |
| 242 | : vsyncPeriod(vsyncPeriod_), configGroup(configGroup_) {} |
| 243 | int32_t vsyncPeriod; |
| 244 | int32_t configGroup; |
| 245 | }; |
| 246 | |
| 247 | void addDisplayConfig(int32_t config, DisplayConfig displayConfig) { |
| 248 | displayConfigs.insert({config, displayConfig}); |
| 249 | } |
| 250 | |
| 251 | DisplayConfig getDisplayConfig(int32_t config) { return displayConfigs.find(config)->second; } |
| 252 | |
| 253 | private: |
| 254 | int64_t mDisplayId; |
| 255 | int32_t mDisplayWidth; |
| 256 | int32_t mDisplayHeight; |
| 257 | std::unordered_map<int32_t, DisplayConfig> displayConfigs; |
| 258 | }; |
Greg Kaiser | c20d70e | 2022-02-09 07:11:33 -0800 | [diff] [blame] | 259 | } // namespace aidl::android::hardware::graphics::composer3::vts |