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> |
| 38 | #include "GraphicsComposerCallback.h" |
| 39 | |
| 40 | using aidl::android::hardware::graphics::common::Dataspace; |
Leon Scroggins III | de05758 | 2022-01-13 12:26:00 -0500 | [diff] [blame] | 41 | using aidl::android::hardware::graphics::common::DisplayDecorationSupport; |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 42 | using aidl::android::hardware::graphics::common::FRect; |
| 43 | using aidl::android::hardware::graphics::common::PixelFormat; |
| 44 | using aidl::android::hardware::graphics::common::Rect; |
| 45 | using namespace ::ndk; |
| 46 | |
| 47 | namespace aidl::android::hardware::graphics::composer3::vts { |
| 48 | |
| 49 | class VtsDisplay; |
| 50 | /** |
| 51 | * A wrapper to IComposerClient. |
| 52 | * This wrapper manages the IComposerClient instance and manages the resources for |
| 53 | * the tests with respect to the IComposerClient calls. |
| 54 | */ |
| 55 | class VtsComposerClient { |
| 56 | public: |
| 57 | VtsComposerClient(const std::string& name); |
| 58 | |
| 59 | ScopedAStatus createClient(); |
| 60 | |
| 61 | bool tearDown(); |
| 62 | |
| 63 | std::pair<ScopedAStatus, VirtualDisplay> createVirtualDisplay(int32_t width, int32_t height, |
| 64 | PixelFormat pixelFormat, |
| 65 | int32_t bufferSlotCount); |
| 66 | |
| 67 | ScopedAStatus destroyVirtualDisplay(int64_t display); |
| 68 | |
| 69 | std::pair<ScopedAStatus, int64_t> createLayer(int64_t display, int32_t bufferSlotCount); |
| 70 | |
| 71 | ScopedAStatus destroyLayer(int64_t display, int64_t layer); |
| 72 | |
| 73 | std::pair<ScopedAStatus, int32_t> getActiveConfig(int64_t display); |
| 74 | |
| 75 | ScopedAStatus setActiveConfig(VtsDisplay* vtsDisplay, int32_t config); |
| 76 | |
| 77 | std::pair<ScopedAStatus, int32_t> getDisplayAttribute(int64_t display, int32_t config, |
| 78 | DisplayAttribute displayAttribute); |
| 79 | |
| 80 | ScopedAStatus setPowerMode(int64_t display, PowerMode powerMode); |
| 81 | |
| 82 | ScopedAStatus setVsync(int64_t display, bool enable); |
| 83 | |
| 84 | void setVsyncAllowed(bool isAllowed); |
| 85 | |
| 86 | std::pair<ScopedAStatus, std::vector<float>> getDataspaceSaturationMatrix(Dataspace dataspace); |
| 87 | |
| 88 | std::pair<ScopedAStatus, std::vector<CommandResultPayload>> executeCommands( |
| 89 | const std::vector<DisplayCommand>& commands); |
| 90 | |
| 91 | std::optional<VsyncPeriodChangeTimeline> takeLastVsyncPeriodChangeTimeline(); |
| 92 | |
| 93 | ScopedAStatus setContentType(int64_t display, ContentType contentType); |
| 94 | |
| 95 | std::pair<ScopedAStatus, VsyncPeriodChangeTimeline> setActiveConfigWithConstraints( |
| 96 | VtsDisplay* vtsDisplay, int32_t config, |
| 97 | const VsyncPeriodChangeConstraints& constraints); |
| 98 | |
| 99 | std::pair<ScopedAStatus, std::vector<DisplayCapability>> getDisplayCapabilities( |
| 100 | int64_t display); |
| 101 | |
| 102 | ScopedAStatus dumpDebugInfo(); |
| 103 | |
| 104 | std::pair<ScopedAStatus, DisplayIdentification> getDisplayIdentificationData(int64_t display); |
| 105 | |
| 106 | std::pair<ScopedAStatus, HdrCapabilities> getHdrCapabilities(int64_t display); |
| 107 | |
| 108 | std::pair<ScopedAStatus, std::vector<PerFrameMetadataKey>> getPerFrameMetadataKeys( |
| 109 | int64_t display); |
| 110 | |
| 111 | std::pair<ScopedAStatus, ReadbackBufferAttributes> getReadbackBufferAttributes(int64_t display); |
| 112 | |
| 113 | ScopedAStatus setReadbackBuffer(int64_t display, const native_handle_t* buffer, |
| 114 | const ScopedFileDescriptor& releaseFence); |
| 115 | |
| 116 | std::pair<ScopedAStatus, ScopedFileDescriptor> getReadbackBufferFence(int64_t display); |
| 117 | |
| 118 | std::pair<ScopedAStatus, std::vector<ColorMode>> getColorModes(int64_t display); |
| 119 | |
| 120 | std::pair<ScopedAStatus, std::vector<RenderIntent>> getRenderIntents(int64_t display, |
| 121 | ColorMode colorMode); |
| 122 | |
| 123 | ScopedAStatus setColorMode(int64_t display, ColorMode colorMode, RenderIntent renderIntent); |
| 124 | |
| 125 | std::pair<ScopedAStatus, DisplayContentSamplingAttributes> |
| 126 | getDisplayedContentSamplingAttributes(int64_t display); |
| 127 | |
| 128 | ScopedAStatus setDisplayedContentSamplingEnabled(int64_t display, bool isEnabled, |
| 129 | FormatColorComponent formatColorComponent, |
| 130 | int64_t maxFrames); |
| 131 | |
| 132 | std::pair<ScopedAStatus, DisplayContentSample> getDisplayedContentSample(int64_t display, |
| 133 | int64_t maxFrames, |
| 134 | int64_t timestamp); |
| 135 | |
| 136 | std::pair<ScopedAStatus, DisplayConnectionType> getDisplayConnectionType(int64_t display); |
| 137 | |
| 138 | std::pair<ScopedAStatus, std::vector<int32_t>> getDisplayConfigs(int64_t display); |
| 139 | |
| 140 | std::pair<ScopedAStatus, int32_t> getDisplayVsyncPeriod(int64_t display); |
| 141 | |
| 142 | ScopedAStatus setAutoLowLatencyMode(int64_t display, bool isEnabled); |
| 143 | |
| 144 | std::pair<ScopedAStatus, std::vector<ContentType>> getSupportedContentTypes(int64_t display); |
| 145 | |
Leon Scroggins III | de05758 | 2022-01-13 12:26:00 -0500 | [diff] [blame] | 146 | std::pair<ScopedAStatus, std::optional<DisplayDecorationSupport>> getDisplayDecorationSupport( |
| 147 | int64_t display); |
| 148 | |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 149 | std::pair<ScopedAStatus, int32_t> getMaxVirtualDisplayCount(); |
| 150 | |
| 151 | std::pair<ScopedAStatus, std::string> getDisplayName(int64_t display); |
| 152 | |
| 153 | ScopedAStatus setClientTargetSlotCount(int64_t display, int32_t bufferSlotCount); |
| 154 | |
| 155 | std::pair<ScopedAStatus, std::vector<Capability>> getCapabilities(); |
| 156 | |
| 157 | ScopedAStatus setBootDisplayConfig(int64_t display, int32_t config); |
| 158 | |
| 159 | ScopedAStatus clearBootDisplayConfig(int64_t display); |
| 160 | |
| 161 | std::pair<ScopedAStatus, int32_t> getPreferredBootDisplayConfig(int64_t display); |
| 162 | |
| 163 | std::pair<ScopedAStatus, common::Transform> getDisplayPhysicalOrientation(int64_t display); |
| 164 | |
| 165 | ScopedAStatus setIdleTimerEnabled(int64_t display, int32_t timeoutMs); |
| 166 | |
| 167 | int32_t getVsyncIdleCount(); |
| 168 | |
| 169 | int64_t getVsyncIdleTime(); |
| 170 | |
| 171 | int64_t getInvalidDisplayId(); |
| 172 | |
| 173 | std::pair<ScopedAStatus, std::vector<VtsDisplay>> getDisplays(); |
| 174 | |
| 175 | private: |
| 176 | ScopedAStatus updateDisplayProperties(VtsDisplay* vtsDisplay, int32_t config); |
| 177 | |
| 178 | ScopedAStatus addDisplayToDisplayResources(int64_t display, bool isVirtual); |
| 179 | |
| 180 | ScopedAStatus addLayerToDisplayResources(int64_t display, int64_t layer); |
| 181 | |
| 182 | void removeLayerFromDisplayResources(int64_t display, int64_t layer); |
| 183 | |
| 184 | bool destroyAllLayers(); |
| 185 | |
| 186 | bool verifyComposerCallbackParams(); |
| 187 | |
| 188 | // Keep track of displays and layers. When a test fails/ends, |
| 189 | // the VtsComposerClient::tearDown should be called from the |
| 190 | // test tearDown to clean up the resources for the test. |
| 191 | struct DisplayResource { |
| 192 | DisplayResource(bool isVirtual_) : isVirtual(isVirtual_) {} |
| 193 | |
| 194 | bool isVirtual; |
| 195 | std::unordered_set<int64_t> layers; |
| 196 | }; |
| 197 | |
| 198 | std::shared_ptr<IComposer> mComposer; |
| 199 | std::shared_ptr<IComposerClient> mComposerClient; |
| 200 | std::shared_ptr<GraphicsComposerCallback> mComposerCallback; |
| 201 | std::unordered_map<int64_t, DisplayResource> mDisplayResources; |
| 202 | }; |
| 203 | |
| 204 | class VtsDisplay { |
| 205 | public: |
Greg Kaiser | c20d70e | 2022-02-09 07:11:33 -0800 | [diff] [blame] | 206 | VtsDisplay(int64_t displayId) : mDisplayId(displayId), mDisplayWidth(0), mDisplayHeight(0) {} |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 207 | |
| 208 | int64_t getDisplayId() const { return mDisplayId; } |
| 209 | |
| 210 | FRect getCrop() const { |
| 211 | return {0, 0, static_cast<float>(mDisplayWidth), static_cast<float>(mDisplayHeight)}; |
| 212 | } |
| 213 | |
| 214 | Rect getFrameRect() const { return {0, 0, mDisplayWidth, mDisplayHeight}; } |
| 215 | |
| 216 | void setDimensions(int32_t displayWidth, int32_t displayHeight) { |
| 217 | mDisplayWidth = displayWidth; |
| 218 | mDisplayHeight = displayHeight; |
| 219 | } |
| 220 | |
| 221 | int32_t getDisplayWidth() const { return mDisplayWidth; } |
| 222 | |
| 223 | int32_t getDisplayHeight() const { return mDisplayHeight; } |
| 224 | |
| 225 | struct DisplayConfig { |
| 226 | DisplayConfig(int32_t vsyncPeriod_, int32_t configGroup_) |
| 227 | : vsyncPeriod(vsyncPeriod_), configGroup(configGroup_) {} |
| 228 | int32_t vsyncPeriod; |
| 229 | int32_t configGroup; |
| 230 | }; |
| 231 | |
| 232 | void addDisplayConfig(int32_t config, DisplayConfig displayConfig) { |
| 233 | displayConfigs.insert({config, displayConfig}); |
| 234 | } |
| 235 | |
| 236 | DisplayConfig getDisplayConfig(int32_t config) { return displayConfigs.find(config)->second; } |
| 237 | |
| 238 | private: |
| 239 | int64_t mDisplayId; |
| 240 | int32_t mDisplayWidth; |
| 241 | int32_t mDisplayHeight; |
| 242 | std::unordered_map<int32_t, DisplayConfig> displayConfigs; |
| 243 | }; |
Greg Kaiser | c20d70e | 2022-02-09 07:11:33 -0800 | [diff] [blame] | 244 | } // namespace aidl::android::hardware::graphics::composer3::vts |