1 /*
2  * Copyright (C) 2022 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 // Thin wrappers around V2_2::hal::ComposerResources related classes that
18 // return HWC3 error codes and accept HWC3 argument types.
19 
20 #ifndef ANDROID_HWC_COMPOSERRESOURCES_H
21 #define ANDROID_HWC_COMPOSERRESOURCES_H
22 
23 // Must include our LOG_TAG first:
24 // clang-format off
25 #include "Common.h"
26 #include <composer-resources/2.2/ComposerResources.h>
27 // clang-format on
28 
29 #include <memory>
30 #include <optional>
31 
32 namespace aidl::android::hardware::graphics::composer3::impl {
33 
34 class ComposerResourceReleaser {
35    public:
ComposerResourceReleaser(bool isBuffer)36     ComposerResourceReleaser(bool isBuffer) : mReplacedHandle(isBuffer) {}
37     virtual ~ComposerResourceReleaser() = default;
38 
39     ::android::hardware::graphics::composer::V2_2::hal::ComposerResources::ReplacedHandle*
getReplacedHandle()40     getReplacedHandle() {
41         return &mReplacedHandle;
42     }
43 
44    private:
45     ::android::hardware::graphics::composer::V2_2::hal::ComposerResources::ReplacedHandle
46         mReplacedHandle;
47 };
48 
49 class ComposerResources {
50    public:
51     ComposerResources() = default;
52 
53     HWC3::Error init();
54 
55     std::unique_ptr<ComposerResourceReleaser> createReleaser(bool isBuffer);
56 
57     void clear(::android::hardware::graphics::composer::V2_2::hal::ComposerResources::RemoveDisplay
58                    removeDisplay);
59 
60     bool hasDisplay(int64_t display);
61 
62     HWC3::Error addPhysicalDisplay(int64_t display);
63 
64     HWC3::Error addVirtualDisplay(int64_t displayId, uint32_t outputBufferCacheSize);
65 
66     HWC3::Error removeDisplay(int64_t display);
67 
68     HWC3::Error setDisplayClientTargetCacheSize(int64_t displayId, uint32_t clientTargetCacheSize);
69 
70     HWC3::Error getDisplayClientTargetCacheSize(int64_t displayId, size_t* outCacheSize);
71 
72     HWC3::Error getDisplayOutputBufferCacheSize(int64_t displayId, size_t* outCacheSize);
73 
74     HWC3::Error addLayer(int64_t displayId, int64_t layerId, uint32_t bufferCacheSize);
75 
76     HWC3::Error removeLayer(int64_t displayId, int64_t layer);
77 
78     void setDisplayMustValidateState(int64_t displayId, bool mustValidate);
79 
80     bool mustValidateDisplay(int64_t displayId);
81 
82     HWC3::Error getDisplayReadbackBuffer(
83         int64_t displayId, const aidl::android::hardware::common::NativeHandle& handle,
84         buffer_handle_t* outHandle, ComposerResourceReleaser* bufReleaser);
85 
86     HWC3::Error getDisplayClientTarget(int64_t displayId, const Buffer& buffer,
87                                        buffer_handle_t* outHandle,
88                                        ComposerResourceReleaser* bufReleaser);
89 
90     HWC3::Error getDisplayOutputBuffer(int64_t displayId, const Buffer& buffer,
91                                        buffer_handle_t* outHandle,
92                                        ComposerResourceReleaser* bufReleaser);
93 
94     HWC3::Error getLayerBuffer(int64_t displayId, int64_t layerId, const Buffer& buffer,
95                                buffer_handle_t* outBufferHandle,
96                                ComposerResourceReleaser* bufReleaser);
97 
98     HWC3::Error getLayerSidebandStream(
99         int64_t displayId, int64_t layerId,
100         const aidl::android::hardware::common::NativeHandle& rawHandle,
101         buffer_handle_t* outStreamHandle, ComposerResourceReleaser* bufReleaser);
102 
103    private:
104     std::unique_ptr< ::android::hardware::graphics::composer::V2_2::hal::ComposerResources> mImpl;
105 };
106 
107 }  // namespace aidl::android::hardware::graphics::composer3::impl
108 
109 #endif