• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 #ifndef ANDROID_HARDWARE_GRAPHICS_BUFFERQUEUE_V2_0_TYPES_H
18 #define ANDROID_HARDWARE_GRAPHICS_BUFFERQUEUE_V2_0_TYPES_H
19 
20 #include <android/hardware/graphics/bufferqueue/2.0/types.h>
21 #include <android/hardware/graphics/common/1.2/types.h>
22 #include <hidl/HidlSupport.h>
23 #include <ui/Fence.h>
24 #include <ui/GraphicBuffer.h>
25 
26 namespace android {
27 namespace hardware {
28 namespace graphics {
29 namespace bufferqueue {
30 namespace V2_0 {
31 namespace utils {
32 
33 // Status
34 // ======
35 
36 using HStatus = ::android::hardware::graphics::bufferqueue::V2_0::
37         Status;
38 
39 // A status_t value may have flags encoded. These flags are decoded into boolean
40 // values if their corresponding output pointers are not null.
41 bool b2h(status_t from, HStatus* to,
42          bool* bufferNeedsReallocation = nullptr,
43          bool* releaseAllBuffers = nullptr);
44 // Simple 1-to-1 mapping. If BUFFER_NEEDS_REALLOCATION or RELEASE_ALL_BUFFERS
45 // needs to be added, it must be done manually afterwards.
46 bool h2b(HStatus from, status_t* to);
47 
48 // Fence
49 // =====
50 
51 using BFence = ::android::Fence;
52 // This class manages the lifetime of a copied handle. Its destructor calls
53 // native_handle_delete() but not native_handle_close().
54 struct HFenceWrapper {
55     HFenceWrapper() = default;
56     // Sets mHandle to a new value.
57     HFenceWrapper(native_handle_t* h);
58     // Deletes mHandle without closing.
59     ~HFenceWrapper();
60     // Deletes mHandle without closing, then sets mHandle to a new value.
61     HFenceWrapper& set(native_handle_t* h);
62     HFenceWrapper& operator=(native_handle_t* h);
63     // Returns a non-owning hidl_handle pointing to mHandle.
64     hidl_handle getHandle() const;
65     operator hidl_handle() const;
66 protected:
67     native_handle_t* mHandle{nullptr};
68 };
69 
70 // Does not clone the fd---only copy the fd. The returned HFenceWrapper should
71 // not outlive the input Fence object.
72 bool b2h(sp<BFence> const& from, HFenceWrapper* to);
73 // Clones the fd and puts it in a new Fence object.
74 bool h2b(native_handle_t const* from, sp<BFence>* to);
75 
76 // ConnectionType
77 // ==============
78 
79 using HConnectionType = ::android::hardware::graphics::bufferqueue::V2_0::
80         ConnectionType;
81 
82 bool b2h(int from, HConnectionType* to);
83 bool h2b(HConnectionType from, int* to);
84 
85 // Rect
86 // ====
87 
88 using BRect = ::android::Rect;
89 using HRect = ::android::hardware::graphics::common::V1_2::Rect;
90 
91 bool b2h(BRect const& from, HRect* to);
92 bool h2b(HRect const& from, BRect* to);
93 
94 // Region
95 // ======
96 
97 using BRegion = ::android::Region;
98 using HRegion = ::android::hardware::hidl_vec<HRect>;
99 
100 bool b2h(BRegion const& from, HRegion* to);
101 bool h2b(HRegion const& from, BRegion* to);
102 
103 // GraphicBuffer
104 // =============
105 
106 using HardwareBuffer = ::android::hardware::graphics::common::V1_2::
107         HardwareBuffer;
108 using HardwareBufferDescription = ::android::hardware::graphics::common::V1_2::
109         HardwareBufferDescription;
110 
111 // Does not clone the handle. The returned HardwareBuffer should not outlive the
112 // input GraphicBuffer. Note that HardwareBuffer does not carry the generation
113 // number, so this function needs another output argument.
114 bool b2h(sp<GraphicBuffer> const& from, HardwareBuffer* to,
115          uint32_t* toGenerationNumber = nullptr);
116 // Clones the handle and creates a new GraphicBuffer from the cloned handle.
117 // Note that the generation number of the GraphicBuffer has to be set manually
118 // afterwards because HardwareBuffer does not have such information.
119 bool h2b(HardwareBuffer const& from, sp<GraphicBuffer>* to);
120 
121 }  // namespace utils
122 }  // namespace V2_0
123 }  // namespace bufferqueue
124 }  // namespace graphics
125 }  // namespace hardware
126 }  // namespace android
127 
128 #endif  // ANDROID_HARDWARE_GRAPHICS_BUFFERQUEUE_V2_0_TYPES_H
129 
130