summaryrefslogtreecommitdiffstats
blob: 0d883e4f845ffd422ae6bf2ecb536e27dd26c3ad (plain) (blame)
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
/*
 * Copyright (C) 2017 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 <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <android/hardware/graphics/composer/2.1/IComposer.h>
#include <composer-command-buffer/2.1/ComposerCommandBuffer.h>
#include <composer-vts/2.1/TestCommandReader.h>
#include <utils/StrongPointer.h>

namespace android {
namespace hardware {
namespace graphics {
namespace composer {
namespace V2_1 {
namespace vts {

using android::hardware::graphics::common::V1_0::ColorMode;
using android::hardware::graphics::common::V1_0::Dataspace;
using android::hardware::graphics::common::V1_0::Hdr;
using android::hardware::graphics::common::V1_0::PixelFormat;

class ComposerClient;

// A wrapper to IComposer.
class Composer {
   public:
    Composer();
    explicit Composer(const std::string& name);

    sp<IComposer> getRaw() const;

    // Returns true when the composer supports the specified capability.
    bool hasCapability(IComposer::Capability capability) const;

    std::vector<IComposer::Capability> getCapabilities();
    std::string dumpDebugInfo();
    std::unique_ptr<ComposerClient> createClient();

   protected:
    sp<IComposer> mComposer;

   private:
    void init();

    std::unordered_set<IComposer::Capability> mCapabilities;
};

// A wrapper to IComposerClient.
class ComposerClient {
   public:
    ComposerClient(const sp<IComposerClient>& client);
    ~ComposerClient();

    sp<IComposerClient> getRaw() const;

    void registerCallback(const sp<IComposerCallback>& callback);
    uint32_t getMaxVirtualDisplayCount();

    Display createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat formatHint,
                                 uint32_t outputBufferSlotCount, PixelFormat* outFormat);
    void destroyVirtualDisplay(Display display);

    Layer createLayer(Display display, uint32_t bufferSlotCount);
    void destroyLayer(Display display, Layer layer);

    Config getActiveConfig(Display display);
    bool getClientTargetSupport(Display display, uint32_t width, uint32_t height,
                                PixelFormat format, Dataspace dataspace);
    std::vector<ColorMode> getColorModes(Display display);
    int32_t getDisplayAttribute(Display display, Config config,
                                IComposerClient::Attribute attribute);
    std::vector<Config> getDisplayConfigs(Display display);
    std::string getDisplayName(Display display);
    IComposerClient::DisplayType getDisplayType(Display display);
    bool getDozeSupport(Display display);
    std::vector<Hdr> getHdrCapabilities(Display display, float* outMaxLuminance,
                                        float* outMaxAverageLuminance, float* outMinLuminance);

    void setClientTargetSlotCount(Display display, uint32_t clientTargetSlotCount);
    void setActiveConfig(Display display, Config config);
    void setColorMode(Display display, ColorMode mode);
    void setPowerMode(Display display, IComposerClient::PowerMode mode);
    void setVsyncEnabled(Display display, bool enabled);

    void execute(TestCommandReader* reader, CommandWriterBase* writer);

   private:
    sp<IComposerClient> mClient;

    // Keep track of all virtual displays and layers.  When a test fails with
    // ASSERT_*, the destructor will clean up the resources for the test.
    struct DisplayResource {
        DisplayResource(bool isVirtual_) : isVirtual(isVirtual_) {}

        bool isVirtual;
        std::unordered_set<Layer> layers;
    };
    std::unordered_map<Display, DisplayResource> mDisplayResources;
};

}  // namespace vts
}  // namespace V2_1
}  // namespace composer
}  // namespace graphics
}  // namespace hardware
}  // namespace android