• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::
40       ReplacedHandle*
getReplacedHandle()41       getReplacedHandle() {
42     return &mReplacedHandle;
43   }
44 
45  private:
46   ::android::hardware::graphics::composer::V2_2::hal::ComposerResources::
47       ReplacedHandle mReplacedHandle;
48 };
49 
50 class ComposerResources {
51  public:
52   ComposerResources() = default;
53 
54   HWC3::Error init();
55 
56   std::unique_ptr<ComposerResourceReleaser> createReleaser(bool isBuffer);
57 
58   void clear(::android::hardware::graphics::composer::V2_2::hal::
59                  ComposerResources::RemoveDisplay removeDisplay);
60 
61   bool hasDisplay(int64_t display);
62 
63   HWC3::Error addPhysicalDisplay(int64_t display);
64 
65   HWC3::Error addVirtualDisplay(int64_t displayId,
66                                 uint32_t outputBufferCacheSize);
67 
68   HWC3::Error removeDisplay(int64_t display);
69 
70   HWC3::Error setDisplayClientTargetCacheSize(int64_t displayId,
71                                               uint32_t clientTargetCacheSize);
72 
73   HWC3::Error getDisplayClientTargetCacheSize(int64_t displayId,
74                                               size_t* outCacheSize);
75 
76   HWC3::Error getDisplayOutputBufferCacheSize(int64_t displayId,
77                                               size_t* outCacheSize);
78 
79   HWC3::Error addLayer(int64_t displayId, int64_t layerId,
80                        uint32_t bufferCacheSize);
81 
82   HWC3::Error removeLayer(int64_t displayId, int64_t layer);
83 
84   void setDisplayMustValidateState(int64_t displayId, bool mustValidate);
85 
86   bool mustValidateDisplay(int64_t displayId);
87 
88   HWC3::Error getDisplayReadbackBuffer(
89       int64_t displayId,
90       const aidl::android::hardware::common::NativeHandle& handle,
91       buffer_handle_t* outHandle, ComposerResourceReleaser* bufReleaser);
92 
93   HWC3::Error getDisplayClientTarget(int64_t displayId, const Buffer& buffer,
94                                      buffer_handle_t* outHandle,
95                                      ComposerResourceReleaser* bufReleaser);
96 
97   HWC3::Error getDisplayOutputBuffer(int64_t displayId, const Buffer& buffer,
98                                      buffer_handle_t* outHandle,
99                                      ComposerResourceReleaser* bufReleaser);
100 
101   HWC3::Error getLayerBuffer(int64_t displayId, int64_t layerId,
102                              const Buffer& buffer,
103                              buffer_handle_t* outBufferHandle,
104                              ComposerResourceReleaser* bufReleaser);
105 
106   HWC3::Error getLayerSidebandStream(
107       int64_t displayId, int64_t layerId,
108       const aidl::android::hardware::common::NativeHandle& rawHandle,
109       buffer_handle_t* outStreamHandle, ComposerResourceReleaser* bufReleaser);
110 
111  private:
112   std::unique_ptr<
113       ::android::hardware::graphics::composer::V2_2::hal::ComposerResources>
114       mImpl;
115 };
116 
117 }  // namespace aidl::android::hardware::graphics::composer3::impl
118 
119 #endif