1/*
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 <IComposerCommandBuffer.h>
27#include <android/hardware/graphics/composer/2.1/IComposer.h>
28#include <utils/StrongPointer.h>
29
30#include "TestCommandReader.h"
31
32namespace 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();
50  explicit Composer(const std::string& name);
51
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
61 private:
62  void init();
63
64  sp<IComposer> mComposer;
65  std::unordered_set<IComposer::Capability> mCapabilities;
66};
67
68// A wrapper to IComposerClient.
69class ComposerClient {
70 public:
71  ComposerClient(const sp<IComposerClient>& client);
72  ~ComposerClient();
73
74  sp<IComposerClient> getRaw() const;
75
76  void registerCallback(const sp<IComposerCallback>& callback);
77  uint32_t getMaxVirtualDisplayCount();
78
79  Display createVirtualDisplay(uint32_t width, uint32_t height,
80                               PixelFormat formatHint,
81                               uint32_t outputBufferSlotCount,
82                               PixelFormat* outFormat);
83  void destroyVirtualDisplay(Display display);
84
85  Layer createLayer(Display display, uint32_t bufferSlotCount);
86  void destroyLayer(Display display, Layer layer);
87
88  Config getActiveConfig(Display display);
89  bool getClientTargetSupport(Display display, uint32_t width, uint32_t height,
90                              PixelFormat format, Dataspace dataspace);
91  std::vector<ColorMode> getColorModes(Display display);
92  int32_t getDisplayAttribute(Display display, Config config,
93                              IComposerClient::Attribute attribute);
94  std::vector<Config> getDisplayConfigs(Display display);
95  std::string getDisplayName(Display display);
96  IComposerClient::DisplayType getDisplayType(Display display);
97  bool getDozeSupport(Display display);
98  std::vector<Hdr> getHdrCapabilities(Display display, float* outMaxLuminance,
99                                      float* outMaxAverageLuminance,
100                                      float* outMinLuminance);
101
102  void setClientTargetSlotCount(Display display,
103                                uint32_t clientTargetSlotCount);
104  void setActiveConfig(Display display, Config config);
105  void setColorMode(Display display, ColorMode mode);
106  void setPowerMode(Display display, IComposerClient::PowerMode mode);
107  void setVsyncEnabled(Display display, bool enabled);
108
109  void execute(TestCommandReader* reader, CommandWriterBase* writer);
110
111 private:
112  sp<IComposerClient> mClient;
113
114  // Keep track of all virtual displays and layers.  When a test fails with
115  // ASSERT_*, the destructor will clean up the resources for the test.
116  struct DisplayResource {
117    DisplayResource(bool isVirtual_) : isVirtual(isVirtual_) {}
118
119    bool isVirtual;
120    std::unordered_set<Layer> layers;
121  };
122  std::unordered_map<Display, DisplayResource> mDisplayResources;
123};
124
125}  // namespace tests
126}  // namespace V2_1
127}  // namespace composer
128}  // namespace graphics
129}  // namespace hardware
130}  // namespace android
131
132#endif  // VTS_HAL_GRAPHICS_COMPOSER_UTILS
133