blob: c04e37ad5a614b73b017f1b88eed0d65a53677ec [file] [log] [blame]
ramindanibab8ba92021-11-18 01:24:11 +00001/**
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
ramindanibab8ba92021-11-18 01:24:11 +000019#include <aidl/android/hardware/graphics/composer3/IComposerClient.h>
Sally Qife454362024-12-18 15:44:09 -080020#include <aidl/android/hardware/graphics/composer3/Luts.h>
ramindanibab8ba92021-11-18 01:24:11 +000021#include <android-base/unique_fd.h>
Ady Abraham91c9d1a2021-12-15 18:14:45 -080022#include <android/hardware/graphics/composer3/ComposerClientReader.h>
23#include <android/hardware/graphics/composer3/ComposerClientWriter.h>
ramindanibab8ba92021-11-18 01:24:11 +000024#include <renderengine/RenderEngine.h>
25#include <ui/GraphicBuffer.h>
ramindanibab8ba92021-11-18 01:24:11 +000026#include <memory>
ramindaniedf3ef92022-01-07 00:04:23 +000027#include "GraphicsComposerCallback.h"
28#include "VtsComposerClient.h"
Ram Indani22884ac2022-01-29 02:00:21 +000029
Sally Qife454362024-12-18 15:44:09 -080030using aidl::android::hardware::graphics::composer3::Luts;
31
ramindanibab8ba92021-11-18 01:24:11 +000032namespace aidl::android::hardware::graphics::composer3::vts {
33
34using ::android::renderengine::LayerSettings;
35using common::Dataspace;
36using common::PixelFormat;
ramindanibab8ba92021-11-18 01:24:11 +000037
Ady Abraham1bee7ab2022-01-06 17:22:08 -080038static const Color BLACK = {0.0f, 0.0f, 0.0f, 1.0f};
39static const Color RED = {1.0f, 0.0f, 0.0f, 1.0f};
Alec Mouri51067012022-01-06 17:28:39 -080040// DIM_RED is 90% dimmed from RED in linear space
41// hard-code as value 243 in 8-bit space here, as calculating it requires
42// oetf(eotf(value) * .9), which is a complex non-linear transformation
43static const Color DIM_RED = {243.f / 255.f, 0.0f, 0.0f, 1.0f};
Ady Abraham1bee7ab2022-01-06 17:22:08 -080044static const Color TRANSLUCENT_RED = {1.0f, 0.0f, 0.0f, 0.3f};
45static const Color GREEN = {0.0f, 1.0f, 0.0f, 1.0f};
46static const Color BLUE = {0.0f, 0.0f, 1.0f, 1.0f};
47static const Color WHITE = {1.0f, 1.0f, 1.0f, 1.0f};
Alec Mourif6c039a2023-10-06 23:02:17 +000048static const Color LIGHT_RED = {0.5f, 0.0f, 0.0f, 1.0f};
49static const Color LIGHT_GREEN = {0.0f, 0.5f, 0.0f, 1.0f};
50static const Color LIGHT_BLUE = {0.0f, 0.0f, 0.5f, 1.0f};
ramindanibab8ba92021-11-18 01:24:11 +000051
52class TestRenderEngine;
53
54class TestLayer {
55 public:
Ady Abrahama00d2462023-12-26 14:21:20 -080056 TestLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display,
57 ComposerClientWriter& writer)
ramindanidcecfd42022-02-03 23:52:19 +000058 : mDisplay(display) {
Ady Abrahama00d2462023-12-26 14:21:20 -080059 const auto& [status, layer] = client->createLayer(display, kBufferSlotCount, &writer);
ramindanidcecfd42022-02-03 23:52:19 +000060 EXPECT_TRUE(status.isOk());
61 mLayer = layer;
ramindanibab8ba92021-11-18 01:24:11 +000062 }
63
64 // ComposerClient will take care of destroying layers, no need to explicitly
65 // call destroyLayers here
66 virtual ~TestLayer(){};
67
Ady Abraham91c9d1a2021-12-15 18:14:45 -080068 virtual void write(ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +000069 virtual LayerSettings toRenderEngineLayerSettings();
70
71 void setDisplayFrame(Rect frame) { mDisplayFrame = frame; }
72 void setSourceCrop(FRect crop) { mSourceCrop = crop; }
73 void setZOrder(uint32_t z) { mZOrder = z; }
Alec Mouri51067012022-01-06 17:28:39 -080074 void setWhitePointNits(float whitePointNits) { mWhitePointNits = whitePointNits; }
Alec Mourib1f16722022-02-07 13:03:44 -080075 void setBrightness(float brightness) { mBrightness = brightness; }
ramindanibab8ba92021-11-18 01:24:11 +000076
77 void setSurfaceDamage(std::vector<Rect> surfaceDamage) {
78 mSurfaceDamage = std::move(surfaceDamage);
79 }
80
Alec Mourif6c039a2023-10-06 23:02:17 +000081 void setDataspace(Dataspace dataspace) { mDataspace = dataspace; }
82
ramindanibab8ba92021-11-18 01:24:11 +000083 void setTransform(Transform transform) { mTransform = transform; }
84 void setAlpha(float alpha) { mAlpha = alpha; }
85 void setBlendMode(BlendMode blendMode) { mBlendMode = blendMode; }
Sally Qife454362024-12-18 15:44:09 -080086 void setLuts(Luts luts) { mLuts = std::move(luts); }
ramindanibab8ba92021-11-18 01:24:11 +000087
88 BlendMode getBlendMode() const { return mBlendMode; }
89
90 uint32_t getZOrder() const { return mZOrder; }
91
92 float getAlpha() const { return mAlpha; }
93
Ady Abraham3192f3d2021-12-03 16:08:56 -080094 int64_t getLayer() const { return mLayer; }
95
Alec Mourib1f16722022-02-07 13:03:44 -080096 float getBrightness() const { return mBrightness; }
Alec Mouri51067012022-01-06 17:28:39 -080097
ramindanibab8ba92021-11-18 01:24:11 +000098 protected:
Ady Abraham3192f3d2021-12-03 16:08:56 -080099 int64_t mDisplay;
ramindanibab8ba92021-11-18 01:24:11 +0000100 int64_t mLayer;
101 Rect mDisplayFrame = {0, 0, 0, 0};
Alec Mourib1f16722022-02-07 13:03:44 -0800102 float mBrightness = 1.f;
Alec Mouri51067012022-01-06 17:28:39 -0800103 float mWhitePointNits = -1.f;
ramindanibab8ba92021-11-18 01:24:11 +0000104 std::vector<Rect> mSurfaceDamage;
105 Transform mTransform = static_cast<Transform>(0);
106 FRect mSourceCrop = {0, 0, 0, 0};
107 static constexpr uint32_t kBufferSlotCount = 64;
108 float mAlpha = 1.0;
109 BlendMode mBlendMode = BlendMode::NONE;
110 uint32_t mZOrder = 0;
Alec Mourif6c039a2023-10-06 23:02:17 +0000111 Dataspace mDataspace = Dataspace::UNKNOWN;
Sally Qife454362024-12-18 15:44:09 -0800112 Luts mLuts;
ramindanibab8ba92021-11-18 01:24:11 +0000113};
114
115class TestColorLayer : public TestLayer {
116 public:
Ady Abrahama00d2462023-12-26 14:21:20 -0800117 TestColorLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display,
118 ComposerClientWriter& writer)
119 : TestLayer{client, display, writer} {}
ramindanibab8ba92021-11-18 01:24:11 +0000120
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800121 void write(ComposerClientWriter& writer) override;
ramindanibab8ba92021-11-18 01:24:11 +0000122
123 LayerSettings toRenderEngineLayerSettings() override;
124
125 void setColor(Color color) { mColor = color; }
126
127 private:
128 Color mColor = WHITE;
129};
130
131class TestBufferLayer : public TestLayer {
132 public:
ramindanidcecfd42022-02-03 23:52:19 +0000133 TestBufferLayer(const std::shared_ptr<VtsComposerClient>& client,
Ady Abraham4aa4ead2021-12-03 16:07:19 -0800134 TestRenderEngine& renderEngine, int64_t display, uint32_t width,
Ady Abrahama00d2462023-12-26 14:21:20 -0800135 uint32_t height, common::PixelFormat format, ComposerClientWriter& writer,
ramindanibab8ba92021-11-18 01:24:11 +0000136 Composition composition = Composition::DEVICE);
137
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800138 void write(ComposerClientWriter& writer) override;
ramindanibab8ba92021-11-18 01:24:11 +0000139
140 LayerSettings toRenderEngineLayerSettings() override;
141
142 void fillBuffer(std::vector<Color>& expectedColors);
143
144 void setBuffer(std::vector<Color> colors);
145
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800146 void setToClientComposition(ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +0000147
148 uint32_t getWidth() const { return mWidth; }
149
150 uint32_t getHeight() const { return mHeight; }
151
152 ::android::Rect getAccessRegion() const { return mAccessRegion; }
153
154 uint32_t getLayerCount() const { return mLayerCount; }
155
156 protected:
157 Composition mComposition;
Brian Lindahle887a252023-01-17 14:54:19 -0700158 ::android::sp<::android::GraphicBuffer> mGraphicBuffer;
ramindanibab8ba92021-11-18 01:24:11 +0000159 TestRenderEngine& mRenderEngine;
160 int32_t mFillFence;
161 uint32_t mWidth;
162 uint32_t mHeight;
163 uint32_t mLayerCount;
164 PixelFormat mPixelFormat;
165 uint32_t mUsage;
ramindanibab8ba92021-11-18 01:24:11 +0000166 ::android::Rect mAccessRegion;
ramindani0a2bee42022-02-10 01:27:42 +0000167
168 private:
169 ::android::sp<::android::GraphicBuffer> allocateBuffer();
ramindanibab8ba92021-11-18 01:24:11 +0000170};
171
172class ReadbackHelper {
173 public:
174 static std::string getColorModeString(ColorMode mode);
175
176 static std::string getDataspaceString(Dataspace dataspace);
177
178 static Dataspace getDataspaceForColorMode(ColorMode mode);
179
Alec Mouri6a000222024-08-16 23:08:09 +0000180 static int32_t GetBitsPerChannel(PixelFormat pixelFormat);
181 static int32_t GetAlphaBits(PixelFormat pixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +0000182
Alec Mouri6a000222024-08-16 23:08:09 +0000183 static void fillBuffer(uint32_t width, uint32_t height, uint32_t stride, int32_t bytesPerPixel,
184 void* bufferData, PixelFormat pixelFormat,
185 std::vector<Color> desiredPixelColors);
ramindanibab8ba92021-11-18 01:24:11 +0000186
Brian Lindahle887a252023-01-17 14:54:19 -0700187 static void clearColors(std::vector<Color>& expectedColors, int32_t width, int32_t height,
ramindanibab8ba92021-11-18 01:24:11 +0000188 int32_t displayWidth);
189
Brian Lindahle887a252023-01-17 14:54:19 -0700190 static void fillColorsArea(std::vector<Color>& expectedColors, int32_t stride, Rect area,
191 Color color);
ramindanibab8ba92021-11-18 01:24:11 +0000192
Brian Lindahle887a252023-01-17 14:54:19 -0700193 static bool readbackSupported(const PixelFormat& pixelFormat, const Dataspace& dataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000194
195 static const std::vector<ColorMode> colorModes;
196 static const std::vector<Dataspace> dataspaces;
Brian Lindahle887a252023-01-17 14:54:19 -0700197
198 static void compareColorBuffers(const std::vector<Color>& expectedColors, void* bufferData,
Alec Mouri6a000222024-08-16 23:08:09 +0000199 const uint32_t stride, int32_t bytesPerPixel,
Alec Mourif6c039a2023-10-06 23:02:17 +0000200 const uint32_t width, const uint32_t height,
201 PixelFormat pixelFormat);
Alec Mouri6a000222024-08-16 23:08:09 +0000202 static void compareColorBuffers(void* expectedBuffer, void* actualBuffer, const uint32_t stride,
203 int32_t bytesPerPixel, const uint32_t width,
204 const uint32_t height, PixelFormat pixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +0000205};
206
207class ReadbackBuffer {
208 public:
ramindanidcecfd42022-02-03 23:52:19 +0000209 ReadbackBuffer(int64_t display, const std::shared_ptr<VtsComposerClient>& client, int32_t width,
Brian Lindahle887a252023-01-17 14:54:19 -0700210 int32_t height, common::PixelFormat pixelFormat, common::Dataspace dataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000211
212 void setReadbackBuffer();
213
ramindanidcecfd42022-02-03 23:52:19 +0000214 void checkReadbackBuffer(const std::vector<Color>& expectedColors);
ramindanibab8ba92021-11-18 01:24:11 +0000215
Alec Mourif6c039a2023-10-06 23:02:17 +0000216 ::android::sp<::android::GraphicBuffer> getBuffer();
217
ramindanibab8ba92021-11-18 01:24:11 +0000218 protected:
219 uint32_t mWidth;
220 uint32_t mHeight;
221 uint32_t mLayerCount;
222 uint32_t mUsage;
Brian Lindahle887a252023-01-17 14:54:19 -0700223 PixelFormat mPixelFormat;
224 Dataspace mDataspace;
ramindanibab8ba92021-11-18 01:24:11 +0000225 int64_t mDisplay;
Brian Lindahle887a252023-01-17 14:54:19 -0700226 ::android::sp<::android::GraphicBuffer> mGraphicBuffer;
ramindanidcecfd42022-02-03 23:52:19 +0000227 std::shared_ptr<VtsComposerClient> mComposerClient;
Brian Lindahle887a252023-01-17 14:54:19 -0700228 ::android::Rect mAccessRegion;
229 native_handle_t mBufferHandle;
230
231 private:
232 ::android::sp<::android::GraphicBuffer> allocateBuffer();
ramindanibab8ba92021-11-18 01:24:11 +0000233};
234
Ady Abraham3192f3d2021-12-03 16:08:56 -0800235} // namespace aidl::android::hardware::graphics::composer3::vts