1/*
2 * Copyright (C) 2018 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
19#include <memory>
20#include <string>
21#include <unordered_map>
22#include <unordered_set>
23#include <vector>
24
25#include <VtsHalHidlTargetTestBase.h>
26#include <android/hardware/graphics/composer/2.2/IComposer.h>
27#include <android/hardware/graphics/composer/2.2/IComposerClient.h>
28#include <composer-command-buffer/2.2/ComposerCommandBuffer.h>
29#include <composer-vts/2.1/ComposerVts.h>
30#include <utils/StrongPointer.h>
31
32namespace android {
33namespace hardware {
34namespace graphics {
35namespace composer {
36namespace V2_2 {
37namespace vts {
38
39using android::hardware::graphics::common::V1_0::Hdr;
40using android::hardware::graphics::common::V1_1::ColorMode;
41using android::hardware::graphics::common::V1_1::Dataspace;
42using android::hardware::graphics::common::V1_1::PixelFormat;
43using android::hardware::graphics::common::V1_1::RenderIntent;
44using android::hardware::graphics::composer::V2_2::IComposer;
45using android::hardware::graphics::composer::V2_2::IComposerClient;
46
47class ComposerClient_v2_2;
48
49// Only thing I need for Composer_v2_2 is to create a v2_2 ComposerClient
50// Everything else is the same
51class Composer_v2_2 : public V2_1::vts::Composer {
52   public:
53    Composer_v2_2() : V2_1::vts::Composer(){};
54    explicit Composer_v2_2(const std::string& name) : V2_1::vts::Composer(name){};
55
56    std::unique_ptr<ComposerClient_v2_2> createClient_v2_2();
57};
58
59// A wrapper to IComposerClient.
60class ComposerClient_v2_2
61    : public android::hardware::graphics::composer::V2_1::vts::ComposerClient {
62   public:
63    ComposerClient_v2_2(const sp<IComposerClient>& client)
64        : V2_1::vts::ComposerClient(client), mClient_v2_2(client){};
65
66    sp<V2_2::IComposerClient> getRaw() const;
67
68    void execute_v2_2(V2_1::vts::TestCommandReader* reader, V2_2::CommandWriterBase* writer);
69
70    std::vector<IComposerClient::PerFrameMetadataKey> getPerFrameMetadataKeys(Display display);
71
72    Display createVirtualDisplay_2_2(uint32_t width, uint32_t height, PixelFormat formatHint,
73                                     uint32_t outputBufferSlotCount, PixelFormat* outFormat);
74    bool getClientTargetSupport_2_2(Display display, uint32_t width, uint32_t height,
75                                    PixelFormat format, Dataspace dataspace);
76    void setPowerMode_2_2(Display display, V2_2::IComposerClient::PowerMode mode);
77    void setReadbackBuffer(Display display, const native_handle_t* buffer, int32_t releaseFence);
78    void getReadbackBufferAttributes(Display display, PixelFormat* outPixelFormat,
79                                     Dataspace* outDataspace);
80    void getReadbackBufferFence(Display display, int32_t* outFence);
81
82    std::vector<ColorMode> getColorModes(Display display);
83    std::vector<RenderIntent> getRenderIntents(Display display, ColorMode mode);
84    void setColorMode(Display display, ColorMode mode, RenderIntent intent);
85
86    std::array<float, 16> getDataspaceSaturationMatrix(Dataspace dataspace);
87
88   private:
89    sp<V2_2::IComposerClient> mClient_v2_2;
90};
91
92}  // namespace vts
93}  // namespace V2_2
94}  // namespace composer
95}  // namespace graphics
96}  // namespace hardware
97}  // namespace android
98