summaryrefslogtreecommitdiff
path: root/graphics/composer/aidl/vts/VtsComposerClient.h
blob: 3625c8ccfec365a8247d666cdab8e503f546219b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/**
 * Copyright (c) 2022, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include <aidl/android/hardware/graphics/common/BlendMode.h>
#include <aidl/android/hardware/graphics/common/BufferUsage.h>
#include <aidl/android/hardware/graphics/common/FRect.h>
#include <aidl/android/hardware/graphics/common/Rect.h>
#include <aidl/android/hardware/graphics/composer3/Composition.h>
#include <aidl/android/hardware/graphics/composer3/IComposer.h>
#include <android-base/properties.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <android/hardware/graphics/composer3/ComposerClientReader.h>
#include <binder/ProcessState.h>
#include <gtest/gtest.h>
#include <ui/Fence.h>
#include <ui/GraphicBuffer.h>
#include <ui/PixelFormat.h>
#include <algorithm>
#include <numeric>
#include <string>
#include <thread>
#include <unordered_map>
#include "GraphicsComposerCallback.h"

using aidl::android::hardware::graphics::common::Dataspace;
using aidl::android::hardware::graphics::common::DisplayDecorationSupport;
using aidl::android::hardware::graphics::common::FRect;
using aidl::android::hardware::graphics::common::PixelFormat;
using aidl::android::hardware::graphics::common::Rect;
using namespace ::ndk;

namespace aidl::android::hardware::graphics::composer3::vts {

class VtsDisplay;
/**
 * A wrapper to IComposerClient.
 * This wrapper manages the IComposerClient instance and manages the resources for
 * the tests with respect to the IComposerClient calls.
 */
class VtsComposerClient {
  public:
    VtsComposerClient(const std::string& name);

    ScopedAStatus createClient();

    bool tearDown();

    std::pair<ScopedAStatus, VirtualDisplay> createVirtualDisplay(int32_t width, int32_t height,
                                                                  PixelFormat pixelFormat,
                                                                  int32_t bufferSlotCount);

    ScopedAStatus destroyVirtualDisplay(int64_t display);

    std::pair<ScopedAStatus, int64_t> createLayer(int64_t display, int32_t bufferSlotCount);

    ScopedAStatus destroyLayer(int64_t display, int64_t layer);

    std::pair<ScopedAStatus, int32_t> getActiveConfig(int64_t display);

    ScopedAStatus setActiveConfig(VtsDisplay* vtsDisplay, int32_t config);

    std::pair<ScopedAStatus, int32_t> getDisplayAttribute(int64_t display, int32_t config,
                                                          DisplayAttribute displayAttribute);

    ScopedAStatus setPowerMode(int64_t display, PowerMode powerMode);

    ScopedAStatus setVsync(int64_t display, bool enable);

    void setVsyncAllowed(bool isAllowed);

    std::pair<ScopedAStatus, std::vector<float>> getDataspaceSaturationMatrix(Dataspace dataspace);

    std::pair<ScopedAStatus, std::vector<CommandResultPayload>> executeCommands(
            const std::vector<DisplayCommand>& commands);

    std::optional<VsyncPeriodChangeTimeline> takeLastVsyncPeriodChangeTimeline();

    ScopedAStatus setContentType(int64_t display, ContentType contentType);

    std::pair<ScopedAStatus, VsyncPeriodChangeTimeline> setActiveConfigWithConstraints(
            VtsDisplay* vtsDisplay, int32_t config,
            const VsyncPeriodChangeConstraints& constraints);

    std::pair<ScopedAStatus, std::vector<DisplayCapability>> getDisplayCapabilities(
            int64_t display);

    ScopedAStatus dumpDebugInfo();

    std::pair<ScopedAStatus, DisplayIdentification> getDisplayIdentificationData(int64_t display);

    std::pair<ScopedAStatus, HdrCapabilities> getHdrCapabilities(int64_t display);

    std::pair<ScopedAStatus, std::vector<PerFrameMetadataKey>> getPerFrameMetadataKeys(
            int64_t display);

    std::pair<ScopedAStatus, ReadbackBufferAttributes> getReadbackBufferAttributes(int64_t display);

    ScopedAStatus setReadbackBuffer(int64_t display, const native_handle_t* buffer,
                                    const ScopedFileDescriptor& releaseFence);

    std::pair<ScopedAStatus, ScopedFileDescriptor> getReadbackBufferFence(int64_t display);

    std::pair<ScopedAStatus, std::vector<ColorMode>> getColorModes(int64_t display);

    std::pair<ScopedAStatus, std::vector<RenderIntent>> getRenderIntents(int64_t display,
                                                                         ColorMode colorMode);

    ScopedAStatus setColorMode(int64_t display, ColorMode colorMode, RenderIntent renderIntent);

