ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2021, 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 | #pragma once |
| 18 | |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 19 | #include <aidl/android/hardware/graphics/composer3/IComposerClient.h> |
| 20 | #include <android-base/unique_fd.h> |
Ady Abraham | 91c9d1a | 2021-12-15 18:14:45 -0800 | [diff] [blame] | 21 | #include <android/hardware/graphics/composer3/ComposerClientReader.h> |
| 22 | #include <android/hardware/graphics/composer3/ComposerClientWriter.h> |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 23 | #include <mapper-vts/2.1/MapperVts.h> |
| 24 | #include <renderengine/RenderEngine.h> |
| 25 | #include <ui/GraphicBuffer.h> |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 26 | #include <memory> |
ramindani | edf3ef9 | 2022-01-07 00:04:23 +0000 | [diff] [blame] | 27 | #include "GraphicsComposerCallback.h" |
| 28 | #include "VtsComposerClient.h" |
Ram Indani | 22884ac | 2022-01-29 02:00:21 +0000 | [diff] [blame] | 29 | |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 30 | namespace aidl::android::hardware::graphics::composer3::vts { |
| 31 | |
| 32 | using ::android::renderengine::LayerSettings; |
| 33 | using common::Dataspace; |
| 34 | using common::PixelFormat; |
| 35 | using IMapper2_1 = ::android::hardware::graphics::mapper::V2_1::IMapper; |
| 36 | |
Ady Abraham | 1bee7ab | 2022-01-06 17:22:08 -0800 | [diff] [blame] | 37 | static const Color BLACK = {0.0f, 0.0f, 0.0f, 1.0f}; |
| 38 | static const Color RED = {1.0f, 0.0f, 0.0f, 1.0f}; |
Alec Mouri | 5106701 | 2022-01-06 17:28:39 -0800 | [diff] [blame] | 39 | // DIM_RED is 90% dimmed from RED in linear space |
| 40 | // hard-code as value 243 in 8-bit space here, as calculating it requires |
| 41 | // oetf(eotf(value) * .9), which is a complex non-linear transformation |
| 42 | static const Color DIM_RED = {243.f / 255.f, 0.0f, 0.0f, 1.0f}; |
Ady Abraham | 1bee7ab | 2022-01-06 17:22:08 -0800 | [diff] [blame] | 43 | static const Color TRANSLUCENT_RED = {1.0f, 0.0f, 0.0f, 0.3f}; |
| 44 | static const Color GREEN = {0.0f, 1.0f, 0.0f, 1.0f}; |
| 45 | static const Color BLUE = {0.0f, 0.0f, 1.0f, 1.0f}; |
| 46 | static const Color WHITE = {1.0f, 1.0f, 1.0f, 1.0f}; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 47 | |
| 48 | class TestRenderEngine; |
| 49 | |
| 50 | class TestLayer { |
| 51 | public: |
ramindani | dcecfd4 | 2022-02-03 23:52:19 +0000 | [diff] [blame] | 52 | TestLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display) |
| 53 | : mDisplay(display) { |
| 54 | const auto& [status, layer] = client->createLayer(display, kBufferSlotCount); |
| 55 | EXPECT_TRUE(status.isOk()); |
| 56 | mLayer = layer; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | // ComposerClient will take care of destroying layers, no need to explicitly |
| 60 | // call destroyLayers here |
| 61 | virtual ~TestLayer(){}; |
| 62 | |
Ady Abraham | 91c9d1a | 2021-12-15 18:14:45 -0800 | [diff] [blame] | 63 | virtual void write(ComposerClientWriter& writer); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 64 | virtual LayerSettings toRenderEngineLayerSettings(); |
| 65 | |
| 66 | void setDisplayFrame(Rect frame) { mDisplayFrame = frame; } |
| 67 | void setSourceCrop(FRect crop) { mSourceCrop = crop; } |
| 68 | void setZOrder(uint32_t z) { mZOrder = z; } |
Alec Mouri | 5106701 | 2022-01-06 17:28:39 -0800 | [diff] [blame] | 69 | void setWhitePointNits(float whitePointNits) { mWhitePointNits = whitePointNits; } |
Alec Mouri | b1f1672 | 2022-02-07 13:03:44 -0800 | [diff] [blame] | 70 | void setBrightness(float brightness) { mBrightness = brightness; } |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 71 | |
| 72 | void setSurfaceDamage(std::vector<Rect> surfaceDamage) { |
| 73 | mSurfaceDamage = std::move(surfaceDamage); |
| 74 | } |
| 75 | |
| 76 | void setTransform(Transform transform) { mTransform = transform; } |
| 77 | void setAlpha(float alpha) { mAlpha = alpha; } |
| 78 | void setBlendMode(BlendMode blendMode) { mBlendMode = blendMode; } |
| 79 | |
| 80 | BlendMode getBlendMode() const { return mBlendMode; } |
| 81 | |
| 82 | uint32_t getZOrder() const { return mZOrder; } |
| 83 | |
| 84 | float getAlpha() const { return mAlpha; } |
| 85 | |
Ady Abraham | 3192f3d | 2021-12-03 16:08:56 -0800 | [diff] [blame] | 86 | int64_t getLayer() const { return mLayer; } |
| 87 | |
Alec Mouri | b1f1672 | 2022-02-07 13:03:44 -0800 | [diff] [blame] | 88 | float getBrightness() const { return mBrightness; } |
Alec Mouri | 5106701 | 2022-01-06 17:28:39 -0800 | [diff] [blame] | 89 | |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 90 | protected: |
Ady Abraham | 3192f3d | 2021-12-03 16:08:56 -0800 | [diff] [blame] | 91 | int64_t mDisplay; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 92 | int64_t mLayer; |
| 93 | Rect mDisplayFrame = {0, 0, 0, 0}; |
Alec Mouri | b1f1672 | 2022-02-07 13:03:44 -0800 | [diff] [blame] | 94 | float mBrightness = 1.f; |
Alec Mouri | 5106701 | 2022-01-06 17:28:39 -0800 | [diff] [blame] | 95 | float mWhitePointNits = -1.f; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 96 | std::vector<Rect> mSurfaceDamage; |
| 97 | Transform mTransform = static_cast<Transform>(0); |
| 98 | FRect mSourceCrop = {0, 0, 0, 0}; |
| 99 | static constexpr uint32_t kBufferSlotCount = 64; |
| 100 | float mAlpha = 1.0; |
| 101 | BlendMode mBlendMode = BlendMode::NONE; |
| 102 | uint32_t mZOrder = 0; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | class TestColorLayer : public TestLayer { |
| 106 | public: |
ramindani | dcecfd4 | 2022-02-03 23:52:19 +0000 | [diff] [blame] | 107 | TestColorLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display) |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 108 | : TestLayer{client, display} {} |
| 109 | |
Ady Abraham | 91c9d1a | 2021-12-15 18:14:45 -0800 | [diff] [blame] | 110 | void write(ComposerClientWriter& writer) override; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 111 | |
| 112 | LayerSettings toRenderEngineLayerSettings() override; |
| 113 | |
| 114 | void setColor(Color color) { mColor = color; } |
| 115 | |
| 116 | private: |
| 117 | Color mColor = WHITE; |
| 118 | }; |
| 119 | |
| 120 | class TestBufferLayer : public TestLayer { |
| 121 | public: |
ramindani | dcecfd4 | 2022-02-03 23:52:19 +0000 | [diff] [blame] | 122 | TestBufferLayer(const std::shared_ptr<VtsComposerClient>& client, |
Ady Abraham | 4aa4ead | 2021-12-03 16:07:19 -0800 | [diff] [blame] | 123 | TestRenderEngine& renderEngine, int64_t display, uint32_t width, |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 124 | uint32_t height, common::PixelFormat format, |
| 125 | Composition composition = Composition::DEVICE); |
| 126 | |
Ady Abraham | 91c9d1a | 2021-12-15 18:14:45 -0800 | [diff] [blame] | 127 | void write(ComposerClientWriter& writer) override; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 128 | |
| 129 | LayerSettings toRenderEngineLayerSettings() override; |
| 130 | |
| 131 | void fillBuffer(std::vector<Color>& expectedColors); |
| 132 | |
| 133 | void setBuffer(std::vector<Color> colors); |
| 134 | |
Ady Abraham | 91c9d1a | 2021-12-15 18:14:45 -0800 | [diff] [blame] | 135 | void setDataspace(Dataspace dataspace, ComposerClientWriter& writer); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 136 | |
Ady Abraham | 91c9d1a | 2021-12-15 18:14:45 -0800 | [diff] [blame] | 137 | void setToClientComposition(ComposerClientWriter& writer); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 138 | |
| 139 | uint32_t getWidth() const { return mWidth; } |
| 140 | |
| 141 | uint32_t getHeight() const { return mHeight; } |
| 142 | |
| 143 | ::android::Rect getAccessRegion() const { return mAccessRegion; } |
| 144 | |
| 145 | uint32_t getLayerCount() const { return mLayerCount; } |
| 146 | |
| 147 | protected: |
| 148 | Composition mComposition; |
Brian Lindahl | e887a25 | 2023-01-17 14:54:19 -0700 | [diff] [blame^] | 149 | ::android::sp<::android::GraphicBuffer> mGraphicBuffer; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 150 | TestRenderEngine& mRenderEngine; |
| 151 | int32_t mFillFence; |
| 152 | uint32_t mWidth; |
| 153 | uint32_t mHeight; |
| 154 | uint32_t mLayerCount; |
| 155 | PixelFormat mPixelFormat; |
| 156 | uint32_t mUsage; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 157 | ::android::Rect mAccessRegion; |
ramindani | 0a2bee4 | 2022-02-10 01:27:42 +0000 | [diff] [blame] | 158 | |
| 159 | private: |
| 160 | ::android::sp<::android::GraphicBuffer> allocateBuffer(); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | class ReadbackHelper { |
| 164 | public: |
| 165 | static std::string getColorModeString(ColorMode mode); |
| 166 | |
| 167 | static std::string getDataspaceString(Dataspace dataspace); |
| 168 | |
| 169 | static Dataspace getDataspaceForColorMode(ColorMode mode); |
| 170 | |
| 171 | static int32_t GetBytesPerPixel(PixelFormat pixelFormat); |
| 172 | |
| 173 | static void fillBuffer(uint32_t width, uint32_t height, uint32_t stride, void* bufferData, |
Brian Lindahl | e887a25 | 2023-01-17 14:54:19 -0700 | [diff] [blame^] | 174 | PixelFormat pixelFormat, std::vector<Color> desiredPixelColors); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 175 | |
Brian Lindahl | e887a25 | 2023-01-17 14:54:19 -0700 | [diff] [blame^] | 176 | static void clearColors(std::vector<Color>& expectedColors, int32_t width, int32_t height, |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 177 | int32_t displayWidth); |
| 178 | |
Brian Lindahl | e887a25 | 2023-01-17 14:54:19 -0700 | [diff] [blame^] | 179 | static void fillColorsArea(std::vector<Color>& expectedColors, int32_t stride, Rect area, |
| 180 | Color color); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 181 | |
Brian Lindahl | e887a25 | 2023-01-17 14:54:19 -0700 | [diff] [blame^] | 182 | static bool readbackSupported(const PixelFormat& pixelFormat, const Dataspace& dataspace); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 183 | |
| 184 | static const std::vector<ColorMode> colorModes; |
| 185 | static const std::vector<Dataspace> dataspaces; |
Brian Lindahl | e887a25 | 2023-01-17 14:54:19 -0700 | [diff] [blame^] | 186 | |
| 187 | static void compareColorBuffers(const std::vector<Color>& expectedColors, void* bufferData, |
| 188 | const uint32_t stride, const uint32_t width, |
| 189 | const uint32_t height, PixelFormat pixelFormat); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | class ReadbackBuffer { |
| 193 | public: |
ramindani | dcecfd4 | 2022-02-03 23:52:19 +0000 | [diff] [blame] | 194 | ReadbackBuffer(int64_t display, const std::shared_ptr<VtsComposerClient>& client, int32_t width, |
Brian Lindahl | e887a25 | 2023-01-17 14:54:19 -0700 | [diff] [blame^] | 195 | int32_t height, common::PixelFormat pixelFormat, common::Dataspace dataspace); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 196 | |
| 197 | void setReadbackBuffer(); |
| 198 | |
ramindani | dcecfd4 | 2022-02-03 23:52:19 +0000 | [diff] [blame] | 199 | void checkReadbackBuffer(const std::vector<Color>& expectedColors); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 200 | |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 201 | protected: |
| 202 | uint32_t mWidth; |
| 203 | uint32_t mHeight; |
| 204 | uint32_t mLayerCount; |
| 205 | uint32_t mUsage; |
Brian Lindahl | e887a25 | 2023-01-17 14:54:19 -0700 | [diff] [blame^] | 206 | PixelFormat mPixelFormat; |
| 207 | Dataspace mDataspace; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 208 | int64_t mDisplay; |
Brian Lindahl | e887a25 | 2023-01-17 14:54:19 -0700 | [diff] [blame^] | 209 | ::android::sp<::android::GraphicBuffer> mGraphicBuffer; |
ramindani | dcecfd4 | 2022-02-03 23:52:19 +0000 | [diff] [blame] | 210 | std::shared_ptr<VtsComposerClient> mComposerClient; |
Brian Lindahl | e887a25 | 2023-01-17 14:54:19 -0700 | [diff] [blame^] | 211 | ::android::Rect mAccessRegion; |
| 212 | native_handle_t mBufferHandle; |
| 213 | |
| 214 | private: |
| 215 | ::android::sp<::android::GraphicBuffer> allocateBuffer(); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 216 | }; |
| 217 | |
Ady Abraham | 3192f3d | 2021-12-03 16:08:56 -0800 | [diff] [blame] | 218 | } // namespace aidl::android::hardware::graphics::composer3::vts |