blob: 8ac0f4bb9962c053879df9d9c234432b3014a745 [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>
20#include <android-base/unique_fd.h>
Ady Abraham91c9d1a2021-12-15 18:14:45 -080021#include <android/hardware/graphics/composer3/ComposerClientReader.h>
22#include <android/hardware/graphics/composer3/ComposerClientWriter.h>
ramindanibab8ba92021-11-18 01:24:11 +000023#include <renderengine/RenderEngine.h>
24#include <ui/GraphicBuffer.h>
ramindanibab8ba92021-11-18 01:24:11 +000025#include <memory>
ramindaniedf3ef92022-01-07 00:04:23 +000026#include "GraphicsComposerCallback.h"
27#include "VtsComposerClient.h"
Ram Indani22884ac2022-01-29 02:00:21 +000028
ramindanibab8ba92021-11-18 01:24:11 +000029namespace aidl::android::hardware::graphics::composer3::vts {
30
31using ::android::renderengine::LayerSettings;
32using common::Dataspace;
33using common::PixelFormat;
ramindanibab8ba92021-11-18 01:24:11 +000034
Ady Abraham1bee7ab2022-01-06 17:22:08 -080035static const Color BLACK = {0.0f, 0.0f, 0.0f, 1.0f};
36static const Color RED = {1.0f, 0.0f, 0.0f, 1.0f};
Alec Mouri51067012022-01-06 17:28:39 -080037// 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
40static const Color DIM_RED = {243.f / 255.f, 0.0f, 0.0f, 1.0f};
Ady Abraham1bee7ab2022-01-06 17:22:08 -080041static const Color TRANSLUCENT_RED = {1.0f, 0.0f, 0.0f, 0.3f};
42static const Color GREEN = {0.0f, 1.0f, 0.0f, 1.0f};
43static const Color BLUE = {0.0f, 0.0f, 1.0f, 1.0f};
44static const Color WHITE = {1.0f, 1.0f, 1.0f, 1.0f};
Alec Mourif6c039a2023-10-06 23:02:17 +000045static const Color LIGHT_RED = {0.5f, 0.0f, 0.0f, 1.0f};
46static const Color LIGHT_GREEN = {0.0f, 0.5f, 0.0f, 1.0f};
47static const Color LIGHT_BLUE = {0.0f, 0.0f, 0.5f, 1.0f};
ramindanibab8ba92021-11-18 01:24:11 +000048
49class TestRenderEngine;
50
51class TestLayer {
52 public:
Ady Abrahama00d2462023-12-26 14:21:20 -080053 TestLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display,
54 ComposerClientWriter& writer)
ramindanidcecfd42022-02-03 23:52:19 +000055 : mDisplay(display) {
Ady Abrahama00d2462023-12-26 14:21:20 -080056 const auto& [status, layer] = client->createLayer(display, kBufferSlotCount, &writer);
ramindanidcecfd42022-02-03 23:52:19 +000057 EXPECT_TRUE(status.isOk());
58 mLayer = layer;
ramindanibab8ba92021-11-18 01:24:11 +000059 }
60
61 // ComposerClient will take care of destroying layers, no need to explicitly
62 // call destroyLayers here
63 virtual ~TestLayer(){};
64
Ady Abraham91c9d1a2021-12-15 18:14:45 -080065 virtual void write(ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +000066 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 Mouri51067012022-01-06 17:28:39 -080071 void setWhitePointNits(float whitePointNits) { mWhitePointNits = whitePointNits; }
Alec Mourib1f16722022-02-07 13:03:44 -080072 void setBrightness(float brightness) { mBrightness = brightness; }
ramindanibab8ba92021-11-18 01:24:11 +000073
74 void setSurfaceDamage(std::vector<Rect> surfaceDamage) {
75 mSurfaceDamage = std::move(surfaceDamage);
76 }
77
Alec Mourif6c039a2023-10-06 23:02:17 +000078 void setDataspace(Dataspace dataspace) { mDataspace = dataspace; }
79
ramindanibab8ba92021-11-18 01:24:11 +000080 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 Abraham3192f3d2021-12-03 16:08:56 -080090 int64_t getLayer() const { return mLayer; }
91
Alec Mourib1f16722022-02-07 13:03:44 -080092 float getBrightness() const { return mBrightness; }
Alec Mouri51067012022-01-06 17:28:39 -080093
ramindanibab8ba92021-11-18 01:24:11 +000094 protected:
Ady Abraham3192f3d2021-12-03 16:08:56 -080095 int64_t mDisplay;
ramindanibab8ba92021-11-18 01:24:11 +000096 int64_t mLayer;
97 Rect mDisplayFrame = {0, 0, 0, 0};
Alec Mourib1f16722022-02-07 13:03:44 -080098 float mBrightness = 1.f;
Alec Mouri51067012022-01-06 17:28:39 -080099 float mWhitePointNits = -1.f;
ramindanibab8ba92021-11-18 01:24:11 +0000100 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 Mourif6c039a2023-10-06 23:02:17 +0000107 Dataspace mDataspace = Dataspace::UNKNOWN;
ramindanibab8ba92021-11-18 01:24:11 +0000108};
109
110class TestColorLayer : public TestLayer {
111 public:
Ady Abrahama00d2462023-12-26 14:21:20 -0800112 TestColorLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display,
113 ComposerClientWriter& writer)
114 : TestLayer{client, display, writer} {}
ramindanibab8ba92021-11-18 01:24:11 +0000115
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800116 void write(ComposerClientWriter& writer) override;
ramindanibab8ba92021-11-18 01:24:11 +0000117
118 LayerSettings toRenderEngineLayerSettings() override;
119
120 void setColor(Color color) { mColor = color; }
121
122 private:
123 Color mColor = WHITE;
124};
125
126class TestBufferLayer : public TestLayer {
127 public:
ramindanidcecfd42022-02-03 23:52:19 +0000128 TestBufferLayer(const std::shared_ptr<VtsComposerClient>& client,
Ady Abraham4aa4ead2021-12-03 16:07:19 -0800129 TestRenderEngine& renderEngine, int64_t display, uint32_t width,
Ady Abrahama00d2462023-12-26 14:21:20 -0800130 uint32_t height, common::PixelFormat format, ComposerClientWriter& writer,
ramindanibab8ba92021-11-18 01:24:11 +0000131 Composition composition = Composition::DEVICE);
132
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800133 void write(ComposerClientWriter& writer) override;
ramindanibab8ba92021-11-18 01:24:11 +0000134
135 LayerSettings toRenderEngineLayerSettings() override;
136
137 void fillBuffer(std::vector<Color>& expectedColors);
138
139 void setBuffer(std::vector<Color> colors);
140
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800141 void setToClientComposition(ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +0000142
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 Lindahle887a252023-01-17 14:54:19 -0700153 ::android::sp<::android::GraphicBuffer> mGraphicBuffer;
ramindanibab8ba92021-11-18 01:24:11 +0000154 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;
ramindanibab8ba92021-11-18 01:24:11 +0000161 ::android::Rect mAccessRegion;
ramindani0a2bee42022-02-10 01:27:42 +0000162
163 private:
164 ::android::sp<::android::GraphicBuffer> allocateBuffer();
ramindanibab8ba92021-11-18 01:24:11 +0000165};
166
167class 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 Lindahle887a252023-01-17 14:54:19 -0700178 PixelFormat pixelFormat, std::vector<Color> desiredPixelColors);
ramindanibab8ba92021-11-18 01:24:11 +0000179
Brian Lindahle887a252023-01-17 14:54:19 -0700180 static void clearColors(std::vector<Color>& expectedColors, int32_t width, int32_t height,
ramindanibab8ba92021-11-18 01:24:11 +0000181 int32_t displayWidth);
182
Brian Lindahle887a252023-01-17 14:54:19 -0700183 static void fillColorsArea(std::vector<Color>& expectedColors, int32_t stride, Rect area,
184 Color color);
ramindanibab8ba92021-11-18 01:24:11 +0000185
Brian Lindahle887a252023-01-17 14:54:19 -0700186 static bool readbackSupported(const PixelFormat& pixelFormat, const Dataspace& dataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000187
188 static const std::vector<ColorMode> colorModes;
189 static const std::vector<Dataspace> dataspaces;
Brian Lindahle887a252023-01-17 14:54:19 -0700190
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 Mourif6c039a2023-10-06 23:02:17 +0000194 static void compareColorBuffers(void* expectedBuffer, void* actualBuffer, const uint32_t stride,
195 const uint32_t width, const uint32_t height,
196 PixelFormat pixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +0000197};
198
199class ReadbackBuffer {
200 public:
ramindanidcecfd42022-02-03 23:52:19 +0000201 ReadbackBuffer(int64_t display, const std::shared_ptr<VtsComposerClient>& client, int32_t width,
Brian Lindahle887a252023-01-17 14:54:19 -0700202 int32_t height, common::PixelFormat pixelFormat, common::Dataspace dataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000203
204 void setReadbackBuffer();
205
ramindanidcecfd42022-02-03 23:52:19 +0000206 void checkReadbackBuffer(const std::vector<Color>& expectedColors);
ramindanibab8ba92021-11-18 01:24:11 +0000207
Alec Mourif6c039a2023-10-06 23:02:17 +0000208 ::android::sp<::android::GraphicBuffer> getBuffer();
209
ramindanibab8ba92021-11-18 01:24:11 +0000210 protected:
211 uint32_t mWidth;
212 uint32_t mHeight;
213 uint32_t mLayerCount;
214 uint32_t mUsage;
Brian Lindahle887a252023-01-17 14:54:19 -0700215 PixelFormat mPixelFormat;
216 Dataspace mDataspace;
ramindanibab8ba92021-11-18 01:24:11 +0000217 int64_t mDisplay;
Brian Lindahle887a252023-01-17 14:54:19 -0700218 ::android::sp<::android::GraphicBuffer> mGraphicBuffer;
ramindanidcecfd42022-02-03 23:52:19 +0000219 std::shared_ptr<VtsComposerClient> mComposerClient;
Brian Lindahle887a252023-01-17 14:54:19 -0700220 ::android::Rect mAccessRegion;
221 native_handle_t mBufferHandle;
222
223 private:
224 ::android::sp<::android::GraphicBuffer> allocateBuffer();
ramindanibab8ba92021-11-18 01:24:11 +0000225};
226
Ady Abraham3192f3d2021-12-03 16:08:56 -0800227} // namespace aidl::android::hardware::graphics::composer3::vts