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