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; |
Brian Lindahl | d103cd6 | 2022-12-09 07:26:28 -0700 | [diff] [blame] | 36 | using ::android::GraphicBuffer; |
| 37 | using ::android::sp; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 38 | |
Ady Abraham | 1bee7ab | 2022-01-06 17:22:08 -0800 | [diff] [blame] | 39 | static const Color BLACK = {0.0f, 0.0f, 0.0f, 1.0f}; |
| 40 | static const Color RED = {1.0f, 0.0f, 0.0f, 1.0f}; |
Alec Mouri | 5106701 | 2022-01-06 17:28:39 -0800 | [diff] [blame] | 41 | // DIM_RED is 90% dimmed from RED in linear space |
| 42 | // hard-code as value 243 in 8-bit space here, as calculating it requires |
| 43 | // oetf(eotf(value) * .9), which is a complex non-linear transformation |
| 44 | 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] | 45 | static const Color TRANSLUCENT_RED = {1.0f, 0.0f, 0.0f, 0.3f}; |
| 46 | static const Color GREEN = {0.0f, 1.0f, 0.0f, 1.0f}; |
| 47 | static const Color BLUE = {0.0f, 0.0f, 1.0f, 1.0f}; |
| 48 | static const Color WHITE = {1.0f, 1.0f, 1.0f, 1.0f}; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 49 | |
| 50 | class TestRenderEngine; |
| 51 | |
| 52 | class TestLayer { |
| 53 | public: |
ramindani | dcecfd4 | 2022-02-03 23:52:19 +0000 | [diff] [blame] | 54 | TestLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display) |
| 55 | : mDisplay(display) { |
| 56 | const auto& [status, layer] = client->createLayer(display, kBufferSlotCount); |
| 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 | |
| 78 | void setTransform(Transform transform) { mTransform = transform; } |
| 79 | void setAlpha(float alpha) { mAlpha = alpha; } |
| 80 | void setBlendMode(BlendMode blendMode) { mBlendMode = blendMode; } |
| 81 | |
| 82 | BlendMode getBlendMode() const { return mBlendMode; } |
| 83 | |
| 84 | uint32_t getZOrder() const { return mZOrder; } |
| 85 | |
| 86 | float getAlpha() const { return mAlpha; } |
| 87 | |
Ady Abraham | 3192f3d | 2021-12-03 16:08:56 -0800 | [diff] [blame] | 88 | int64_t getLayer() const { return mLayer; } |
| 89 | |
Alec Mouri | b1f1672 | 2022-02-07 13:03:44 -0800 | [diff] [blame] | 90 | float getBrightness() const { return mBrightness; } |
Alec Mouri | 5106701 | 2022-01-06 17:28:39 -0800 | [diff] [blame] | 91 | |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 92 | protected: |
Ady Abraham | 3192f3d | 2021-12-03 16:08:56 -0800 | [diff] [blame] | 93 | int64_t mDisplay; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 94 | int64_t mLayer; |
| 95 | Rect mDisplayFrame = {0, 0, 0, 0}; |
Alec Mouri | b1f1672 | 2022-02-07 13:03:44 -0800 | [diff] [blame] | 96 | float mBrightness = 1.f; |
Alec Mouri | 5106701 | 2022-01-06 17:28:39 -0800 | [diff] [blame] | 97 | float mWhitePointNits = -1.f; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 98 | std::vector<Rect> mSurfaceDamage; |
| 99 | Transform mTransform = static_cast<Transform>(0); |
| 100 | FRect mSourceCrop = {0, 0, 0, 0}; |
| 101 | static constexpr uint32_t kBufferSlotCount = 64; |
| 102 | float mAlpha = 1.0; |
| 103 | BlendMode mBlendMode = BlendMode::NONE; |
| 104 | uint32_t mZOrder = 0; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | class TestColorLayer : public TestLayer { |
| 108 | public: |
ramindani | dcecfd4 | 2022-02-03 23:52:19 +0000 | [diff] [blame] | 109 | TestColorLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display) |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 110 | : TestLayer{client, display} {} |
| 111 | |
Ady Abraham | 91c9d1a | 2021-12-15 18:14:45 -0800 | [diff] [blame] | 112 | void write(ComposerClientWriter& writer) override; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 113 | |
| 114 | LayerSettings toRenderEngineLayerSettings() override; |
| 115 | |
| 116 | void setColor(Color color) { mColor = color; } |
| 117 | |
| 118 | private: |
| 119 | Color mColor = WHITE; |
| 120 | }; |
| 121 | |
| 122 | class TestBufferLayer : public TestLayer { |
| 123 | public: |
ramindani | dcecfd4 | 2022-02-03 23:52:19 +0000 | [diff] [blame] | 124 | TestBufferLayer(const std::shared_ptr<VtsComposerClient>& client, |
Ady Abraham | 4aa4ead | 2021-12-03 16:07:19 -0800 | [diff] [blame] | 125 | TestRenderEngine& renderEngine, int64_t display, uint32_t width, |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 126 | uint32_t height, common::PixelFormat format, |
| 127 | Composition composition = Composition::DEVICE); |
| 128 | |
Ady Abraham | 91c9d1a | 2021-12-15 18:14:45 -0800 | [diff] [blame] | 129 | void write(ComposerClientWriter& writer) override; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 130 | |
| 131 | LayerSettings toRenderEngineLayerSettings() override; |
| 132 | |
| 133 | void fillBuffer(std::vector<Color>& expectedColors); |
| 134 | |
| 135 | void setBuffer(std::vector<Color> colors); |
| 136 | |
Ady Abraham | 91c9d1a | 2021-12-15 18:14:45 -0800 | [diff] [blame] | 137 | void setDataspace(Dataspace dataspace, ComposerClientWriter& writer); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 138 | |
Ady Abraham | 91c9d1a | 2021-12-15 18:14:45 -0800 | [diff] [blame] | 139 | void setToClientComposition(ComposerClientWriter& writer); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 140 | |
| 141 | uint32_t getWidth() const { return mWidth; } |
| 142 | |
| 143 | uint32_t getHeight() const { return mHeight; } |
| 144 | |
| 145 | ::android::Rect getAccessRegion() const { return mAccessRegion; } |
| 146 | |
| 147 | uint32_t getLayerCount() const { return mLayerCount; } |
| 148 | |
| 149 | protected: |
| 150 | Composition mComposition; |
Brian Lindahl | d103cd6 | 2022-12-09 07:26:28 -0700 | [diff] [blame] | 151 | sp<GraphicBuffer> mGraphicBuffer; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 152 | TestRenderEngine& mRenderEngine; |
| 153 | int32_t mFillFence; |
| 154 | uint32_t mWidth; |
| 155 | uint32_t mHeight; |
| 156 | uint32_t mLayerCount; |
| 157 | PixelFormat mPixelFormat; |
| 158 | uint32_t mUsage; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 159 | ::android::Rect mAccessRegion; |
ramindani | 0a2bee4 | 2022-02-10 01:27:42 +0000 | [diff] [blame] | 160 | |
| 161 | private: |
| 162 | ::android::sp<::android::GraphicBuffer> allocateBuffer(); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | class ReadbackHelper { |
| 166 | public: |
Brian Lindahl | d103cd6 | 2022-12-09 07:26:28 -0700 | [diff] [blame] | 167 | static bool readbackSupported(const PixelFormat& pixelFormat, const Dataspace& dataspace); |
| 168 | |
| 169 | static void createReadbackBuffer(ReadbackBufferAttributes readbackBufferAttributes, |
| 170 | const VtsDisplay& display, sp<GraphicBuffer>* graphicBuffer); |
| 171 | |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 172 | static std::string getColorModeString(ColorMode mode); |
| 173 | |
| 174 | static std::string getDataspaceString(Dataspace dataspace); |
| 175 | |
| 176 | static Dataspace getDataspaceForColorMode(ColorMode mode); |
| 177 | |
| 178 | static int32_t GetBytesPerPixel(PixelFormat pixelFormat); |
| 179 | |
| 180 | static void fillBuffer(uint32_t width, uint32_t height, uint32_t stride, void* bufferData, |
Brian Lindahl | d103cd6 | 2022-12-09 07:26:28 -0700 | [diff] [blame] | 181 | PixelFormat pixelFormat, const std::vector<Color>& desriedColors); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 182 | |
Brian Lindahl | d103cd6 | 2022-12-09 07:26:28 -0700 | [diff] [blame] | 183 | static void clearColors(std::vector<Color>& colors, int32_t width, int32_t height, |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 184 | int32_t displayWidth); |
| 185 | |
Brian Lindahl | d103cd6 | 2022-12-09 07:26:28 -0700 | [diff] [blame] | 186 | static void fillColorsArea(std::vector<Color>& colors, int32_t stride, Rect area, |
| 187 | Color desiredColor); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 188 | |
Brian Lindahl | d103cd6 | 2022-12-09 07:26:28 -0700 | [diff] [blame] | 189 | static void fillBufferAndGetFence(const sp<GraphicBuffer>& buffer, Color desiredColor, |
| 190 | int* fillFence); |
| 191 | |
| 192 | static void fillBufferAndGetFence(const sp<GraphicBuffer>& buffer, |
| 193 | const std::vector<Color>& desiredColors, int* fillFence); |
| 194 | |
| 195 | static void compareColorToBuffer( |
| 196 | Color expectedColor, const sp<GraphicBuffer>& graphicBuffer, |
| 197 | const ndk::ScopedFileDescriptor& fence = ::ndk::ScopedFileDescriptor(-1)); |
| 198 | |
| 199 | static void compareColorsToBuffer( |
| 200 | const std::vector<Color>& expectedColors, const sp<GraphicBuffer>& graphicBuffer, |
| 201 | const ndk::ScopedFileDescriptor& fence = ::ndk::ScopedFileDescriptor(-1)); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 202 | |
| 203 | static const std::vector<ColorMode> colorModes; |
| 204 | static const std::vector<Dataspace> dataspaces; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 205 | }; |
| 206 | |
| 207 | class ReadbackBuffer { |
| 208 | public: |
ramindani | dcecfd4 | 2022-02-03 23:52:19 +0000 | [diff] [blame] | 209 | ReadbackBuffer(int64_t display, const std::shared_ptr<VtsComposerClient>& client, int32_t width, |
Brian Lindahl | d103cd6 | 2022-12-09 07:26:28 -0700 | [diff] [blame] | 210 | int32_t height, common::PixelFormat pixelFormat); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 211 | |
| 212 | void setReadbackBuffer(); |
| 213 | |
ramindani | dcecfd4 | 2022-02-03 23:52:19 +0000 | [diff] [blame] | 214 | void checkReadbackBuffer(const std::vector<Color>& expectedColors); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 215 | |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 216 | protected: |
| 217 | uint32_t mWidth; |
| 218 | uint32_t mHeight; |
Brian Lindahl | d103cd6 | 2022-12-09 07:26:28 -0700 | [diff] [blame] | 219 | PixelFormat mPixelFormat; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 220 | uint32_t mLayerCount; |
| 221 | uint32_t mUsage; |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 222 | int64_t mDisplay; |
Brian Lindahl | d103cd6 | 2022-12-09 07:26:28 -0700 | [diff] [blame] | 223 | sp<GraphicBuffer> mGraphicBuffer; |
ramindani | dcecfd4 | 2022-02-03 23:52:19 +0000 | [diff] [blame] | 224 | std::shared_ptr<VtsComposerClient> mComposerClient; |
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 |