    std::pair<ScopedAStatus, DisplayContentSamplingAttributes>
    getDisplayedContentSamplingAttributes(int64_t display);

    ScopedAStatus setDisplayedContentSamplingEnabled(int64_t display, bool isEnabled,
                                                     FormatColorComponent formatColorComponent,
                                                     int64_t maxFrames);

    std::pair<ScopedAStatus, DisplayContentSample> getDisplayedContentSample(int64_t display,
                                                                             int64_t maxFrames,
                                                                             int64_t timestamp);

    std::pair<ScopedAStatus, DisplayConnectionType> getDisplayConnectionType(int64_t display);

    std::pair<ScopedAStatus, std::vector<int32_t>> getDisplayConfigs(int64_t display);

    std::pair<ScopedAStatus, int32_t> getDisplayVsyncPeriod(int64_t display);

    ScopedAStatus setAutoLowLatencyMode(int64_t display, bool isEnabled);

    std::pair<ScopedAStatus, std::vector<ContentType>> getSupportedContentTypes(int64_t display);

    std::pair<ScopedAStatus, std::optional<DisplayDecorationSupport>> getDisplayDecorationSupport(
            int64_t display);

    std::pair<ScopedAStatus, int32_t> getMaxVirtualDisplayCount();

    std::pair<ScopedAStatus, std::string> getDisplayName(int64_t display);

    ScopedAStatus setClientTargetSlotCount(int64_t display, int32_t bufferSlotCount);

    std::pair<ScopedAStatus, std::vector<Capability>> getCapabilities();

    ScopedAStatus setBootDisplayConfig(int64_t display, int32_t config);

    ScopedAStatus clearBootDisplayConfig(int64_t display);

    std::pair<ScopedAStatus, int32_t> getPreferredBootDisplayConfig(int64_t display);

    std::pair<ScopedAStatus, common::Transform> getDisplayPhysicalOrientation(int64_t display);

    ScopedAStatus setIdleTimerEnabled(int64_t display, int32_t timeoutMs);

    int32_t getVsyncIdleCount();

    int64_t getVsyncIdleTime();

    int64_t getInvalidDisplayId();

    std::pair<ScopedAStatus, std::vector<VtsDisplay>> getDisplays();

  private:
    ScopedAStatus updateDisplayProperties(VtsDisplay* vtsDisplay, int32_t config);

    ScopedAStatus addDisplayToDisplayResources(int64_t display, bool isVirtual);

    ScopedAStatus addLayerToDisplayResources(int64_t display, int64_t layer);

    void removeLayerFromDisplayResources(int64_t display, int64_t layer);

    bool destroyAllLayers();

    bool verifyComposerCallbackParams();

    // Keep track of displays and layers. When a test fails/ends,
    // the VtsComposerClient::tearDown should be called from the
    // test tearDown to clean up the resources for the test.
    struct DisplayResource {
        DisplayResource(bool isVirtual_) : isVirtual(isVirtual_) {}

        bool isVirtual;
        std::unordered_set<int64_t> layers;
    };

    std::shared_ptr<IComposer> mComposer;
    std::shared_ptr<IComposerClient> mComposerClient;
    std::shared_ptr<GraphicsComposerCallback> mComposerCallback;
    std::unordered_map<int64_t, DisplayResource> mDisplayResources;
};

class VtsDisplay {
  public:
    VtsDisplay(int64_t displayId) : mDisplayId(displayId), mDisplayWidth(0), mDisplayHeight(0) {}

    int64_t getDisplayId() const { return mDisplayId; }

    FRect getCrop() const {
        return {0, 0, static_cast<float>(mDisplayWidth), static_cast<float>(mDisplayHeight)};
    }

    Rect getFrameRect() const { return {0, 0, mDisplayWidth, mDisplayHeight}; }

    void setDimensions(int32_t displayWidth, int32_t displayHeight) {
        mDisplayWidth = displayWidth;
        mDisplayHeight = displayHeight;
    }

    int32_t getDisplayWidth() const { return mDisplayWidth; }

    int32_t getDisplayHeight() const { return mDisplayHeight; }

    struct DisplayConfig {
        DisplayConfig(int32_t vsyncPeriod_, int32_t configGroup_)
            : vsyncPeriod(vsyncPeriod_), configGroup(configGroup_) {}
        int32_t vsyncPeriod;
        int32_t configGroup;
    };

    void addDisplayConfig(int32_t config, DisplayConfig displayConfig) {
        displayConfigs.insert({config, displayConfig});
    }

    DisplayConfig getDisplayConfig(int32_t config) { return displayConfigs.find(config)->second; }

  private:
    int64_t mDisplayId;
    int32_t mDisplayWidth;
    int32_t mDisplayHeight;
    std::unordered_map<int32_t, DisplayConfig> displayConfigs;
};
}  // namespace aidl::android::hardware::graphics::composer3::vts