blob: ee205735f199c732b4da21c4b2f4646388ec9334 [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:
ramindanidcecfd42022-02-03 23:52:19 +000053 TestLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display)
54 : mDisplay(display) {
55 const auto& [status, layer] = client->createLayer(display, kBufferSlotCount);
56 EXPECT_TRUE(status.isOk());
57 mLayer = layer;
ramindanibab8ba92021-11-18 01:24:11 +000058 }
59
60 // ComposerClient will take care of destroying layers, no need to explicitly
61 // call destroyLayers here
62 virtual ~TestLayer(){};
63
Ady Abraham91c9d1a2021-12-15 18:14:45 -080064 virtual void write(ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +000065 virtual LayerSettings toRenderEngineLayerSettings();
66
67 void setDisplayFrame(Rect frame) { mDisplayFrame = frame; }
68 void setSourceCrop(FRect crop) { mSourceCrop = crop; }
69 void setZOrder(uint32_t z) { mZOrder = z; }
Alec Mouri51067012022-01-06 17:28:39 -080070 void setWhitePointNits(float whitePointNits) { mWhitePointNits = whitePointNits; }
Alec Mourib1f16722022-02-07 13:03:44 -080071 void setBrightness(float brightness) { mBrightness = brightness; }
ramindanibab8ba92021-11-18 01:24:11 +000072
73 void setSurfaceDamage(std::vector<Rect> surfaceDamage) {
74 mSurfaceDamage = std::move(surfaceDamage);
75 }
76
Alec Mourif6c039a2023-10-06 23:02:17 +000077 void setDataspace(Dataspace dataspace) { mDataspace = dataspace; }
78
ramindanibab8ba92021-11-18 01:24:11 +000079 void setTransform(Transform transform) { mTransform = transform; }
80 void setAlpha(float alpha) { mAlpha = alpha; }
81 void setBlendMode(BlendMode blendMode) { mBlendMode = blendMode; }
82
83 BlendMode getBlendMode() const { return mBlendMode; }
84
85 uint32_t getZOrder() const { return mZOrder; }
86
87 float getAlpha() const { return mAlpha; }
88
Ady Abraham3192f3d2021-12-03 16:08:56 -080089 int64_t getLayer() const { return mLayer; }
90
Alec Mourib1f16722022-02-07 13:03:44 -080091 float getBrightness() const { return mBrightness; }
Alec Mouri51067012022-01-06 17:28:39 -080092
ramindanibab8ba92021-11-18 01:24:11 +000093 protected:
Ady Abraham3192f3d2021-12-03 16:08:56 -080094 int64_t mDisplay;
ramindanibab8ba92021-11-18 01:24:11 +000095 int64_t mLayer;
96 Rect mDisplayFrame = {0, 0, 0, 0};
Alec Mourib1f16722022-02-07 13:03:44 -080097 float mBrightness = 1.f;
Alec Mouri51067012022-01-06 17:28:39 -080098 float mWhitePointNits = -1.f;
ramindanibab8ba92021-11-18 01:24:11 +000099 std::vector<Rect> mSurfaceDamage;
100 Transform mTransform = static_cast<Transform>(0);
101 FRect mSourceCrop = {0, 0, 0, 0};
102 static constexpr uint32_t kBufferSlotCount = 64;
103 float mAlpha = 1.0;
104 BlendMode mBlendMode = BlendMode::NONE;
105 uint32_t mZOrder = 0;
Alec Mourif6c039a2023-10-06 23:02:17 +0000106 Dataspace mDataspace = Dataspace::UNKNOWN;
ramindanibab8ba92021-11-18 01:24:11 +0000107};
108
109class TestColorLayer : public TestLayer {
110 public:
ramindanidcecfd42022-02-03 23:52:19 +0000111 TestColorLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display)
ramindanibab8ba92021-11-18 01:24:11 +0000112 : TestLayer{client, display} {}
113
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800114 void write(ComposerClientWriter& writer) override;
ramindanibab8ba92021-11-18 01:24:11 +0000115
116 LayerSettings toRenderEngineLayerSettings() override;
117
118 void setColor(Color color) { mColor = color; }
119
120 private:
121 Color mColor = WHITE;
122};
123
124class TestBufferLayer : public TestLayer {
125 public:
ramindanidcecfd42022-02-03 23:52:19 +0000126 TestBufferLayer(const std::shared_ptr<VtsComposerClient>& client,
Ady Abraham4aa4ead2021-12-03 16:07:19 -0800127 TestRenderEngine& renderEngine, int64_t display, uint32_t width,
ramindanibab8ba92021-11-18 01:24:11 +0000128 uint32_t height, common::PixelFormat format,
129 Composition composition = Composition::DEVICE);
130
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800131 void write(ComposerClientWriter& writer) override;
ramindanibab8ba92021-11-18 01:24:11 +0000132
133 LayerSettings toRenderEngineLayerSettings() override;
134
135 void fillBuffer(std::vector<Color>& expectedColors);
136
137 void setBuffer(std::vector<Color> colors);
138
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800139 void setToClientComposition(ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +0000140
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 Lindahle887a252023-01-17 14:54:19 -0700151 ::android::sp<::android::GraphicBuffer> mGraphicBuffer;
ramindanibab8ba92021-11-18 01:24:11 +0000152 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;
ramindanibab8ba92021-11-18 01:24:11 +0000159 ::android::Rect mAccessRegion;
ramindani0a2bee42022-02-10 01:27:42 +0000160
161 private:
162 ::android::sp<::android::GraphicBuffer> allocateBuffer();
ramindanibab8ba92021-11-18 01:24:11 +0000163};
164
165class ReadbackHelper {
166 public:
167 static std::string getColorModeString(ColorMode mode);
168
169 static std::string getDataspaceString(Dataspace dataspace);
170
171 static Dataspace getDataspaceForColorMode(ColorMode mode);
172
173 static int32_t GetBytesPerPixel(PixelFormat pixelFormat);
174
175 static void fillBuffer(uint32_t width, uint32_t height, uint32_t stride, void* bufferData,
Brian Lindahle887a252023-01-17 14:54:19 -0700176 PixelFormat pixelFormat, std::vector<Color> desiredPixelColors);
ramindanibab8ba92021-11-18 01:24:11 +0000177
Brian Lindahle887a252023-01-17 14:54:19 -0700178 static void clearColors(std::vector<Color>& expectedColors, int32_t width, int32_t height,
ramindanibab8ba92021-11-18 01:24:11 +0000179 int32_t displayWidth);
180
Brian Lindahle887a252023-01-17 14:54:19 -0700181 static void fillColorsArea(std::vector<Color>& expectedColors, int32_t stride, Rect area,
182 Color color);
ramindanibab8ba92021-11-18 01:24:11 +0000183
Brian Lindahle887a252023-01-17 14:54:19 -0700184 static bool readbackSupported(const PixelFormat& pixelFormat, const Dataspace& dataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000185
186 static const std::vector<ColorMode> colorModes;
187 static const std::vector<Dataspace> dataspaces;
Brian Lindahle887a252023-01-17 14:54:19 -0700188
189 static void compareColorBuffers(const std::vector<Color>& expectedColors, void* bufferData,
190 const uint32_t stride, const uint32_t width,
191 const uint32_t height, PixelFormat pixelFormat);
Alec Mourif6c039a2023-10-06 23:02:17 +0000192 static void compareColorBuffers(void* expectedBuffer, void* actualBuffer, const uint32_t stride,
193 const uint32_t width, const uint32_t height,
194 PixelFormat pixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +0000195};
196
197class ReadbackBuffer {
198 public:
ramindanidcecfd42022-02-03 23:52:19 +0000199 ReadbackBuffer(int64_t display, const std::shared_ptr<VtsComposerClient>& client, int32_t width,
Brian Lindahle887a252023-01-17 14:54:19 -0700200 int32_t height, common::PixelFormat pixelFormat, common::Dataspace dataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000201
202 void setReadbackBuffer();
203
ramindanidcecfd42022-02-03 23:52:19 +0000204 void checkReadbackBuffer(const std::vector<Color>& expectedColors);
ramindanibab8ba92021-11-18 01:24:11 +0000205
Alec Mourif6c039a2023-10-06 23:02:17 +0000206 ::android::sp<::android::GraphicBuffer> getBuffer();
207
ramindanibab8ba92021-11-18 01:24:11 +0000208 protected:
209 uint32_t mWidth;
210 uint32_t mHeight;
211 uint32_t mLayerCount;
212 uint32_t mUsage;
Brian Lindahle887a252023-01-17 14:54:19 -0700213 PixelFormat mPixelFormat;
214 Dataspace mDataspace;
ramindanibab8ba92021-11-18 01:24:11 +0000215 int64_t mDisplay;
Brian Lindahle887a252023-01-17 14:54:19 -0700216 ::android::sp<::android::GraphicBuffer> mGraphicBuffer;
ramindanidcecfd42022-02-03 23:52:19 +0000217 std::shared_ptr<VtsComposerClient> mComposerClient;
Brian Lindahle887a252023-01-17 14:54:19 -0700218 ::android::Rect mAccessRegion;
219 native_handle_t mBufferHandle;
220
221 private:
222 ::android::sp<::android::GraphicBuffer> allocateBuffer();
ramindanibab8ba92021-11-18 01:24:11 +0000223};
224
Ady Abraham3192f3d2021-12-03 16:08:56 -0800225} // namespace aidl::android::hardware::graphics::composer3::vts