xref: /aosp_15_r20/external/drm_hwcomposer/hwc3/ComposerResources.h (revision 0a9764fe0a15e71ebbeb85e87e10990c23aab47f)
1 /*
2  * Copyright (C) 2024 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 
21 #include "aidl/android/hardware/graphics/composer3/IComposerClient.h"
22 #include "composer-resources/2.2/ComposerResources.h"
23 #include "cutils/native_handle.h"
24 #include "hwc3/Utils.h"
25 
26 namespace aidl::android::hardware::graphics::composer3::impl {
27 
28 class ComposerResourceReleaser {
29  public:
ComposerResourceReleaser(bool is_buffer)30   explicit ComposerResourceReleaser(bool is_buffer)
31       : replaced_handle_(is_buffer) {
32   }
33   virtual ~ComposerResourceReleaser() = default;
34 
35   ::android::hardware::graphics::composer::V2_2::hal::ComposerResources::
36       ReplacedHandle*
GetReplacedHandle()37       GetReplacedHandle() {
38     return &replaced_handle_;
39   }
40 
41  private:
42   ::android::hardware::graphics::composer::V2_2::hal::ComposerResources::
43       ReplacedHandle replaced_handle_;
44 };
45 
46 class ComposerResources {
47  public:
48   static std::unique_ptr<ComposerResources> Create();
49   ~ComposerResources() = default;
50 
51   hwc3::Error GetLayerBuffer(uint64_t display_id, int64_t layer_id,
52                              const Buffer& buffer,
53                              buffer_handle_t* out_buffer_handle,
54                              ComposerResourceReleaser* releaser);
55   hwc3::Error GetLayerSidebandStream(
56       uint64_t display_id, int64_t layer_id,
57       const aidl::android::hardware::common::NativeHandle& handle,
58       buffer_handle_t* out_handle, ComposerResourceReleaser* releaser);
59 
60   hwc3::Error AddLayer(uint64_t display, int64_t layer,
61                        uint32_t buffer_cache_size);
62   hwc3::Error RemoveLayer(uint64_t display, int64_t layer);
63 
64   bool HasDisplay(uint64_t display);
65   hwc3::Error AddPhysicalDisplay(uint64_t display);
66   hwc3::Error AddVirtualDisplay(uint64_t display,
67                                 uint32_t output_buffer_cache_size);
68   hwc3::Error RemoveDisplay(uint64_t display);
69 
70   void SetDisplayMustValidateState(uint64_t display_id, bool must_validate);
71   bool MustValidateDisplay(uint64_t display_id);
72 
73   hwc3::Error GetDisplayClientTarget(uint64_t display_id, const Buffer& buffer,
74                                      buffer_handle_t* out_handle,
75                                      ComposerResourceReleaser* releaser);
76 
77   hwc3::Error SetDisplayClientTargetCacheSize(
78       uint64_t display_id, uint32_t client_target_cache_size);
79   hwc3::Error GetDisplayClientTargetCacheSize(uint64_t display_id,
80                                               size_t* out_cache_size);
81   hwc3::Error GetDisplayOutputBufferCacheSize(uint64_t display,
82                                               size_t* out_cache_size);
83   hwc3::Error GetDisplayOutputBuffer(uint64_t display_id, const Buffer& buffer,
84                                      buffer_handle_t* out_handle,
85                                      ComposerResourceReleaser* releaser);
86 
87   static std::unique_ptr<ComposerResourceReleaser> CreateResourceReleaser(
88       bool is_buffer);
89 
90  private:
91   ComposerResources() = default;
92 
93   std::unique_ptr<
94       ::android::hardware::graphics::composer::V2_2::hal::ComposerResources>
95       resources_ = ::android::hardware::graphics::composer::V2_2::hal::
96           ComposerResources::create();
97 };
98 
99 }  // namespace aidl::android::hardware::graphics::composer3::impl