blob: d5602c1716db8ae17c756d9a36f69fecab151423 [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};
ramindanibab8ba92021-11-18 01:24:11 +000045
46class TestRenderEngine;
47
48class TestLayer {
49 public:
ramindanidcecfd42022-02-03 23:52:19 +000050 TestLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display)
51 : mDisplay(display) {
52 const auto& [status, layer] = client->createLayer(display, kBufferSlotCount);
53 EXPECT_TRUE(status.isOk());
54 mLayer = layer;
ramindanibab8ba92021-11-18 01:24:11 +000055 }
56
57 // ComposerClient will take care of destroying layers, no need to explicitly
58 // call destroyLayers here
59 virtual ~TestLayer(){};
60
Ady Abraham91c9d1a2021-12-15 18:14:45 -080061 virtual void write(ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +000062 virtual LayerSettings toRenderEngineLayerSettings();
63
64 void setDisplayFrame(Rect frame) { mDisplayFrame = frame; }
65 void setSourceCrop(FRect crop) { mSourceCrop = crop; }
66 void setZOrder(uint32_t z) { mZOrder = z; }
Alec Mouri51067012022-01-06 17:28:39 -080067 void setWhitePointNits(float whitePointNits) { mWhitePointNits = whitePointNits; }
Alec Mourib1f16722022-02-07 13:03:44 -080068 void setBrightness(float brightness) { mBrightness = brightness; }
ramindanibab8ba92021-11-18 01:24:11 +000069
70 void setSurfaceDamage(std::vector<Rect> surfaceDamage) {
71 mSurfaceDamage = std::move(surfaceDamage);
72 }
73
74 void setTransform(Transform transform) { mTransform = transform; }
75 void setAlpha(float alpha) { mAlpha = alpha; }
76 void setBlendMode(BlendMode blendMode) { mBlendMode = blendMode; }
77
78 BlendMode getBlendMode() const { return mBlendMode; }
79
80 uint32_t getZOrder() const { return mZOrder; }
81
82 float getAlpha() const { return mAlpha; }
83
Ady Abraham3192f3d2021-12-03 16:08:56 -080084 int64_t getLayer() const { return mLayer; }
85
Alec Mourib1f16722022-02-07 13:03:44 -080086 float getBrightness() const { return mBrightness; }
Alec Mouri51067012022-01-06 17:28:39 -080087
ramindanibab8ba92021-11-18 01:24:11 +000088 protected:
Ady Abraham3192f3d2021-12-03 16:08:56 -080089 int64_t mDisplay;
ramindanibab8ba92021-11-18 01:24:11 +000090 int64_t mLayer;
91 Rect mDisplayFrame = {0, 0, 0, 0};
Alec Mourib1f16722022-02-07 13:03:44 -080092 float mBrightness = 1.f;
Alec Mouri51067012022-01-06 17:28:39 -080093 float mWhitePointNits = -1.f;
ramindanibab8ba92021-11-18 01:24:11 +000094 std::vector<Rect> mSurfaceDamage;
95 Transform mTransform = static_cast<Transform>(0);
96 FRect mSourceCrop = {0, 0, 0, 0};
97 static constexpr uint32_t kBufferSlotCount = 64;
98 float mAlpha = 1.0;
99 BlendMode mBlendMode = BlendMode::NONE;
100 uint32_t mZOrder = 0;
ramindanibab8ba92021-11-18 01:24:11 +0000101};
102
103class TestColorLayer : public TestLayer {
104 public:
ramindanidcecfd42022-02-03 23:52:19 +0000105 TestColorLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display)
ramindanibab8ba92021-11-18 01:24:11 +0000106 : TestLayer{client, display} {}
107
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800108 void write(ComposerClientWriter& writer) override;
ramindanibab8ba92021-11-18 01:24:11 +0000109
110 LayerSettings toRenderEngineLayerSettings() override;
111
112 void setColor(Color color) { mColor = color; }
113
114 private:
115 Color mColor = WHITE;
116};
117
118class TestBufferLayer : public TestLayer {
119 public:
ramindanidcecfd42022-02-03 23:52:19 +0000120 TestBufferLayer(const std::shared_ptr<VtsComposerClient>& client,
Ady Abraham4aa4ead2021-12-03 16:07:19 -0800121 TestRenderEngine& renderEngine, int64_t display, uint32_t width,
ramindanibab8ba92021-11-18 01:24:11 +0000122 uint32_t height, common::PixelFormat format,
123 Composition composition = Composition::DEVICE);
124
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800125 void write(ComposerClientWriter& writer) override;
ramindanibab8ba92021-11-18 01:24:11 +0000126
127 LayerSettings toRenderEngineLayerSettings() override;
128
129 void fillBuffer(std::vector<Color>& expectedColors);
130
131 void setBuffer(std::vector<Color> colors);
132
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800133 void setDataspace(Dataspace dataspace, ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +0000134
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800135 void setToClientComposition(ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +0000136
137 uint32_t getWidth() const { return mWidth; }
138
139 uint32_t getHeight() const { return mHeight; }
140
141 ::android::Rect getAccessRegion() const { return mAccessRegion; }
142
143 uint32_t getLayerCount() const { return mLayerCount; }
144
145 protected:
146 Composition mComposition;
Brian Lindahle887a252023-01-17 14:54:19 -0700147 ::android::sp<::android::GraphicBuffer> mGraphicBuffer;
ramindanibab8ba92021-11-18 01:24:11 +0000148 TestRenderEngine& mRenderEngine;
149 int32_t mFillFence;
150 uint32_t mWidth;
151 uint32_t mHeight;
152 uint32_t mLayerCount;
153 PixelFormat mPixelFormat;
154 uint32_t mUsage;
ramindanibab8ba92021-11-18 01:24:11 +0000155 ::android::Rect mAccessRegion;
ramindani0a2bee42022-02-10 01:27:42 +0000156
157 private:
158 ::android::sp<::android::GraphicBuffer> allocateBuffer();
ramindanibab8ba92021-11-18 01:24:11 +0000159};
160
161class ReadbackHelper {
162 public:
163 static std::string getColorModeString(ColorMode mode);
164
165 static std::string getDataspaceString(Dataspace dataspace);
166
167 static Dataspace getDataspaceForColorMode(ColorMode mode);
168
169 static int32_t GetBytesPerPixel(PixelFormat pixelFormat);
170
171 static void fillBuffer(uint32_t width, uint32_t height, uint32_t stride, void* bufferData,
Brian Lindahle887a252023-01-17 14:54:19 -0700172 PixelFormat pixelFormat, std::vector<Color> desiredPixelColors);
ramindanibab8ba92021-11-18 01:24:11 +0000173
Brian Lindahle887a252023-01-17 14:54:19 -0700174 static void clearColors(std::vector<Color>& expectedColors, int32_t width, int32_t height,
ramindanibab8ba92021-11-18 01:24:11 +0000175 int32_t displayWidth);
176
Brian Lindahle887a252023-01-17 14:54:19 -0700177 static void fillColorsArea(std::vector<Color>& expectedColors, int32_t stride, Rect area,
178 Color color);
ramindanibab8ba92021-11-18 01:24:11 +0000179
Brian Lindahle887a252023-01-17 14:54:19 -0700180 static bool readbackSupported(const PixelFormat& pixelFormat, const Dataspace& dataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000181
182 static const std::vector<ColorMode> colorModes;
183 static const std::vector<Dataspace> dataspaces;
Brian Lindahle887a252023-01-17 14:54:19 -0700184
185 static void compareColorBuffers(const std::vector<Color>& expectedColors, void* bufferData,
186 const uint32_t stride, const uint32_t width,
187 const uint32_t height, PixelFormat pixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +0000188};
189
190class ReadbackBuffer {
191 public:
ramindanidcecfd42022-02-03 23:52:19 +0000192 ReadbackBuffer(int64_t display, const std::shared_ptr<VtsComposerClient>& client, int32_t width,
Brian Lindahle887a252023-01-17 14:54:19 -0700193 int32_t height, common::PixelFormat pixelFormat, common::Dataspace dataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000194
195 void setReadbackBuffer();
196
ramindanidcecfd42022-02-03 23:52:19 +0000197 void checkReadbackBuffer(const std::vector<Color>& expectedColors);
ramindanibab8ba92021-11-18 01:24:11 +0000198
ramindanibab8ba92021-11-18 01:24:11 +0000199 protected:
200 uint32_t mWidth;
201 uint32_t mHeight;
202 uint32_t mLayerCount;
203 uint32_t mUsage;
Brian Lindahle887a252023-01-17 14:54:19 -0700204 PixelFormat mPixelFormat;
205 Dataspace mDataspace;
ramindanibab8ba92021-11-18 01:24:11 +0000206 int64_t mDisplay;
Brian Lindahle887a252023-01-17 14:54:19 -0700207 ::android::sp<::android::GraphicBuffer> mGraphicBuffer;
ramindanidcecfd42022-02-03 23:52:19 +0000208 std::shared_ptr<VtsComposerClient> mComposerClient;
Brian Lindahle887a252023-01-17 14:54:19 -0700209 ::android::Rect mAccessRegion;
210 native_handle_t mBufferHandle;
211
212 private:
213 ::android::sp<::android::GraphicBuffer> allocateBuffer();
ramindanibab8ba92021-11-18 01:24:11 +0000214};
215
Ady Abraham3192f3d2021-12-03 16:08:56 -0800216} // namespace aidl::android::hardware::graphics::composer3::vts