blob: 00d9d8c94c3cbc47b38e1eeacb9fa7109e762fcd [file] [log] [blame]
Chia-I Wu8cc5a152017-02-24 14:34:02 -08001/*
2 * Copyright (C) 2017 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#ifndef VTS_HAL_GRAPHICS_COMPOSER_UTILS
18#define VTS_HAL_GRAPHICS_COMPOSER_UTILS
19
20#include <memory>
21#include <string>
22#include <unordered_map>
23#include <unordered_set>
24#include <vector>
25
26#include <android/hardware/graphics/composer/2.1/IComposer.h>
Courtney Goeltzenleuchter5ecd86a2018-01-12 14:00:56 -080027#include <composer-command-buffer/2.1/ComposerCommandBuffer.h>
Chia-I Wu8cc5a152017-02-24 14:34:02 -080028#include <utils/StrongPointer.h>
29
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040030#include "TestCommandReader.h"
31
Chia-I Wu8cc5a152017-02-24 14:34:02 -080032namespace android {
33namespace hardware {
34namespace graphics {
35namespace composer {
36namespace V2_1 {
37namespace tests {
38
39using android::hardware::graphics::common::V1_0::ColorMode;
40using android::hardware::graphics::common::V1_0::Dataspace;
41using android::hardware::graphics::common::V1_0::Hdr;
42using android::hardware::graphics::common::V1_0::PixelFormat;
43
44class ComposerClient;
45
46// A wrapper to IComposer.
47class Composer {
48 public:
49 Composer();
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040050 explicit Composer(const std::string& name);
Chia-I Wu8cc5a152017-02-24 14:34:02 -080051
52 sp<IComposer> getRaw() const;
53
54 // Returns true when the composer supports the specified capability.
55 bool hasCapability(IComposer::Capability capability) const;
56
57 std::vector<IComposer::Capability> getCapabilities();
58 std::string dumpDebugInfo();
59 std::unique_ptr<ComposerClient> createClient();
60
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080061 protected:
62 sp<IComposer> mComposer;
63
Chia-I Wu8cc5a152017-02-24 14:34:02 -080064 private:
65 void init();
66
Chia-I Wu8cc5a152017-02-24 14:34:02 -080067 std::unordered_set<IComposer::Capability> mCapabilities;
68};
69
70// A wrapper to IComposerClient.
71class ComposerClient {
72 public:
73 ComposerClient(const sp<IComposerClient>& client);
74 ~ComposerClient();
75
76 sp<IComposerClient> getRaw() const;
77
78 void registerCallback(const sp<IComposerCallback>& callback);
79 uint32_t getMaxVirtualDisplayCount();
80
81 Display createVirtualDisplay(uint32_t width, uint32_t height,
82 PixelFormat formatHint,
83 uint32_t outputBufferSlotCount,
84 PixelFormat* outFormat);
85 void destroyVirtualDisplay(Display display);
86
87 Layer createLayer(Display display, uint32_t bufferSlotCount);
88 void destroyLayer(Display display, Layer layer);
89
90 Config getActiveConfig(Display display);
91 bool getClientTargetSupport(Display display, uint32_t width, uint32_t height,
92 PixelFormat format, Dataspace dataspace);
93 std::vector<ColorMode> getColorModes(Display display);
94 int32_t getDisplayAttribute(Display display, Config config,
95 IComposerClient::Attribute attribute);
96 std::vector<Config> getDisplayConfigs(Display display);
97 std::string getDisplayName(Display display);
98 IComposerClient::DisplayType getDisplayType(Display display);
99 bool getDozeSupport(Display display);
100 std::vector<Hdr> getHdrCapabilities(Display display, float* outMaxLuminance,
101 float* outMaxAverageLuminance,
102 float* outMinLuminance);
103
104 void setClientTargetSlotCount(Display display,
105 uint32_t clientTargetSlotCount);
106 void setActiveConfig(Display display, Config config);
107 void setColorMode(Display display, ColorMode mode);
108 void setPowerMode(Display display, IComposerClient::PowerMode mode);
109 void setVsyncEnabled(Display display, bool enabled);
110
Daniel Nicoarad47f4a92017-05-30 15:38:30 -0400111 void execute(TestCommandReader* reader, CommandWriterBase* writer);
112
Chia-I Wu8cc5a152017-02-24 14:34:02 -0800113 private:
114 sp<IComposerClient> mClient;
115
116 // Keep track of all virtual displays and layers. When a test fails with
117 // ASSERT_*, the destructor will clean up the resources for the test.
118 struct DisplayResource {
119 DisplayResource(bool isVirtual_) : isVirtual(isVirtual_) {}
120
121 bool isVirtual;
122 std::unordered_set<Layer> layers;
123 };
124 std::unordered_map<Display, DisplayResource> mDisplayResources;
125};
126
127} // namespace tests
128} // namespace V2_1
129} // namespace composer
130} // namespace graphics
131} // namespace hardware
132} // namespace android
133
134#endif // VTS_HAL_GRAPHICS_COMPOSER_UTILS