• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 STAGEFRIGHT_CODEC2_ALLOCATOR_GRALLOC_H_
18 #define STAGEFRIGHT_CODEC2_ALLOCATOR_GRALLOC_H_
19 
20 #include <functional>
21 
22 #include <C2Buffer.h>
23 
24 namespace android {
25 
26 /**
27  * Unwrap the native handle from a Codec2 handle allocated by C2AllocatorGralloc.
28  *
29  * @param handle a handle allocated by C2AllocatorGralloc. This includes handles returned for a
30  * graphic block allocation handle returned.
31  *
32  * @return a new NON-OWNING native handle that must be deleted using native_handle_delete.
33  */
34 native_handle_t *UnwrapNativeCodec2GrallocHandle(const C2Handle *const handle);
35 
36 /**
37  * Wrap the gralloc handle and metadata into Codec2 handle recognized by
38  * C2AllocatorGralloc.
39  *
40  * @return a new NON-OWNING C2Handle that must be closed and deleted using native_handle_close and
41  * native_handle_delete.
42  */
43 C2Handle *WrapNativeCodec2GrallocHandle(
44         const native_handle_t *const handle,
45         uint32_t width, uint32_t height, uint32_t format, uint64_t usage, uint32_t stride,
46         uint32_t generation = 0, uint64_t igbp_id = 0, uint32_t igbp_slot = 0);
47 
48 /**
49  * Extract pixel format from the extra data of gralloc handle.
50  *
51  * @return 0 when no valid pixel format exists.
52  */
53 uint32_t ExtractFormatFromCodec2GrallocHandle(const C2Handle *const handle);
54 
55 /**
56  * When the gralloc handle is migrated to another bufferqueue, update
57  * bufferqueue information.
58  *
59  * @return {@code true} when native_handle is a wrapped codec2 handle.
60  */
61 bool MigrateNativeCodec2GrallocHandle(
62         native_handle_t *handle,
63         uint32_t generation, uint64_t igbp_id, uint32_t igbp_slot);
64 
65 /**
66  * \todo Get this from the buffer
67  */
68 void _UnwrapNativeCodec2GrallocMetadata(
69         const C2Handle *const handle,
70         uint32_t *width, uint32_t *height, uint32_t *format, uint64_t *usage, uint32_t *stride,
71         uint32_t *generation, uint64_t *igbp_id, uint32_t *igbp_slot);
72 
73 class C2AllocatorGralloc : public C2Allocator {
74 public:
75     virtual id_t getId() const override;
76 
77     virtual C2String getName() const override;
78 
79     virtual std::shared_ptr<const Traits> getTraits() const override;
80 
81     virtual c2_status_t newGraphicAllocation(
82             uint32_t width, uint32_t height, uint32_t format, C2MemoryUsage usage,
83             std::shared_ptr<C2GraphicAllocation> *allocation) override;
84 
85     virtual c2_status_t priorGraphicAllocation(
86             const C2Handle *handle,
87             std::shared_ptr<C2GraphicAllocation> *allocation) override;
88 
89     C2AllocatorGralloc(id_t id, bool bufferQueue = false);
90 
91     c2_status_t status() const;
92 
93     virtual ~C2AllocatorGralloc() override;
94 
checkHandle(const C2Handle * const o)95     virtual bool checkHandle(const C2Handle* const o) const override { return CheckHandle(o); }
96 
97     static bool CheckHandle(const C2Handle* const o);
98 
99     // deprecated
isValid(const C2Handle * const o)100     static bool isValid(const C2Handle* const o) { return CheckHandle(o); }
101 
102 private:
103     class Impl;
104     Impl *mImpl;
105 };
106 
107 } // namespace android
108 
109 #endif // STAGEFRIGHT_CODEC2_ALLOCATOR_GRALLOC_H_
110