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