blob: ee9f0d58ad4d772e76cf78798780cbb646a8eadd [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 <mapper-vts/2.1/MapperVts.h>
24#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
ramindanibab8ba92021-11-18 01:24:11 +000030namespace aidl::android::hardware::graphics::composer3::vts {
31
32using ::android::renderengine::LayerSettings;
33using common::Dataspace;
34using common::PixelFormat;
35using IMapper2_1 = ::android::hardware::graphics::mapper::V2_1::IMapper;
36
Ady Abraham1bee7ab2022-01-06 17:22:08 -080037static const Color BLACK = {0.0f, 0.0f, 0.0f, 1.0f};
38static const Color RED = {1.0f, 0.0f, 0.0f, 1.0f};
Alec Mouri51067012022-01-06 17:28:39 -080039// DIM_RED is 90% dimmed from RED in linear space
40// hard-code as value 243 in 8-bit space here, as calculating it requires
41// oetf(eotf(value) * .9), which is a complex non-linear transformation
42static const Color DIM_RED = {243.f / 255.f, 0.0f, 0.0f, 1.0f};
Ady Abraham1bee7ab2022-01-06 17:22:08 -080043static const Color TRANSLUCENT_RED = {1.0f, 0.0f, 0.0f, 0.3f};
44static const Color GREEN = {0.0f, 1.0f, 0.0f, 1.0f};
45static const Color BLUE = {0.0f, 0.0f, 1.0f, 1.0f};
46static const Color WHITE = {1.0f, 1.0f, 1.0f, 1.0f};
ramindanibab8ba92021-11-18 01:24:11 +000047
48class TestRenderEngine;
49
50class TestLayer {
51 public:
ramindanidcecfd42022-02-03 23:52:19 +000052 TestLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display)
53 : mDisplay(display) {
54 const auto& [status, layer] = client->createLayer(display, kBufferSlotCount);
55 EXPECT_TRUE(status.isOk());
56 mLayer = layer;
ramindanibab8ba92021-11-18 01:24:11 +000057 }
58
59 // ComposerClient will take care of destroying layers, no need to explicitly
60 // call destroyLayers here
61 virtual ~TestLayer(){};
62
Ady Abraham91c9d1a2021-12-15 18:14:45 -080063 virtual void write(ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +000064 virtual LayerSettings toRenderEngineLayerSettings();
65
66 void setDisplayFrame(Rect frame) { mDisplayFrame = frame; }
67 void setSourceCrop(FRect crop) { mSourceCrop = crop; }
68 void setZOrder(uint32_t z) { mZOrder = z; }
Alec Mouri51067012022-01-06 17:28:39 -080069 void setWhitePointNits(float whitePointNits) { mWhitePointNits = whitePointNits; }
Alec Mourib1f16722022-02-07 13:03:44 -080070 void setBrightness(float brightness) { mBrightness = brightness; }
ramindanibab8ba92021-11-18 01:24:11 +000071
72 void setSurfaceDamage(std::vector<Rect> surfaceDamage) {
73 mSurfaceDamage = std::move(surfaceDamage);
74 }
75
76 void setTransform(Transform transform) { mTransform = transform; }
77 void setAlpha(float alpha) { mAlpha = alpha; }
78 void setBlendMode(BlendMode blendMode) { mBlendMode = blendMode; }
79
80 BlendMode getBlendMode() const { return mBlendMode; }
81
82 uint32_t getZOrder() const { return mZOrder; }
83
84 float getAlpha() const { return mAlpha; }
85
Ady Abraham3192f3d2021-12-03 16:08:56 -080086 int64_t getLayer() const { return mLayer; }
87
Alec Mourib1f16722022-02-07 13:03:44 -080088 float getBrightness() const { return mBrightness; }
Alec Mouri51067012022-01-06 17:28:39 -080089
ramindanibab8ba92021-11-18 01:24:11 +000090 protected:
Ady Abraham3192f3d2021-12-03 16:08:56 -080091 int64_t mDisplay;
ramindanibab8ba92021-11-18 01:24:11 +000092 int64_t mLayer;
93 Rect mDisplayFrame = {0, 0, 0, 0};
Alec Mourib1f16722022-02-07 13:03:44 -080094 float mBrightness = 1.f;
Alec Mouri51067012022-01-06 17:28:39 -080095 float mWhitePointNits = -1.f;
ramindanibab8ba92021-11-18 01:24:11 +000096 std::vector<Rect> mSurfaceDamage;
97 Transform mTransform = static_cast<Transform>(0);
98 FRect mSourceCrop = {0, 0, 0, 0};
99 static constexpr uint32_t kBufferSlotCount = 64;
100 float mAlpha = 1.0;
101 BlendMode mBlendMode = BlendMode::NONE;
102 uint32_t mZOrder = 0;
ramindanibab8ba92021-11-18 01:24:11 +0000103};
104
105class TestColorLayer : public TestLayer {
106 public:
ramindanidcecfd42022-02-03 23:52:19 +0000107 TestColorLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display)
ramindanibab8ba92021-11-18 01:24:11 +0000108 : TestLayer{client, display} {}
109
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800110 void write(ComposerClientWriter& writer) override;
ramindanibab8ba92021-11-18 01:24:11 +0000111
112 LayerSettings toRenderEngineLayerSettings() override;
113
114 void setColor(Color color) { mColor = color; }
115
116 private:
117 Color mColor = WHITE;
118};
119
120class TestBufferLayer : public TestLayer {
121 public:
ramindanidcecfd42022-02-03 23:52:19 +0000122 TestBufferLayer(const std::shared_ptr<VtsComposerClient>& client,
Ady Abraham4aa4ead2021-12-03 16:07:19 -0800123 TestRenderEngine& renderEngine, int64_t display, uint32_t width,
ramindanibab8ba92021-11-18 01:24:11 +0000124 uint32_t height, common::PixelFormat format,
125 Composition composition = Composition::DEVICE);
126
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800127 void write(ComposerClientWriter& writer) override;
ramindanibab8ba92021-11-18 01:24:11 +0000128
129 LayerSettings toRenderEngineLayerSettings() override;
130
131 void fillBuffer(std::vector<Color>& expectedColors);
132
133 void setBuffer(std::vector<Color> colors);
134
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800135 void setDataspace(Dataspace dataspace, ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +0000136
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800137 void setToClientComposition(ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +0000138
139 uint32_t getWidth() const { return mWidth; }
140
141 uint32_t getHeight() const { return mHeight; }
142
143 ::android::Rect getAccessRegion() const { return mAccessRegion; }
144
145 uint32_t getLayerCount() const { return mLayerCount; }
146
147 protected:
148 Composition mComposition;
Brian Lindahle887a252023-01-17 14:54:19 -0700149 ::android::sp<::android::GraphicBuffer> mGraphicBuffer;
ramindanibab8ba92021-11-18 01:24:11 +0000150 TestRenderEngine& mRenderEngine;
151 int32_t mFillFence;
152 uint32_t mWidth;
153 uint32_t mHeight;
154 uint32_t mLayerCount;
155 PixelFormat mPixelFormat;
156 uint32_t mUsage;
ramindanibab8ba92021-11-18 01:24:11 +0000157 ::android::Rect mAccessRegion;
ramindani0a2bee42022-02-10 01:27:42 +0000158
159 private:
160 ::android::sp<::android::GraphicBuffer> allocateBuffer();
ramindanibab8ba92021-11-18 01:24:11 +0000161};
162
163class ReadbackHelper {
164 public:
165 static std::string getColorModeString(ColorMode mode);
166
167 static std::string getDataspaceString(Dataspace dataspace);
168
169 static Dataspace getDataspaceForColorMode(ColorMode mode);
170
171 static int32_t GetBytesPerPixel(PixelFormat pixelFormat);
172
173 static void fillBuffer(uint32_t width, uint32_t height, uint32_t stride, void* bufferData,
Brian Lindahle887a252023-01-17 14:54:19 -0700174 PixelFormat pixelFormat, std::vector<Color> desiredPixelColors);
ramindanibab8ba92021-11-18 01:24:11 +0000175
Brian Lindahle887a252023-01-17 14:54:19 -0700176 static void clearColors(std::vector<Color>& expectedColors, int32_t width, int32_t height,
ramindanibab8ba92021-11-18 01:24:11 +0000177 int32_t displayWidth);
178
Brian Lindahle887a252023-01-17 14:54:19 -0700179 static void fillColorsArea(std::vector<Color>& expectedColors, int32_t stride, Rect area,
180 Color color);
ramindanibab8ba92021-11-18 01:24:11 +0000181
Brian Lindahle887a252023-01-17 14:54:19 -0700182 static bool readbackSupported(const PixelFormat& pixelFormat, const Dataspace& dataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000183
184 static const std::vector<ColorMode> colorModes;
185 static const std::vector<Dataspace> dataspaces;
Brian Lindahle887a252023-01-17 14:54:19 -0700186
187 static void compareColorBuffers(const std::vector<Color>& expectedColors, void* bufferData,
188 const uint32_t stride, const uint32_t width,
189 const uint32_t height, PixelFormat pixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +0000190};
191
192class ReadbackBuffer {
193 public:
ramindanidcecfd42022-02-03 23:52:19 +0000194 ReadbackBuffer(int64_t display, const std::shared_ptr<VtsComposerClient>& client, int32_t width,
Brian Lindahle887a252023-01-17 14:54:19 -0700195 int32_t height, common::PixelFormat pixelFormat, common::Dataspace dataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000196
197 void setReadbackBuffer();
198
ramindanidcecfd42022-02-03 23:52:19 +0000199 void checkReadbackBuffer(const std::vector<Color>& expectedColors);
ramindanibab8ba92021-11-18 01:24:11 +0000200
ramindanibab8ba92021-11-18 01:24:11 +0000201 protected:
202 uint32_t mWidth;
203 uint32_t mHeight;
204 uint32_t mLayerCount;
205 uint32_t mUsage;
Brian Lindahle887a252023-01-17 14:54:19 -0700206 PixelFormat mPixelFormat;
207 Dataspace mDataspace;
ramindanibab8ba92021-11-18 01:24:11 +0000208 int64_t mDisplay;
Brian Lindahle887a252023-01-17 14:54:19 -0700209 ::android::sp<::android::GraphicBuffer> mGraphicBuffer;
ramindanidcecfd42022-02-03 23:52:19 +0000210 std::shared_ptr<VtsComposerClient> mComposerClient;
Brian Lindahle887a252023-01-17 14:54:19 -0700211 ::android::Rect mAccessRegion;
212 native_handle_t mBufferHandle;
213
214 private:
215 ::android::sp<::android::GraphicBuffer> allocateBuffer();
ramindanibab8ba92021-11-18 01:24:11 +0000216};
217
Ady Abraham3192f3d2021-12-03 16:08:56 -0800218} // namespace aidl::android::hardware::graphics::composer3::vts