blob: ecf0d52f65d6506385d7bbddd13e86f6035ab648 [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;
Brian Lindahld103cd62022-12-09 07:26:28 -070036using ::android::GraphicBuffer;
37using ::android::sp;
ramindanibab8ba92021-11-18 01:24:11 +000038
Ady Abraham1bee7ab2022-01-06 17:22:08 -080039static const Color BLACK = {0.0f, 0.0f, 0.0f, 1.0f};
40static const Color RED = {1.0f, 0.0f, 0.0f, 1.0f};
Alec Mouri51067012022-01-06 17:28:39 -080041// DIM_RED is 90% dimmed from RED in linear space
42// hard-code as value 243 in 8-bit space here, as calculating it requires
43// oetf(eotf(value) * .9), which is a complex non-linear transformation
44static const Color DIM_RED = {243.f / 255.f, 0.0f, 0.0f, 1.0f};
Ady Abraham1bee7ab2022-01-06 17:22:08 -080045static const Color TRANSLUCENT_RED = {1.0f, 0.0f, 0.0f, 0.3f};
46static const Color GREEN = {0.0f, 1.0f, 0.0f, 1.0f};
47static const Color BLUE = {0.0f, 0.0f, 1.0f, 1.0f};
48static const Color WHITE = {1.0f, 1.0f, 1.0f, 1.0f};
ramindanibab8ba92021-11-18 01:24:11 +000049
50class TestRenderEngine;
51
52class TestLayer {
53 public:
ramindanidcecfd42022-02-03 23:52:19 +000054 TestLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display)
55 : mDisplay(display) {
56 const auto& [status, layer] = client->createLayer(display, kBufferSlotCount);
57 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
78 void setTransform(Transform transform) { mTransform = transform; }
79 void setAlpha(float alpha) { mAlpha = alpha; }
80 void setBlendMode(BlendMode blendMode) { mBlendMode = blendMode; }
81
82 BlendMode getBlendMode() const { return mBlendMode; }
83
84 uint32_t getZOrder() const { return mZOrder; }
85
86 float getAlpha() const { return mAlpha; }
87
Ady Abraham3192f3d2021-12-03 16:08:56 -080088 int64_t getLayer() const { return mLayer; }
89
Alec Mourib1f16722022-02-07 13:03:44 -080090 float getBrightness() const { return mBrightness; }
Alec Mouri51067012022-01-06 17:28:39 -080091
ramindanibab8ba92021-11-18 01:24:11 +000092 protected:
Ady Abraham3192f3d2021-12-03 16:08:56 -080093 int64_t mDisplay;
ramindanibab8ba92021-11-18 01:24:11 +000094 int64_t mLayer;
95 Rect mDisplayFrame = {0, 0, 0, 0};
Alec Mourib1f16722022-02-07 13:03:44 -080096 float mBrightness = 1.f;
Alec Mouri51067012022-01-06 17:28:39 -080097 float mWhitePointNits = -1.f;
ramindanibab8ba92021-11-18 01:24:11 +000098 std::vector<Rect> mSurfaceDamage;
99 Transform mTransform = static_cast<Transform>(0);
100 FRect mSourceCrop = {0, 0, 0, 0};
101 static constexpr uint32_t kBufferSlotCount = 64;
102 float mAlpha = 1.0;
103 BlendMode mBlendMode = BlendMode::NONE;
104 uint32_t mZOrder = 0;
ramindanibab8ba92021-11-18 01:24:11 +0000105};
106
107class TestColorLayer : public TestLayer {
108 public:
ramindanidcecfd42022-02-03 23:52:19 +0000109 TestColorLayer(const std::shared_ptr<VtsComposerClient>& client, int64_t display)
ramindanibab8ba92021-11-18 01:24:11 +0000110 : TestLayer{client, display} {}
111
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800112 void write(ComposerClientWriter& writer) override;
ramindanibab8ba92021-11-18 01:24:11 +0000113
114 LayerSettings toRenderEngineLayerSettings() override;
115
116 void setColor(Color color) { mColor = color; }
117
118 private:
119 Color mColor = WHITE;
120};
121
122class TestBufferLayer : public TestLayer {
123 public:
ramindanidcecfd42022-02-03 23:52:19 +0000124 TestBufferLayer(const std::shared_ptr<VtsComposerClient>& client,
Ady Abraham4aa4ead2021-12-03 16:07:19 -0800125 TestRenderEngine& renderEngine, int64_t display, uint32_t width,
ramindanibab8ba92021-11-18 01:24:11 +0000126 uint32_t height, common::PixelFormat format,
127 Composition composition = Composition::DEVICE);
128
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800129 void write(ComposerClientWriter& writer) override;
ramindanibab8ba92021-11-18 01:24:11 +0000130
131 LayerSettings toRenderEngineLayerSettings() override;
132
133 void fillBuffer(std::vector<Color>& expectedColors);
134
135 void setBuffer(std::vector<Color> colors);
136
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800137 void setDataspace(Dataspace dataspace, ComposerClientWriter& writer);
ramindanibab8ba92021-11-18 01:24:11 +0000138
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 Lindahld103cd62022-12-09 07:26:28 -0700151 sp<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:
Brian Lindahld103cd62022-12-09 07:26:28 -0700167 static bool readbackSupported(const PixelFormat& pixelFormat, const Dataspace& dataspace);
168
169 static void createReadbackBuffer(ReadbackBufferAttributes readbackBufferAttributes,
170 const VtsDisplay& display, sp<GraphicBuffer>* graphicBuffer);
171
ramindanibab8ba92021-11-18 01:24:11 +0000172 static std::string getColorModeString(ColorMode mode);
173
174 static std::string getDataspaceString(Dataspace dataspace);
175
176 static Dataspace getDataspaceForColorMode(ColorMode mode);
177
178 static int32_t GetBytesPerPixel(PixelFormat pixelFormat);
179
180 static void fillBuffer(uint32_t width, uint32_t height, uint32_t stride, void* bufferData,
Brian Lindahld103cd62022-12-09 07:26:28 -0700181 PixelFormat pixelFormat, const std::vector<Color>& desriedColors);
ramindanibab8ba92021-11-18 01:24:11 +0000182
Brian Lindahld103cd62022-12-09 07:26:28 -0700183 static void clearColors(std::vector<Color>& colors, int32_t width, int32_t height,
ramindanibab8ba92021-11-18 01:24:11 +0000184 int32_t displayWidth);
185
Brian Lindahld103cd62022-12-09 07:26:28 -0700186 static void fillColorsArea(std::vector<Color>& colors, int32_t stride, Rect area,
187 Color desiredColor);
ramindanibab8ba92021-11-18 01:24:11 +0000188
Brian Lindahld103cd62022-12-09 07:26:28 -0700189 static void fillBufferAndGetFence(const sp<GraphicBuffer>& buffer, Color desiredColor,
190 int* fillFence);
191
192 static void fillBufferAndGetFence(const sp<GraphicBuffer>& buffer,
193 const std::vector<Color>& desiredColors, int* fillFence);
194
195 static void compareColorToBuffer(
196 Color expectedColor, const sp<GraphicBuffer>& graphicBuffer,
197 const ndk::ScopedFileDescriptor& fence = ::ndk::ScopedFileDescriptor(-1));
198
199 static void compareColorsToBuffer(
200 const std::vector<Color>& expectedColors, const sp<GraphicBuffer>& graphicBuffer,
201 const ndk::ScopedFileDescriptor& fence = ::ndk::ScopedFileDescriptor(-1));
ramindanibab8ba92021-11-18 01:24:11 +0000202
203 static const std::vector<ColorMode> colorModes;
204 static const std::vector<Dataspace> dataspaces;
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 Lindahld103cd62022-12-09 07:26:28 -0700210 int32_t height, common::PixelFormat pixelFormat);
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
ramindanibab8ba92021-11-18 01:24:11 +0000216 protected:
217 uint32_t mWidth;
218 uint32_t mHeight;
Brian Lindahld103cd62022-12-09 07:26:28 -0700219 PixelFormat mPixelFormat;
ramindanibab8ba92021-11-18 01:24:11 +0000220 uint32_t mLayerCount;
221 uint32_t mUsage;
ramindanibab8ba92021-11-18 01:24:11 +0000222 int64_t mDisplay;
Brian Lindahld103cd62022-12-09 07:26:28 -0700223 sp<GraphicBuffer> mGraphicBuffer;
ramindanidcecfd42022-02-03 23:52:19 +0000224 std::shared_ptr<VtsComposerClient> mComposerClient;
ramindanibab8ba92021-11-18 01:24:11 +0000225};
226
Ady Abraham3192f3d2021-12-03 16:08:56 -0800227} // namespace aidl::android::hardware::graphics::composer3::vts